@openchamber/web 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-zm3C1FvM.js → CodeMirrorCommentWidgets-CmKmyb9T.js} +1 -1
  2. package/dist/assets/{DiffView-DNExNi1z.js → DiffView-8-PFpZ2p.js} +1 -1
  3. package/dist/assets/{FilesView-DUCLmHBi.js → FilesView-0Ie20mEk.js} +9 -9
  4. package/dist/assets/{GitView-Bz9z6gZA.js → GitView-DNUSu00w.js} +1 -1
  5. package/dist/assets/{GuestAttachDialog-UGp4KDlK.js → GuestAttachDialog-Cv6QzjHC.js} +1 -1
  6. package/dist/assets/{GuestSurfacePane-B3pdB_2u.js → GuestSurfacePane-Bt3jB_Ye.js} +1 -1
  7. package/dist/assets/{JsonTreeView-7lVecnZl.js → JsonTreeView-BlyHTRhM.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-CTGRS9Vq.js → LinearIssuesView-CSl2MUfA.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-2UXJF-5B.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +12 -0
  11. package/dist/assets/{OnboardingScreen-CBx6cXPP.js → OnboardingScreen-CIdXJpfc.js} +1 -1
  12. package/dist/assets/{PatchDiff-D7VVpR_l.js → PatchDiff-ByvnbG5T.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-Gbfks1pk.js → PierreDiffViewer-BXieg0mH.js} +1 -1
  14. package/dist/assets/{PlanView-CPSK0x97.js → PlanView-DEIi3Q7M.js} +3 -3
  15. package/dist/assets/PluginPane-BEPUWVho.js +3 -0
  16. package/dist/assets/{SettingsView-Dql7z6Ww.js → SettingsView-CiNh-RbW.js} +16 -16
  17. package/dist/assets/{SettingsWindow-D6oi-UmV.js → SettingsWindow-BIz224xs.js} +1 -1
  18. package/dist/assets/{SubmoduleDiffSummary-BXA0FAWj.js → SubmoduleDiffSummary-CXKmlps9.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-BQJsSbDm.js → ToolOutputDialog-BsgAK8xu.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-FY9w0TVT.js → ToolPartDiffPreview-vdPObXOf.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-B9YhAya5.js → VirtualizedFileDiff-BkFNKWS5.js} +1 -1
  22. package/dist/assets/{WalkthroughView-CmFgOUFN.js → WalkthroughView-6oE-MuDL.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-BebxalUt.js → appThemeRegistry-aHUNHoqP.js} +1 -1
  24. package/dist/assets/{commitAndPush-Wfxng_IK.js → commitAndPush-Bon9r94r.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-BCOqgixN.js → computeVirtualFileMetrics-DKqr_1AQ.js} +1 -1
  26. package/dist/assets/de-CgAJ51z7.js +10 -0
  27. package/dist/assets/es-zGi_ravM.js +16 -0
  28. package/dist/assets/fr-CPfogrWx.js +14 -0
  29. package/dist/assets/index-CHfphYL3.js +41 -0
  30. package/dist/assets/{index-3TiDNtfN.js → index-DpFttslC.js} +1 -1
  31. package/dist/assets/index-DvMJ3w6V.css +1 -0
  32. package/dist/assets/{isDiffPlainText-DnDYQmWK.js → isDiffPlainText-kzAgpIgi.js} +1 -1
  33. package/dist/assets/{isFilePlainText-BA_AHX7d.js → isFilePlainText-Uj6y-jzz.js} +1 -1
  34. package/dist/assets/ja-DMk6wd-U.js +16 -0
  35. package/dist/assets/ko-BFpzJ8jc.js +16 -0
  36. package/dist/assets/{main-DtUmJp9B.js → main-CbfMxn-I.js} +2 -2
  37. package/dist/assets/main-anyZFMIs.js +896 -0
  38. package/dist/assets/{markdownCore-BSnlUXBf.js → markdownCore-CmM47cAE.js} +5 -5
  39. package/dist/assets/{miniChat-BYfLUnDK.js → miniChat-CiAKBC10.js} +2 -2
  40. package/dist/assets/{mobile-DH3hI6gd.js → mobile-CsT4sJwC.js} +2 -2
  41. package/dist/assets/{patchFileDiff--L7lt_GZ.js → patchFileDiff-DeaE08W0.js} +1 -1
  42. package/dist/assets/{pl-BkI_xHqz.js → pl-VdRPcZrB.js} +5 -5
  43. package/dist/assets/pt-BR-BRys_lOW.js +16 -0
  44. package/dist/assets/{renderElectronMiniChatApp-C7kpNW_-.js → renderElectronMiniChatApp-C5677jy0.js} +2 -2
  45. package/dist/assets/{renderMobileApp-i0nq7Dwy.js → renderMobileApp-D4dBBAqQ.js} +7 -7
  46. package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +27 -0
  47. package/dist/assets/{scheduledTasksApi-Cy7uZCaI.js → scheduledTasksApi-BZCNJ588.js} +1 -1
  48. package/dist/assets/{shikiHighlight-D4vxipfr.js → shikiHighlight-BSUEa3yF.js} +1 -1
  49. package/dist/assets/{textMateThemeFromAppTheme-BYAHtJwQ.js → textMateThemeFromAppTheme-CsATFZIV.js} +1 -1
  50. package/dist/assets/tr-CA9ckNnm.js +7 -0
  51. package/dist/assets/uk-byjR-y8D.js +16 -0
  52. package/dist/assets/{useAppFontEffects-DHZ9-L30.js → useAppFontEffects-BWQZ5DeI.js} +153 -150
  53. package/dist/assets/{useInlineCommentController-CvpOMK-R.js → useInlineCommentController-DlFyVfBu.js} +1 -1
  54. package/dist/assets/{useRootScrollLock-DzNFi-fn.js → useRootScrollLock-Cp1eFoM2.js} +2 -2
  55. package/dist/assets/{vendor-codemirror-language-data-j3fhlwUM.js → vendor-codemirror-language-data-BwwommM0.js} +2 -2
  56. package/dist/assets/{web-components-BvHNFSEG.js → web-components-D3Yjr4Zx.js} +1 -1
  57. package/dist/assets/zh-CN-DRabgxdG.js +16 -0
  58. package/dist/assets/zh-TW-rbY5c9UK.js +16 -0
  59. package/dist/index.html +3 -3
  60. package/dist/mini-chat.html +3 -3
  61. package/dist/mobile.html +3 -3
  62. package/package.json +2 -2
  63. package/server/index.js +64 -0
  64. package/server/lib/event-stream/global-hub.js +23 -1
  65. package/server/lib/event-stream/global-hub.test.js +35 -0
  66. package/server/lib/event-stream/global-ws-bridge.js +3 -1
  67. package/server/lib/event-stream/upstream-reader.js +3 -2
  68. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  69. package/server/lib/opencode/bootstrap-runtime.js +2 -1
  70. package/server/lib/opencode/config-entity-v2.test.js +27 -0
  71. package/server/lib/opencode/config-paths.test.js +12 -0
  72. package/server/lib/opencode/core-routes.js +17 -4
  73. package/server/lib/opencode/core-routes.test.js +26 -0
  74. package/server/lib/opencode/mcp.js +7 -2
  75. package/server/lib/opencode/project-directory-runtime.js +8 -0
  76. package/server/lib/opencode/project-directory-runtime.test.js +13 -0
  77. package/server/lib/opencode/proxy.js +38 -2
  78. package/server/lib/opencode/routes.js +18 -0
  79. package/server/lib/opencode/server-utils-runtime.js +5 -0
  80. package/server/lib/opencode/settings-helpers.js +3 -0
  81. package/server/lib/opencode/settings-helpers.test.js +1 -1
  82. package/server/lib/opencode/settings-registry.json +3 -0
  83. package/server/lib/opencode/shared.js +17 -2
  84. package/server/lib/opencode/shutdown-runtime.js +3 -0
  85. package/server/lib/opencode/watcher.js +3 -1
  86. package/server/lib/realtime-proxy.js +5 -1
  87. package/server/lib/realtime-proxy.test.js +29 -0
  88. package/server/lib/relay/tunnel-host.js +4 -1
  89. package/server/lib/relay/tunnel-host.test.js +11 -0
  90. package/server/lib/small-model/DOCUMENTATION.md +11 -10
  91. package/server/lib/small-model/index.js +27 -32
  92. package/server/lib/small-model/index.test.js +28 -16
  93. package/server/lib/spaces/DOCUMENTATION.md +381 -20
  94. package/server/lib/spaces/code-in-bait.js +145 -6
  95. package/server/lib/spaces/code-in.js +10 -150
  96. package/server/lib/spaces/code-in.test.js +7 -83
  97. package/server/lib/spaces/code-out.js +1819 -0
  98. package/server/lib/spaces/code-out.test.js +3945 -0
  99. package/server/lib/spaces/code-transfer.js +173 -0
  100. package/server/lib/spaces/command-stream.test.js +181 -0
  101. package/server/lib/spaces/dispatcher.js +670 -0
  102. package/server/lib/spaces/dispatcher.test.js +582 -0
  103. package/server/lib/spaces/gatekeeper-channel.js +2 -0
  104. package/server/lib/spaces/gatekeeper-channel.test.js +9 -3
  105. package/server/lib/spaces/gatekeeper-program.cjs +4 -1
  106. package/server/lib/spaces/gatekeeper-program.test.js +3 -0
  107. package/server/lib/spaces/hardening.js +20 -4
  108. package/server/lib/spaces/hardening.test.js +18 -3
  109. package/server/lib/spaces/host-git.js +7 -4
  110. package/server/lib/spaces/host-git.test.js +6 -2
  111. package/server/lib/spaces/host.js +304 -0
  112. package/server/lib/spaces/host.test.js +273 -0
  113. package/server/lib/spaces/journey.js +393 -0
  114. package/server/lib/spaces/journey.test.js +384 -0
  115. package/server/lib/spaces/layout.js +26 -2
  116. package/server/lib/spaces/manager.js +4 -3
  117. package/server/lib/spaces/manager.test.js +6 -0
  118. package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
  119. package/server/lib/spaces/places/contract-suite.js +36 -0
  120. package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
  121. package/server/lib/spaces/places/docker.js +15 -3
  122. package/server/lib/spaces/places/docker.test.js +33 -2
  123. package/server/lib/spaces/places/escape-suite.js +86 -14
  124. package/server/lib/spaces/places/memory-place.js +24 -1
  125. package/server/lib/spaces/places/registry.js +1 -1
  126. package/server/lib/spaces/places/server.docker.live.test.js +69 -33
  127. package/server/lib/spaces/places/sessions.docker.live.test.js +220 -0
  128. package/server/lib/spaces/routes.js +207 -0
  129. package/server/lib/spaces/routes.test.js +211 -0
  130. package/server/lib/spaces/run-command.js +261 -8
  131. package/server/lib/spaces/run-command.test.js +193 -3
  132. package/server/lib/spaces/space-events.js +153 -0
  133. package/server/lib/spaces/space-events.test.js +160 -0
  134. package/server/lib/spaces/space-records.js +98 -0
  135. package/server/lib/spaces/space-records.test.js +73 -0
  136. package/server/lib/spaces/space-sessions.js +210 -0
  137. package/server/lib/spaces/space-sessions.test.js +161 -0
  138. package/server/lib/spaces/websocket.js +329 -0
  139. package/server/lib/spaces/websocket.test.js +345 -0
  140. package/server/lib/ui-auth/ui-auth.js +8 -2
  141. package/server/lib/ui-auth/ui-auth.test.js +29 -0
  142. package/server/opencode-proxy.test.js +113 -0
  143. package/dist/assets/MarkdownImageGallery-DQk5adUs.js +0 -1
  144. package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +0 -12
  145. package/dist/assets/PluginPane-BIGsUx69.js +0 -3
  146. package/dist/assets/de-CMA45TC-.js +0 -10
  147. package/dist/assets/es-DPL4fBtl.js +0 -16
  148. package/dist/assets/fr-OHBKBseP.js +0 -14
  149. package/dist/assets/index-BLUZa5u0.js +0 -41
  150. package/dist/assets/index-Cm2rrq69.css +0 -1
  151. package/dist/assets/ja-DvX4WSRf.js +0 -16
  152. package/dist/assets/ko-BUcLd8YZ.js +0 -16
  153. package/dist/assets/main-B_jri4i-.js +0 -896
  154. package/dist/assets/pt-BR-7wFtQlV9.js +0 -16
  155. package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +0 -27
  156. package/dist/assets/tr-TsD-AqEH.js +0 -7
  157. package/dist/assets/uk-B-qspCmD.js +0 -16
  158. package/dist/assets/zh-CN-DYuPJV5i.js +0 -16
  159. package/dist/assets/zh-TW-BX_2D_lV.js +0 -16
@@ -1,30 +1,30 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-capacitor-core-B4EWRrHz.js"])))=>i.map(i=>d[i]);
2
- import{R as o,j as s,f as at,r as et}from"./vendor-react-BUCujlKS.js";import{f as Ze,B as G,I as z,o as yn,bj as Qn,t as B,O as Od,g$ as Fd,e$ as qe,h0 as Nt,g as za,eK as kc,b as rn,T as fa,h as Ie,au as Ld,h1 as Ir,h2 as Kd,cl as zt,ck as Pt,cn as mt,cm as At,cj as Tt,eR as Wn,h3 as Nc,h4 as _d,h5 as Ua,h6 as Pn,c8 as bs,c2 as _t,c3 as Ut,c4 as Bt,c5 as Vt,c6 as Ht,c7 as as,X as We,h7 as mi,av as _n,bh as wn,at as Un,as as zn,h8 as Zr,h9 as Vi,ad as Jn,ac as un,f5 as qt,ha as mn,hb as go,hc as ys,l as it,hd as ci,fm as Ln,he as Sc,fj as Ct,fg as $t,hf as Ot,co as As,ea as ca,fi as Ws,fk as an,hg as ps,ef as gs,hh as vs,cW as gt,hi as Cc,hj as Ud,hk as zd,hl as pi,hm as $d,hn as ks,e_ as Ps,ho as sn,gj as Ga,gp as nn,hp as $a,hq as Ic,hr as ho,eb as fo,ah as Ba,hs as Xr,ht as Uo,hu as Bd,cg as kn,cr as Nn,ch as Sn,hv as zo,hw as Cn,hx as Wt,hy as xo,ae as nr,af as ar,ag as bo,hz as vo,hA as sa,hB as Pc,hC as On,a7 as gi,cw as yo,hD as $o,ay as Vd,cp as Hd,da as qd,U as Gd,V as Wd,W as Jd,_ as jo,hE as Qd,hF as Yd,ce as Zd,cq as eo,hG as Ac,fl as Tc,P as na,hH as Rs,a6 as Xd,hI as eu,n as rs,ex as Ji,y as Ec,x as tu,i as su,j as nu,ey as au,p as iu,hJ as ru,hK as ou,hL as Bo,eg as Dc,hM as lu,hN as Pr,hO as Vo,hP as cu,hQ as du,hR as uu,hS as mu,gd as Qi,hT as cs,hU as ws,dh as Mc,bZ as Rc,di as Oc,b_ as Hs,hV as Fn,hW as wo,aH as Gn,aI as Ma,hX as en,hY as Rn,dv as Fc,hZ as Lc,h_ as Kc,h$ as pu,eZ as gu,eY as hu,i0 as to,eI as fu,i1 as aa,i2 as Ms,i3 as Vs,g6 as ia,i4 as Ns,i5 as xu,i6 as Ho,i7 as _c,i8 as ra,i9 as bu,ia as vu,R as Uc,db as yu,d5 as ju,d6 as wu,cJ as ku,eT as Nu,d7 as Su,d1 as Cu,bp as Iu,ib as Wa,ff as Ra,ic as qo,id as Oa,ie as Fa,b$ as ua,ig as Pu,ih as Au,ii as Tu,ij as Eu,ik as Ar,il as Go,im as Du,io as Mu,ip as Ru,iq as Ou,ir as Wo,z as Fu,m as Jo,dz as Lu,is as Ku,it as Tr,iu as Qo,eC as _u,iv as ir,iw as Uu,ix as zu,iy as $u,iz as Bu,iA as Vu,iB as Er,cX as Hu,c0 as zc,aB as Hn,aC as qu}from"./useAppFontEffects-DHZ9-L30.js";import{h as St,i as ko,u as fe,O as fs,dE as Gu,dF as Yo,t as ft,aD as An,B as Gs,a as jn,E as ls,P as Zo,cL as Xo,cS as el,U as Za,p as Wu,dG as Ju,k as Qu,cK as Ka,dH as Yu,al as Zu,cP as Xu,dI as em,dJ as tm,s as sm,e as hi,cQ as nm,F as fi,dK as $c,_ as am,dL as im,a3 as Bc,aC as os,dM as Vc,b9 as Hc,x as Va,b2 as qc,af as rm,ag as om,aM as No,dN as lm,y as rr,Z as cm,q as tl,aR as sl,bd as Di,aS as dm,dO as um,ab as da,dP as mm,dQ as nl,dD as al,dR as il,aP as rl,dS as pm,dT as gm,dU as hm,dV as fm,dW as ol,b as xm,dX as bm,dY as vm,dZ as ym,d_ as jm,d$ as wm,e0 as km,aw as Nm}from"./index-BLUZa5u0.js";import{u as Sm,X as ll,aq as Cm,ar as Im,as as Pm,Z as ma,$ as pa,a0 as ga,a1 as ha,m as So,at as oa,a5 as Am,z as Is,au as Tm,ao as Em,a3 as Dm,av as _a,aw as Gc,a2 as Mm,a4 as Rm}from"./runtimeEndpointReset-CfEYbcCc.js";import{u as $s,c as Om}from"./vendor-zustand-BAGL70zf.js";import{o as Ts,s as Dt,b as Co,l as Fm,r as Kn,c as so,a as xa,_ as Io,u as no}from"./vendor-zod-BSoePkpP.js";import{s as Lm,p as Km}from"./vendor-yaml-3778uTud.js";import{c as cl,s as _m,C as dl,P as Um}from"./shikiHighlight-D4vxipfr.js";import{getResolvedShikiTheme as zm}from"./appThemeRegistry-BebxalUt.js";import{E as ul}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Wc}from"./vendor-qrcode-DTJ12-WC.js";import{u as Dr,s as $m,d as Bm,b as Vm,A as Hm,c as qm,e as Gm,f as Wm,h as Jm,i as Mr,j as Qm}from"./PluginPane-BIGsUx69.js";import{toast as Ha}from"./vendor-sonner-DFyL3AvE.js";import{s as Ym}from"./vendor-strip-json-comments-5dJlOkP1.js";import{Y as Zm,U as Xm,X as ep,W as tp,V as sp}from"./vendor-base-ui-CsXYnR5c.js";import{_ as np}from"./vendor-vite-runtime-DD1OZmLC.js";const ml=()=>{const{t}=Ze(),[e,a]=o.useState(null);o.useEffect(()=>{let r=!1;const i=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const d=await St("/api/system/info",{signal:i?.signal,headers:{Accept:"application/json"}});if(!d.ok)return;const c=await d.json().catch(()=>null);if(!c||r)return;const h=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,g=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:h,tunnelUrl:g})}catch{}})(),()=>{r=!0,i?.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(r=>s.jsxs(G,{type:"button",variant:"outline",size:"sm",title:r.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{yn(r.url)},children:[s.jsx(z,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:r.url})]},r.key))})},pl="https://github.com/openchamber/openchamber",ap="https://discord.gg/ZYRSdnwwKA",gl="https://x.com/openchamber_dev",ip=800,rp={info:null,checking:!1,available:!1,error:null};function op(t){const e=at.c(5),[a,n]=o.useState(rp);let r;e[0]!==t?(r=async()=>{if(t){n(lp);try{const d=await Cm();n({info:d,checking:!1,available:d.available,error:null})}catch(d){const c=d;n({info:null,checking:!1,available:!1,error:c instanceof Error?c.message:String(c)})}}},e[0]=t,e[1]=r):r=e[1];const i=r;let l;return e[2]!==i||e[3]!==a?(l={...a,check:i},e[2]=i,e[3]=a,e[4]=l):l=e[4],l}function lp(t){return{...t,checking:!0,error:null}}function cp(t){const e=at.c(11),[a,n]=o.useState(null);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"idle"},e[0]=r):r=e[0];const[i,l]=o.useState(r);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=async()=>{try{const b=await Im();return n(b),b}catch{return null}},e[1]=d):d=e[1];const c=d;let h,g;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{c()},g=[c],e[2]=h,e[3]=g):(h=e[2],g=e[3]),o.useEffect(h,g);let f;e[4]!==t?(f=async()=>{l({kind:"upgrading"});try{const b=await Pm(t);l({kind:"installed",version:b})}catch(b){const k=b;l({kind:"failed",error:k instanceof Error?k.message:t})}},e[4]=t,e[5]=f):f=e[5];const p=f;let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=async b=>{await b().catch(dp);const k=await c();k?.currentVersion&&l(m=>m.kind!=="installed"||m.version&&m.version.replace(/^v/,"")!==k.currentVersion?m:{kind:"idle"})},e[6]=u):u=e[6];const v=u;let w;return e[7]!==i||e[8]!==a||e[9]!==p?(w={status:a,phase:i,refresh:c,upgrade:p,reloadAfterUpgrade:v},e[7]=i,e[8]=a,e[9]=p,e[10]=w):w=e[10],w}function dp(){}function up(t){const[e,a]=o.useState(null);return o.useEffect(()=>{if(!t)return;let n=!1;return np(async()=>{const{App:r}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:r}},__vite__mapDeps([0,1,2])).then(({App:r})=>r.getInfo()).then(r=>{n||a(r.version.trim()||null)}).catch(()=>{}),()=>{n=!0}},[t]),e}const Jc=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=Ze(),[a,n]=o.useState(t),[r,i]=o.useState(!1),[l,d]=o.useState(null),c=Sm($s(F=>({info:F.info,checking:F.checking,available:F.available,error:F.error,downloading:F.downloading,downloaded:F.downloaded,progress:F.progress,runtimeType:F.runtimeType,checkForUpdates:F.checkForUpdates,downloadUpdate:F.downloadUpdate,restartToUpdate:F.restartToUpdate}))),{isMobile:h}=Qn(),g=o.useMemo(()=>ko(),[]),f=op(g),p=up(g),u=g?{info:f.info,checking:f.checking,available:f.available,error:f.error,checkForUpdates:f.check,runtimeType:"web"}:{info:c.info,checking:c.checking,available:c.available,error:c.error,checkForUpdates:c.checkForUpdates,runtimeType:c.runtimeType},v=l||u.info?.currentVersion||"unknown",w=cp(e("opencodeUpdate.toast.failed.description")),b=w.status?.currentVersion??null,k=w.phase.kind==="installed"?null:w.status?.availableVersion??null,[m,S]=o.useState(!1),P=(()=>{const F=u.info?.version||"";return g?u.info?.packageManager==="electron"?e("settings.openchamber.about.actions.updateDesktopToVersion",{version:F}):e("settings.openchamber.about.actions.updateServerToVersion",{version:F}):e("settings.openchamber.about.actions.updateOpenChamberToVersion",{version:F})})(),I=u.available&&u.info?.installBlocked==="service-manager",j=u.info?.updateCommand||"openchamber update",D=()=>{u.checkForUpdates(),w.refresh()},x=async()=>{(await za(j)).ok&&(S(!0),setTimeout(()=>S(!1),2e3))},A=()=>{w.reloadAfterUpgrade(async()=>{await kc({message:e("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})})},R=I?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.serviceManagerUpdate",{version:u.info?.version||""})}),s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-elevated/50 p-1 pl-3",children:[s.jsx("code",{className:"flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm text-foreground",children:j}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{x()},"aria-label":e(m?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:s.jsx(z,{name:m?"check":"clipboard",className:"size-4"})})]})]}):null,C=(()=>{const{phase:F}=w;if(F.kind==="installed")return s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:F.version?e("settings.openchamber.about.openCode.installedVersion",{version:F.version}):e("settings.openchamber.about.openCode.installed")}),s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:A,children:e("opencodeUpdate.toast.actions.reload")})]});if(!k)return null;if(!w.status?.supported)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.openCode.manualUpdate",{version:k})});const N=F.kind==="upgrading";return s.jsxs("div",{className:"space-y-2",children:[s.jsxs(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{w.upgrade()},disabled:N,children:[s.jsx(z,{name:N?"loader":"download",className:N?"size-4 animate-spin":"size-4"}),N?e("opencodeUpdate.toast.upgrading.title"):e("settings.openchamber.about.actions.updateOpenCodeToVersion",{version:k})]}),F.kind==="failed"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:F.error})]})})();o.useEffect(()=>{let F=!1;return(async()=>{try{const M=await St("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!M.ok)return;const U=await M.json().catch(()=>null),K=typeof U?.openchamberVersion=="string"&&U.openchamberVersion.trim().length>0?U.openchamberVersion.trim():null;F||d(K)}catch{F||d(null)}})(),()=>{F=!0}},[]);const E=o.useRef(!1);o.useEffect(()=>{if(u.checking)i(!0),E.current=!0;else if(r){const F=setTimeout(()=>{i(!1),E.current&&!u.available&&!u.error&&(B.success(e(g?"settings.openchamber.about.toast.serverLatestVersion":"settings.openchamber.about.toast.latestVersion")),E.current=!1)},ip);return()=>clearTimeout(F)}},[e,g,u.checking,r,u.available,u.error]);const O=u.checking||r;return h?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(Od,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Fd}`,children:"OpenChamber"}),s.jsx("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:g?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:v})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:b||e("settings.openchamber.about.state.unknown")})}),p&&s.jsx("p",{children:e("settings.openchamber.about.native.appVersion",{version:p})})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:v})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:b||e("settings.openchamber.about.state.unknown")})})]})}),s.jsx(ml,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!u.available&&!u.error&&s.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:D,disabled:O,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[O?s.jsx(z,{name:"loader",className:"size-4 animate-spin"}):s.jsx(z,{name:"refresh",className:"size-4"}),e(O?"settings.openchamber.about.state.checking":g?"settings.openchamber.about.actions.checkServerForUpdates":"settings.openchamber.about.actions.checkForUpdates")]}),!O&&u.available&&!I&&s.jsxs(G,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(z,{name:"download",className:"size-4"}),P]})]}),R,C&&s.jsx("div",{className:"flex justify-center text-center",children:C}),u.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:u.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:pl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:ap,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:gl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(ll,{open:a,onOpenChange:n,info:u.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:u.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:u.runtimeType})]}):s.jsxs(qe,{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:Nt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:v})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:b||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[u.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(z,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!u.checking&&u.available&&!I&&s.jsxs(G,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(z,{name:"download",className:"h-4 w-4 mr-1"}),P]}),!u.checking&&!u.available&&!u.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(G,{size:"sm",variant:"outline",onClick:D,disabled:u.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),R&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:R}),C&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:C}),u.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:u.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:Nt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(ml,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:pl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:gl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(ll,{open:a,onOpenChange:n,info:u.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:u.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:u.runtimeType})]})},mp=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,Js=()=>{const t=at.c(4),e=fe(pp),a=rn(gp),n=rn(hp);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=mp(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function pp(t){return t.settingsProjectPath}function gp(t){return t.projects}function hp(t){return t.activeProjectId}const fp=t=>[...t].sort((e,a)=>(e.label||e.path).localeCompare(a.label||a.path)),xi=t=>{const e=at.c(75),{className:a}=t,{t:n}=Ze(),{currentTheme:r}=fa(),i=fe(xp),[l,d]=o.useState(!1),c=rn(bp),h=Js(),g=fe(vp),f=fs();let p;e[0]!==c?(p=fp(c),e[0]=c,e[1]=p):p=e[1];const u=p;let v;e[2]!==h||e[3]!==u?(v=u.find(O=>O.path===h)??u[0]??null,e[2]=h,e[3]=u,e[4]=v):v=e[4];const w=v;if(f||!w)return null;let b;e[5]!==g||e[6]!==u?(b=O=>{const F=u.find(N=>N.id===O);F&&g(F.path)},e[5]=g,e[6]=u,e[7]=b):b=e[7];const k=b;if(i){let O;e[8]!==a?(O=Ie(a),e[8]=a,e[9]=O):O=e[9];let F;e[10]!==n?(F=n("settings.shared.projectSelector.switchProjectAria"),e[10]=n,e[11]=F):F=e[11];let N;e[12]!==n?(N=n("settings.shared.projectSelector.switchProjectTitle"),e[12]=n,e[13]=N):N=e[13];let M,U;e[14]===Symbol.for("react.memo_cache_sentinel")?(M=()=>d(!0),U=Ie(Ld({size:"touch"}),"w-full min-w-0"),e[14]=M,e[15]=U):(M=e[14],U=e[15]);let K;e[16]!==w||e[17]!==r?(K=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(Ir,{project:w,theme:r})}),e[16]=w,e[17]=r,e[18]=K):K=e[18];let W;e[19]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=W):W=e[19];let te;e[20]!==l||e[21]!==F||e[22]!==N||e[23]!==U||e[24]!==K?(te=s.jsxs("button",{type:"button","aria-label":F,title:N,"aria-haspopup":"dialog","aria-expanded":l,onClick:M,className:U,children:[K,W]}),e[20]=l,e[21]=F,e[22]=N,e[23]=U,e[24]=K,e[25]=te):te=e[25];let Q;e[26]!==te||e[27]!==O?(Q=s.jsx("div",{className:O,children:te}),e[26]=te,e[27]=O,e[28]=Q):Q=e[28];let H;e[29]===Symbol.for("react.memo_cache_sentinel")?(H=()=>d(!1),e[29]=H):H=e[29];const _=w.id;let V;e[30]!==n?(V=n("settings.shared.projectSelector.sheetTitle"),e[30]=n,e[31]=V):V=e[31];let X;e[32]!==n?(X=n("settings.shared.projectSelector.searchPlaceholder"),e[32]=n,e[33]=X):X=e[33];let $;e[34]!==w.id||e[35]!==r||e[36]!==k||e[37]!==l||e[38]!==u||e[39]!==V||e[40]!==X?($=s.jsx(Kd,{open:l,onClose:H,projects:u,selectedProjectId:_,onSelectProject:k,theme:r,title:V,searchPlaceholder:X}),e[34]=w.id,e[35]=r,e[36]=k,e[37]=l,e[38]=u,e[39]=V,e[40]=X,e[41]=$):$=e[41];let ee;return e[42]!==Q||e[43]!==$?(ee=s.jsxs(s.Fragment,{children:[Q,$]}),e[42]=Q,e[43]=$,e[44]=ee):ee=e[44],ee}let m;e[45]!==a?(m=Ie(a),e[45]=a,e[46]=m):m=e[46];const S=w.id;let P;e[47]!==k?(P=O=>{O&&k(O)},e[47]=k,e[48]=P):P=e[48];let I;e[49]!==n?(I=n("settings.shared.projectSelector.switchProjectAria"),e[49]=n,e[50]=I):I=e[50];let j;e[51]!==n?(j=n("settings.shared.projectSelector.switchProjectTitle"),e[51]=n,e[52]=j):j=e[52];let D;e[53]!==w||e[54]!==r?(D=s.jsx(zt,{children:s.jsx(Ir,{project:w,theme:r})}),e[53]=w,e[54]=r,e[55]=D):D=e[55];let x;e[56]!==I||e[57]!==j||e[58]!==D?(x=s.jsx(Pt,{size:"settings",className:"w-full","aria-label":I,title:j,children:D}),e[56]=I,e[57]=j,e[58]=D,e[59]=x):x=e[59];let A;if(e[60]!==r||e[61]!==u){let O;e[63]!==r?(O=F=>s.jsx(mt,{value:F.id,className:"max-w-[24rem] truncate",children:s.jsx(Ir,{project:F,theme:r})},F.id),e[63]=r,e[64]=O):O=e[64],A=u.map(O),e[60]=r,e[61]=u,e[62]=A}else A=e[62];let R;e[65]!==A?(R=s.jsx(At,{fitContent:!0,children:A}),e[65]=A,e[66]=R):R=e[66];let C;e[67]!==w.id||e[68]!==x||e[69]!==R||e[70]!==P?(C=s.jsxs(Tt,{value:S,onValueChange:P,children:[x,R]}),e[67]=w.id,e[68]=x,e[69]=R,e[70]=P,e[71]=C):C=e[71];let E;return e[72]!==C||e[73]!==m?(E=s.jsx("div",{className:m,children:C}),e[72]=C,e[73]=m,e[74]=E):E=e[74],E};function xp(t){return t.isMobile}function bp(t){return t.projects}function vp(t){return t.setSettingsProjectPath}function yp(t,e){return`opencode:sidebar-group:${t}:${e}`}const ao=t=>{const e=at.c(33),{label:a,count:n,storageKey:r,defaultExpanded:i,children:l}=t,d=i===void 0?!0:i;let c;e[0]!==a||e[1]!==r?(c=yp(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const h=c,g=o.useId();let f;e[3]!==d||e[4]!==h?(f=()=>{try{const C=localStorage.getItem(h);if(C!==null)return C==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=f):f=e[5];const[p,u]=et.useState(f);let v,w;e[6]!==p||e[7]!==h?(v=()=>{try{localStorage.setItem(h,String(p))}catch{}},w=[h,p],e[6]=p,e[7]=h,e[8]=v,e[9]=w):(v=e[8],w=e[9]),et.useEffect(v,w);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>u(jp),e[10]=b):b=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=Ie("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-ring"),e[11]=k):k=e[11];const m=!p&&"-rotate-90";let S;e[12]!==m?(S=Ie("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",m),e[12]=m,e[13]=S):S=e[13];let P;e[14]!==S?(P=s.jsx(z,{name:"arrow-down-s",className:S}),e[14]=S,e[15]=P):P=e[15];let I;e[16]!==a?(I=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=I):I=e[17];let j;e[18]!==n?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=j):j=e[19];let D;e[20]!==g||e[21]!==p||e[22]!==P||e[23]!==I||e[24]!==j?(D=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":p,"aria-controls":g,className:k,children:[P,I,j]}),e[20]=g,e[21]=p,e[22]=P,e[23]=I,e[24]=j,e[25]=D):D=e[25];const x=!p;let A;e[26]!==l||e[27]!==g||e[28]!==x?(A=s.jsx("div",{id:g,hidden:x,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]=g,e[28]=x,e[29]=A):A=e[29];let R;return e[30]!==D||e[31]!==A?(R=s.jsxs("div",{children:[D,A]}),e[30]=D,e[31]=A,e[32]=R):R=e[32],R};function jp(t){return!t}const wp=({onItemSelect:t})=>{const{t:e}=Ze(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,d]=o.useState(null),[c,h]=o.useState(null),[g,f]=o.useState(!1),[p,u]=o.useState(null),{selectedAgentName:v,setSelectedAgent:w,setAgentDraft:b,createAgent:k,deleteAgent:m,loadAgents:S,fetchAgentEntity:P}=Wn($s(H=>({selectedAgentName:H.selectedAgentName,setSelectedAgent:H.setSelectedAgent,setAgentDraft:H.setAgentDraft,createAgent:H.createAgent,deleteAgent:H.deleteAgent,loadAgents:H.loadAgents,fetchAgentEntity:H.fetchAgentEntity}))),I=Js(),j=Wn(H=>Nc(H,I));o.useEffect(()=>{S(I)},[S,I]);const D="bg-background",x=()=>{const H="new-agent";let _=H,V=1;for(;j.some(X=>X.name===_);)_=`${H}-${V}`,V++;b({name:_,scope:"user"}),w(_),t?.()},A=async H=>{if(Ua(H)){B.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(H),h("delete")},R=async H=>{Ua(H)&&(d(H),h("reset"))},C=()=>{d(null),h(null)},E=async()=>{if(!(!l||!c)){f(!0);try{(await m(l.name,l.scope,I)).ok?(c==="delete"?B.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):B.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),C()):c==="delete"?B.error(e("settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(H){const _=H instanceof Error?H.message:"",V=/built-in|not deletable|not found/i.test(_);c==="delete"?B.error(e(V?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}f(!1)}},O=async H=>{const _=H.name;let V=1,X=`${_}-copy`;for(;j.some(Y=>Y.name===X);)V++,X=`${_}-copy-${V}`;const $=H,ee=await P(H.name,I);if(!ee){B.error(e("settings.agents.sidebar.toast.renameFailed"));return}const L=ee.config.request?.body;b({name:X,scope:ee.scope??$.scope??"user",description:ee.config.description??void 0,model:ee.config.model??null,system:ee.config.system??void 0,steps:ee.config.steps??void 0,temperature:L?.temperature,top_p:L?.top_p,mode:ee.config.mode??$.mode,permissions:ee.config.permissions??void 0}),w(X),t?.()},F=H=>{i(H.name),n(H)},N=async()=>{if(!a)return;const H=r.trim().replace(/\s+/g,"-");if(!H){B.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(H===a.name){n(null);return}if(j.some($=>$.name===H)){B.error(e("settings.agents.sidebar.toast.agentExists"));return}const _=a,V=await P(a.name,I);if(!V){B.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await k({...V.config,name:H,scope:V.scope??_.scope},I)).ok?(await m(a.name,_.scope,I)).ok?(B.success(e("settings.agents.sidebar.toast.agentRenamed",{name:H})),w(H)):B.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):B.error(e("settings.agents.sidebar.toast.renameFailed")),n(null)},M=H=>{switch(H){case"primary":return s.jsx(z,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(z,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(z,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},U=j.filter(H=>!_d(H)),K=U.filter(Ua),W=U.filter(H=>!Ua(H)),{groupedCustomAgents:te,ungroupedCustomAgents:Q}=et.useMemo(()=>{const H={},_=[];for(const X of W){const $=X;$.group?(H[$.group]||(H[$.group]=[]),H[$.group].push(X)):_.push(X)}return{groupedCustomAgents:Object.keys(H).sort((X,$)=>X.localeCompare($)).map(X=>({name:X,agents:H[X]})),ungroupedCustomAgents:_}},[W]);return s.jsxs("div",{className:Ie("flex h-full flex-col",D),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Pn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(xi,{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:U.length})}),s.jsx(G,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:x,children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:U.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[K.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")}),K.map(H=>s.jsx(Rr,{agent:H,isSelected:v===H.name,onSelect:()=>{w(H.name),t?.()},onReset:()=>R(H),onDuplicate:()=>{O(H)},getAgentModeIcon:M,isMenuOpen:p===H.name,onMenuOpenChange:_=>u(_?H.name:null)},H.name))]}),W.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),te.map(({name:H,agents:_})=>s.jsx(ao,{label:H,count:_.length,storageKey:"agents",children:_.map(V=>s.jsx(Rr,{agent:V,isSelected:v===V.name,onSelect:()=>{w(V.name),t?.()},onRename:()=>F(V),onDelete:()=>A(V),onDuplicate:()=>{O(V)},getAgentModeIcon:M,isMenuOpen:p===V.name,onMenuOpenChange:X=>u(X?V.name:null)},V.name))},H)),Q.map(H=>s.jsx(Rr,{agent:H,isSelected:v===H.name,onSelect:()=>{w(H.name),t?.()},onRename:()=>F(H),onDelete:()=>A(H),onDuplicate:()=>{O(H)},getAgentModeIcon:M,isMenuOpen:p===H.name,onMenuOpenChange:_=>u(_?H.name:null)},H.name))]})]})}),s.jsx(_t,{open:l!==null&&c!==null,onOpenChange:H=>{!H&&!g&&C()},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Ht,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:C,disabled:g,children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:E,disabled:g,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(_t,{open:a!==null,onOpenChange:H=>!H&&n(null),children:s.jsxs(Ut,{children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(We,{value:r,onChange:H=>i(H.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:H=>{H.key==="Enter"&&N()}}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:N,children:e("settings.common.actions.rename")})]})]})})]})},Rr=t=>{const e=at.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:g,onMenuOpenChange:f}=t,{t:p}=Ze(),u=a;let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=mi(),e[0]=v):v=e[0];const w=v,[b,k]=o.useState(!1);let m;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==p?(m=H=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(H,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=p,e[6]=m):m=e[6];const S=m,P=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==P?(I=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",P),e[7]=P,e[8]=I):I=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=w?void 0:H=>{H.preventDefault(),k(!0)},e[9]=j):j=e[9];let D;e[10]!==I?(D=s.jsx("div",{className:I,onContextMenu:j}),e[10]=I,e[11]=D):D=e[11];let x;e[12]!==a.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=x):x=e[13];let A;e[14]!==a.mode||e[15]!==h?(A=h(a.mode),e[14]=a.mode,e[15]=h,e[16]=A):A=e[16];let R;e[17]!==a||e[18]!==u.scope||e[19]!==p?(R=(u.scope||Ua(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:Ua(a)?p("settings.agents.sidebar.badge.system"):u.scope}),e[17]=a,e[18]=u.scope,e[19]=p,e[20]=R):R=e[20];let C;e[21]!==x||e[22]!==A||e[23]!==R?(C=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,A,R]}),e[21]=x,e[22]=A,e[23]=R,e[24]=C):C=e[24];let E;e[25]!==a.description?(E=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=E):E=e[26];let O;e[27]!==r||e[28]!==C||e[29]!==E?(O=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-ring",tabIndex:0,children:[C,E]}),e[27]=r,e[28]=C,e[29]=E,e[30]=O):O=e[30];let F;e[31]!==f?(F=H=>{H&&k(!1),f(H)},e[31]=f,e[32]=F):F=e[32];let N;e[33]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=N):N=e[33];let M;e[34]!==S?(M=s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:S(wn)}),e[34]=S,e[35]=M):M=e[35];let U;e[36]!==g||e[37]!==F||e[38]!==M?(U=s.jsxs(zn,{open:g,onOpenChange:F,children:[N,M]}),e[36]=g,e[37]=F,e[38]=M,e[39]=U):U=e[39];let K;e[40]!==O||e[41]!==U?(K=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,U]}),e[40]=O,e[41]=U,e[42]=K):K=e[42];let W;e[43]!==K||e[44]!==D?(W=s.jsx(ga,{render:D,children:K}),e[43]=K,e[44]=D,e[45]=W):W=e[45];let te;e[46]!==S?(te=s.jsx(ma,{className:"w-fit min-w-20",children:S(pa)}),e[46]=S,e[47]=te):te=e[47];let Q;return e[48]!==b||e[49]!==W||e[50]!==te?(Q=s.jsxs(ha,{open:b,onOpenChange:k,children:[W,te]}),e[48]=b,e[49]=W,e[50]=te,e[51]=Q):Q=e[51],Q},ns=t=>{const e=at.c(22),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:d,description:c,headerEnd:h,showSaveStatus:g,onBlurCapture:f}=t,p=g===void 0?!1:g,u=i!=null||c!=null||h!=null||p,v=typeof i=="string"||typeof i=="number",w=l!=null||d!=null;let b;e[0]!==r?(b=Ie("h-full overlay-scrollbar-wrapper--stable-gutter",r),e[0]=r,e[1]=b):b=e[1];let k;e[2]!==n?(k=Ie("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]=k):k=e[3];let m;e[4]!==c||e[5]!==u||e[6]!==w||e[7]!==h||e[8]!==v||e[9]!==p||e[10]!==i||e[11]!==d||e[12]!==l?(m=u&&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:[i!=null?v?w?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Ie(Zr,"min-w-0 truncate"),children:i}),s.jsx("span",{className:"shrink-0",children:d})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Zr,children:i}):i:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Vi,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[h,p&&s.jsx(Np,{})]})]}),e[4]=c,e[5]=u,e[6]=w,e[7]=h,e[8]=v,e[9]=p,e[10]=i,e[11]=d,e[12]=l,e[13]=m):m=e[13];let S;e[14]!==a||e[15]!==f||e[16]!==k||e[17]!==m?(S=s.jsxs("div",{className:k,onBlurCapture:f,children:[m,a]}),e[14]=a,e[15]=f,e[16]=k,e[17]=m,e[18]=S):S=e[18];let P;return e[19]!==b||e[20]!==S?(P=s.jsx(bs,{outerClassName:b,className:"w-full @container",children:S}),e[19]=b,e[20]=S,e[21]=P):P=e[21],P},kp=500,Np=()=>{const t=at.c(13),{t:e}=Ze(),a=o.useSyncExternalStore(Gu,Yo,Yo),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const g=setTimeout(()=>r(!0),kp);return()=>clearTimeout(g)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let g;t[3]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(z,{name:"error-warning",className:"size-3.5"}),t[3]=g):g=t[3];let f;t[4]!==e?(f=e("settings.common.status.saveFailed"),t[4]=e,t[5]=f):f=t[5];let p;return t[6]!==f?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[g,s.jsx("span",{children:f})]}),t[6]=f,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=d):d=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let h;return t[11]!==c?(h=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[d,s.jsx("span",{children:c})]}),t[11]=c,t[12]=h):h=t[12],h},Os={ok:!0,changed:!1},In={ok:!0,changed:!0},hs=t=>({ok:!1,reason:t}),Sp=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,Ja=t=>{const{t:e}=Ze(),[a,n]=o.useState(0),r=o.useRef(t);r.current=t;const i=o.useRef(e);i.current=e;const l=o.useRef(!1),d=o.useRef(!1),c=o.useRef(!1),h=o.useCallback(()=>{n(p=>p+1)},[]),g=o.useCallback(p=>{Sp(p.target)&&h()},[h]),f=o.useCallback(async()=>{l.current=!0;try{for(;;){d.current=!1;let p;try{p=await r.current()}catch(u){p={ok:!1,reason:u instanceof Error?u.message:String(u)}}if(!c.current)return;if(!d.current){p.ok||B.error(i.current("settings.common.status.saveFailedReason",{reason:p.reason}));return}}}finally{l.current=!1}},[]);return o.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),o.useEffect(()=>{if(a!==0){if(l.current){d.current=!0;return}f()}},[a,f]),{requestSave:h,onBlurCapture:g}},Cp=["allow","ask","deny"],Ip=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],Pp=["openchamber","openchamber_web","openchamber_memory","openchamber_notify"],Ap=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),Qc=t=>Ap.has(t),Tp=[{action:"*",resource:"*",effect:"allow"},{action:"external_directory",resource:"*",effect:"ask"},{action:"read",resource:"*.env",effect:"ask"},{action:"read",resource:"*.env.*",effect:"ask"},{action:"read",resource:"*.env.example",effect:"allow"}],hl=()=>({global:null,keys:{},source:[]}),Xn=t=>({global:t.global,source:t.source,keys:Object.fromEntries(Object.entries(t.keys).map(([e,a])=>[e,{effect:a.effect,patterns:a.patterns.map(n=>({...n}))}]))}),Ep=t=>{const e={global:null,keys:{},source:t.map(a=>({...a}))};for(const a of t){if(Qc(a.action))continue;if(a.action==="*"){a.resource==="*"&&(e.global=a.effect);continue}const n=e.keys[a.action]??{effect:null,patterns:[]};if(a.resource==="*")n.effect=a.effect;else{const r=n.patterns.findIndex(i=>i.pattern===a.resource);r>=0?n.patterns[r]={pattern:a.resource,effect:a.effect}:n.patterns.push({pattern:a.resource,effect:a.effect})}e.keys[a.action]=n}return e},Dp=t=>t.action!=="*"||t.resource==="*",la=(t,e)=>`${t}\0${e}`,Mp=t=>{const e=new Map;t.global!==null&&e.set(la("*","*"),t.global);for(const[a,n]of Object.entries(t.keys)){n.effect!==null&&e.set(la(a,"*"),n.effect);for(const r of n.patterns){const i=r.pattern.trim();i.length!==0&&e.set(la(a,i),r.effect)}}return e},io=t=>{const e=Mp(t),a=new Set,n=[];for(const i of t.source){if(Qc(i.action))continue;if(!Dp(i)){n.push({...i});continue}const l=la(i.action,i.resource),d=e.get(l);d!==void 0&&(n.push({action:i.action,resource:i.resource,effect:d}),a.add(l))}const r=la("*","*");t.global!==null&&!a.has(r)&&n.unshift({action:"*",resource:"*",effect:t.global});for(const[i,l]of Object.entries(t.keys)){const d=la(i,"*");if(l.effect!==null&&!a.has(d)){const c=n.findIndex(g=>g.action===i),h={action:i,resource:"*",effect:l.effect};c>=0?n.splice(c,0,h):n.push(h)}for(const c of l.patterns){const h=c.pattern.trim();if(h.length===0)continue;const g=la(i,h),f=e.get(g);f===void 0||a.has(g)||(a.add(g),n.push({action:i,resource:h,effect:f}))}}return n},Rp=(t,e)=>JSON.stringify(io(t))===JSON.stringify(io(e)),Op=(t,e)=>{const a=[...Tp,...e.global,...e.agentGlobal?[{action:"*",resource:"*",effect:e.agentGlobal}]:[]];let n="ask";for(const r of a)r.resource==="*"&&(r.action==="*"||r.action===t)&&(n=r.effect);return n},Fp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Lp=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),Kp={effect:null,patterns:[]},_p=t=>{const e=at.c(163),{agent:a,registerSave:n,requestSave:r}=t,{t:i}=Ze(),l=Wn(Up),d=Wn(zp);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];const[h,g]=o.useState(c),[f,p]=o.useState(hl),[u,v]=o.useState(hl),[w,b]=o.useState(!0),[k,m]=o.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S={},e[1]=S):S=e[1];const[P,I]=o.useState(S),[j,D]=o.useState(""),[x,A]=o.useState(0),R=a.name,C=Js(),E=Jn($p);let O;e[2]!==C?(O=Ne=>go(Ne,C),e[2]=C,e[3]=O):O=e[3];const F=Jn(O);let N;e[4]!==C?(N=Ne=>Ne.getStatusForDirectory(C),e[4]=C,e[5]=N):N=e[5];const M=un(N);let U,K;e[6]!==E||e[7]!==C?(U=()=>{E({directory:C})},K=[E,C],e[6]=E,e[7]=C,e[8]=U,e[9]=K):(U=e[8],K=e[9]),o.useEffect(U,K);let W;e[10]!==R||e[11]!==d||e[12]!==C?(W=()=>{let Ne=!1;return b(!0),m(!1),(async()=>{const Ae=await d(R,C);if(Ne)return;if(!Ae){m(!0),b(!1);return}const q=Ep(Ae.agent);g(Ae.global),p(Xn(q)),v(q),I({}),b(!1)})(),()=>{Ne=!0}},e[10]=R,e[11]=d,e[12]=C,e[13]=W):W=e[13];let te;e[14]!==R||e[15]!==d||e[16]!==x||e[17]!==C?(te=[R,d,x,C],e[14]=R,e[15]=d,e[16]=x,e[17]=C,e[18]=te):te=e[18],o.useEffect(W,te);let Q;e[19]!==R||e[20]!==f||e[21]!==u||e[22]!==C||e[23]!==i||e[24]!==l?(Q=async()=>Rp(u,f)?Os:(await l(R,{permissions:io(u)},C)).ok?(p(Xn(u)),In):hs(i("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=R,e[20]=f,e[21]=u,e[22]=C,e[23]=i,e[24]=l,e[25]=Q):Q=e[25];const H=Q;let _,V;e[26]!==n||e[27]!==H?(_=()=>(n(H),()=>n(null)),V=[n,H],e[26]=n,e[27]=H,e[28]=_,e[29]=V):(_=e[28],V=e[29]),o.useEffect(_,V);let X;e[30]!==F?(X=F.map(Bp),e[30]=F,e[31]=X):X=e[31];const $=X;let ee;if(e[32]!==$||e[33]!==u.keys){ee=[...Ip,...Pp];const Ne=new Set($.map(Vp));let Ae;e[35]!==u.keys?(Ae=Object.keys(u.keys),e[35]=u.keys,e[36]=Ae):Ae=e[36];for(const q of Ae)!ee.includes(q)&&!Ne.has(q)&&ee.push(q);e[32]=$,e[33]=u.keys,e[34]=ee}else ee=e[34];const L=ee;let Y;e[37]!==M||e[38]!==i?(Y=Ne=>{switch(M?.[Ne]?.status.status){case"connected":return i("settings.mcp.page.status.label.connected");case"failed":return i("settings.mcp.page.status.label.failed");case"needs_auth":return i("settings.mcp.page.status.label.needsAuth");case"disabled":return i("settings.agents.page.permissionsEditor.mcpStatus.disabled");case"pending":return i("settings.agents.page.permissionsEditor.mcpStatus.pending");default:return null}},e[37]=M,e[38]=i,e[39]=Y):Y=e[39];const oe=Y;let de;e[40]!==h||e[41]!==u.global?(de=Ne=>Op(Ne,{global:h,agentGlobal:u.global}),e[40]=h,e[41]=u.global,e[42]=de):de=e[42];const ge=de;let ce;e[43]!==r?(ce=Ne=>{v(Ae=>({...Ae,global:Ne})),r()},e[43]=r,e[44]=ce):ce=e[44];const Se=ce;let ie;e[45]!==r?(ie=(Ne,Ae)=>{v(q=>{const Le=Xn(q),Qe=Le.keys[Ne]??{effect:null,patterns:[]};return Qe.effect=Ae,Qe.effect===null&&Qe.patterns.length===0?delete Le.keys[Ne]:Le.keys[Ne]=Qe,Le}),r()},e[45]=r,e[46]=ie):ie=e[46];const be=ie;let ae;e[47]!==r?(ae=(Ne,Ae,q,Le,Qe)=>{v(lt=>{const ot=Xn(lt),bt=ot.keys[Ne]??{effect:null,patterns:[]};return bt.patterns[Ae]={pattern:q,effect:Le},ot.keys[Ne]=bt,ot}),Qe&&r()},e[47]=r,e[48]=ae):ae=e[48];const me=ae;let je;e[49]===Symbol.for("react.memo_cache_sentinel")?(je=Ne=>{v(Ae=>{const q=Xn(Ae),Le=q.keys[Ne]??{effect:null,patterns:[]};return Le.patterns.push({pattern:"",effect:"allow"}),q.keys[Ne]=Le,q}),I(Ae=>({...Ae,[Ne]:!0}))},e[49]=je):je=e[49];const De=je;let ue;e[50]!==r?(ue=(Ne,Ae)=>{v(q=>{const Le=Xn(q),Qe=Le.keys[Ne];return Qe?(Qe.patterns.splice(Ae,1),Qe.effect===null&&Qe.patterns.length===0&&delete Le.keys[Ne],Le):q}),r()},e[50]=r,e[51]=ue):ue=e[51];const $e=ue;let Ge;e[52]!==j||e[53]!==r?(Ge=()=>{const Ne=j.trim();!Ne||Ne==="*"||(v(Ae=>{if(Ae.keys[Ne])return Ae;const q=Xn(Ae);return q.keys[Ne]={effect:"ask",patterns:[]},q}),D(""),r())},e[52]=j,e[53]=r,e[54]=Ge):Ge=e[54];const xe=Ge;let Pe;e[55]!==i?(Pe=Ne=>i(Ne==="allow"?"settings.agents.page.permissionsEditor.action.allow":Ne==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=i,e[56]=Pe):Pe=e[56];const J=Pe;let se,he,ve,Fe,Ke,Be,ze,_e,Me;if(e[57]!==J||e[58]!==ge||e[59]!==P||e[60]!==w||e[61]!==k||e[62]!==$||e[63]!==oe||e[64]!==u.global||e[65]!==u.keys||e[66]!==$e||e[67]!==Se||e[68]!==be||e[69]!==me||e[70]!==i||e[71]!==L){Me=Symbol.for("react.early_return_sentinel");e:{const Ne=i("settings.agents.page.permissionsEditor.action.inherit"),Ae=i("settings.agents.page.permissionsEditor.action.default");let q;e[81]!==J?(q=Ve=>[...Ve?[{value:"inherit",label:Ve}]:[],...Cp.map(Z=>({value:Z,label:J(Z)}))],e[81]=J,e[82]=q):q=e[82];const Le=q,Qe=(Ve,Z,pe,Oe)=>{const Ee=Oe===void 0?Ne:Oe;return s.jsx(mn,{value:Ve??"inherit",options:Le(Ee),onChange:Ye=>Z(Ye==="inherit"?null:Ye),"aria-label":pe})};if(w){let Ve;e[83]!==i?(Ve=i("settings.agents.page.section.toolPermissions"),e[83]=i,e[84]=Ve):Ve=e[84];let Z;e[85]!==i?(Z=i("common.loading"),e[85]=i,e[86]=Z):Z=e[86];let pe;e[87]!==Z?(pe=s.jsx("p",{className:ys,children:Z}),e[87]=Z,e[88]=pe):pe=e[88];let Oe;e[89]!==Ve||e[90]!==pe?(Oe=s.jsx(qe,{title:Ve,children:pe}),e[89]=Ve,e[90]=pe,e[91]=Oe):Oe=e[91],Me=Oe;break e}if(k){let Ve;e[92]!==i?(Ve=i("settings.agents.page.section.toolPermissions"),e[92]=i,e[93]=Ve):Ve=e[93];let Z;e[94]!==i?(Z=i("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=i,e[95]=Z):Z=e[95];let pe;e[96]!==Z?(pe=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Z}),e[96]=Z,e[97]=pe):pe=e[97];let Oe;e[98]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>A(Hp),e[98]=Oe):Oe=e[98];let Ee;e[99]!==i?(Ee=i("settings.agents.page.permissionsEditor.actions.retry"),e[99]=i,e[100]=Ee):Ee=e[100];let Ye;e[101]!==Ee?(Ye=s.jsx(G,{variant:"outline",size:"xs",onClick:Oe,children:Ee}),e[101]=Ee,e[102]=Ye):Ye=e[102];let ne;e[103]!==pe||e[104]!==Ye?(ne=s.jsxs("div",{className:"flex items-center gap-3",children:[pe,Ye]}),e[103]=pe,e[104]=Ye,e[105]=ne):ne=e[105];let we;e[106]!==Ve||e[107]!==ne?(we=s.jsx(qe,{title:Ve,children:ne}),e[106]=Ve,e[107]=ne,e[108]=we):we=e[108],Me=we;break e}const lt=(Ve,Z,pe)=>{const Oe=u.keys[Ve]??Kp,Ee=Lp.has(Ve)||Oe.patterns.length>0,Ye=P[Ve]===!0;return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:Ee?()=>I(ne=>({...ne,[Ve]:!Ye})):void 0,className:Ie("flex min-w-0 items-center gap-1.5 text-left",!Ee&&"cursor-default"),"aria-expanded":Ee?Ye:void 0,children:[s.jsx(z,{name:Ye&&Ee?"arrow-down-s":"arrow-right-s",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",!Ee&&"opacity-0")}),s.jsx("span",{className:Nt,children:Z}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:Ve}),pe&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:pe}),Oe.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:J(ge(Ve))})}),Oe.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:i("settings.agents.page.permissionsEditor.ruleCount",{count:String(Oe.patterns.length)})})]}),Qe(Oe.effect,ne=>be(Ve,ne),i("settings.agents.page.permissionsEditor.keyAria",{key:Ve}))]}),Ye&&Ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[Oe.patterns.map((ne,we)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(We,{value:ne.pattern,onChange:nt=>me(Ve,we,nt.target.value,ne.effect,!1),placeholder:i("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ve}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(mn,{value:ne.effect,options:Le(),onChange:nt=>me(Ve,we,ne.pattern,nt,!0),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ve})}),s.jsx(G,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>$e(Ve,we),"aria-label":i("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]},we)),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>De(Ve),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),i("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},Ve)};se=qe,e[109]!==i?(he=i("settings.agents.page.section.toolPermissions"),e[109]=i,e[110]=he):he=e[110],ve="agents.permissions",e[111]!==i?(Fe=i("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=i,e[112]=Fe):Fe=e[112],Ke="space-y-4";let ot;e[113]!==i?(ot=i("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=i,e[114]=ot):ot=e[114];let bt;e[115]!==ot?(bt=s.jsx("span",{className:Nt,children:ot}),e[115]=ot,e[116]=bt):bt=e[116];let wt;e[117]!==i?(wt=i("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=i,e[118]=wt):wt=e[118];let jt;e[119]!==wt?(jt=s.jsx(qt,{children:wt}),e[119]=wt,e[120]=jt):jt=e[120];let vt;e[121]!==J||e[122]!==ge||e[123]!==u.global||e[124]!==i?(vt=u.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:J(ge("*"))})}),e[121]=J,e[122]=ge,e[123]=u.global,e[124]=i,e[125]=vt):vt=e[125];let Xe;e[126]!==bt||e[127]!==jt||e[128]!==vt?(Xe=s.jsxs("div",{className:"flex items-center gap-1.5",children:[bt,jt,vt]}),e[126]=bt,e[127]=jt,e[128]=vt,e[129]=Xe):Xe=e[129];const kt=u.global;let Re;e[130]!==i?(Re=i("settings.agents.page.permissionsEditor.defaultAria"),e[130]=i,e[131]=Re):Re=e[131],Be=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[Xe,Qe(kt,Se,Re,Ae)]}),ze=s.jsx("div",{children:L.map(Ve=>lt(Ve,Fp(Ve),null))}),_e=$.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/40 pt-3 pb-1",children:[s.jsx("span",{className:Nt,children:i("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(qt,{children:i("settings.agents.page.permissionsEditor.mcpInfo")})]}),$.map(Ve=>lt(Ve.key,Ve.server,oe(Ve.server)))]})}e[57]=J,e[58]=ge,e[59]=P,e[60]=w,e[61]=k,e[62]=$,e[63]=oe,e[64]=u.global,e[65]=u.keys,e[66]=$e,e[67]=Se,e[68]=be,e[69]=me,e[70]=i,e[71]=L,e[72]=se,e[73]=he,e[74]=ve,e[75]=Fe,e[76]=Ke,e[77]=Be,e[78]=ze,e[79]=_e,e[80]=Me}else se=e[72],he=e[73],ve=e[74],Fe=e[75],Ke=e[76],Be=e[77],ze=e[78],_e=e[79],Me=e[80];if(Me!==Symbol.for("react.early_return_sentinel"))return Me;let tt;e[132]===Symbol.for("react.memo_cache_sentinel")?(tt=Ne=>D(Ne.target.value),e[132]=tt):tt=e[132];let pt;e[133]!==xe?(pt=Ne=>{Ne.key==="Enter"&&(Ne.preventDefault(),xe())},e[133]=xe,e[134]=pt):pt=e[134];let ct;e[135]!==i?(ct=i("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=i,e[136]=ct):ct=e[136];let dt;e[137]!==j||e[138]!==pt||e[139]!==ct?(dt=s.jsx(We,{value:j,onChange:tt,onKeyDown:pt,placeholder:ct,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=j,e[138]=pt,e[139]=ct,e[140]=dt):dt=e[140];let ht;e[141]!==j?(ht=j.trim(),e[141]=j,e[142]=ht):ht=e[142];const Ue=!ht;let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=st):st=e[143];let ut;e[144]!==i?(ut=i("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=i,e[145]=ut):ut=e[145];let ye;e[146]!==xe||e[147]!==Ue||e[148]!==ut?(ye=s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:xe,disabled:Ue,children:[st,ut]}),e[146]=xe,e[147]=Ue,e[148]=ut,e[149]=ye):ye=e[149];let re;e[150]!==dt||e[151]!==ye?(re=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[dt,ye]}),e[150]=dt,e[151]=ye,e[152]=re):re=e[152];let Te;return e[153]!==se||e[154]!==he||e[155]!==ve||e[156]!==Fe||e[157]!==Ke||e[158]!==Be||e[159]!==ze||e[160]!==_e||e[161]!==re?(Te=s.jsxs(se,{title:he,settingsItem:ve,info:Fe,contentClassName:Ke,children:[Be,ze,_e,re]}),e[153]=se,e[154]=he,e[155]=ve,e[156]=Fe,e[157]=Ke,e[158]=Be,e[159]=ze,e[160]=_e,e[161]=re,e[162]=Te):Te=e[162],Te};function Up(t){return t.updateAgent}function zp(t){return t.fetchAgentPermissions}function $p(t){return t.loadMcpConfigs}function Bp(t){return{key:`${t.name}_*`,server:t.name}}function Vp(t){return t.key}function Hp(t){return t+1}const Po=t=>{const e=at.c(11),{legacy:a,path:n,className:r}=t,{t:i}=Ze();if(!a)return null;let l;e[0]!==r?(l=Ie("mb-4 flex items-start gap-1.5",ys,r),e[0]=r,e[1]=l):l=e[1];const d=n??void 0;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(z,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),e[2]=c):c=e[2];let h;e[3]!==i?(h=i("settings.common.legacyFormat.note"),e[3]=i,e[4]=h):h=e[4];let g;e[5]!==h?(g=s.jsx("span",{children:h}),e[5]=h,e[6]=g):g=e[6];let f;return e[7]!==l||e[8]!==d||e[9]!==g?(f=s.jsxs("p",{className:l,title:d,children:[c,g]}),e[7]=l,e[8]=d,e[9]=g,e[10]=f):f=e[10],f},qp=(t,e)=>{const a=Ln(e);return a?t.find(i=>i.id===a.providerId)?.models.find(i=>i.modelID===a.modelId)?.variants.map(i=>i.id)??[]:[]},Gp=()=>{const{t}=Ze(),e=it(xe=>xe.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,fetchAgentEntity:l,agentDraft:d,setAgentDraft:c,setSelectedAgent:h}=Wn($s(xe=>({selectedAgentName:xe.selectedAgentName,getAgentByName:xe.getAgentByName,createAgent:xe.createAgent,updateAgent:xe.updateAgent,fetchAgentEntity:xe.fetchAgentEntity,agentDraft:xe.agentDraft,setAgentDraft:xe.setAgentDraft,setSelectedAgent:xe.setSelectedAgent}))),g=Js(),f=Wn(xe=>Nc(xe,g)),p=a?n(a,g):null,u=!!(d&&d.name===a&&!p),v=u?"":p?.description?.trim()??"",w=u?"":p?.system?.trim()??"",[b,k]=o.useState(""),[m,S]=o.useState("user"),[P,I]=o.useState(""),[j,D]=o.useState("subagent"),[x,A]=o.useState(""),[R,C]=o.useState(""),[E,O]=o.useState(void 0),[F,N]=o.useState(void 0),[M,U]=o.useState(void 0),[K,W]=o.useState(""),[te,Q]=o.useState(!1),[H,_]=o.useState(null),V=o.useRef({}),X=o.useRef(null),$=o.useCallback(xe=>{X.current=xe},[]),ee=o.useRef(null),L=JSON.stringify([a,g,u]),Y=o.useRef(L);Y.current=L;const oe=o.useRef(null),de={description:P,mode:j,model:x,variant:R,steps:E,temperature:F,topP:M,system:K},ge=o.useRef(de);ge.current=de;const ce=o.useMemo(()=>qp(e,x),[x,e]),Se=ce.length>0,ie=R||"__default",be=Se,ae=o.useMemo(()=>R&&!ce.includes(R)?[R,...ce]:ce,[R,ce]);o.useEffect(()=>{if(!u||!d)return;oe.current=null;const xe=ci(d.model),Pe=d.name||"",J=d.scope||"user",se=d.description||"",he=d.mode||"subagent",ve=xe?`${xe.providerID}/${xe.modelID}`:"",Fe=xe?.variant||"",Ke=d.steps??void 0,Be=d.temperature??void 0,ze=d.top_p??void 0,_e=d.system||"";V.current={},_(null),k(Pe),S(J),I(se),D(he),A(ve),C(Fe),O(Ke),N(Be),U(ze),W(_e),ee.current={draftName:Pe,draftScope:J,description:se,mode:he,model:ve,variant:Fe,steps:Ke,temperature:Be,topP:ze,system:_e}},[d,u]),o.useEffect(()=>{if(u||!a)return;let xe=!1;return(async()=>{const Pe=await l(a,g);if(xe||Y.current!==L||!Pe)return;const J=Pe.config;V.current=J;const se=ci(J.model),he=J.request?.body,ve={draftName:"",draftScope:"user",description:J.description||"",mode:J.mode||p?.mode||"subagent",model:se?`${se.providerID}/${se.modelID}`:"",variant:se?.variant||"",steps:J.steps??void 0,temperature:he?.temperature,topP:he?.top_p,system:J.system||""},Fe=ee.current,Ke=ge.current,Be=Fe!==null&&(Ke.description!==Fe.description||Ke.mode!==Fe.mode||Ke.model!==Fe.model||Ke.variant!==Fe.variant||Ke.steps!==Fe.steps||Ke.temperature!==Fe.temperature||Ke.topP!==Fe.topP||Ke.system!==Fe.system);_({legacy:Pe.legacy===!0,path:Pe.path,source:Pe.source}),!(oe.current===L&&Be)&&(oe.current=L,I(ve.description),D(ve.mode),A(ve.model),C(ve.variant),O(ve.steps),N(ve.temperature),U(ve.topP),W(ve.system),ee.current=ve)})(),()=>{xe=!0}},[l,u,p,a,g,L]);const me=o.useCallback(xe=>{const Pe=Ln(x.trim()),J=Pe?Sc({providerID:Pe.providerId,modelID:Pe.modelId,variant:R.trim()||void 0}):null,se=V.current.request,he={...se?.body};F===void 0?delete he.temperature:he.temperature=F,M===void 0?delete he.top_p:he.top_p=M;const ve=se?.headers,Fe={};ve&&Object.keys(ve).length>0&&(Fe.headers=ve),Object.keys(he).length>0&&(Fe.body=he);const Ke=P.trim(),Be=K.trim(),ze={name:xe,mode:j,model:J,steps:E??null,system:Be||(u?void 0:null),request:Object.keys(Fe).length>0?Fe:null};return Ke&&(ze.description=Ke),u&&m&&(ze.scope=m),u&&d?.permissions?.length&&(ze.permissions=d.permissions),ze},[d,P,m,u,j,x,E,K,F,M,R]),je=o.useCallback(async()=>{const xe=ee.current,Pe=a?.trim();if(u||!xe||!Pe)return Os;const J=X.current?await X.current():Os;if(P===xe.description&&j===xe.mode&&x===xe.model&&R===xe.variant&&E===xe.steps&&F===xe.temperature&&M===xe.topP&&K===xe.system||!J.ok)return J;const he=me(Pe);return(await i(Pe,he,g)).ok?(Y.current!==L||(V.current={...V.current,model:he.model,system:he.system??void 0,steps:he.steps,request:he.request??void 0},ee.current={...xe,description:P,mode:j,model:x,variant:R,steps:E,temperature:F,topP:M,system:K}),In):hs(t("settings.agents.page.toast.updateFailed"))},[me,P,u,j,x,a,L,g,E,K,t,F,M,i,R]),De=Ja(je),{requestSave:ue}=De,$e=async()=>{const xe=b.trim().replace(/\s+/g,"-");if(!xe){B.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(f.some(Pe=>Pe.name===xe)){B.error(t("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{(await r(me(xe),g)).ok?(c(null),B.success(t("settings.agents.page.toast.created"))):B.error(t("settings.agents.page.toast.createFailed"))}catch(Pe){console.error("Error creating agent:",Pe);const J=Pe instanceof Error&&Pe.message?Pe.message:t("settings.agents.page.toast.saveUnexpectedError");B.error(J)}finally{Q(!1)}},Ge=()=>{c(null),h(null)};return a?s.jsxs(ns,{title:u?t("settings.agents.page.title.new"):a,description:t(u?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:De.onBlurCapture,children:[!u&&H&&s.jsx(Po,{legacy:H.legacy,path:H.path}),!u&&H?.source==="none"&&s.jsxs("p",{className:`mb-4 flex items-start gap-1.5 ${ys}`,children:[s.jsx(z,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),s.jsx("span",{children:t("settings.agents.page.runtimeProvided.note")})]}),s.jsxs(qe,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[u&&s.jsxs(Ct,{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(We,{value:b,onChange:xe=>k(xe.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:m,onValueChange:xe=>S(xe),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Ot,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:P,onChange:xe=>I(xe.target.value),placeholder:v||t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Ot,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(mn,{"aria-label":t("settings.agents.page.field.mode"),value:j,onChange:xe=>{D(xe),ue()},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(qe,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ct,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ca,{providerId:Ln(x)?.providerId??"",modelId:Ln(x)?.modelId??"",onChange:(xe,Pe)=>{A(xe&&Pe?`${xe}/${Pe}`:""),C(""),ue()},className:Ws})}),s.jsx(Ct,{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:be?s.jsxs(Tt,{value:ie,onValueChange:xe=>{C(xe==="__default"?"":xe),ue()},children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:xe=>xe==="__default"?t("chat.modelControls.default"):xe})}),s.jsxs(At,{children:[s.jsx(mt,{value:"__default",children:t("chat.modelControls.default")}),ae.map(xe=>s.jsx(mt,{value:xe,children:xe},xe))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(We,{value:R,onChange:xe=>C(xe.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!x&&!R,className:"h-8 w-40 rounded-md px-3"}),R&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{C(""),ue()},className:ps,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ct,{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(gs,{value:F,fallbackValue:.7,onValueChange:N,onClear:()=>{N(void 0),ue()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:vs}),F!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{N(void 0),ue()},className:ps,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{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(gs,{value:M,fallbackValue:.9,onValueChange:U,onClear:()=>{U(void 0),ue()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:vs}),M!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{U(void 0),ue()},className:ps,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(gs,{value:E,fallbackValue:20,onValueChange:O,onClear:()=>{O(void 0),ue()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:vs}),E!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{O(void 0),ue()},className:ps,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(qe,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:K,onChange:xe=>W(xe.target.value),placeholder:w||t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent"})}),!u&&p&&s.jsx(_p,{agent:p,registerSave:$,requestSave:ue}),u&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(G,{onClick:()=>{$e()},disabled:te||!b.trim(),size:"xs",className:"!font-normal",children:t(te?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:Ge,disabled:te,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})};function Wp(t,e){return t.kind==="file"?t.content:e??""}const Jp=Ts({content:Dt(),exists:Co(),path:Dt().min(1).optional()}),Qp=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Yp=t=>t.length>0&&!t.endsWith(`
2
+ import{R as o,j as s,f as at,r as et}from"./vendor-react-BUCujlKS.js";import{f as Ze,B as G,I as z,o as yn,bj as Qn,t as B,O as Ld,g$ as Kd,e$ as qe,h0 as St,g as za,eK as Sc,b as rn,T as fa,h as Ie,au as _d,h1 as Ir,h2 as Ud,cl as zt,ck as Pt,cn as mt,cm as At,cj as Tt,eR as Wn,h3 as Cc,h4 as zd,h5 as Ua,h6 as Pn,c8 as bs,c2 as _t,c3 as Ut,c4 as Bt,c5 as Vt,c6 as Ht,c7 as as,X as We,h7 as mi,av as _n,bh as wn,at as Un,as as zn,h8 as Zr,h9 as Vi,ad as Jn,ac as un,f5 as qt,ha as mn,hb as go,hc as ys,l as it,hd as ci,fm as Ln,he as Ic,fj as Ct,fg as $t,hf as Ot,co as As,ea as ca,fi as Ws,fk as an,hg as gs,ef as hs,hh as vs,cW as gt,hi as Pc,hj as $d,hk as Bd,hl as pi,hm as Vd,hn as ks,e_ as Ps,ho as sn,gj as Ga,gp as nn,hp as $a,hq as Ac,hr as ho,eb as fo,ah as Ba,hs as Xr,ht as zo,hu as Hd,cg as kn,cr as Nn,ch as Sn,hv as $o,hw as Cn,hx as Wt,hy as xo,ae as nr,af as ar,ag as bo,hz as vo,hA as sa,hB as Tc,hC as On,a7 as gi,cw as yo,hD as Bo,ay as qd,cp as Gd,da as Wd,U as Jd,V as Qd,W as Yd,_ as jo,hE as Zd,hF as Xd,ce as eu,cq as eo,hG as Ec,fl as Dc,P as na,hH as Rs,a6 as tu,hI as su,n as rs,ex as Ji,y as Mc,x as nu,i as au,j as iu,ey as ru,p as ou,hJ as lu,hK as cu,hL as Vo,eg as Rc,hM as du,hN as Pr,hO as Ho,hP as uu,hQ as mu,hR as pu,hS as gu,gd as Qi,hT as cs,hU as ws,dh as Oc,bZ as Fc,di as Lc,b_ as Hs,hV as Fn,hW as wo,aH as Gn,aI as Ma,hX as en,hY as Rn,dv as Kc,hZ as _c,h_ as Uc,h$ as hu,eZ as fu,eY as xu,i0 as to,eI as bu,i1 as aa,i2 as Ms,i3 as Vs,g6 as ia,i4 as Ns,i5 as vu,i6 as qo,i7 as zc,i8 as ra,i9 as yu,ia as ju,R as $c,db as wu,d5 as ku,d6 as Nu,cJ as Su,eT as Cu,d7 as Iu,d1 as Pu,bp as Au,ib as Wa,ff as Ra,ic as Go,id as Oa,ie as Fa,b$ as ua,ig as Tu,ih as Eu,ii as Du,ij as Mu,ik as Ar,il as Wo,im as Ru,io as Ou,ip as Fu,iq as Lu,ir as Jo,z as Ku,m as Qo,dz as _u,is as Uu,it as Tr,iu as Yo,eC as zu,iv as ir,iw as $u,ix as Bu,iy as Vu,iz as Hu,iA as qu,iB as Er,cX as Gu,c0 as Bc,aB as Hn,aC as Wu}from"./useAppFontEffects-BWQZ5DeI.js";import{h as Nt,i as ko,u as fe,P as fs,dG as Ju,dH as Zo,v as ft,aF as An,C as Gs,a as jn,F as ls,Q as Xo,cN as el,cU as tl,V as Za,p as Qu,dI as Yu,k as Zu,cM as Ka,dJ as Xu,an as em,cR as tm,dK as sm,dL as nm,s as am,e as hi,cS as im,H as fi,dM as Vc,$ as rm,dN as om,a4 as Hc,aE as os,dO as qc,bb as Gc,y as Va,b4 as Wc,ag as lm,ah as cm,aO as No,dP as dm,z as rr,_ as um,q as sl,aT as nl,bf as Di,aU as mm,dQ as pm,ac as da,dR as gm,dS as al,dF as il,dT as rl,aR as ol,dU as hm,dV as fm,dW as xm,dX as bm,dY as ll,b as vm,dZ as ym,d_ as jm,d$ as wm,e0 as km,e1 as Nm,e2 as Sm,ay as Cm}from"./index-CHfphYL3.js";import{u as Im,X as cl,aq as Pm,ar as Am,as as Tm,Z as ma,$ as pa,a0 as ga,a1 as ha,m as So,at as oa,a5 as Em,z as Is,au as Dm,ao as Mm,a3 as Rm,av as _a,aw as Jc,a2 as Om,a4 as Fm}from"./runtimeEndpointReset-5r0hkd-2.js";import{u as $s,c as Lm}from"./vendor-zustand-BAGL70zf.js";import{o as Ts,s as Dt,b as Co,l as Km,r as Kn,c as so,a as xa,_ as Io,u as no}from"./vendor-zod-BSoePkpP.js";import{s as _m,p as Um}from"./vendor-yaml-3778uTud.js";import{c as dl,s as zm,C as ul,P as $m}from"./shikiHighlight-BSUEa3yF.js";import{getResolvedShikiTheme as Bm}from"./appThemeRegistry-aHUNHoqP.js";import{E as ml}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Qc}from"./vendor-qrcode-DTJ12-WC.js";import{u as Dr,s as Vm,d as Hm,b as qm,A as Gm,c as Wm,e as Jm,f as Qm,h as Ym,i as Mr,j as Zm}from"./PluginPane-BEPUWVho.js";import{toast as Ha}from"./vendor-sonner-DFyL3AvE.js";import{s as Xm}from"./vendor-strip-json-comments-5dJlOkP1.js";import{Y as ep,U as tp,X as sp,W as np,V as ap}from"./vendor-base-ui-CsXYnR5c.js";import{_ as ip}from"./vendor-vite-runtime-DD1OZmLC.js";const pl=()=>{const{t}=Ze(),[e,a]=o.useState(null);o.useEffect(()=>{let r=!1;const i=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const d=await Nt("/api/system/info",{signal:i?.signal,headers:{Accept:"application/json"}});if(!d.ok)return;const c=await d.json().catch(()=>null);if(!c||r)return;const h=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,p=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:h,tunnelUrl:p})}catch{}})(),()=>{r=!0,i?.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(r=>s.jsxs(G,{type:"button",variant:"outline",size:"sm",title:r.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{yn(r.url)},children:[s.jsx(z,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:r.url})]},r.key))})},gl="https://github.com/openchamber/openchamber",rp="https://discord.gg/ZYRSdnwwKA",hl="https://x.com/openchamber_dev",op=800,lp={info:null,checking:!1,available:!1,error:null};function cp(t){const e=at.c(5),[a,n]=o.useState(lp);let r;e[0]!==t?(r=async()=>{if(t){n(dp);try{const d=await Pm();n({info:d,checking:!1,available:d.available,error:null})}catch(d){const c=d;n({info:null,checking:!1,available:!1,error:c instanceof Error?c.message:String(c)})}}},e[0]=t,e[1]=r):r=e[1];const i=r;let l;return e[2]!==i||e[3]!==a?(l={...a,check:i},e[2]=i,e[3]=a,e[4]=l):l=e[4],l}function dp(t){return{...t,checking:!0,error:null}}function up(t){const e=at.c(11),[a,n]=o.useState(null);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"idle"},e[0]=r):r=e[0];const[i,l]=o.useState(r);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=async()=>{try{const b=await Am();return n(b),b}catch{return null}},e[1]=d):d=e[1];const c=d;let h,p;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{c()},p=[c],e[2]=h,e[3]=p):(h=e[2],p=e[3]),o.useEffect(h,p);let f;e[4]!==t?(f=async()=>{l({kind:"upgrading"});try{const b=await Tm(t);l({kind:"installed",version:b})}catch(b){const k=b;l({kind:"failed",error:k instanceof Error?k.message:t})}},e[4]=t,e[5]=f):f=e[5];const m=f;let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=async b=>{await b().catch(mp);const k=await c();k?.currentVersion&&l(g=>g.kind!=="installed"||g.version&&g.version.replace(/^v/,"")!==k.currentVersion?g:{kind:"idle"})},e[6]=u):u=e[6];const v=u;let w;return e[7]!==i||e[8]!==a||e[9]!==m?(w={status:a,phase:i,refresh:c,upgrade:m,reloadAfterUpgrade:v},e[7]=i,e[8]=a,e[9]=m,e[10]=w):w=e[10],w}function mp(){}function pp(t){const[e,a]=o.useState(null);return o.useEffect(()=>{if(!t)return;let n=!1;return ip(async()=>{const{App:r}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:r}},__vite__mapDeps([0,1,2])).then(({App:r})=>r.getInfo()).then(r=>{n||a(r.version.trim()||null)}).catch(()=>{}),()=>{n=!0}},[t]),e}const Yc=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=Ze(),[a,n]=o.useState(t),[r,i]=o.useState(!1),[l,d]=o.useState(null),c=Im($s(F=>({info:F.info,checking:F.checking,available:F.available,error:F.error,downloading:F.downloading,downloaded:F.downloaded,progress:F.progress,runtimeType:F.runtimeType,checkForUpdates:F.checkForUpdates,downloadUpdate:F.downloadUpdate,restartToUpdate:F.restartToUpdate}))),{isMobile:h}=Qn(),p=o.useMemo(()=>ko(),[]),f=cp(p),m=pp(p),u=p?{info:f.info,checking:f.checking,available:f.available,error:f.error,checkForUpdates:f.check,runtimeType:"web"}:{info:c.info,checking:c.checking,available:c.available,error:c.error,checkForUpdates:c.checkForUpdates,runtimeType:c.runtimeType},v=l||u.info?.currentVersion||"unknown",w=up(e("opencodeUpdate.toast.failed.description")),b=w.status?.currentVersion??null,k=w.phase.kind==="installed"?null:w.status?.availableVersion??null,[g,I]=o.useState(!1),C=(()=>{const F=u.info?.version||"";return p?u.info?.packageManager==="electron"?e("settings.openchamber.about.actions.updateDesktopToVersion",{version:F}):e("settings.openchamber.about.actions.updateServerToVersion",{version:F}):e("settings.openchamber.about.actions.updateOpenChamberToVersion",{version:F})})(),P=u.available&&u.info?.installBlocked==="service-manager",j=u.info?.updateCommand||"openchamber update",T=()=>{u.checkForUpdates(),w.refresh()},x=async()=>{(await za(j)).ok&&(I(!0),setTimeout(()=>I(!1),2e3))},A=()=>{w.reloadAfterUpgrade(async()=>{await Sc({message:e("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})})},M=P?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.serviceManagerUpdate",{version:u.info?.version||""})}),s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-elevated/50 p-1 pl-3",children:[s.jsx("code",{className:"flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm text-foreground",children:j}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{x()},"aria-label":e(g?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:s.jsx(z,{name:g?"check":"clipboard",className:"size-4"})})]})]}):null,S=(()=>{const{phase:F}=w;if(F.kind==="installed")return s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:F.version?e("settings.openchamber.about.openCode.installedVersion",{version:F.version}):e("settings.openchamber.about.openCode.installed")}),s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:A,children:e("opencodeUpdate.toast.actions.reload")})]});if(!k)return null;if(!w.status?.supported)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.openCode.manualUpdate",{version:k})});const N=F.kind==="upgrading";return s.jsxs("div",{className:"space-y-2",children:[s.jsxs(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{w.upgrade()},disabled:N,children:[s.jsx(z,{name:N?"loader":"download",className:N?"size-4 animate-spin":"size-4"}),N?e("opencodeUpdate.toast.upgrading.title"):e("settings.openchamber.about.actions.updateOpenCodeToVersion",{version:k})]}),F.kind==="failed"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:F.error})]})})();o.useEffect(()=>{let F=!1;return(async()=>{try{const R=await Nt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!R.ok)return;const U=await R.json().catch(()=>null),K=typeof U?.openchamberVersion=="string"&&U.openchamberVersion.trim().length>0?U.openchamberVersion.trim():null;F||d(K)}catch{F||d(null)}})(),()=>{F=!0}},[]);const D=o.useRef(!1);o.useEffect(()=>{if(u.checking)i(!0),D.current=!0;else if(r){const F=setTimeout(()=>{i(!1),D.current&&!u.available&&!u.error&&(B.success(e(p?"settings.openchamber.about.toast.serverLatestVersion":"settings.openchamber.about.toast.latestVersion")),D.current=!1)},op);return()=>clearTimeout(F)}},[e,p,u.checking,r,u.available,u.error]);const O=u.checking||r;return h?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(Ld,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Kd}`,children:"OpenChamber"}),s.jsx("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:p?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:v})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:b||e("settings.openchamber.about.state.unknown")})}),m&&s.jsx("p",{children:e("settings.openchamber.about.native.appVersion",{version:m})})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:v})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:b||e("settings.openchamber.about.state.unknown")})})]})}),s.jsx(pl,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!u.available&&!u.error&&s.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:T,disabled:O,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[O?s.jsx(z,{name:"loader",className:"size-4 animate-spin"}):s.jsx(z,{name:"refresh",className:"size-4"}),e(O?"settings.openchamber.about.state.checking":p?"settings.openchamber.about.actions.checkServerForUpdates":"settings.openchamber.about.actions.checkForUpdates")]}),!O&&u.available&&!P&&s.jsxs(G,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(z,{name:"download",className:"size-4"}),C]})]}),M,S&&s.jsx("div",{className:"flex justify-center text-center",children:S}),u.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:u.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:gl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:rp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:hl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(cl,{open:a,onOpenChange:n,info:u.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:u.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:u.runtimeType})]}):s.jsxs(qe,{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:St,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:v})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:St,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:b||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[u.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(z,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!u.checking&&u.available&&!P&&s.jsxs(G,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(z,{name:"download",className:"h-4 w-4 mr-1"}),C]}),!u.checking&&!u.available&&!u.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(G,{size:"sm",variant:"outline",onClick:T,disabled:u.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),M&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:M}),S&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:S}),u.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:u.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:St,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(pl,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:gl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:hl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(cl,{open:a,onOpenChange:n,info:u.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:u.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:u.runtimeType})]})},gp=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,Js=()=>{const t=at.c(4),e=fe(hp),a=rn(fp),n=rn(xp);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=gp(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function hp(t){return t.settingsProjectPath}function fp(t){return t.projects}function xp(t){return t.activeProjectId}const bp=t=>[...t].sort((e,a)=>(e.label||e.path).localeCompare(a.label||a.path)),xi=t=>{const e=at.c(75),{className:a}=t,{t:n}=Ze(),{currentTheme:r}=fa(),i=fe(vp),[l,d]=o.useState(!1),c=rn(yp),h=Js(),p=fe(jp),f=fs();let m;e[0]!==c?(m=bp(c),e[0]=c,e[1]=m):m=e[1];const u=m;let v;e[2]!==h||e[3]!==u?(v=u.find(O=>O.path===h)??u[0]??null,e[2]=h,e[3]=u,e[4]=v):v=e[4];const w=v;if(f||!w)return null;let b;e[5]!==p||e[6]!==u?(b=O=>{const F=u.find(N=>N.id===O);F&&p(F.path)},e[5]=p,e[6]=u,e[7]=b):b=e[7];const k=b;if(i){let O;e[8]!==a?(O=Ie(a),e[8]=a,e[9]=O):O=e[9];let F;e[10]!==n?(F=n("settings.shared.projectSelector.switchProjectAria"),e[10]=n,e[11]=F):F=e[11];let N;e[12]!==n?(N=n("settings.shared.projectSelector.switchProjectTitle"),e[12]=n,e[13]=N):N=e[13];let R,U;e[14]===Symbol.for("react.memo_cache_sentinel")?(R=()=>d(!0),U=Ie(_d({size:"touch"}),"w-full min-w-0"),e[14]=R,e[15]=U):(R=e[14],U=e[15]);let K;e[16]!==w||e[17]!==r?(K=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(Ir,{project:w,theme:r})}),e[16]=w,e[17]=r,e[18]=K):K=e[18];let W;e[19]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=W):W=e[19];let te;e[20]!==l||e[21]!==F||e[22]!==N||e[23]!==U||e[24]!==K?(te=s.jsxs("button",{type:"button","aria-label":F,title:N,"aria-haspopup":"dialog","aria-expanded":l,onClick:R,className:U,children:[K,W]}),e[20]=l,e[21]=F,e[22]=N,e[23]=U,e[24]=K,e[25]=te):te=e[25];let Q;e[26]!==te||e[27]!==O?(Q=s.jsx("div",{className:O,children:te}),e[26]=te,e[27]=O,e[28]=Q):Q=e[28];let H;e[29]===Symbol.for("react.memo_cache_sentinel")?(H=()=>d(!1),e[29]=H):H=e[29];const _=w.id;let V;e[30]!==n?(V=n("settings.shared.projectSelector.sheetTitle"),e[30]=n,e[31]=V):V=e[31];let X;e[32]!==n?(X=n("settings.shared.projectSelector.searchPlaceholder"),e[32]=n,e[33]=X):X=e[33];let $;e[34]!==w.id||e[35]!==r||e[36]!==k||e[37]!==l||e[38]!==u||e[39]!==V||e[40]!==X?($=s.jsx(Ud,{open:l,onClose:H,projects:u,selectedProjectId:_,onSelectProject:k,theme:r,title:V,searchPlaceholder:X}),e[34]=w.id,e[35]=r,e[36]=k,e[37]=l,e[38]=u,e[39]=V,e[40]=X,e[41]=$):$=e[41];let ee;return e[42]!==Q||e[43]!==$?(ee=s.jsxs(s.Fragment,{children:[Q,$]}),e[42]=Q,e[43]=$,e[44]=ee):ee=e[44],ee}let g;e[45]!==a?(g=Ie(a),e[45]=a,e[46]=g):g=e[46];const I=w.id;let C;e[47]!==k?(C=O=>{O&&k(O)},e[47]=k,e[48]=C):C=e[48];let P;e[49]!==n?(P=n("settings.shared.projectSelector.switchProjectAria"),e[49]=n,e[50]=P):P=e[50];let j;e[51]!==n?(j=n("settings.shared.projectSelector.switchProjectTitle"),e[51]=n,e[52]=j):j=e[52];let T;e[53]!==w||e[54]!==r?(T=s.jsx(zt,{children:s.jsx(Ir,{project:w,theme:r})}),e[53]=w,e[54]=r,e[55]=T):T=e[55];let x;e[56]!==P||e[57]!==j||e[58]!==T?(x=s.jsx(Pt,{size:"settings",className:"w-full","aria-label":P,title:j,children:T}),e[56]=P,e[57]=j,e[58]=T,e[59]=x):x=e[59];let A;if(e[60]!==r||e[61]!==u){let O;e[63]!==r?(O=F=>s.jsx(mt,{value:F.id,className:"max-w-[24rem] truncate",children:s.jsx(Ir,{project:F,theme:r})},F.id),e[63]=r,e[64]=O):O=e[64],A=u.map(O),e[60]=r,e[61]=u,e[62]=A}else A=e[62];let M;e[65]!==A?(M=s.jsx(At,{fitContent:!0,children:A}),e[65]=A,e[66]=M):M=e[66];let S;e[67]!==w.id||e[68]!==x||e[69]!==M||e[70]!==C?(S=s.jsxs(Tt,{value:I,onValueChange:C,children:[x,M]}),e[67]=w.id,e[68]=x,e[69]=M,e[70]=C,e[71]=S):S=e[71];let D;return e[72]!==S||e[73]!==g?(D=s.jsx("div",{className:g,children:S}),e[72]=S,e[73]=g,e[74]=D):D=e[74],D};function vp(t){return t.isMobile}function yp(t){return t.projects}function jp(t){return t.setSettingsProjectPath}function wp(t,e){return`opencode:sidebar-group:${t}:${e}`}const ao=t=>{const e=at.c(33),{label:a,count:n,storageKey:r,defaultExpanded:i,children:l}=t,d=i===void 0?!0:i;let c;e[0]!==a||e[1]!==r?(c=wp(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const h=c,p=o.useId();let f;e[3]!==d||e[4]!==h?(f=()=>{try{const S=localStorage.getItem(h);if(S!==null)return S==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=f):f=e[5];const[m,u]=et.useState(f);let v,w;e[6]!==m||e[7]!==h?(v=()=>{try{localStorage.setItem(h,String(m))}catch{}},w=[h,m],e[6]=m,e[7]=h,e[8]=v,e[9]=w):(v=e[8],w=e[9]),et.useEffect(v,w);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>u(kp),e[10]=b):b=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=Ie("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-ring"),e[11]=k):k=e[11];const g=!m&&"-rotate-90";let I;e[12]!==g?(I=Ie("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=I):I=e[13];let C;e[14]!==I?(C=s.jsx(z,{name:"arrow-down-s",className:I}),e[14]=I,e[15]=C):C=e[15];let P;e[16]!==a?(P=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=P):P=e[17];let j;e[18]!==n?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=j):j=e[19];let T;e[20]!==p||e[21]!==m||e[22]!==C||e[23]!==P||e[24]!==j?(T=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":m,"aria-controls":p,className:k,children:[C,P,j]}),e[20]=p,e[21]=m,e[22]=C,e[23]=P,e[24]=j,e[25]=T):T=e[25];const x=!m;let A;e[26]!==l||e[27]!==p||e[28]!==x?(A=s.jsx("div",{id:p,hidden:x,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]=p,e[28]=x,e[29]=A):A=e[29];let M;return e[30]!==T||e[31]!==A?(M=s.jsxs("div",{children:[T,A]}),e[30]=T,e[31]=A,e[32]=M):M=e[32],M};function kp(t){return!t}const Np=({onItemSelect:t})=>{const{t:e}=Ze(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,d]=o.useState(null),[c,h]=o.useState(null),[p,f]=o.useState(!1),[m,u]=o.useState(null),{selectedAgentName:v,setSelectedAgent:w,setAgentDraft:b,createAgent:k,deleteAgent:g,loadAgents:I,fetchAgentEntity:C}=Wn($s(H=>({selectedAgentName:H.selectedAgentName,setSelectedAgent:H.setSelectedAgent,setAgentDraft:H.setAgentDraft,createAgent:H.createAgent,deleteAgent:H.deleteAgent,loadAgents:H.loadAgents,fetchAgentEntity:H.fetchAgentEntity}))),P=Js(),j=Wn(H=>Cc(H,P));o.useEffect(()=>{I(P)},[I,P]);const T="bg-background",x=()=>{const H="new-agent";let _=H,V=1;for(;j.some(X=>X.name===_);)_=`${H}-${V}`,V++;b({name:_,scope:"user"}),w(_),t?.()},A=async H=>{if(Ua(H)){B.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(H),h("delete")},M=async H=>{Ua(H)&&(d(H),h("reset"))},S=()=>{d(null),h(null)},D=async()=>{if(!(!l||!c)){f(!0);try{(await g(l.name,l.scope,P)).ok?(c==="delete"?B.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):B.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),S()):c==="delete"?B.error(e("settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(H){const _=H instanceof Error?H.message:"",V=/built-in|not deletable|not found/i.test(_);c==="delete"?B.error(e(V?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}f(!1)}},O=async H=>{const _=H.name;let V=1,X=`${_}-copy`;for(;j.some(Y=>Y.name===X);)V++,X=`${_}-copy-${V}`;const $=H,ee=await C(H.name,P);if(!ee){B.error(e("settings.agents.sidebar.toast.renameFailed"));return}const L=ee.config.request?.body;b({name:X,scope:ee.scope??$.scope??"user",description:ee.config.description??void 0,model:ee.config.model??null,system:ee.config.system??void 0,steps:ee.config.steps??void 0,temperature:L?.temperature,top_p:L?.top_p,mode:ee.config.mode??$.mode,permissions:ee.config.permissions??void 0}),w(X),t?.()},F=H=>{i(H.name),n(H)},N=async()=>{if(!a)return;const H=r.trim().replace(/\s+/g,"-");if(!H){B.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(H===a.name){n(null);return}if(j.some($=>$.name===H)){B.error(e("settings.agents.sidebar.toast.agentExists"));return}const _=a,V=await C(a.name,P);if(!V){B.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await k({...V.config,name:H,scope:V.scope??_.scope},P)).ok?(await g(a.name,_.scope,P)).ok?(B.success(e("settings.agents.sidebar.toast.agentRenamed",{name:H})),w(H)):B.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):B.error(e("settings.agents.sidebar.toast.renameFailed")),n(null)},R=H=>{switch(H){case"primary":return s.jsx(z,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(z,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(z,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},U=j.filter(H=>!zd(H)),K=U.filter(Ua),W=U.filter(H=>!Ua(H)),{groupedCustomAgents:te,ungroupedCustomAgents:Q}=et.useMemo(()=>{const H={},_=[];for(const X of W){const $=X;$.group?(H[$.group]||(H[$.group]=[]),H[$.group].push(X)):_.push(X)}return{groupedCustomAgents:Object.keys(H).sort((X,$)=>X.localeCompare($)).map(X=>({name:X,agents:H[X]})),ungroupedCustomAgents:_}},[W]);return s.jsxs("div",{className:Ie("flex h-full flex-col",T),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Pn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(xi,{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:U.length})}),s.jsx(G,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:x,children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:U.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[K.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")}),K.map(H=>s.jsx(Rr,{agent:H,isSelected:v===H.name,onSelect:()=>{w(H.name),t?.()},onReset:()=>M(H),onDuplicate:()=>{O(H)},getAgentModeIcon:R,isMenuOpen:m===H.name,onMenuOpenChange:_=>u(_?H.name:null)},H.name))]}),W.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),te.map(({name:H,agents:_})=>s.jsx(ao,{label:H,count:_.length,storageKey:"agents",children:_.map(V=>s.jsx(Rr,{agent:V,isSelected:v===V.name,onSelect:()=>{w(V.name),t?.()},onRename:()=>F(V),onDelete:()=>A(V),onDuplicate:()=>{O(V)},getAgentModeIcon:R,isMenuOpen:m===V.name,onMenuOpenChange:X=>u(X?V.name:null)},V.name))},H)),Q.map(H=>s.jsx(Rr,{agent:H,isSelected:v===H.name,onSelect:()=>{w(H.name),t?.()},onRename:()=>F(H),onDelete:()=>A(H),onDuplicate:()=>{O(H)},getAgentModeIcon:R,isMenuOpen:m===H.name,onMenuOpenChange:_=>u(_?H.name:null)},H.name))]})]})}),s.jsx(_t,{open:l!==null&&c!==null,onOpenChange:H=>{!H&&!p&&S()},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Ht,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:S,disabled:p,children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:D,disabled:p,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(_t,{open:a!==null,onOpenChange:H=>!H&&n(null),children:s.jsxs(Ut,{children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(We,{value:r,onChange:H=>i(H.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:H=>{H.key==="Enter"&&N()}}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:N,children:e("settings.common.actions.rename")})]})]})})]})},Rr=t=>{const e=at.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:p,onMenuOpenChange:f}=t,{t:m}=Ze(),u=a;let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=mi(),e[0]=v):v=e[0];const w=v,[b,k]=o.useState(!1);let g;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==m?(g=H=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),s.jsxs(H,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),l&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),m("settings.common.actions.reset")]}),i&&s.jsxs(H,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=m,e[6]=g):g=e[6];const I=g,C=n?"bg-interactive-selection":"hover:bg-interactive-hover";let P;e[7]!==C?(P=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",C),e[7]=C,e[8]=P):P=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=w?void 0:H=>{H.preventDefault(),k(!0)},e[9]=j):j=e[9];let T;e[10]!==P?(T=s.jsx("div",{className:P,onContextMenu:j}),e[10]=P,e[11]=T):T=e[11];let x;e[12]!==a.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=x):x=e[13];let A;e[14]!==a.mode||e[15]!==h?(A=h(a.mode),e[14]=a.mode,e[15]=h,e[16]=A):A=e[16];let M;e[17]!==a||e[18]!==u.scope||e[19]!==m?(M=(u.scope||Ua(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:Ua(a)?m("settings.agents.sidebar.badge.system"):u.scope}),e[17]=a,e[18]=u.scope,e[19]=m,e[20]=M):M=e[20];let S;e[21]!==x||e[22]!==A||e[23]!==M?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,A,M]}),e[21]=x,e[22]=A,e[23]=M,e[24]=S):S=e[24];let D;e[25]!==a.description?(D=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=D):D=e[26];let O;e[27]!==r||e[28]!==S||e[29]!==D?(O=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-ring",tabIndex:0,children:[S,D]}),e[27]=r,e[28]=S,e[29]=D,e[30]=O):O=e[30];let F;e[31]!==f?(F=H=>{H&&k(!1),f(H)},e[31]=f,e[32]=F):F=e[32];let N;e[33]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=N):N=e[33];let R;e[34]!==I?(R=s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:I(wn)}),e[34]=I,e[35]=R):R=e[35];let U;e[36]!==p||e[37]!==F||e[38]!==R?(U=s.jsxs(zn,{open:p,onOpenChange:F,children:[N,R]}),e[36]=p,e[37]=F,e[38]=R,e[39]=U):U=e[39];let K;e[40]!==O||e[41]!==U?(K=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,U]}),e[40]=O,e[41]=U,e[42]=K):K=e[42];let W;e[43]!==K||e[44]!==T?(W=s.jsx(ga,{render:T,children:K}),e[43]=K,e[44]=T,e[45]=W):W=e[45];let te;e[46]!==I?(te=s.jsx(ma,{className:"w-fit min-w-20",children:I(pa)}),e[46]=I,e[47]=te):te=e[47];let Q;return e[48]!==b||e[49]!==W||e[50]!==te?(Q=s.jsxs(ha,{open:b,onOpenChange:k,children:[W,te]}),e[48]=b,e[49]=W,e[50]=te,e[51]=Q):Q=e[51],Q},ns=t=>{const e=at.c(22),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:d,description:c,headerEnd:h,showSaveStatus:p,onBlurCapture:f}=t,m=p===void 0?!1:p,u=i!=null||c!=null||h!=null||m,v=typeof i=="string"||typeof i=="number",w=l!=null||d!=null;let b;e[0]!==r?(b=Ie("h-full overlay-scrollbar-wrapper--stable-gutter",r),e[0]=r,e[1]=b):b=e[1];let k;e[2]!==n?(k=Ie("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]=k):k=e[3];let g;e[4]!==c||e[5]!==u||e[6]!==w||e[7]!==h||e[8]!==v||e[9]!==m||e[10]!==i||e[11]!==d||e[12]!==l?(g=u&&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:[i!=null?v?w?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Ie(Zr,"min-w-0 truncate"),children:i}),s.jsx("span",{className:"shrink-0",children:d})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Zr,children:i}):i:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Vi,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[h,m&&s.jsx(Cp,{})]})]}),e[4]=c,e[5]=u,e[6]=w,e[7]=h,e[8]=v,e[9]=m,e[10]=i,e[11]=d,e[12]=l,e[13]=g):g=e[13];let I;e[14]!==a||e[15]!==f||e[16]!==k||e[17]!==g?(I=s.jsxs("div",{className:k,onBlurCapture:f,children:[g,a]}),e[14]=a,e[15]=f,e[16]=k,e[17]=g,e[18]=I):I=e[18];let C;return e[19]!==b||e[20]!==I?(C=s.jsx(bs,{outerClassName:b,className:"w-full @container",children:I}),e[19]=b,e[20]=I,e[21]=C):C=e[21],C},Sp=500,Cp=()=>{const t=at.c(13),{t:e}=Ze(),a=o.useSyncExternalStore(Ju,Zo,Zo),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const p=setTimeout(()=>r(!0),Sp);return()=>clearTimeout(p)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let p;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(z,{name:"error-warning",className:"size-3.5"}),t[3]=p):p=t[3];let f;t[4]!==e?(f=e("settings.common.status.saveFailed"),t[4]=e,t[5]=f):f=t[5];let m;return t[6]!==f?(m=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[p,s.jsx("span",{children:f})]}),t[6]=f,t[7]=m):m=t[7],m}if(a!=="saving"||!n)return null;let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=d):d=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let h;return t[11]!==c?(h=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[d,s.jsx("span",{children:c})]}),t[11]=c,t[12]=h):h=t[12],h},Os={ok:!0,changed:!1},In={ok:!0,changed:!0},us=t=>({ok:!1,reason:t}),Ip=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,Ja=t=>{const{t:e}=Ze(),[a,n]=o.useState(0),r=o.useRef(t);r.current=t;const i=o.useRef(e);i.current=e;const l=o.useRef(!1),d=o.useRef(!1),c=o.useRef(!1),h=o.useCallback(()=>{n(m=>m+1)},[]),p=o.useCallback(m=>{Ip(m.target)&&h()},[h]),f=o.useCallback(async()=>{l.current=!0;try{for(;;){d.current=!1;let m;try{m=await r.current()}catch(u){m={ok:!1,reason:u instanceof Error?u.message:String(u)}}if(!c.current)return;if(!d.current){m.ok||B.error(i.current("settings.common.status.saveFailedReason",{reason:m.reason}));return}}}finally{l.current=!1}},[]);return o.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),o.useEffect(()=>{if(a!==0){if(l.current){d.current=!0;return}f()}},[a,f]),{requestSave:h,onBlurCapture:p}},Pp=["allow","ask","deny"],Ap=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],Tp=["openchamber","openchamber_web","openchamber_memory","openchamber_notify"],Ep=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),Zc=t=>Ep.has(t),Dp=[{action:"*",resource:"*",effect:"allow"},{action:"external_directory",resource:"*",effect:"ask"},{action:"read",resource:"*.env",effect:"ask"},{action:"read",resource:"*.env.*",effect:"ask"},{action:"read",resource:"*.env.example",effect:"allow"}],fl=()=>({global:null,keys:{},source:[]}),Xn=t=>({global:t.global,source:t.source,keys:Object.fromEntries(Object.entries(t.keys).map(([e,a])=>[e,{effect:a.effect,patterns:a.patterns.map(n=>({...n}))}]))}),Mp=t=>{const e={global:null,keys:{},source:t.map(a=>({...a}))};for(const a of t){if(Zc(a.action))continue;if(a.action==="*"){a.resource==="*"&&(e.global=a.effect);continue}const n=e.keys[a.action]??{effect:null,patterns:[]};if(a.resource==="*")n.effect=a.effect;else{const r=n.patterns.findIndex(i=>i.pattern===a.resource);r>=0?n.patterns[r]={pattern:a.resource,effect:a.effect}:n.patterns.push({pattern:a.resource,effect:a.effect})}e.keys[a.action]=n}return e},Rp=t=>t.action!=="*"||t.resource==="*",la=(t,e)=>`${t}\0${e}`,Op=t=>{const e=new Map;t.global!==null&&e.set(la("*","*"),t.global);for(const[a,n]of Object.entries(t.keys)){n.effect!==null&&e.set(la(a,"*"),n.effect);for(const r of n.patterns){const i=r.pattern.trim();i.length!==0&&e.set(la(a,i),r.effect)}}return e},io=t=>{const e=Op(t),a=new Set,n=[];for(const i of t.source){if(Zc(i.action))continue;if(!Rp(i)){n.push({...i});continue}const l=la(i.action,i.resource),d=e.get(l);d!==void 0&&(n.push({action:i.action,resource:i.resource,effect:d}),a.add(l))}const r=la("*","*");t.global!==null&&!a.has(r)&&n.unshift({action:"*",resource:"*",effect:t.global});for(const[i,l]of Object.entries(t.keys)){const d=la(i,"*");if(l.effect!==null&&!a.has(d)){const c=n.findIndex(p=>p.action===i),h={action:i,resource:"*",effect:l.effect};c>=0?n.splice(c,0,h):n.push(h)}for(const c of l.patterns){const h=c.pattern.trim();if(h.length===0)continue;const p=la(i,h),f=e.get(p);f===void 0||a.has(p)||(a.add(p),n.push({action:i,resource:h,effect:f}))}}return n},Fp=(t,e)=>JSON.stringify(io(t))===JSON.stringify(io(e)),Lp=(t,e)=>{const a=[...Dp,...e.global,...e.agentGlobal?[{action:"*",resource:"*",effect:e.agentGlobal}]:[]];let n="ask";for(const r of a)r.resource==="*"&&(r.action==="*"||r.action===t)&&(n=r.effect);return n},Kp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),_p=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),Up={effect:null,patterns:[]},zp=t=>{const e=at.c(163),{agent:a,registerSave:n,requestSave:r}=t,{t:i}=Ze(),l=Wn($p),d=Wn(Bp);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];const[h,p]=o.useState(c),[f,m]=o.useState(fl),[u,v]=o.useState(fl),[w,b]=o.useState(!0),[k,g]=o.useState(!1);let I;e[1]===Symbol.for("react.memo_cache_sentinel")?(I={},e[1]=I):I=e[1];const[C,P]=o.useState(I),[j,T]=o.useState(""),[x,A]=o.useState(0),M=a.name,S=Js(),D=Jn(Vp);let O;e[2]!==S?(O=Ne=>go(Ne,S),e[2]=S,e[3]=O):O=e[3];const F=Jn(O);let N;e[4]!==S?(N=Ne=>Ne.getStatusForDirectory(S),e[4]=S,e[5]=N):N=e[5];const R=un(N);let U,K;e[6]!==D||e[7]!==S?(U=()=>{D({directory:S})},K=[D,S],e[6]=D,e[7]=S,e[8]=U,e[9]=K):(U=e[8],K=e[9]),o.useEffect(U,K);let W;e[10]!==M||e[11]!==d||e[12]!==S?(W=()=>{let Ne=!1;return b(!0),g(!1),(async()=>{const Ae=await d(M,S);if(Ne)return;if(!Ae){g(!0),b(!1);return}const q=Mp(Ae.agent);p(Ae.global),m(Xn(q)),v(q),P({}),b(!1)})(),()=>{Ne=!0}},e[10]=M,e[11]=d,e[12]=S,e[13]=W):W=e[13];let te;e[14]!==M||e[15]!==d||e[16]!==x||e[17]!==S?(te=[M,d,x,S],e[14]=M,e[15]=d,e[16]=x,e[17]=S,e[18]=te):te=e[18],o.useEffect(W,te);let Q;e[19]!==M||e[20]!==f||e[21]!==u||e[22]!==S||e[23]!==i||e[24]!==l?(Q=async()=>Fp(u,f)?Os:(await l(M,{permissions:io(u)},S)).ok?(m(Xn(u)),In):us(i("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=M,e[20]=f,e[21]=u,e[22]=S,e[23]=i,e[24]=l,e[25]=Q):Q=e[25];const H=Q;let _,V;e[26]!==n||e[27]!==H?(_=()=>(n(H),()=>n(null)),V=[n,H],e[26]=n,e[27]=H,e[28]=_,e[29]=V):(_=e[28],V=e[29]),o.useEffect(_,V);let X;e[30]!==F?(X=F.map(Hp),e[30]=F,e[31]=X):X=e[31];const $=X;let ee;if(e[32]!==$||e[33]!==u.keys){ee=[...Ap,...Tp];const Ne=new Set($.map(qp));let Ae;e[35]!==u.keys?(Ae=Object.keys(u.keys),e[35]=u.keys,e[36]=Ae):Ae=e[36];for(const q of Ae)!ee.includes(q)&&!Ne.has(q)&&ee.push(q);e[32]=$,e[33]=u.keys,e[34]=ee}else ee=e[34];const L=ee;let Y;e[37]!==R||e[38]!==i?(Y=Ne=>{switch(R?.[Ne]?.status.status){case"connected":return i("settings.mcp.page.status.label.connected");case"failed":return i("settings.mcp.page.status.label.failed");case"needs_auth":return i("settings.mcp.page.status.label.needsAuth");case"disabled":return i("settings.agents.page.permissionsEditor.mcpStatus.disabled");case"pending":return i("settings.agents.page.permissionsEditor.mcpStatus.pending");default:return null}},e[37]=R,e[38]=i,e[39]=Y):Y=e[39];const oe=Y;let de;e[40]!==h||e[41]!==u.global?(de=Ne=>Lp(Ne,{global:h,agentGlobal:u.global}),e[40]=h,e[41]=u.global,e[42]=de):de=e[42];const ue=de;let ce;e[43]!==r?(ce=Ne=>{v(Ae=>({...Ae,global:Ne})),r()},e[43]=r,e[44]=ce):ce=e[44];const Se=ce;let ie;e[45]!==r?(ie=(Ne,Ae)=>{v(q=>{const Le=Xn(q),Qe=Le.keys[Ne]??{effect:null,patterns:[]};return Qe.effect=Ae,Qe.effect===null&&Qe.patterns.length===0?delete Le.keys[Ne]:Le.keys[Ne]=Qe,Le}),r()},e[45]=r,e[46]=ie):ie=e[46];const be=ie;let ae;e[47]!==r?(ae=(Ne,Ae,q,Le,Qe)=>{v(lt=>{const ot=Xn(lt),bt=ot.keys[Ne]??{effect:null,patterns:[]};return bt.patterns[Ae]={pattern:q,effect:Le},ot.keys[Ne]=bt,ot}),Qe&&r()},e[47]=r,e[48]=ae):ae=e[48];const pe=ae;let je;e[49]===Symbol.for("react.memo_cache_sentinel")?(je=Ne=>{v(Ae=>{const q=Xn(Ae),Le=q.keys[Ne]??{effect:null,patterns:[]};return Le.patterns.push({pattern:"",effect:"allow"}),q.keys[Ne]=Le,q}),P(Ae=>({...Ae,[Ne]:!0}))},e[49]=je):je=e[49];const De=je;let me;e[50]!==r?(me=(Ne,Ae)=>{v(q=>{const Le=Xn(q),Qe=Le.keys[Ne];return Qe?(Qe.patterns.splice(Ae,1),Qe.effect===null&&Qe.patterns.length===0&&delete Le.keys[Ne],Le):q}),r()},e[50]=r,e[51]=me):me=e[51];const $e=me;let Ge;e[52]!==j||e[53]!==r?(Ge=()=>{const Ne=j.trim();!Ne||Ne==="*"||(v(Ae=>{if(Ae.keys[Ne])return Ae;const q=Xn(Ae);return q.keys[Ne]={effect:"ask",patterns:[]},q}),T(""),r())},e[52]=j,e[53]=r,e[54]=Ge):Ge=e[54];const xe=Ge;let Pe;e[55]!==i?(Pe=Ne=>i(Ne==="allow"?"settings.agents.page.permissionsEditor.action.allow":Ne==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=i,e[56]=Pe):Pe=e[56];const J=Pe;let se,he,ve,Fe,Ke,Be,ze,_e,Me;if(e[57]!==J||e[58]!==ue||e[59]!==C||e[60]!==w||e[61]!==k||e[62]!==$||e[63]!==oe||e[64]!==u.global||e[65]!==u.keys||e[66]!==$e||e[67]!==Se||e[68]!==be||e[69]!==pe||e[70]!==i||e[71]!==L){Me=Symbol.for("react.early_return_sentinel");e:{const Ne=i("settings.agents.page.permissionsEditor.action.inherit"),Ae=i("settings.agents.page.permissionsEditor.action.default");let q;e[81]!==J?(q=Ve=>[...Ve?[{value:"inherit",label:Ve}]:[],...Pp.map(Z=>({value:Z,label:J(Z)}))],e[81]=J,e[82]=q):q=e[82];const Le=q,Qe=(Ve,Z,ge,Oe)=>{const Ee=Oe===void 0?Ne:Oe;return s.jsx(mn,{value:Ve??"inherit",options:Le(Ee),onChange:Ye=>Z(Ye==="inherit"?null:Ye),"aria-label":ge})};if(w){let Ve;e[83]!==i?(Ve=i("settings.agents.page.section.toolPermissions"),e[83]=i,e[84]=Ve):Ve=e[84];let Z;e[85]!==i?(Z=i("common.loading"),e[85]=i,e[86]=Z):Z=e[86];let ge;e[87]!==Z?(ge=s.jsx("p",{className:ys,children:Z}),e[87]=Z,e[88]=ge):ge=e[88];let Oe;e[89]!==Ve||e[90]!==ge?(Oe=s.jsx(qe,{title:Ve,children:ge}),e[89]=Ve,e[90]=ge,e[91]=Oe):Oe=e[91],Me=Oe;break e}if(k){let Ve;e[92]!==i?(Ve=i("settings.agents.page.section.toolPermissions"),e[92]=i,e[93]=Ve):Ve=e[93];let Z;e[94]!==i?(Z=i("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=i,e[95]=Z):Z=e[95];let ge;e[96]!==Z?(ge=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Z}),e[96]=Z,e[97]=ge):ge=e[97];let Oe;e[98]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>A(Gp),e[98]=Oe):Oe=e[98];let Ee;e[99]!==i?(Ee=i("settings.agents.page.permissionsEditor.actions.retry"),e[99]=i,e[100]=Ee):Ee=e[100];let Ye;e[101]!==Ee?(Ye=s.jsx(G,{variant:"outline",size:"xs",onClick:Oe,children:Ee}),e[101]=Ee,e[102]=Ye):Ye=e[102];let ne;e[103]!==ge||e[104]!==Ye?(ne=s.jsxs("div",{className:"flex items-center gap-3",children:[ge,Ye]}),e[103]=ge,e[104]=Ye,e[105]=ne):ne=e[105];let we;e[106]!==Ve||e[107]!==ne?(we=s.jsx(qe,{title:Ve,children:ne}),e[106]=Ve,e[107]=ne,e[108]=we):we=e[108],Me=we;break e}const lt=(Ve,Z,ge)=>{const Oe=u.keys[Ve]??Up,Ee=_p.has(Ve)||Oe.patterns.length>0,Ye=C[Ve]===!0;return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:Ee?()=>P(ne=>({...ne,[Ve]:!Ye})):void 0,className:Ie("flex min-w-0 items-center gap-1.5 text-left",!Ee&&"cursor-default"),"aria-expanded":Ee?Ye:void 0,children:[s.jsx(z,{name:Ye&&Ee?"arrow-down-s":"arrow-right-s",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",!Ee&&"opacity-0")}),s.jsx("span",{className:St,children:Z}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:Ve}),ge&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:ge}),Oe.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:J(ue(Ve))})}),Oe.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:i("settings.agents.page.permissionsEditor.ruleCount",{count:String(Oe.patterns.length)})})]}),Qe(Oe.effect,ne=>be(Ve,ne),i("settings.agents.page.permissionsEditor.keyAria",{key:Ve}))]}),Ye&&Ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[Oe.patterns.map((ne,we)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(We,{value:ne.pattern,onChange:nt=>pe(Ve,we,nt.target.value,ne.effect,!1),placeholder:i("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ve}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(mn,{value:ne.effect,options:Le(),onChange:nt=>pe(Ve,we,ne.pattern,nt,!0),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ve})}),s.jsx(G,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>$e(Ve,we),"aria-label":i("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]},we)),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>De(Ve),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),i("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},Ve)};se=qe,e[109]!==i?(he=i("settings.agents.page.section.toolPermissions"),e[109]=i,e[110]=he):he=e[110],ve="agents.permissions",e[111]!==i?(Fe=i("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=i,e[112]=Fe):Fe=e[112],Ke="space-y-4";let ot;e[113]!==i?(ot=i("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=i,e[114]=ot):ot=e[114];let bt;e[115]!==ot?(bt=s.jsx("span",{className:St,children:ot}),e[115]=ot,e[116]=bt):bt=e[116];let wt;e[117]!==i?(wt=i("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=i,e[118]=wt):wt=e[118];let jt;e[119]!==wt?(jt=s.jsx(qt,{children:wt}),e[119]=wt,e[120]=jt):jt=e[120];let vt;e[121]!==J||e[122]!==ue||e[123]!==u.global||e[124]!==i?(vt=u.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:J(ue("*"))})}),e[121]=J,e[122]=ue,e[123]=u.global,e[124]=i,e[125]=vt):vt=e[125];let Xe;e[126]!==bt||e[127]!==jt||e[128]!==vt?(Xe=s.jsxs("div",{className:"flex items-center gap-1.5",children:[bt,jt,vt]}),e[126]=bt,e[127]=jt,e[128]=vt,e[129]=Xe):Xe=e[129];const kt=u.global;let Re;e[130]!==i?(Re=i("settings.agents.page.permissionsEditor.defaultAria"),e[130]=i,e[131]=Re):Re=e[131],Be=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[Xe,Qe(kt,Se,Re,Ae)]}),ze=s.jsx("div",{children:L.map(Ve=>lt(Ve,Kp(Ve),null))}),_e=$.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/40 pt-3 pb-1",children:[s.jsx("span",{className:St,children:i("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(qt,{children:i("settings.agents.page.permissionsEditor.mcpInfo")})]}),$.map(Ve=>lt(Ve.key,Ve.server,oe(Ve.server)))]})}e[57]=J,e[58]=ue,e[59]=C,e[60]=w,e[61]=k,e[62]=$,e[63]=oe,e[64]=u.global,e[65]=u.keys,e[66]=$e,e[67]=Se,e[68]=be,e[69]=pe,e[70]=i,e[71]=L,e[72]=se,e[73]=he,e[74]=ve,e[75]=Fe,e[76]=Ke,e[77]=Be,e[78]=ze,e[79]=_e,e[80]=Me}else se=e[72],he=e[73],ve=e[74],Fe=e[75],Ke=e[76],Be=e[77],ze=e[78],_e=e[79],Me=e[80];if(Me!==Symbol.for("react.early_return_sentinel"))return Me;let tt;e[132]===Symbol.for("react.memo_cache_sentinel")?(tt=Ne=>T(Ne.target.value),e[132]=tt):tt=e[132];let pt;e[133]!==xe?(pt=Ne=>{Ne.key==="Enter"&&(Ne.preventDefault(),xe())},e[133]=xe,e[134]=pt):pt=e[134];let ct;e[135]!==i?(ct=i("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=i,e[136]=ct):ct=e[136];let dt;e[137]!==j||e[138]!==pt||e[139]!==ct?(dt=s.jsx(We,{value:j,onChange:tt,onKeyDown:pt,placeholder:ct,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=j,e[138]=pt,e[139]=ct,e[140]=dt):dt=e[140];let ht;e[141]!==j?(ht=j.trim(),e[141]=j,e[142]=ht):ht=e[142];const Ue=!ht;let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=st):st=e[143];let ut;e[144]!==i?(ut=i("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=i,e[145]=ut):ut=e[145];let ye;e[146]!==xe||e[147]!==Ue||e[148]!==ut?(ye=s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:xe,disabled:Ue,children:[st,ut]}),e[146]=xe,e[147]=Ue,e[148]=ut,e[149]=ye):ye=e[149];let re;e[150]!==dt||e[151]!==ye?(re=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[dt,ye]}),e[150]=dt,e[151]=ye,e[152]=re):re=e[152];let Te;return e[153]!==se||e[154]!==he||e[155]!==ve||e[156]!==Fe||e[157]!==Ke||e[158]!==Be||e[159]!==ze||e[160]!==_e||e[161]!==re?(Te=s.jsxs(se,{title:he,settingsItem:ve,info:Fe,contentClassName:Ke,children:[Be,ze,_e,re]}),e[153]=se,e[154]=he,e[155]=ve,e[156]=Fe,e[157]=Ke,e[158]=Be,e[159]=ze,e[160]=_e,e[161]=re,e[162]=Te):Te=e[162],Te};function $p(t){return t.updateAgent}function Bp(t){return t.fetchAgentPermissions}function Vp(t){return t.loadMcpConfigs}function Hp(t){return{key:`${t.name}_*`,server:t.name}}function qp(t){return t.key}function Gp(t){return t+1}const Po=t=>{const e=at.c(11),{legacy:a,path:n,className:r}=t,{t:i}=Ze();if(!a)return null;let l;e[0]!==r?(l=Ie("mb-4 flex items-start gap-1.5",ys,r),e[0]=r,e[1]=l):l=e[1];const d=n??void 0;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(z,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),e[2]=c):c=e[2];let h;e[3]!==i?(h=i("settings.common.legacyFormat.note"),e[3]=i,e[4]=h):h=e[4];let p;e[5]!==h?(p=s.jsx("span",{children:h}),e[5]=h,e[6]=p):p=e[6];let f;return e[7]!==l||e[8]!==d||e[9]!==p?(f=s.jsxs("p",{className:l,title:d,children:[c,p]}),e[7]=l,e[8]=d,e[9]=p,e[10]=f):f=e[10],f},Wp=(t,e)=>{const a=Ln(e);return a?t.find(i=>i.id===a.providerId)?.models.find(i=>i.modelID===a.modelId)?.variants.map(i=>i.id)??[]:[]},Jp=()=>{const{t}=Ze(),e=it(xe=>xe.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,fetchAgentEntity:l,agentDraft:d,setAgentDraft:c,setSelectedAgent:h}=Wn($s(xe=>({selectedAgentName:xe.selectedAgentName,getAgentByName:xe.getAgentByName,createAgent:xe.createAgent,updateAgent:xe.updateAgent,fetchAgentEntity:xe.fetchAgentEntity,agentDraft:xe.agentDraft,setAgentDraft:xe.setAgentDraft,setSelectedAgent:xe.setSelectedAgent}))),p=Js(),f=Wn(xe=>Cc(xe,p)),m=a?n(a,p):null,u=!!(d&&d.name===a&&!m),v=u?"":m?.description?.trim()??"",w=u?"":m?.system?.trim()??"",[b,k]=o.useState(""),[g,I]=o.useState("user"),[C,P]=o.useState(""),[j,T]=o.useState("subagent"),[x,A]=o.useState(""),[M,S]=o.useState(""),[D,O]=o.useState(void 0),[F,N]=o.useState(void 0),[R,U]=o.useState(void 0),[K,W]=o.useState(""),[te,Q]=o.useState(!1),[H,_]=o.useState(null),V=o.useRef({}),X=o.useRef(null),$=o.useCallback(xe=>{X.current=xe},[]),ee=o.useRef(null),L=JSON.stringify([a,p,u]),Y=o.useRef(L);Y.current=L;const oe=o.useRef(null),de={description:C,mode:j,model:x,variant:M,steps:D,temperature:F,topP:R,system:K},ue=o.useRef(de);ue.current=de;const ce=o.useMemo(()=>Wp(e,x),[x,e]),Se=ce.length>0,ie=M||"__default",be=Se,ae=o.useMemo(()=>M&&!ce.includes(M)?[M,...ce]:ce,[M,ce]);o.useEffect(()=>{if(!u||!d)return;oe.current=null;const xe=ci(d.model),Pe=d.name||"",J=d.scope||"user",se=d.description||"",he=d.mode||"subagent",ve=xe?`${xe.providerID}/${xe.modelID}`:"",Fe=xe?.variant||"",Ke=d.steps??void 0,Be=d.temperature??void 0,ze=d.top_p??void 0,_e=d.system||"";V.current={},_(null),k(Pe),I(J),P(se),T(he),A(ve),S(Fe),O(Ke),N(Be),U(ze),W(_e),ee.current={draftName:Pe,draftScope:J,description:se,mode:he,model:ve,variant:Fe,steps:Ke,temperature:Be,topP:ze,system:_e}},[d,u]),o.useEffect(()=>{if(u||!a)return;let xe=!1;return(async()=>{const Pe=await l(a,p);if(xe||Y.current!==L||!Pe)return;const J=Pe.config;V.current=J;const se=ci(J.model),he=J.request?.body,ve={draftName:"",draftScope:"user",description:J.description||"",mode:J.mode||m?.mode||"subagent",model:se?`${se.providerID}/${se.modelID}`:"",variant:se?.variant||"",steps:J.steps??void 0,temperature:he?.temperature,topP:he?.top_p,system:J.system||""},Fe=ee.current,Ke=ue.current,Be=Fe!==null&&(Ke.description!==Fe.description||Ke.mode!==Fe.mode||Ke.model!==Fe.model||Ke.variant!==Fe.variant||Ke.steps!==Fe.steps||Ke.temperature!==Fe.temperature||Ke.topP!==Fe.topP||Ke.system!==Fe.system);_({legacy:Pe.legacy===!0,path:Pe.path,source:Pe.source}),!(oe.current===L&&Be)&&(oe.current=L,P(ve.description),T(ve.mode),A(ve.model),S(ve.variant),O(ve.steps),N(ve.temperature),U(ve.topP),W(ve.system),ee.current=ve)})(),()=>{xe=!0}},[l,u,m,a,p,L]);const pe=o.useCallback(xe=>{const Pe=Ln(x.trim()),J=Pe?Ic({providerID:Pe.providerId,modelID:Pe.modelId,variant:M.trim()||void 0}):null,se=V.current.request,he={...se?.body};F===void 0?delete he.temperature:he.temperature=F,R===void 0?delete he.top_p:he.top_p=R;const ve=se?.headers,Fe={};ve&&Object.keys(ve).length>0&&(Fe.headers=ve),Object.keys(he).length>0&&(Fe.body=he);const Ke=C.trim(),Be=K.trim(),ze={name:xe,mode:j,model:J,steps:D??null,system:Be||(u?void 0:null),request:Object.keys(Fe).length>0?Fe:null};return Ke&&(ze.description=Ke),u&&g&&(ze.scope=g),u&&d?.permissions?.length&&(ze.permissions=d.permissions),ze},[d,C,g,u,j,x,D,K,F,R,M]),je=o.useCallback(async()=>{const xe=ee.current,Pe=a?.trim();if(u||!xe||!Pe)return Os;const J=X.current?await X.current():Os;if(C===xe.description&&j===xe.mode&&x===xe.model&&M===xe.variant&&D===xe.steps&&F===xe.temperature&&R===xe.topP&&K===xe.system||!J.ok)return J;const he=pe(Pe);return(await i(Pe,he,p)).ok?(Y.current!==L||(V.current={...V.current,model:he.model,system:he.system??void 0,steps:he.steps,request:he.request??void 0},ee.current={...xe,description:C,mode:j,model:x,variant:M,steps:D,temperature:F,topP:R,system:K}),In):us(t("settings.agents.page.toast.updateFailed"))},[pe,C,u,j,x,a,L,p,D,K,t,F,R,i,M]),De=Ja(je),{requestSave:me}=De,$e=async()=>{const xe=b.trim().replace(/\s+/g,"-");if(!xe){B.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(f.some(Pe=>Pe.name===xe)){B.error(t("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{(await r(pe(xe),p)).ok?(c(null),B.success(t("settings.agents.page.toast.created"))):B.error(t("settings.agents.page.toast.createFailed"))}catch(Pe){console.error("Error creating agent:",Pe);const J=Pe instanceof Error&&Pe.message?Pe.message:t("settings.agents.page.toast.saveUnexpectedError");B.error(J)}finally{Q(!1)}},Ge=()=>{c(null),h(null)};return a?s.jsxs(ns,{title:u?t("settings.agents.page.title.new"):a,description:t(u?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:De.onBlurCapture,children:[!u&&H&&s.jsx(Po,{legacy:H.legacy,path:H.path}),!u&&H?.source==="none"&&s.jsxs("p",{className:`mb-4 flex items-start gap-1.5 ${ys}`,children:[s.jsx(z,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),s.jsx("span",{children:t("settings.agents.page.runtimeProvided.note")})]}),s.jsxs(qe,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[u&&s.jsxs(Ct,{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(We,{value:b,onChange:xe=>k(xe.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:g,onValueChange:xe=>I(xe),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Ot,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:C,onChange:xe=>P(xe.target.value),placeholder:v||t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Ot,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(mn,{"aria-label":t("settings.agents.page.field.mode"),value:j,onChange:xe=>{T(xe),me()},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(qe,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ct,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ca,{providerId:Ln(x)?.providerId??"",modelId:Ln(x)?.modelId??"",onChange:(xe,Pe)=>{A(xe&&Pe?`${xe}/${Pe}`:""),S(""),me()},className:Ws})}),s.jsx(Ct,{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:be?s.jsxs(Tt,{value:ie,onValueChange:xe=>{S(xe==="__default"?"":xe),me()},children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:xe=>xe==="__default"?t("chat.modelControls.default"):xe})}),s.jsxs(At,{children:[s.jsx(mt,{value:"__default",children:t("chat.modelControls.default")}),ae.map(xe=>s.jsx(mt,{value:xe,children:xe},xe))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(We,{value:M,onChange:xe=>S(xe.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!x&&!M,className:"h-8 w-40 rounded-md px-3"}),M&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{S(""),me()},className:gs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ct,{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(hs,{value:F,fallbackValue:.7,onValueChange:N,onClear:()=>{N(void 0),me()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:vs}),F!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{N(void 0),me()},className:gs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{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(hs,{value:R,fallbackValue:.9,onValueChange:U,onClear:()=>{U(void 0),me()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:vs}),R!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{U(void 0),me()},className:gs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(hs,{value:D,fallbackValue:20,onValueChange:O,onClear:()=>{O(void 0),me()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:vs}),D!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{O(void 0),me()},className:gs,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(qe,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:K,onChange:xe=>W(xe.target.value),placeholder:w||t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent"})}),!u&&m&&s.jsx(zp,{agent:m,registerSave:$,requestSave:me}),u&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(G,{onClick:()=>{$e()},disabled:te||!b.trim(),size:"xs",className:"!font-normal",children:t(te?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:Ge,disabled:te,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})};function Qp(t,e){return t.kind==="file"?t.content:e??""}const xl=Ts({content:Dt(),exists:Co(),path:Dt().min(1).optional()}),Yp=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Zp=t=>t.length>0&&!t.endsWith(`
3
3
  `)?`${t}
4
- `:t,Mi={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Zp=(t,e)=>t==="custom"?e:zd(t),Xp=t=>t==="custom"?"custom":Cc(t)?t:"concise",fl={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"},eg=()=>{const{t}=Ze(),[e,a]=o.useState(""),[n,r]=o.useState("AGENTS.md"),[i,l]=o.useState(Mi.responseStyleEnabled),[d,c]=o.useState(Mi.responseStylePreset),[h,g]=o.useState(Mi.responseStyleCustomInstructions),[f,p]=o.useState(!0),u=o.useRef(null);o.useEffect(()=>{const m=new AbortController;return(async()=>{try{const[P,I]=await Promise.all([An(),St("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:m.signal})]);let j=Mi,D;P&&(j={...j,responseStyleEnabled:P.responseStyleEnabled===!0,responseStylePreset:Xp(P.responseStylePreset),responseStyleCustomInstructions:P.responseStyleCustomInstructions??""},P.globalBehaviorPrompt!==void 0&&(D=P.globalBehaviorPrompt));let x={kind:"missing"};if(I.ok){const A=Jp.parse(await I.json());if(m.signal.aborted)return;r(A.path??"AGENTS.md"),A.exists&&(x={kind:"file",content:A.content})}j={...j,prompt:Wp(x,D)},a(j.prompt),l(j.responseStyleEnabled),c(j.responseStylePreset),g(j.responseStyleCustomInstructions),u.current=j}catch(P){P.name!=="AbortError"&&console.warn("Failed to load behavior settings:",P)}finally{p(!1)}})(),()=>m.abort()},[]);const v=o.useCallback(async()=>{const m=u.current;if(!m||f)return Os;const S=e!==m.prompt,P=i!==m.responseStyleEnabled||d!==m.responseStylePreset||h!==m.responseStyleCustomInstructions;if(!S&&!P)return Os;const I=S?Yp(e):m.prompt;if(S){const D=await St("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:I})});if(!D.ok)return hs(await Qp(D,t("settings.behavior.page.toast.saveFailed")));a(x=>x===e?I:x)}return(await ft({...S?{globalBehaviorPrompt:I}:{},responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h})).ok?(u.current={prompt:I,responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h},In):hs(t("settings.behavior.page.toast.saveFailed"))},[f,e,h,i,d,t]),w=Ja(v),{requestSave:b}=w,k=Zp(d,h);return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:w.onBlurCapture,children:[s.jsx(qe,{title:t("settings.behavior.page.section.systemPrompt"),divider:!1,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:n})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:s.jsx(As,{value:e,onChange:m=>a(m.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"})}),s.jsxs(qe,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:i,onChange:m=>{l(m),b()},disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ct,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Tt,{value:d,onValueChange:m=>{c(m),b()},disabled:f||!i,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{children:m=>m==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Cc(m)?t(fl[m]):null})}),s.jsxs(At,{children:[Ud.map(m=>s.jsx(mt,{value:m,children:t(fl[m])},m)),s.jsx(mt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:k,onChange:m=>g(m.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!i||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},tg=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),sg=t=>{const e=at.c(73),{snapshot:a}=t,{t:n}=Ze(),r=pi(rg),i=a.selection,l=a.projectOverride!==null;let d;e[0]!==l||e[1]!==i||e[2]!==r||e[3]!==n?(d=F=>{l||tg(F,i)||r(F).then(N=>{N||B.error(n("settings.webSearch.toast.saveFailed"))})},e[0]=l,e[1]=i,e[2]=r,e[3]=n,e[4]=d):d=e[4];const c=d,h=i.kind==="provider"&&!a.providers.some(F=>F.id===i.id)?i.id:null;let g;e[5]!==n?(g=n("settings.webSearch.section.provider"),e[5]=n,e[6]=g):g=e[6];let f;e[7]!==n?(f=n("settings.webSearch.section.providerInfo"),e[7]=n,e[8]=f):f=e[8];let p;e[9]!==n?(p=n("settings.webSearch.section.provider"),e[9]=n,e[10]=p):p=e[10];const u=i.kind==="default";let v;e[11]!==c?(v=()=>c({kind:"default"}),e[11]=c,e[12]=v):v=e[12];let w;e[13]!==n?(w=n("settings.webSearch.option.default"),e[13]=n,e[14]=w):w=e[14];let b;e[15]!==n?(b=n("settings.webSearch.option.defaultDescription"),e[15]=n,e[16]=b):b=e[16];let k;e[17]!==l||e[18]!==u||e[19]!==v||e[20]!==w||e[21]!==b?(k=s.jsx(ks,{selected:u,onSelect:v,disabled:l,label:w,description:b}),e[17]=l,e[18]=u,e[19]=v,e[20]=w,e[21]=b,e[22]=k):k=e[22];let m;e[23]!==c||e[24]!==l||e[25]!==i.kind||e[26]!==a.providers.length||e[27]!==n?(m=a.providers.length>0?s.jsx(ks,{selected:i.kind==="random",onSelect:()=>c({kind:"random"}),disabled:l,label:n("settings.webSearch.option.random"),description:n("settings.webSearch.option.randomDescription")}):null,e[23]=c,e[24]=l,e[25]=i.kind,e[26]=a.providers.length,e[27]=n,e[28]=m):m=e[28];let S;if(e[29]!==c||e[30]!==l||e[31]!==i.id||e[32]!==i.kind||e[33]!==a.providers){let F;e[35]!==c||e[36]!==l||e[37]!==i.id||e[38]!==i.kind?(F=N=>s.jsx(ks,{selected:i.kind==="provider"&&i.id===N.id,onSelect:()=>c({kind:"provider",id:N.id}),disabled:l,label:N.name},N.id),e[35]=c,e[36]=l,e[37]=i.id,e[38]=i.kind,e[39]=F):F=e[39],S=a.providers.map(F),e[29]=c,e[30]=l,e[31]=i.id,e[32]=i.kind,e[33]=a.providers,e[34]=S}else S=e[34];let P;e[40]!==h||e[41]!==n?(P=h?s.jsx(ks,{selected:!0,onSelect:og,label:h,description:n("settings.webSearch.option.missing")}):null,e[40]=h,e[41]=n,e[42]=P):P=e[42];const I=i.kind==="off";let j;e[43]!==c?(j=()=>c({kind:"off"}),e[43]=c,e[44]=j):j=e[44];let D;e[45]!==n?(D=n("settings.webSearch.option.off"),e[45]=n,e[46]=D):D=e[46];let x;e[47]!==l||e[48]!==I||e[49]!==j||e[50]!==D?(x=s.jsx(ks,{selected:I,onSelect:j,disabled:l,label:D}),e[47]=l,e[48]=I,e[49]=j,e[50]=D,e[51]=x):x=e[51];let A;e[52]!==m||e[53]!==S||e[54]!==P||e[55]!==x||e[56]!==p||e[57]!==k?(A=s.jsxs(sn,{"aria-label":p,children:[k,m,S,P,x]}),e[52]=m,e[53]=S,e[54]=P,e[55]=x,e[56]=p,e[57]=k,e[58]=A):A=e[58];let R;e[59]!==a.projectOverride||e[60]!==n?(R=a.projectOverride?s.jsx("p",{className:`${ys} mt-2 break-all`,children:n("settings.webSearch.state.projectOverride",{path:a.projectOverride})}):null,e[59]=a.projectOverride,e[60]=n,e[61]=R):R=e[61];let C;e[62]!==a.providers.length||e[63]!==n?(C=a.providers.length===0?s.jsx("p",{className:`${ys} mt-2`,children:n("settings.webSearch.state.noProviders")}):null,e[62]=a.providers.length,e[63]=n,e[64]=C):C=e[64];let E;e[65]!==A||e[66]!==R||e[67]!==C?(E=s.jsxs("div",{children:[A,R,C]}),e[65]=A,e[66]=R,e[67]=C,e[68]=E):E=e[68];let O;return e[69]!==g||e[70]!==E||e[71]!==f?(O=s.jsx(qe,{title:g,info:f,divider:!1,settingsItem:"web-search.provider",children:E}),e[69]=g,e[70]=E,e[71]=f,e[72]=O):O=e[72],O},ng=t=>{const e=at.c(26),{provider:a,access:n}=t,{t:r}=Ze(),i=pi(lg),l=pi(cg),[d,c]=o.useState(""),[h,g]=o.useState(!1);let f;e[0]!==n.envNames||e[1]!==r?(f=n.envNames.length>0?r("settings.webSearch.keys.envHint",{names:n.envNames.join(", ")}):void 0,e[0]=n.envNames,e[1]=r,e[2]=f):f=e[2];const p=f;let u;e[3]!==d||e[4]!==a.id||e[5]!==a.name||e[6]!==i||e[7]!==r?(u=async()=>{const P=d.trim();if(!P)return;g(!0);const I=await i(a.id,P);g(!1),I?(c(""),B.success(r("settings.webSearch.toast.keySaved",{provider:a.name}))):B.error(r("settings.webSearch.toast.keySaveFailed"))},e[3]=d,e[4]=a.id,e[5]=a.name,e[6]=i,e[7]=r,e[8]=u):u=e[8];const v=u;let w;e[9]!==a.id||e[10]!==l||e[11]!==r?(w=async()=>{g(!0);const P=await l(a.id);g(!1),P||B.error(r("settings.webSearch.toast.keyRemoveFailed"))},e[9]=a.id,e[10]=l,e[11]=r,e[12]=w):w=e[12];const b=w,k=n.key;let m;e[13]!==h||e[14]!==d||e[15]!==b||e[16]!==v||e[17]!==a.name||e[18]!==k.kind||e[19]!==k.name||e[20]!==r?(m=k.kind==="stored"?s.jsxs("div",{className:`${Ps} flex items-center justify-end gap-2`,children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.webSearch.keys.saved")}),s.jsx(G,{variant:"outline",size:"xs",disabled:h,onClick:()=>{b()},children:r("settings.webSearch.keys.remove")})]}):k.kind==="env"?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.webSearch.keys.fromEnv",{name:k.name})}):s.jsxs("div",{className:`${Ps} flex items-center gap-2`,children:[s.jsx(We,{type:"password",value:d,onChange:P=>c(P.target.value),onKeyDown:P=>{P.key==="Enter"&&v()},placeholder:r("settings.webSearch.keys.placeholder"),"aria-label":r("settings.webSearch.keys.inputAria",{provider:a.name}),className:"h-8 min-w-0 flex-1 rounded-md px-3 font-mono text-xs"}),s.jsx(G,{size:"xs",disabled:h||d.trim().length===0,onClick:()=>{v()},children:r("settings.webSearch.keys.save")})]}),e[13]=h,e[14]=d,e[15]=b,e[16]=v,e[17]=a.name,e[18]=k.kind,e[19]=k.name,e[20]=r,e[21]=m):m=e[21];let S;return e[22]!==p||e[23]!==a.name||e[24]!==m?(S=s.jsx(Ct,{label:a.name,info:p,children:m}),e[22]=p,e[23]=a.name,e[24]=m,e[25]=S):S=e[25],S},ag=t=>{const e=at.c(23),{snapshot:a}=t,{t:n}=Ze(),r=a.access;let i,l,d,c,h,g,f;if(e[0]!==r||e[1]!==a.providers||e[2]!==n){f=Symbol.for("react.early_return_sentinel");e:{const v=r?a.providers.flatMap(w=>{const b=r[w.id];return b&&b.key.kind!=="unsupported"?[{provider:w,access:b}]:[]}):[];if(r&&v.length===0){f=null;break e}i=qe,e[10]!==n?(c=n("settings.webSearch.section.keys"),e[10]=n,e[11]=c):c=e[11],e[12]!==n?(h=n("settings.webSearch.section.keysInfo"),e[12]=n,e[13]=h):h=e[13],g="web-search.keys",l="space-y-4",d=r===null?s.jsx("p",{className:ys,children:n("settings.webSearch.state.keysUnavailable")}):v.map(dg)}e[0]=r,e[1]=a.providers,e[2]=n,e[3]=i,e[4]=l,e[5]=d,e[6]=c,e[7]=h,e[8]=g,e[9]=f}else i=e[3],l=e[4],d=e[5],c=e[6],h=e[7],g=e[8],f=e[9];if(f!==Symbol.for("react.early_return_sentinel"))return f;let p;e[14]!==l||e[15]!==d?(p=s.jsx("div",{className:l,children:d}),e[14]=l,e[15]=d,e[16]=p):p=e[16];let u;return e[17]!==i||e[18]!==c||e[19]!==h||e[20]!==g||e[21]!==p?(u=s.jsx(i,{title:c,info:h,settingsItem:g,children:p}),e[17]=i,e[18]=c,e[19]=h,e[20]=g,e[21]=p,e[22]=u):u=e[22],u},ig=()=>{const t=at.c(17),{t:e}=Ze(),a=pi(ug),n=pi(mg);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=$d(),t[0]=r):r=t[0];const i=r;let l,d;t[1]!==n?(l=()=>{n()},d=[n,i],t[1]=n,t[2]=l,t[3]=d):(l=t[2],d=t[3]),o.useEffect(l,d);const c=a.kind==="ready"&&a.snapshot.scope===i?a.snapshot:null;let h;t[4]!==e?(h=e("settings.page.webSearch.title"),t[4]=e,t[5]=h):h=t[5];let g;t[6]!==e?(g=e("settings.page.webSearch.description"),t[6]=e,t[7]=g):g=t[7];let f;t[8]!==n||t[9]!==c||t[10]!==a.kind||t[11]!==e?(f=c?s.jsxs(s.Fragment,{children:[s.jsx(sg,{snapshot:c}),s.jsx(ag,{snapshot:c})]}):a.kind==="failed"?s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.webSearch.state.loadFailed")}),s.jsx(G,{variant:"outline",size:"xs",onClick:()=>{n()},children:e("settings.webSearch.actions.retry")})]})}):s.jsx(qe,{divider:!1,children:s.jsx("p",{className:ys,children:e("settings.webSearch.state.loading")})}),t[8]=n,t[9]=c,t[10]=a.kind,t[11]=e,t[12]=f):f=t[12];let p;return t[13]!==h||t[14]!==g||t[15]!==f?(p=s.jsx(ns,{title:h,description:g,showSaveStatus:!0,children:f}),t[13]=h,t[14]=g,t[15]=f,t[16]=p):p=t[16],p};function rg(t){return t.setSelection}function og(){}function lg(t){return t.saveKey}function cg(t){return t.removeKey}function dg(t){const{provider:e,access:a}=t;return s.jsx(ng,{provider:e,access:a},e.id)}function ug(t){return t.state}function mg(t){return t.load}const pg=t=>{const e=at.c(176),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[g,f]=o.useState(null),[p,u]=o.useState(!1),[v,w]=o.useState(null),{selectedCommandName:b,setSelectedCommand:k,setCommandDraft:m,createCommand:S,deleteCommand:P,loadCommands:I}=Ga($s(gg)),j=Js();let D;e[0]!==j?(D=Xe=>Ic(Xe,j),e[0]=j,e[1]=D):D=e[1];const x=Ga(D);let A;e[2]!==j?(A=Xe=>ho(Xe,j),e[2]=j,e[3]=A):A=e[3];const R=nn(A),C=nn(hg);let E,O;e[4]!==I||e[5]!==C||e[6]!==j?(E=()=>{I(j),C(j)},O=[I,C,j],e[4]=I,e[5]=C,e[6]=j,e[7]=E,e[8]=O):(E=e[7],O=e[8]),o.useEffect(E,O);let F;e[9]!==R?(F=new Set(R.map(fg)),e[9]=R,e[10]=F):F=e[10];const N=F;let M;if(e[11]!==x||e[12]!==N){let Xe;e[14]!==N?(Xe=kt=>!N.has(kt.name),e[14]=N,e[15]=Xe):Xe=e[15],M=x.filter(Xe),e[11]=x,e[12]=N,e[13]=M}else M=e[13];const U=M;let K,W;e[16]!==b||e[17]!==k||e[18]!==N?(K=()=>{b&&N.has(b)&&k(null)},W=[b,k,N],e[16]=b,e[17]=k,e[18]=N,e[19]=K,e[20]=W):(K=e[19],W=e[20]),o.useEffect(K,W);let te;e[21]!==x||e[22]!==a||e[23]!==m||e[24]!==k?(te=()=>{let Xe="new-command",kt=1;for(;x.some(Re=>Re.name===Xe);)Xe=`new-command-${kt}`,kt++;m({name:Xe,scope:"user"}),k(Xe),a?.()},e[21]=x,e[22]=a,e[23]=m,e[24]=k,e[25]=te):te=e[25];const Q=te;let H;e[26]!==n?(H=async Xe=>{if($a(Xe)){B.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(Xe),f("delete")},e[26]=n,e[27]=H):H=e[27];const _=H;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Xe=>{$a(Xe)&&(h(Xe),f("reset"))},e[28]=V):V=e[28];const X=V;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=()=>{h(null),f(null)},e[29]=$):$=e[29];const ee=$;let L;e[30]!==c||e[31]!==g||e[32]!==P||e[33]!==j||e[34]!==n?(L=async()=>{if(!c||!g)return;u(!0),await P(c.name,j)?(g==="delete"?B.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):B.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),ee()):g==="delete"?B.error(n("settings.commands.sidebar.toast.deleteFailed")):B.error(n("settings.commands.sidebar.toast.resetFailed")),u(!1)},e[30]=c,e[31]=g,e[32]=P,e[33]=j,e[34]=n,e[35]=L):L=e[35];const Y=L;let oe;e[36]!==x||e[37]!==m||e[38]!==k?(oe=Xe=>{const kt=Xe.name;let Re=1,Ve=`${kt}-copy`;for(;x.some(Z=>Z.name===Ve);)Re++,Ve=`${kt}-copy-${Re}`;m({name:Ve,scope:Xe.scope||"user",description:Xe.description,template:Xe.template,agent:Xe.agent,model:Xe.model,subagent:Xe.subagent}),k(Ve)},e[36]=x,e[37]=m,e[38]=k,e[39]=oe):oe=e[39];const de=oe;let ge;e[40]===Symbol.for("react.memo_cache_sentinel")?(ge=Xe=>{d(Xe.name),i(Xe)},e[40]=ge):ge=e[40];const ce=ge;let Se;e[41]!==x||e[42]!==S||e[43]!==P||e[44]!==r||e[45]!==l||e[46]!==k||e[47]!==j||e[48]!==n?(Se=async()=>{if(!r)return;const Xe=l.trim().replace(/\s+/g,"-");if(!Xe){B.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Xe===r.name){i(null);return}if(x.some(Re=>Re.name===Xe)){B.error(n("settings.commands.sidebar.toast.commandExists"));return}await S({name:Xe,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},j)?await P(r.name,j)?(B.success(`Command renamed to "${Xe}"`),k(Xe)):B.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):B.error(n("settings.commands.sidebar.toast.renameFailed")),i(null)},e[41]=x,e[42]=S,e[43]=P,e[44]=r,e[45]=l,e[46]=k,e[47]=j,e[48]=n,e[49]=Se):Se=e[49];const ie=Se;let be,ae,me,je,De,ue;if(e[50]!==U||e[51]!==Q||e[52]!==_||e[53]!==de||e[54]!==a||e[55]!==v||e[56]!==b||e[57]!==k||e[58]!==n){const Xe=U.filter($a),kt=U.filter(xg);e[65]===Symbol.for("react.memo_cache_sentinel")?(De=Ie("flex h-full flex-col","bg-background"),e[65]=De):De=e[65];let Re;e[66]!==n?(Re=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Re):Re=e[67];let Ve;e[68]!==Re?(Ve=s.jsx("h2",{className:`${Pn} mb-3`,children:Re}),e[68]=Re,e[69]=Ve):Ve=e[69];let Z;e[70]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(xi,{className:"mb-3"}),e[70]=Z):Z=e[70];let pe;e[71]!==U.length||e[72]!==n?(pe=n("settings.commands.sidebar.total",{count:U.length}),e[71]=U.length,e[72]=n,e[73]=pe):pe=e[73];let Oe;e[74]!==pe?(Oe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:pe}),e[74]=pe,e[75]=Oe):Oe=e[75];let Ee;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ee=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ee):Ee=e[76];let Ye;e[77]!==Q?(Ye=s.jsx(G,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,children:Ee}),e[77]=Q,e[78]=Ye):Ye=e[78];let ne;e[79]!==Oe||e[80]!==Ye?(ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Oe,Ye]}),e[79]=Oe,e[80]=Ye,e[81]=ne):ne=e[81],e[82]!==Ve||e[83]!==ne?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ve,Z,ne]}),e[82]=Ve,e[83]=ne,e[84]=ue):ue=e[84],be=bs,ae="flex-1 min-h-0",me="space-y-1 px-3 py-2",je=U.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Xe.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")}),[...Xe].sort(bg).map(we=>s.jsx(xl,{command:we,isSelected:b===we.name,onSelect:()=>{k(we.name),a?.()},onReset:()=>X(we),onDuplicate:()=>de(we),isMenuOpen:v===we.name,onMenuOpenChange:nt=>w(nt?we.name:null)},we.name))]}),kt.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")}),[...kt].sort(vg).map(we=>s.jsx(xl,{command:we,isSelected:b===we.name,onSelect:()=>{k(we.name),a?.()},onRename:()=>ce(we),onDelete:()=>_(we),onDuplicate:()=>de(we),isMenuOpen:v===we.name,onMenuOpenChange:nt=>w(nt?we.name:null)},we.name))]})]}),e[50]=U,e[51]=Q,e[52]=_,e[53]=de,e[54]=a,e[55]=v,e[56]=b,e[57]=k,e[58]=n,e[59]=be,e[60]=ae,e[61]=me,e[62]=je,e[63]=De,e[64]=ue}else be=e[59],ae=e[60],me=e[61],je=e[62],De=e[63],ue=e[64];let $e;e[85]!==be||e[86]!==ae||e[87]!==me||e[88]!==je?($e=s.jsx(be,{outerClassName:ae,className:me,children:je}),e[85]=be,e[86]=ae,e[87]=me,e[88]=je,e[89]=$e):$e=e[89];const Ge=c!==null&&g!==null;let xe;e[90]!==p?(xe=Xe=>{!Xe&&!p&&ee()},e[90]=p,e[91]=xe):xe=e[91];let Pe;e[92]!==g||e[93]!==n?(Pe=n(g==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=g,e[93]=n,e[94]=Pe):Pe=e[94];let J;e[95]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[95]=Pe,e[96]=J):J=e[96];let se;e[97]!==c?.name||e[98]!==g||e[99]!==n?(se=g==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[97]=c?.name,e[98]=g,e[99]=n,e[100]=se):se=e[100];let he;e[101]!==se?(he=s.jsx(Ht,{children:se}),e[101]=se,e[102]=he):he=e[102];let ve;e[103]!==J||e[104]!==he?(ve=s.jsxs(Bt,{children:[J,he]}),e[103]=J,e[104]=he,e[105]=ve):ve=e[105];let Fe;e[106]!==n?(Fe=n("settings.common.actions.cancel"),e[106]=n,e[107]=Fe):Fe=e[107];let Ke;e[108]!==p||e[109]!==Fe?(Ke=s.jsx(G,{size:"sm",variant:"ghost",onClick:ee,disabled:p,children:Fe}),e[108]=p,e[109]=Fe,e[110]=Ke):Ke=e[110];let Be;e[111]!==g||e[112]!==n?(Be=n(g==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=g,e[112]=n,e[113]=Be):Be=e[113];let ze;e[114]!==Y||e[115]!==p||e[116]!==Be?(ze=s.jsx(G,{size:"sm",onClick:Y,disabled:p,children:Be}),e[114]=Y,e[115]=p,e[116]=Be,e[117]=ze):ze=e[117];let _e;e[118]!==Ke||e[119]!==ze?(_e=s.jsxs(as,{children:[Ke,ze]}),e[118]=Ke,e[119]=ze,e[120]=_e):_e=e[120];let Me;e[121]!==ve||e[122]!==_e?(Me=s.jsxs(Ut,{className:"max-w-md",children:[ve,_e]}),e[121]=ve,e[122]=_e,e[123]=Me):Me=e[123];let tt;e[124]!==Ge||e[125]!==xe||e[126]!==Me?(tt=s.jsx(_t,{open:Ge,onOpenChange:xe,children:Me}),e[124]=Ge,e[125]=xe,e[126]=Me,e[127]=tt):tt=e[127];const pt=r!==null;let ct;e[128]===Symbol.for("react.memo_cache_sentinel")?(ct=Xe=>!Xe&&i(null),e[128]=ct):ct=e[128];let dt;e[129]!==n?(dt=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=dt):dt=e[130];let ht;e[131]!==dt?(ht=s.jsx(Vt,{children:dt}),e[131]=dt,e[132]=ht):ht=e[132];const Ue=r?.name??"";let st;e[133]!==n||e[134]!==Ue?(st=n("settings.commands.sidebar.renameDialog.description",{name:Ue}),e[133]=n,e[134]=Ue,e[135]=st):st=e[135];let ut;e[136]!==st?(ut=s.jsx(Ht,{children:st}),e[136]=st,e[137]=ut):ut=e[137];let ye;e[138]!==ht||e[139]!==ut?(ye=s.jsxs(Bt,{children:[ht,ut]}),e[138]=ht,e[139]=ut,e[140]=ye):ye=e[140];let re;e[141]===Symbol.for("react.memo_cache_sentinel")?(re=Xe=>d(Xe.target.value),e[141]=re):re=e[141];let Te;e[142]!==n?(Te=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=Te):Te=e[143];let Ne;e[144]!==ie?(Ne=Xe=>{Xe.key==="Enter"&&ie()},e[144]=ie,e[145]=Ne):Ne=e[145];let Ae;e[146]!==l||e[147]!==Te||e[148]!==Ne?(Ae=s.jsx(We,{value:l,onChange:re,placeholder:Te,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ne}),e[146]=l,e[147]=Te,e[148]=Ne,e[149]=Ae):Ae=e[149];let q;e[150]===Symbol.for("react.memo_cache_sentinel")?(q=()=>i(null),e[150]=q):q=e[150];let Le;e[151]!==n?(Le=n("settings.common.actions.cancel"),e[151]=n,e[152]=Le):Le=e[152];let Qe;e[153]!==Le?(Qe=s.jsx(G,{size:"sm",variant:"ghost",onClick:q,children:Le}),e[153]=Le,e[154]=Qe):Qe=e[154];let lt;e[155]!==n?(lt=n("settings.common.actions.rename"),e[155]=n,e[156]=lt):lt=e[156];let ot;e[157]!==ie||e[158]!==lt?(ot=s.jsx(G,{size:"sm",onClick:ie,children:lt}),e[157]=ie,e[158]=lt,e[159]=ot):ot=e[159];let bt;e[160]!==Qe||e[161]!==ot?(bt=s.jsxs(as,{children:[Qe,ot]}),e[160]=Qe,e[161]=ot,e[162]=bt):bt=e[162];let wt;e[163]!==ye||e[164]!==Ae||e[165]!==bt?(wt=s.jsxs(Ut,{children:[ye,Ae,bt]}),e[163]=ye,e[164]=Ae,e[165]=bt,e[166]=wt):wt=e[166];let jt;e[167]!==pt||e[168]!==wt?(jt=s.jsx(_t,{open:pt,onOpenChange:ct,children:wt}),e[167]=pt,e[168]=wt,e[169]=jt):jt=e[169];let vt;return e[170]!==De||e[171]!==ue||e[172]!==$e||e[173]!==tt||e[174]!==jt?(vt=s.jsxs("div",{className:De,children:[ue,$e,tt,jt]}),e[170]=De,e[171]=ue,e[172]=$e,e[173]=tt,e[174]=jt,e[175]=vt):vt=e[175],vt},xl=t=>{const e=at.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,isMenuOpen:h,onMenuOpenChange:g}=t,{t:f}=Ze();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=mi(),e[0]=p):p=e[0];const u=p,[v,w]=o.useState(!1);let b;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==f?(b=W=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),d()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(W,{onClick:te=>{te.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),l&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),i&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=f,e[6]=b):b=e[6];const k=b,m=n?"bg-interactive-selection":"hover:bg-interactive-hover";let S;e[7]!==m?(S=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m),e[7]=m,e[8]=S):S=e[8];let P;e[9]===Symbol.for("react.memo_cache_sentinel")?(P=u?void 0:W=>{W.preventDefault(),w(!0)},e[9]=P):P=e[9];let I;e[10]!==S?(I=s.jsx("div",{className:S,onContextMenu:P}),e[10]=S,e[11]=I):I=e[11];let j;e[12]!==a.name?(j=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=j):j=e[13];let D;e[14]!==a||e[15]!==f?(D=(a.scope||$a(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:$a(a)?f("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=f,e[16]=D):D=e[16];let x;e[17]!==j||e[18]!==D?(x=s.jsxs("div",{className:"flex items-center gap-2",children:[j,D]}),e[17]=j,e[18]=D,e[19]=x):x=e[19];let A;e[20]!==a.description?(A=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=A):A=e[21];let R;e[22]!==r||e[23]!==A||e[24]!==x?(R=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-ring",tabIndex:0,children:[x,A]}),e[22]=r,e[23]=A,e[24]=x,e[25]=R):R=e[25];let C;e[26]!==g?(C=W=>{W&&w(!1),g(W)},e[26]=g,e[27]=C):C=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=E):E=e[28];let O;e[29]!==k?(O=s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:k(wn)}),e[29]=k,e[30]=O):O=e[30];let F;e[31]!==h||e[32]!==C||e[33]!==O?(F=s.jsxs(zn,{open:h,onOpenChange:C,children:[E,O]}),e[31]=h,e[32]=C,e[33]=O,e[34]=F):F=e[34];let N;e[35]!==R||e[36]!==F?(N=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,F]}),e[35]=R,e[36]=F,e[37]=N):N=e[37];let M;e[38]!==N||e[39]!==I?(M=s.jsx(ga,{render:I,children:N}),e[38]=N,e[39]=I,e[40]=M):M=e[40];let U;e[41]!==k?(U=s.jsx(ma,{className:"w-fit min-w-20",children:k(pa)}),e[41]=k,e[42]=U):U=e[42];let K;return e[43]!==v||e[44]!==M||e[45]!==U?(K=s.jsxs(ha,{open:v,onOpenChange:w,children:[M,U]}),e[43]=v,e[44]=M,e[45]=U,e[46]=K):K=e[46],K};function gg(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function hg(t){return t.loadSkills}function fg(t){return t.name}function xg(t){return!$a(t)}function bg(t,e){return t.name.localeCompare(e.name)}function vg(t,e){return t.name.localeCompare(e.name)}const yg=()=>{const{t}=Ze(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l,setSelectedCommand:d}=Ga($s(V=>({selectedCommandName:V.selectedCommandName,getCommandByName:V.getCommandByName,createCommand:V.createCommand,updateCommand:V.updateCommand,commandDraft:V.commandDraft,setCommandDraft:V.setCommandDraft,setSelectedCommand:V.setSelectedCommand}))),c=Js(),h=Ga(V=>Ic(V,c)),g=e?a(e,c):null,f=!!(i&&i.name===e&&!g),[p,u]=o.useState(""),[v,w]=o.useState("user"),[b,k]=o.useState(""),[m,S]=o.useState(""),[P,I]=o.useState(""),[j,D]=o.useState(""),[x,A]=o.useState(!1),[R,C]=o.useState(""),[E,O]=o.useState(!1),F=o.useRef(null),N=JSON.stringify([c,e]),M=o.useRef(null),U=o.useRef(null);o.useEffect(()=>{const V=M.current===N;if(M.current=N,f&&i){const X=i.name||"",$=i.scope||"user",ee=i.description||"",L=i.agent||"",Y=ci(i.model),oe=Y?`${Y.providerID}/${Y.modelID}`:"",de=Y?.variant||"",ge=i.subagent===!0,ce=i.template||"";u(X),w($),k(ee),S(L),I(oe),D(de),A(ge),C(ce),F.current={draftName:X,draftScope:$,description:ee,agent:L,model:oe,variant:de,subagent:ge,template:ce}}else if(g){const X=g.description||"",$=g.agent||"",ee=ci(g.model),L=ee?`${ee.providerID}/${ee.modelID}`:"",Y=ee?.variant||"",oe=g.subagent===!0,de=g.template||"",ge=U.current,ce=[F.current,ge?.identity===N?ge.form:null];if(V&&ce.some(Se=>Se&&Se.description===X&&Se.agent===$&&Se.model===L&&Se.variant===Y&&Se.subagent===oe&&Se.template===de))return;k(X),S($),I(L),D(Y),A(oe),C(de),F.current={draftName:"",draftScope:"user",description:X,agent:$,model:L,variant:Y,subagent:oe,template:de}}},[g,f,e,h,i,N]);const K=o.useCallback(V=>{const X=m.trim(),$=Ln(P.trim()),ee=$?Sc({providerID:$.providerId,modelID:$.modelId,variant:j.trim()||void 0}):null;return{name:V,description:b.trim()||void 0,agent:X===""?null:X,model:ee,subagent:x,template:R.trim(),scope:f?v:void 0}},[m,b,v,f,P,x,R,j]),W=o.useCallback(async()=>{const V=F.current,X=e?.trim();if(f||!V||!X||b.trim()===V.description.trim()&&m.trim()===V.agent.trim()&&P.trim()===V.model.trim()&&j.trim()===V.variant.trim()&&x===V.subagent&&R.trim()===V.template.trim())return Os;if(!R.trim())return hs(t("settings.commands.page.toast.templateRequired"));const ee=K(X),L=ci(ee.model),Y={identity:N,form:{...V,description:ee.description||"",agent:ee.agent||"",model:L?`${L.providerID}/${L.modelID}`:"",variant:L?.variant||"",subagent:ee.subagent===!0,template:ee.template||""}};U.current=Y;try{return await r(X,ee,c)?(M.current===N&&(F.current=Y.form),In):hs(t("settings.commands.page.toast.updateFailed"))}finally{U.current===Y&&(U.current=null)}},[m,K,b,N,f,P,e,c,x,t,R,r,j]),te=Ja(W),{requestSave:Q}=te,H=async()=>{const V=p.trim().replace(/\s+/g,"-");if(!V){B.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!R.trim()){B.error(t("settings.commands.page.toast.templateRequired"));return}if(h.some(X=>X.name===V)){B.error(t("settings.commands.sidebar.toast.commandExists"));return}O(!0);try{await n(K(V),c)?(l(null),B.success(t("settings.commands.page.toast.created"))):B.error(t("settings.commands.page.toast.createFailed"))}catch(X){console.error("Error creating command:",X),B.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{O(!1)}},_=()=>{l(null),d(null)};return e?s.jsxs(ns,{title:f?t("settings.commands.page.title.new"):`/${e}`,description:t(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),onBlurCapture:te.onBlurCapture,children:[!f&&g&&s.jsx(Po,{legacy:g.legacy===!0,path:g.path}),s.jsxs(qe,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[f&&s.jsxs(Ct,{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(We,{value:p,onChange:V=>u(V.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:v,onValueChange:V=>w(V),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(As,{value:b,onChange:V=>k(V.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(qe,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ct,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(fo,{agentName:m,onChange:V=>{S(V),Q()},className:Ws})}),s.jsx(Ct,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ca,{providerId:Ln(P)?.providerId??"",modelId:Ln(P)?.modelId??"",onChange:(V,X)=>{I(V&&X?`${V}/${X}`:""),Q()},className:Ws})}),s.jsx(Ct,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(We,{value:j,onChange:V=>D(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!P&&!j,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(Ct,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(Ba,{checked:x,onCheckedChange:V=>{A(V),Q()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(qe,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:R,onChange:V=>C(V.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"}),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")]}),f&&s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(G,{onClick:()=>{H()},disabled:E||!p.trim()||!R.trim(),size:"xs",className:"!font-normal",children:t(E?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:_,disabled:E,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},Yi={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},jg=t=>t===!1?{...Yi,oauthEnabled:!1}:t?{oauthEnabled:!0,oauthClientId:t.client_id??"",oauthClientSecret:t.client_secret??"",oauthScope:t.scope??"",oauthRedirectUri:t.redirect_uri??"",oauthCallbackPort:t.callback_port===void 0?"":String(t.callback_port)}:Yi,bl=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":return"warning";default:return"idle"}},vl=t=>{const e=at.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 r;e[1]!==a?(r=Ie("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]=r):r=e[2];let i;return e[3]!==r?(i=s.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},wg=t=>{const e=at.c(124),{onItemSelect:a}=t,{t:n}=Ze(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:d,deleteMcp:c}=Jn($s(kg)),h=Js();let g;e[0]!==h?(g=Ue=>go(Ue,h),e[0]=h,e[1]=g):g=e[1];const f=Jn(g);let p;e[2]!==h?(p=Ue=>Ue.getStatusForDirectory(h),e[2]=h,e[3]=p):p=e[3];const u=un(p),v=un(Ng),w=un(Sg),[b,k]=o.useState(null),[m,S]=o.useState(!1),[P,I]=o.useState(null),[j,D]=o.useState(null),[x,A]=o.useState(!1);let R;e[4]!==f?(R=f.filter(Cg),e[4]=f,e[5]=R):R=e[5];const C=R;let E;e[6]!==f?(E=f.filter(Ig),e[6]=f,e[7]=E):E=e[7];const O=E;let F,N;e[8]!==d||e[9]!==h?(F=()=>{d({directory:h})},N=[d,h],e[8]=d,e[9]=h,e[10]=F,e[11]=N):(F=e[10],N=e[11]),o.useEffect(F,N);let M;e[12]!==w||e[13]!==x||e[14]!==v||e[15]!==h?(M=()=>{if(x)return;A(!0);const Ue=new Promise(Pg);Promise.all([v({directory:h,silent:!0}),Ue]).then(()=>{const st=w(h);st&&B.error(st)}).finally(()=>{A(!1)})},e[12]=w,e[13]=x,e[14]=v,e[15]=h,e[16]=M):M=e[16];const U=M;let K;e[17]!==f||e[18]!==a||e[19]!==l||e[20]!==i?(K=()=>{let Ue="new-mcp-server",st=1;for(;f.some(ye=>ye.name===Ue);)Ue=`new-mcp-server-${st}`,st++;const ut={name:Ue,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...Yi,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1};l(ut),i(Ue),a?.()},e[17]=f,e[18]=a,e[19]=l,e[20]=i,e[21]=K):K=e[21];const W=K;let te;e[22]!==c||e[23]!==b||e[24]!==h||e[25]!==n?(te=async()=>{if(!b)return;S(!0);const Ue=await c(b.name,h);Ue.ok?Ue.reloadFailed?B.warning(Ue.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:Ue.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):B.success(Ue.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):B.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),S(!1)},e[22]=c,e[23]=b,e[24]=h,e[25]=n,e[26]=te):te=e[26];const Q=te;let H;e[27]!==n?(H=(Ue,st)=>s.jsxs(st,{onClick:ut=>{ut.stopPropagation(),k(Ue)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=H):H=e[28];const _=H;let V;e[29]===Symbol.for("react.memo_cache_sentinel")?(V=Ie("flex h-full flex-col","bg-background"),e[29]=V):V=e[29];let X;e[30]!==n?(X=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=X):X=e[31];let $;e[32]!==X?($=s.jsx("h2",{className:Pn,children:X}),e[32]=X,e[33]=$):$=e[33];let ee;e[34]!==n?(ee=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=ee):ee=e[35];let L;e[36]!==n?(L=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=L):L=e[37];const Y=x&&"animate-spin";let oe;e[38]!==Y?(oe=Ie("h-4 w-4",Y),e[38]=Y,e[39]=oe):oe=e[39];let de;e[40]!==oe?(de=s.jsx(z,{name:"refresh",className:oe}),e[40]=oe,e[41]=de):de=e[41];let ge;e[42]!==U||e[43]!==x||e[44]!==ee||e[45]!==L||e[46]!==de?(ge=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-ring",disabled:x,onClick:U,"aria-label":ee,title:L,children:de}),e[42]=U,e[43]=x,e[44]=ee,e[45]=L,e[46]=de,e[47]=ge):ge=e[47];let ce;e[48]!==$||e[49]!==ge?(ce=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[$,ge]}),e[48]=$,e[49]=ge,e[50]=ce):ce=e[50];let Se;e[51]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(xi,{className:"mb-3"}),e[51]=Se):Se=e[51];let ie;e[52]!==f.length||e[53]!==n?(ie=n("settings.mcp.sidebar.total",{count:f.length}),e[52]=f.length,e[53]=n,e[54]=ie):ie=e[54];let be;e[55]!==ie?(be=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ie}),e[55]=ie,e[56]=be):be=e[56];let ae;e[57]!==n?(ae=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=ae):ae=e[58];let me;e[59]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[59]=me):me=e[59];let je;e[60]!==W||e[61]!==ae?(je=s.jsx(G,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:W,title:ae,children:me}),e[60]=W,e[61]=ae,e[62]=je):je=e[62];let De;e[63]!==be||e[64]!==je?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,je]}),e[63]=be,e[64]=je,e[65]=De):De=e[65];let ue;e[66]!==ce||e[67]!==De?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ce,Se,De]}),e[66]=ce,e[67]=De,e[68]=ue):ue=e[68];let $e;e[69]!==f.length||e[70]!==u||e[71]!==a||e[72]!==P||e[73]!==C||e[74]!==_||e[75]!==j||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==O?($e=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:f.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),C.map(Ue=>{const st=u[Ue.name],ut=bl(st?.status.status),ye=r===Ue.name,re=mi();return s.jsxs(ha,{open:j===Ue.name,onOpenChange:Te=>D(Te?Ue.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ye?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:re?void 0:Te=>{Te.preventDefault(),D(Ue.name)}}),children:[s.jsxs("button",{onClick:()=>{i(Ue.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vl,{tone:ut,enabled:Ue.disabled!==!0}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ue.name}),s.jsx("span",{title:Ue.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Ue.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ue.type==="local"?Ue.command?.join(" ")??"":Ue.url??""})]}),s.jsxs(zn,{open:P===Ue.name,onOpenChange:Te=>{Te&&D(null),I(Te?Ue.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:_(Ue,wn)})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:_(Ue,pa)})]},Ue.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(Ue=>{const st=u[Ue.name],ut=bl(st?.status.status),ye=r===Ue.name,re=mi();return s.jsxs(ha,{open:j===Ue.name,onOpenChange:Te=>D(Te?Ue.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ye?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:re?void 0:Te=>{Te.preventDefault(),D(Ue.name)}}),children:[s.jsxs("button",{onClick:()=>{i(Ue.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vl,{tone:ut,enabled:Ue.disabled!==!0}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ue.name}),s.jsx("span",{title:Ue.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Ue.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ue.type==="local"?Ue.command?.join(" ")??"":Ue.url??""})]}),s.jsxs(zn,{open:P===Ue.name,onOpenChange:Te=>{Te&&D(null),I(Te?Ue.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:_(Ue,wn)})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:_(Ue,pa)})]},Ue.name)})]})]})}),e[69]=f.length,e[70]=u,e[71]=a,e[72]=P,e[73]=C,e[74]=_,e[75]=j,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=O,e[81]=$e):$e=e[81];const Ge=b!==null;let xe;e[82]!==m?(xe=Ue=>{!Ue&&!m&&k(null)},e[82]=m,e[83]=xe):xe=e[83];let Pe;e[84]!==n?(Pe=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Pe):Pe=e[85];let J;e[86]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[86]=Pe,e[87]=J):J=e[87];const se=b?.name||"";let he;e[88]!==n||e[89]!==se?(he=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[88]=n,e[89]=se,e[90]=he):he=e[90];let ve;e[91]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ve):ve=e[91];let Fe;e[92]!==he?(Fe=s.jsxs(Ht,{children:[he," ",ve,"."]}),e[92]=he,e[93]=Fe):Fe=e[93];let Ke;e[94]!==J||e[95]!==Fe?(Ke=s.jsxs(Bt,{children:[J,Fe]}),e[94]=J,e[95]=Fe,e[96]=Ke):Ke=e[96];let Be;e[97]===Symbol.for("react.memo_cache_sentinel")?(Be=()=>k(null),e[97]=Be):Be=e[97];let ze;e[98]!==n?(ze=n("settings.common.actions.cancel"),e[98]=n,e[99]=ze):ze=e[99];let _e;e[100]!==m||e[101]!==ze?(_e=s.jsx(G,{size:"sm",variant:"ghost",onClick:Be,disabled:m,children:ze}),e[100]=m,e[101]=ze,e[102]=_e):_e=e[102];let Me;e[103]!==m||e[104]!==n?(Me=n(m?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=m,e[104]=n,e[105]=Me):Me=e[105];let tt;e[106]!==Q||e[107]!==m||e[108]!==Me?(tt=s.jsx(G,{size:"sm",onClick:Q,disabled:m,children:Me}),e[106]=Q,e[107]=m,e[108]=Me,e[109]=tt):tt=e[109];let pt;e[110]!==_e||e[111]!==tt?(pt=s.jsxs(as,{children:[_e,tt]}),e[110]=_e,e[111]=tt,e[112]=pt):pt=e[112];let ct;e[113]!==Ke||e[114]!==pt?(ct=s.jsxs(Ut,{className:"max-w-md",children:[Ke,pt]}),e[113]=Ke,e[114]=pt,e[115]=ct):ct=e[115];let dt;e[116]!==Ge||e[117]!==xe||e[118]!==ct?(dt=s.jsx(_t,{open:Ge,onOpenChange:xe,children:ct}),e[116]=Ge,e[117]=xe,e[118]=ct,e[119]=dt):dt=e[119];let ht;return e[120]!==ue||e[121]!==$e||e[122]!==dt?(ht=s.jsxs("div",{className:V,children:[ue,$e,dt]}),e[120]=ue,e[121]=$e,e[122]=dt,e[123]=ht):ht=e[123],ht};function kg(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Ng(t){return t.refresh}function Sg(t){return t.getErrorForDirectory}function Cg(t){return t.scope==="project"}function Ig(t){return t.scope!=="project"}function Pg(t){return setTimeout(t,500)}function qs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Xa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function vn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ri(t,e,a){const n=Tg(a),r=typeof a.url=="string"?a.url.trim():"",i=yl(a,"env","environment"),l=yl(a,"headers"),d=qs(a.oauth)?a.oauth:null,c=ei(d,"client_id","clientId"),h=ei(d,"client_secret","clientSecret"),g=ei(d,"scope"),f=ei(d,"redirect_uri","redirectUri"),p=Ag(d,"callback_port","callbackPort"),u=ei(d,"auth_server_metadata_url","authServerMetadataUrl"),v=a.oauth===!1||a.oauth===null||a.oauth===void 0?!1:!!d&&!!(c||h||g||f||p||u),w=Eg(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:v,oauthClientId:c,oauthClientSecret:h,oauthScope:g,oauthRedirectUri:f,oauthCallbackPort:p,oauthAuthServerMetadataUrl:u,timeoutStartup:w.startup,timeoutCatalog:w.catalog,timeoutExecution:w.execution,codemode:a.codemode===!0?"on":a.codemode===!1?"off":"default",disabled:Dg(a),protocol:Xr.find(b=>b===a.protocol)??"legacy"}}function ei(t,...e){if(!t)return"";for(const a of e){const n=t[a];if(typeof n=="string"&&n.trim())return n.trim()}return""}function Ag(t,...e){if(!t)return"";for(const a of e){const n=oi(t[a]);if(n)return n}return""}function oi(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return String(Math.floor(t));if(typeof t=="string"&&t.trim()){const e=Number(t);if(Number.isFinite(e)&&e>0)return String(Math.floor(e))}return""}function Tg(t){const e=t.command,a=t.args;if(Xa(e)&&Xa(a))return[...e,...a];if(Xa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Xa(a)?[...n,...a]:n}return Xa(a)?a:[]}function yl(t,...e){for(const a of e){const n=t[a];if(!qs(n))continue;const r=Object.entries(n).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function Eg(t){return qs(t.timeout)?{startup:oi(t.timeout.startup),catalog:oi(t.timeout.catalog),execution:oi(t.timeout.execution)}:{startup:"",catalog:"",execution:oi(t.timeout)}}function Dg(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function Mg(t){const e=t.mcpServers;if(qs(e)){const n=Object.keys(e);if(n.length===1){const r=n[0],i=e[r];if(qs(i))return{name:r,entry:i}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const r=t[n];return n!=="mcpServers"&&qs(r)});if(a.length===1){const n=a[0],r=t[n];if(Yc(r))return{name:n,entry:r}}return null}function Yc(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Rg(t,e){let a;try{const c=t.trim();if(!c)return vn("No JSON content provided");a=JSON.parse(c)}catch(c){return vn(c instanceof Error?`Invalid JSON: ${c.message}`:"Invalid JSON")}if(!qs(a))return vn("Expected a JSON object, not an array or primitive");const n=a,r=n.mcpServers;if(qs(r)){const c=Object.keys(r);if(c.length===0)return vn("mcpServers object is empty",a);if(c.length>1)return vn("Paste one server at a time. Found "+c.length+" servers in mcpServers",a);const h=c[0],g=r[h];return qs(g)?Ri(h,Oi(g),g):vn("Server entry is not a valid object",a)}const i=n.mcp,l=qs(i)&&qs(i.servers)?i.servers:i;if(qs(l)){const c=Object.keys(l);if(c.length===0)return vn("mcp object is empty",a);if(c.length>1)return vn("Paste one server at a time. Found "+c.length+" servers in mcp",a);const h=c[0],g=l[h];return qs(g)?Ri(h,Oi(g),g):vn("Server entry in mcp is not a valid object",a)}const d=Mg(n);if(d)return Ri(d.name,Oi(d.entry),d.entry);if(Yc(n)){const c=Oi(n),h=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ri(h,c,n)}return vn("No recognizable MCP server configuration found in JSON",a)}function Oi(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 Og(t,e,a){const n=a?.isNewServer??!1,r=t.name,i=n&&r?r:e.name??"";return{...e,name:i,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:"",oauthCallbackPort:t.type==="remote"?t.oauthCallbackPort:"",oauthAuthServerMetadataUrl:t.type==="remote"?t.oauthAuthServerMetadataUrl:"",timeoutStartup:t.type==="local"?t.timeoutStartup:"",timeoutCatalog:t.timeoutCatalog,timeoutExecution:t.timeoutExecution,codemode:t.codemode,disabled:t.disabled,protocol:t.protocol}}const Fg=(t,e)=>!!e&&t!=="claude-code",Lg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Kg=t=>Lg.exec(t)?.[0]??void 0,bi=t=>t.type!=="external",Fi=t=>t.title??t.key,_g=(t,e)=>{if(e===void 0)return!1;const a=String(e),n=String(t.value);return t.op==="eq"?a===n:a!==n},Ug=(t,e)=>bi(t)?(t.when??[]).every(a=>_g(a,e[a.key])):!0,Ao=(t,e)=>{const a={},n=[];for(const r of t){if(!Ug(r,a))continue;n.push(r);const i=e[r.key];bi(r)&&i!==void 0&&(a[r.key]=i)}return n},zg=t=>{const e={};for(const a of t)switch(a.type){case"external":break;case"boolean":e[a.key]=a.default??!1;break;case"number":case"integer":typeof a.default=="number"&&(e[a.key]=a.default);break;case"multiselect":e[a.key]=a.default??[];break;case"string":e[a.key]=a.default??a.options?.[0]?.value??"";break}return e},Zc=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,$g=(t,e)=>Ao(t,e).find(a=>bi(a)&&a.required===!0&&Zc(e[a.key]))??null,Bg=(t,e)=>{const a={};for(const n of Ao(t,e)){if(!bi(n))continue;const r=e[n.key];Zc(r)||r===void 0||(a[n.key]=typeof r=="string"?r.trim():r)}return a},jl=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),wl=t=>typeof t=="string"&&t.length>0?t:void 0,Vg=(t,e,a)=>{const n=jl(t)?t:{},r=jl(n.data)?n.data:{};switch(n.name){case"IntegrationOauthAttemptMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"IntegrationOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"IntegrationOauthFailed":return e("settings.providers.page.auth.oauth.error.declined");case"IntegrationValidationFailed":return wl(r.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return wl(n.message)??e(a)}},Or={phase:"idle"},Hg=1500,ro=({integrationId:t,methods:e,onConnected:a,directory:n,className:r})=>{const{t:i}=Ze(),l=o.useCallback(()=>n?Gs.getScopedSdkClient(n):Gs.getSdkClient(),[n]),[d,c]=o.useState(Or),[h,g]=o.useState({}),[f,p]=o.useState(""),u=o.useRef(null),v=o.useCallback(E=>{u.current=null,l().integration.oauth.cancel({integrationID:t,attemptID:E}).catch(()=>{})},[t,l]);o.useEffect(()=>()=>{const E=u.current;E&&v(E)},[v]);const w=d.phase==="idle"?null:d.methodID,b=d.phase==="connecting"||d.phase==="waiting"||d.phase==="awaitingCode"&&d.submitting,k=async(E,O,F)=>{const N=await za(E);if(N.ok){B.success(i(O));return}console.error("Failed to copy OAuth value:",N.error),B.error(i(F))},m=async()=>{u.current=null,c(Or),B.success(i("settings.providers.page.toast.oauthCompleted")),await a()},S=(E,O,F)=>{u.current=null,console.error("OAuth flow failed:",O),c({phase:"failed",methodID:E,message:Vg(O,i,F)})},P=async(E,O)=>{const F=l();for(;u.current===O;){if(await new Promise(N=>setTimeout(N,Hg)),u.current!==O)return;try{const{data:N}=await F.integration.oauth.status({integrationID:t,attemptID:O});if(u.current!==O)return;if(N.status==="complete"){await m();return}if(N.status==="failed"){c({phase:"failed",methodID:E,message:N.message}),u.current=null;return}}catch(N){if(u.current!==O)return;S(E,N,"settings.providers.page.toast.oauthCompleteFailed");return}}},I=async(E,O)=>{c({phase:"connecting",methodID:E.id});let F;try{const{data:N}=await l().integration.oauth.connect({integrationID:t,methodID:E.id,...Object.keys(O).length>0?{answer:O}:{}});F={attemptID:N.attemptID,mode:N.mode,url:N.url,instructions:N.instructions}}catch(N){S(E.id,N,"settings.providers.page.toast.oauthStartFailed");return}if(u.current=F.attemptID,Fg(t,F.url)&&yn(F.url),F.mode==="code"){p(""),c({phase:"awaitingCode",methodID:E.id,attempt:F,submitting:!1});return}c({phase:"waiting",methodID:E.id,attempt:F}),await P(E.id,F.attemptID)},j=E=>{const O=(E.form??[]).filter(bi);if(O.length===0){I(E,{});return}g(zg(O)),c({phase:"prompting",methodID:E.id,fields:O,error:null})},D=E=>{if(d.phase!=="prompting")return;const O=$g(d.fields,h);if(O){c({...d,error:i("settings.providers.page.auth.oauth.promptRequired",{field:Fi(O)})});return}I(E,Bg(d.fields,h))},x=async()=>{if(d.phase!=="awaitingCode")return;const E=f.trim();if(!E)return;const{methodID:O,attempt:F}=d;c({...d,submitting:!0});try{await l().integration.oauth.complete({integrationID:t,attemptID:F.attemptID,code:E}),await m()}catch(N){S(O,N,"settings.providers.page.toast.oauthCompleteFailed")}},A=()=>{(d.phase==="waiting"||d.phase==="awaitingCode")&&v(d.attempt.attemptID),c(Or)},R=E=>{if(E.type==="external")return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Fi(E)}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(E.url)},children:i("settings.providers.page.actions.open")})]},E.key);const O=h[E.key],F=typeof O=="string"?O:"",N=U=>g(K=>({...K,[E.key]:U})),M=E.type==="string"||E.type==="multiselect"?E.options??[]:[];return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Fi(E)}),E.description&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:E.description}),M.length>0?s.jsxs(Tt,{value:F,onValueChange:N,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{children:U=>M.find(K=>K.value===U)?.label??null})}),s.jsx(At,{children:M.map(U=>s.jsx(mt,{value:U.value,children:U.description?`${U.label} · ${U.description}`:U.label},U.value))})]}):E.type==="boolean"?s.jsx("input",{type:"checkbox",checked:O===!0,onChange:U=>N(U.target.checked),"aria-label":Fi(E)}):s.jsx(We,{value:F,onChange:U=>N(U.target.value),placeholder:E.type==="string"?E.placeholder:void 0,className:"max-w-[24rem] text-xs"})]},E.key)},C=E=>{const O=Kg(E.instructions);return s.jsxs(s.Fragment,{children:[E.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:E.instructions}),O&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:O,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{k(O,"settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),E.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:E.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(E.url)},children:i("settings.providers.page.actions.open")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{k(E.url,"settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]})};return s.jsx("div",{className:Ie("space-y-4",r),children:e.map(E=>{const O=w===E.id;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:E.label}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>j(E),disabled:b,children:i("settings.providers.page.actions.connect")})]}),O&&d.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Ao(d.fields,h).map(R),d.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{size:"xs",className:"!font-normal",onClick:()=>D(E),children:i("settings.providers.page.actions.continue")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:A,children:i("settings.providers.page.actions.cancel")})]})]}),O&&d.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),O&&d.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[C(d.attempt),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:A,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),O&&d.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[C(d.attempt),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(We,{value:f,onChange:F=>p(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:d.submitting}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{x()},disabled:d.submitting||f.trim().length===0,children:d.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:A,disabled:d.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),O&&d.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.message}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>j(E),children:i("settings.providers.page.actions.tryAgain")})]})]},E.id)})})},qg=(t,e)=>t.find(a=>a.id.startsWith("mcp_")&&a.metadata?.source==="mcp"&&a.name===e),Gg=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Wg=({serverName:t,directory:e,onConnected:a})=>{const[n,r]=o.useState(null);o.useEffect(()=>{let l=!1;r(null);const d=e?Gs.getScopedSdkClient(e):Gs.getSdkClient();return(async()=>{try{const{data:h}=await d.integration.list();l||r(qg(h,t)??null)}catch(h){console.error("Failed to load MCP integrations:",h)}})(),()=>{l=!0}},[e,t]);const i=Gg(n??void 0);return!n||i.length===0?null:s.jsx(ro,{integrationId:n.id,methods:i,directory:e,onConnected:a},n.id)},Fr=t=>t===void 0?"":String(t),Lr=t=>{const e=t.trim();if(!e)return null;const a=Number(e);return!Number.isFinite(a)||a<=0?null:a%1e3===0?`${a/1e3}s`:`${a}ms`},Kr={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},kl={default:"settings.mcp.page.advanced.codemodeOption.default",on:"settings.mcp.page.advanced.codemodeOption.on",off:"settings.mcp.page.advanced.codemodeOption.off"},Jg=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},ti=t=>t?.status.status,_r=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function Xc(t){const e=[];let a="",n=!1,r=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!r){n=!n;continue}if(l==='"'&&!n){r=!r;continue}if((l===" "||l===" ")&&!n&&!r){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}const Qg=t=>{const e=at.c(27),{value:a,onChange:n,preview:r,onDetectUrl:i}=t;let l;e[0]!==a?(l=()=>a.join(`
5
- `),e[0]=a,e[1]=l):l=e[1];const[d,c]=o.useState(l),h=o.useRef(a);let g,f;e[2]!==a?(g=()=>{JSON.stringify(h.current)!==JSON.stringify(a)&&(h.current=a,c(a.join(`
6
- `)))},f=[a],e[2]=a,e[3]=g,e[4]=f):(g=e[3],f=e[4]),o.useEffect(g,f);let p;e[5]!==n||e[6]!==i?(p=j=>{const D=j.split(`
7
- `).filter(nh);if(i&&D.length===1&&/^https?:\/\/\S+$/i.test(D[0].trim())){i(D[0].trim());return}n(D)},e[5]=n,e[6]=i,e[7]=p):p=e[7];const u=p;let v;e[8]!==n?(v=j=>{const x=j.clipboardData.getData("text").trim();if(!x||x.includes(`
8
- `)||!/\s/.test(x))return;const A=j.currentTarget;if(A.selectionStart!==0||A.selectionEnd!==A.value.length)return;j.preventDefault();const R=Xc(x);c(R.join(`
9
- `)),n(R)},e[8]=n,e[9]=v):v=e[9];const w=v;let b;e[10]!==u?(b=j=>{c(j.target.value),u(j.target.value)},e[10]=u,e[11]=b):b=e[11];let k;e[12]!==u||e[13]!==d?(k=()=>{const j=d.split(`
10
- `).map(ah).join(`
11
- `);c(j),u(j)},e[12]=u,e[13]=d,e[14]=k):k=e[14];const m=Math.max(4,a.length+1);let S;e[15]!==w||e[16]!==b||e[17]!==k||e[18]!==m||e[19]!==d?(S=s.jsx(As,{onPaste:w,value:d,onChange:b,onBlur:k,placeholder:`npx
4
+ `:t,Mi={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Xp=(t,e)=>t==="custom"?e:Bd(t),eg=t=>t==="custom"?"custom":Pc(t)?t:"concise",bl={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"},tg=()=>{const{t}=Ze(),[e,a]=o.useState(""),[n,r]=o.useState("AGENTS.md"),[i,l]=o.useState(Mi.responseStyleEnabled),[d,c]=o.useState(Mi.responseStylePreset),[h,p]=o.useState(Mi.responseStyleCustomInstructions),[f,m]=o.useState(!0),u=o.useRef(null),v=o.useRef(null);o.useEffect(()=>{const C=new AbortController;return(async()=>{try{const[j,T]=await Promise.all([An(),Nt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:C.signal})]);let x=Mi,A;j&&(x={...x,responseStyleEnabled:j.responseStyleEnabled===!0,responseStylePreset:eg(j.responseStylePreset),responseStyleCustomInstructions:j.responseStyleCustomInstructions??""},j.globalBehaviorPrompt!==void 0&&(A=j.globalBehaviorPrompt));let M={kind:"missing"};if(T.ok){const S=xl.parse(await T.json());if(C.signal.aborted)return;r(S.path??"AGENTS.md"),v.current=S.exists?S.content:null,S.exists&&(M={kind:"file",content:S.content})}x={...x,prompt:Qp(M,A)},a(x.prompt),l(x.responseStyleEnabled),c(x.responseStylePreset),p(x.responseStyleCustomInstructions),u.current=x}catch(j){j.name!=="AbortError"&&console.warn("Failed to load behavior settings:",j)}finally{m(!1)}})(),()=>C.abort()},[]);const w=o.useRef(e);w.current=e,o.useEffect(()=>{let C=null;const P=async()=>{if(document.visibilityState!=="visible"||!u.current)return;C?.abort();const T=new AbortController;C=T;try{const x=await Nt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:T.signal});if(!x.ok)return;const A=xl.parse(await x.json()),M=u.current;if(T.signal.aborted||!M||!A.exists||A.content===v.current||w.current!==M.prompt)return;v.current=A.content,u.current={...M,prompt:A.content},a(A.content)}catch(x){x instanceof DOMException&&x.name==="AbortError"||console.warn("Failed to refresh AGENTS.md:",x)}},j=()=>{P()};return window.addEventListener("focus",j),document.addEventListener("visibilitychange",j),()=>{C?.abort(),window.removeEventListener("focus",j),document.removeEventListener("visibilitychange",j)}},[]);const b=o.useCallback(async()=>{const C=u.current;if(!C||f)return Os;const P=e!==C.prompt,j=i!==C.responseStyleEnabled||d!==C.responseStylePreset||h!==C.responseStyleCustomInstructions;if(!P&&!j)return Os;const T=P?Zp(e):C.prompt;if(P){const A=await Nt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:T,expectedContent:v.current})});if(A.status===409)return us(t("settings.behavior.page.toast.agentsMdChangedOnDisk"));if(!A.ok)return us(await Yp(A,t("settings.behavior.page.toast.saveFailed")));v.current=T,a(M=>M===e?T:M)}return(await ft({...P?{globalBehaviorPrompt:T}:{},responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h})).ok?(u.current={prompt:T,responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h},In):us(t("settings.behavior.page.toast.saveFailed"))},[f,e,h,i,d,t]),k=Ja(b),{requestSave:g}=k,I=Xp(d,h);return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:k.onBlurCapture,children:[s.jsx(qe,{title:t("settings.behavior.page.section.systemPrompt"),divider:!1,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:n})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:s.jsx(As,{value:e,onChange:C=>a(C.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"})}),s.jsxs(qe,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:i,onChange:C=>{l(C),g()},disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ct,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Tt,{value:d,onValueChange:C=>{c(C),g()},disabled:f||!i,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{children:C=>C==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Pc(C)?t(bl[C]):null})}),s.jsxs(At,{children:[$d.map(C=>s.jsx(mt,{value:C,children:t(bl[C])},C)),s.jsx(mt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:I,onChange:C=>p(C.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!i||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},sg=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),ng=t=>{const e=at.c(73),{snapshot:a}=t,{t:n}=Ze(),r=pi(og),i=a.selection,l=a.projectOverride!==null;let d;e[0]!==l||e[1]!==i||e[2]!==r||e[3]!==n?(d=F=>{l||sg(F,i)||r(F).then(N=>{N||B.error(n("settings.webSearch.toast.saveFailed"))})},e[0]=l,e[1]=i,e[2]=r,e[3]=n,e[4]=d):d=e[4];const c=d,h=i.kind==="provider"&&!a.providers.some(F=>F.id===i.id)?i.id:null;let p;e[5]!==n?(p=n("settings.webSearch.section.provider"),e[5]=n,e[6]=p):p=e[6];let f;e[7]!==n?(f=n("settings.webSearch.section.providerInfo"),e[7]=n,e[8]=f):f=e[8];let m;e[9]!==n?(m=n("settings.webSearch.section.provider"),e[9]=n,e[10]=m):m=e[10];const u=i.kind==="default";let v;e[11]!==c?(v=()=>c({kind:"default"}),e[11]=c,e[12]=v):v=e[12];let w;e[13]!==n?(w=n("settings.webSearch.option.default"),e[13]=n,e[14]=w):w=e[14];let b;e[15]!==n?(b=n("settings.webSearch.option.defaultDescription"),e[15]=n,e[16]=b):b=e[16];let k;e[17]!==l||e[18]!==u||e[19]!==v||e[20]!==w||e[21]!==b?(k=s.jsx(ks,{selected:u,onSelect:v,disabled:l,label:w,description:b}),e[17]=l,e[18]=u,e[19]=v,e[20]=w,e[21]=b,e[22]=k):k=e[22];let g;e[23]!==c||e[24]!==l||e[25]!==i.kind||e[26]!==a.providers.length||e[27]!==n?(g=a.providers.length>0?s.jsx(ks,{selected:i.kind==="random",onSelect:()=>c({kind:"random"}),disabled:l,label:n("settings.webSearch.option.random"),description:n("settings.webSearch.option.randomDescription")}):null,e[23]=c,e[24]=l,e[25]=i.kind,e[26]=a.providers.length,e[27]=n,e[28]=g):g=e[28];let I;if(e[29]!==c||e[30]!==l||e[31]!==i.id||e[32]!==i.kind||e[33]!==a.providers){let F;e[35]!==c||e[36]!==l||e[37]!==i.id||e[38]!==i.kind?(F=N=>s.jsx(ks,{selected:i.kind==="provider"&&i.id===N.id,onSelect:()=>c({kind:"provider",id:N.id}),disabled:l,label:N.name},N.id),e[35]=c,e[36]=l,e[37]=i.id,e[38]=i.kind,e[39]=F):F=e[39],I=a.providers.map(F),e[29]=c,e[30]=l,e[31]=i.id,e[32]=i.kind,e[33]=a.providers,e[34]=I}else I=e[34];let C;e[40]!==h||e[41]!==n?(C=h?s.jsx(ks,{selected:!0,onSelect:lg,label:h,description:n("settings.webSearch.option.missing")}):null,e[40]=h,e[41]=n,e[42]=C):C=e[42];const P=i.kind==="off";let j;e[43]!==c?(j=()=>c({kind:"off"}),e[43]=c,e[44]=j):j=e[44];let T;e[45]!==n?(T=n("settings.webSearch.option.off"),e[45]=n,e[46]=T):T=e[46];let x;e[47]!==l||e[48]!==P||e[49]!==j||e[50]!==T?(x=s.jsx(ks,{selected:P,onSelect:j,disabled:l,label:T}),e[47]=l,e[48]=P,e[49]=j,e[50]=T,e[51]=x):x=e[51];let A;e[52]!==g||e[53]!==I||e[54]!==C||e[55]!==x||e[56]!==m||e[57]!==k?(A=s.jsxs(sn,{"aria-label":m,children:[k,g,I,C,x]}),e[52]=g,e[53]=I,e[54]=C,e[55]=x,e[56]=m,e[57]=k,e[58]=A):A=e[58];let M;e[59]!==a.projectOverride||e[60]!==n?(M=a.projectOverride?s.jsx("p",{className:`${ys} mt-2 break-all`,children:n("settings.webSearch.state.projectOverride",{path:a.projectOverride})}):null,e[59]=a.projectOverride,e[60]=n,e[61]=M):M=e[61];let S;e[62]!==a.providers.length||e[63]!==n?(S=a.providers.length===0?s.jsx("p",{className:`${ys} mt-2`,children:n("settings.webSearch.state.noProviders")}):null,e[62]=a.providers.length,e[63]=n,e[64]=S):S=e[64];let D;e[65]!==A||e[66]!==M||e[67]!==S?(D=s.jsxs("div",{children:[A,M,S]}),e[65]=A,e[66]=M,e[67]=S,e[68]=D):D=e[68];let O;return e[69]!==p||e[70]!==D||e[71]!==f?(O=s.jsx(qe,{title:p,info:f,divider:!1,settingsItem:"web-search.provider",children:D}),e[69]=p,e[70]=D,e[71]=f,e[72]=O):O=e[72],O},ag=t=>{const e=at.c(26),{provider:a,access:n}=t,{t:r}=Ze(),i=pi(cg),l=pi(dg),[d,c]=o.useState(""),[h,p]=o.useState(!1);let f;e[0]!==n.envNames||e[1]!==r?(f=n.envNames.length>0?r("settings.webSearch.keys.envHint",{names:n.envNames.join(", ")}):void 0,e[0]=n.envNames,e[1]=r,e[2]=f):f=e[2];const m=f;let u;e[3]!==d||e[4]!==a.id||e[5]!==a.name||e[6]!==i||e[7]!==r?(u=async()=>{const C=d.trim();if(!C)return;p(!0);const P=await i(a.id,C);p(!1),P?(c(""),B.success(r("settings.webSearch.toast.keySaved",{provider:a.name}))):B.error(r("settings.webSearch.toast.keySaveFailed"))},e[3]=d,e[4]=a.id,e[5]=a.name,e[6]=i,e[7]=r,e[8]=u):u=e[8];const v=u;let w;e[9]!==a.id||e[10]!==l||e[11]!==r?(w=async()=>{p(!0);const C=await l(a.id);p(!1),C||B.error(r("settings.webSearch.toast.keyRemoveFailed"))},e[9]=a.id,e[10]=l,e[11]=r,e[12]=w):w=e[12];const b=w,k=n.key;let g;e[13]!==h||e[14]!==d||e[15]!==b||e[16]!==v||e[17]!==a.name||e[18]!==k.kind||e[19]!==k.name||e[20]!==r?(g=k.kind==="stored"?s.jsxs("div",{className:`${Ps} flex items-center justify-end gap-2`,children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.webSearch.keys.saved")}),s.jsx(G,{variant:"outline",size:"xs",disabled:h,onClick:()=>{b()},children:r("settings.webSearch.keys.remove")})]}):k.kind==="env"?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.webSearch.keys.fromEnv",{name:k.name})}):s.jsxs("div",{className:`${Ps} flex items-center gap-2`,children:[s.jsx(We,{type:"password",value:d,onChange:C=>c(C.target.value),onKeyDown:C=>{C.key==="Enter"&&v()},placeholder:r("settings.webSearch.keys.placeholder"),"aria-label":r("settings.webSearch.keys.inputAria",{provider:a.name}),className:"h-8 min-w-0 flex-1 rounded-md px-3 font-mono text-xs"}),s.jsx(G,{size:"xs",disabled:h||d.trim().length===0,onClick:()=>{v()},children:r("settings.webSearch.keys.save")})]}),e[13]=h,e[14]=d,e[15]=b,e[16]=v,e[17]=a.name,e[18]=k.kind,e[19]=k.name,e[20]=r,e[21]=g):g=e[21];let I;return e[22]!==m||e[23]!==a.name||e[24]!==g?(I=s.jsx(Ct,{label:a.name,info:m,children:g}),e[22]=m,e[23]=a.name,e[24]=g,e[25]=I):I=e[25],I},ig=t=>{const e=at.c(23),{snapshot:a}=t,{t:n}=Ze(),r=a.access;let i,l,d,c,h,p,f;if(e[0]!==r||e[1]!==a.providers||e[2]!==n){f=Symbol.for("react.early_return_sentinel");e:{const v=r?a.providers.flatMap(w=>{const b=r[w.id];return b&&b.key.kind!=="unsupported"?[{provider:w,access:b}]:[]}):[];if(r&&v.length===0){f=null;break e}i=qe,e[10]!==n?(c=n("settings.webSearch.section.keys"),e[10]=n,e[11]=c):c=e[11],e[12]!==n?(h=n("settings.webSearch.section.keysInfo"),e[12]=n,e[13]=h):h=e[13],p="web-search.keys",l="space-y-4",d=r===null?s.jsx("p",{className:ys,children:n("settings.webSearch.state.keysUnavailable")}):v.map(ug)}e[0]=r,e[1]=a.providers,e[2]=n,e[3]=i,e[4]=l,e[5]=d,e[6]=c,e[7]=h,e[8]=p,e[9]=f}else i=e[3],l=e[4],d=e[5],c=e[6],h=e[7],p=e[8],f=e[9];if(f!==Symbol.for("react.early_return_sentinel"))return f;let m;e[14]!==l||e[15]!==d?(m=s.jsx("div",{className:l,children:d}),e[14]=l,e[15]=d,e[16]=m):m=e[16];let u;return e[17]!==i||e[18]!==c||e[19]!==h||e[20]!==p||e[21]!==m?(u=s.jsx(i,{title:c,info:h,settingsItem:p,children:m}),e[17]=i,e[18]=c,e[19]=h,e[20]=p,e[21]=m,e[22]=u):u=e[22],u},rg=()=>{const t=at.c(17),{t:e}=Ze(),a=pi(mg),n=pi(pg);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=Vd(),t[0]=r):r=t[0];const i=r;let l,d;t[1]!==n?(l=()=>{n()},d=[n,i],t[1]=n,t[2]=l,t[3]=d):(l=t[2],d=t[3]),o.useEffect(l,d);const c=a.kind==="ready"&&a.snapshot.scope===i?a.snapshot:null;let h;t[4]!==e?(h=e("settings.page.webSearch.title"),t[4]=e,t[5]=h):h=t[5];let p;t[6]!==e?(p=e("settings.page.webSearch.description"),t[6]=e,t[7]=p):p=t[7];let f;t[8]!==n||t[9]!==c||t[10]!==a.kind||t[11]!==e?(f=c?s.jsxs(s.Fragment,{children:[s.jsx(ng,{snapshot:c}),s.jsx(ig,{snapshot:c})]}):a.kind==="failed"?s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.webSearch.state.loadFailed")}),s.jsx(G,{variant:"outline",size:"xs",onClick:()=>{n()},children:e("settings.webSearch.actions.retry")})]})}):s.jsx(qe,{divider:!1,children:s.jsx("p",{className:ys,children:e("settings.webSearch.state.loading")})}),t[8]=n,t[9]=c,t[10]=a.kind,t[11]=e,t[12]=f):f=t[12];let m;return t[13]!==h||t[14]!==p||t[15]!==f?(m=s.jsx(ns,{title:h,description:p,showSaveStatus:!0,children:f}),t[13]=h,t[14]=p,t[15]=f,t[16]=m):m=t[16],m};function og(t){return t.setSelection}function lg(){}function cg(t){return t.saveKey}function dg(t){return t.removeKey}function ug(t){const{provider:e,access:a}=t;return s.jsx(ag,{provider:e,access:a},e.id)}function mg(t){return t.state}function pg(t){return t.load}const gg=t=>{const e=at.c(176),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[p,f]=o.useState(null),[m,u]=o.useState(!1),[v,w]=o.useState(null),{selectedCommandName:b,setSelectedCommand:k,setCommandDraft:g,createCommand:I,deleteCommand:C,loadCommands:P}=Ga($s(hg)),j=Js();let T;e[0]!==j?(T=Xe=>Ac(Xe,j),e[0]=j,e[1]=T):T=e[1];const x=Ga(T);let A;e[2]!==j?(A=Xe=>ho(Xe,j),e[2]=j,e[3]=A):A=e[3];const M=nn(A),S=nn(fg);let D,O;e[4]!==P||e[5]!==S||e[6]!==j?(D=()=>{P(j),S(j)},O=[P,S,j],e[4]=P,e[5]=S,e[6]=j,e[7]=D,e[8]=O):(D=e[7],O=e[8]),o.useEffect(D,O);let F;e[9]!==M?(F=new Set(M.map(xg)),e[9]=M,e[10]=F):F=e[10];const N=F;let R;if(e[11]!==x||e[12]!==N){let Xe;e[14]!==N?(Xe=kt=>!N.has(kt.name),e[14]=N,e[15]=Xe):Xe=e[15],R=x.filter(Xe),e[11]=x,e[12]=N,e[13]=R}else R=e[13];const U=R;let K,W;e[16]!==b||e[17]!==k||e[18]!==N?(K=()=>{b&&N.has(b)&&k(null)},W=[b,k,N],e[16]=b,e[17]=k,e[18]=N,e[19]=K,e[20]=W):(K=e[19],W=e[20]),o.useEffect(K,W);let te;e[21]!==x||e[22]!==a||e[23]!==g||e[24]!==k?(te=()=>{let Xe="new-command",kt=1;for(;x.some(Re=>Re.name===Xe);)Xe=`new-command-${kt}`,kt++;g({name:Xe,scope:"user"}),k(Xe),a?.()},e[21]=x,e[22]=a,e[23]=g,e[24]=k,e[25]=te):te=e[25];const Q=te;let H;e[26]!==n?(H=async Xe=>{if($a(Xe)){B.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(Xe),f("delete")},e[26]=n,e[27]=H):H=e[27];const _=H;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Xe=>{$a(Xe)&&(h(Xe),f("reset"))},e[28]=V):V=e[28];const X=V;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=()=>{h(null),f(null)},e[29]=$):$=e[29];const ee=$;let L;e[30]!==c||e[31]!==p||e[32]!==C||e[33]!==j||e[34]!==n?(L=async()=>{if(!c||!p)return;u(!0),await C(c.name,j)?(p==="delete"?B.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):B.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),ee()):p==="delete"?B.error(n("settings.commands.sidebar.toast.deleteFailed")):B.error(n("settings.commands.sidebar.toast.resetFailed")),u(!1)},e[30]=c,e[31]=p,e[32]=C,e[33]=j,e[34]=n,e[35]=L):L=e[35];const Y=L;let oe;e[36]!==x||e[37]!==g||e[38]!==k?(oe=Xe=>{const kt=Xe.name;let Re=1,Ve=`${kt}-copy`;for(;x.some(Z=>Z.name===Ve);)Re++,Ve=`${kt}-copy-${Re}`;g({name:Ve,scope:Xe.scope||"user",description:Xe.description,template:Xe.template,agent:Xe.agent,model:Xe.model,subagent:Xe.subagent}),k(Ve)},e[36]=x,e[37]=g,e[38]=k,e[39]=oe):oe=e[39];const de=oe;let ue;e[40]===Symbol.for("react.memo_cache_sentinel")?(ue=Xe=>{d(Xe.name),i(Xe)},e[40]=ue):ue=e[40];const ce=ue;let Se;e[41]!==x||e[42]!==I||e[43]!==C||e[44]!==r||e[45]!==l||e[46]!==k||e[47]!==j||e[48]!==n?(Se=async()=>{if(!r)return;const Xe=l.trim().replace(/\s+/g,"-");if(!Xe){B.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Xe===r.name){i(null);return}if(x.some(Re=>Re.name===Xe)){B.error(n("settings.commands.sidebar.toast.commandExists"));return}await I({name:Xe,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},j)?await C(r.name,j)?(B.success(`Command renamed to "${Xe}"`),k(Xe)):B.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):B.error(n("settings.commands.sidebar.toast.renameFailed")),i(null)},e[41]=x,e[42]=I,e[43]=C,e[44]=r,e[45]=l,e[46]=k,e[47]=j,e[48]=n,e[49]=Se):Se=e[49];const ie=Se;let be,ae,pe,je,De,me;if(e[50]!==U||e[51]!==Q||e[52]!==_||e[53]!==de||e[54]!==a||e[55]!==v||e[56]!==b||e[57]!==k||e[58]!==n){const Xe=U.filter($a),kt=U.filter(bg);e[65]===Symbol.for("react.memo_cache_sentinel")?(De=Ie("flex h-full flex-col","bg-background"),e[65]=De):De=e[65];let Re;e[66]!==n?(Re=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Re):Re=e[67];let Ve;e[68]!==Re?(Ve=s.jsx("h2",{className:`${Pn} mb-3`,children:Re}),e[68]=Re,e[69]=Ve):Ve=e[69];let Z;e[70]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(xi,{className:"mb-3"}),e[70]=Z):Z=e[70];let ge;e[71]!==U.length||e[72]!==n?(ge=n("settings.commands.sidebar.total",{count:U.length}),e[71]=U.length,e[72]=n,e[73]=ge):ge=e[73];let Oe;e[74]!==ge?(Oe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ge}),e[74]=ge,e[75]=Oe):Oe=e[75];let Ee;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ee=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ee):Ee=e[76];let Ye;e[77]!==Q?(Ye=s.jsx(G,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,children:Ee}),e[77]=Q,e[78]=Ye):Ye=e[78];let ne;e[79]!==Oe||e[80]!==Ye?(ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Oe,Ye]}),e[79]=Oe,e[80]=Ye,e[81]=ne):ne=e[81],e[82]!==Ve||e[83]!==ne?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ve,Z,ne]}),e[82]=Ve,e[83]=ne,e[84]=me):me=e[84],be=bs,ae="flex-1 min-h-0",pe="space-y-1 px-3 py-2",je=U.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Xe.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")}),[...Xe].sort(vg).map(we=>s.jsx(vl,{command:we,isSelected:b===we.name,onSelect:()=>{k(we.name),a?.()},onReset:()=>X(we),onDuplicate:()=>de(we),isMenuOpen:v===we.name,onMenuOpenChange:nt=>w(nt?we.name:null)},we.name))]}),kt.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")}),[...kt].sort(yg).map(we=>s.jsx(vl,{command:we,isSelected:b===we.name,onSelect:()=>{k(we.name),a?.()},onRename:()=>ce(we),onDelete:()=>_(we),onDuplicate:()=>de(we),isMenuOpen:v===we.name,onMenuOpenChange:nt=>w(nt?we.name:null)},we.name))]})]}),e[50]=U,e[51]=Q,e[52]=_,e[53]=de,e[54]=a,e[55]=v,e[56]=b,e[57]=k,e[58]=n,e[59]=be,e[60]=ae,e[61]=pe,e[62]=je,e[63]=De,e[64]=me}else be=e[59],ae=e[60],pe=e[61],je=e[62],De=e[63],me=e[64];let $e;e[85]!==be||e[86]!==ae||e[87]!==pe||e[88]!==je?($e=s.jsx(be,{outerClassName:ae,className:pe,children:je}),e[85]=be,e[86]=ae,e[87]=pe,e[88]=je,e[89]=$e):$e=e[89];const Ge=c!==null&&p!==null;let xe;e[90]!==m?(xe=Xe=>{!Xe&&!m&&ee()},e[90]=m,e[91]=xe):xe=e[91];let Pe;e[92]!==p||e[93]!==n?(Pe=n(p==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=p,e[93]=n,e[94]=Pe):Pe=e[94];let J;e[95]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[95]=Pe,e[96]=J):J=e[96];let se;e[97]!==c?.name||e[98]!==p||e[99]!==n?(se=p==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[97]=c?.name,e[98]=p,e[99]=n,e[100]=se):se=e[100];let he;e[101]!==se?(he=s.jsx(Ht,{children:se}),e[101]=se,e[102]=he):he=e[102];let ve;e[103]!==J||e[104]!==he?(ve=s.jsxs(Bt,{children:[J,he]}),e[103]=J,e[104]=he,e[105]=ve):ve=e[105];let Fe;e[106]!==n?(Fe=n("settings.common.actions.cancel"),e[106]=n,e[107]=Fe):Fe=e[107];let Ke;e[108]!==m||e[109]!==Fe?(Ke=s.jsx(G,{size:"sm",variant:"ghost",onClick:ee,disabled:m,children:Fe}),e[108]=m,e[109]=Fe,e[110]=Ke):Ke=e[110];let Be;e[111]!==p||e[112]!==n?(Be=n(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=p,e[112]=n,e[113]=Be):Be=e[113];let ze;e[114]!==Y||e[115]!==m||e[116]!==Be?(ze=s.jsx(G,{size:"sm",onClick:Y,disabled:m,children:Be}),e[114]=Y,e[115]=m,e[116]=Be,e[117]=ze):ze=e[117];let _e;e[118]!==Ke||e[119]!==ze?(_e=s.jsxs(as,{children:[Ke,ze]}),e[118]=Ke,e[119]=ze,e[120]=_e):_e=e[120];let Me;e[121]!==ve||e[122]!==_e?(Me=s.jsxs(Ut,{className:"max-w-md",children:[ve,_e]}),e[121]=ve,e[122]=_e,e[123]=Me):Me=e[123];let tt;e[124]!==Ge||e[125]!==xe||e[126]!==Me?(tt=s.jsx(_t,{open:Ge,onOpenChange:xe,children:Me}),e[124]=Ge,e[125]=xe,e[126]=Me,e[127]=tt):tt=e[127];const pt=r!==null;let ct;e[128]===Symbol.for("react.memo_cache_sentinel")?(ct=Xe=>!Xe&&i(null),e[128]=ct):ct=e[128];let dt;e[129]!==n?(dt=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=dt):dt=e[130];let ht;e[131]!==dt?(ht=s.jsx(Vt,{children:dt}),e[131]=dt,e[132]=ht):ht=e[132];const Ue=r?.name??"";let st;e[133]!==n||e[134]!==Ue?(st=n("settings.commands.sidebar.renameDialog.description",{name:Ue}),e[133]=n,e[134]=Ue,e[135]=st):st=e[135];let ut;e[136]!==st?(ut=s.jsx(Ht,{children:st}),e[136]=st,e[137]=ut):ut=e[137];let ye;e[138]!==ht||e[139]!==ut?(ye=s.jsxs(Bt,{children:[ht,ut]}),e[138]=ht,e[139]=ut,e[140]=ye):ye=e[140];let re;e[141]===Symbol.for("react.memo_cache_sentinel")?(re=Xe=>d(Xe.target.value),e[141]=re):re=e[141];let Te;e[142]!==n?(Te=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=Te):Te=e[143];let Ne;e[144]!==ie?(Ne=Xe=>{Xe.key==="Enter"&&ie()},e[144]=ie,e[145]=Ne):Ne=e[145];let Ae;e[146]!==l||e[147]!==Te||e[148]!==Ne?(Ae=s.jsx(We,{value:l,onChange:re,placeholder:Te,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ne}),e[146]=l,e[147]=Te,e[148]=Ne,e[149]=Ae):Ae=e[149];let q;e[150]===Symbol.for("react.memo_cache_sentinel")?(q=()=>i(null),e[150]=q):q=e[150];let Le;e[151]!==n?(Le=n("settings.common.actions.cancel"),e[151]=n,e[152]=Le):Le=e[152];let Qe;e[153]!==Le?(Qe=s.jsx(G,{size:"sm",variant:"ghost",onClick:q,children:Le}),e[153]=Le,e[154]=Qe):Qe=e[154];let lt;e[155]!==n?(lt=n("settings.common.actions.rename"),e[155]=n,e[156]=lt):lt=e[156];let ot;e[157]!==ie||e[158]!==lt?(ot=s.jsx(G,{size:"sm",onClick:ie,children:lt}),e[157]=ie,e[158]=lt,e[159]=ot):ot=e[159];let bt;e[160]!==Qe||e[161]!==ot?(bt=s.jsxs(as,{children:[Qe,ot]}),e[160]=Qe,e[161]=ot,e[162]=bt):bt=e[162];let wt;e[163]!==ye||e[164]!==Ae||e[165]!==bt?(wt=s.jsxs(Ut,{children:[ye,Ae,bt]}),e[163]=ye,e[164]=Ae,e[165]=bt,e[166]=wt):wt=e[166];let jt;e[167]!==pt||e[168]!==wt?(jt=s.jsx(_t,{open:pt,onOpenChange:ct,children:wt}),e[167]=pt,e[168]=wt,e[169]=jt):jt=e[169];let vt;return e[170]!==De||e[171]!==me||e[172]!==$e||e[173]!==tt||e[174]!==jt?(vt=s.jsxs("div",{className:De,children:[me,$e,tt,jt]}),e[170]=De,e[171]=me,e[172]=$e,e[173]=tt,e[174]=jt,e[175]=vt):vt=e[175],vt},vl=t=>{const e=at.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,isMenuOpen:h,onMenuOpenChange:p}=t,{t:f}=Ze();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=mi(),e[0]=m):m=e[0];const u=m,[v,w]=o.useState(!1);let b;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==f?(b=W=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),d()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(W,{onClick:te=>{te.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),l&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),i&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=f,e[6]=b):b=e[6];const k=b,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==g?(I=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=I):I=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=u?void 0:W=>{W.preventDefault(),w(!0)},e[9]=C):C=e[9];let P;e[10]!==I?(P=s.jsx("div",{className:I,onContextMenu:C}),e[10]=I,e[11]=P):P=e[11];let j;e[12]!==a.name?(j=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=j):j=e[13];let T;e[14]!==a||e[15]!==f?(T=(a.scope||$a(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:$a(a)?f("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=f,e[16]=T):T=e[16];let x;e[17]!==j||e[18]!==T?(x=s.jsxs("div",{className:"flex items-center gap-2",children:[j,T]}),e[17]=j,e[18]=T,e[19]=x):x=e[19];let A;e[20]!==a.description?(A=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=A):A=e[21];let M;e[22]!==r||e[23]!==A||e[24]!==x?(M=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-ring",tabIndex:0,children:[x,A]}),e[22]=r,e[23]=A,e[24]=x,e[25]=M):M=e[25];let S;e[26]!==p?(S=W=>{W&&w(!1),p(W)},e[26]=p,e[27]=S):S=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=D):D=e[28];let O;e[29]!==k?(O=s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:k(wn)}),e[29]=k,e[30]=O):O=e[30];let F;e[31]!==h||e[32]!==S||e[33]!==O?(F=s.jsxs(zn,{open:h,onOpenChange:S,children:[D,O]}),e[31]=h,e[32]=S,e[33]=O,e[34]=F):F=e[34];let N;e[35]!==M||e[36]!==F?(N=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[M,F]}),e[35]=M,e[36]=F,e[37]=N):N=e[37];let R;e[38]!==N||e[39]!==P?(R=s.jsx(ga,{render:P,children:N}),e[38]=N,e[39]=P,e[40]=R):R=e[40];let U;e[41]!==k?(U=s.jsx(ma,{className:"w-fit min-w-20",children:k(pa)}),e[41]=k,e[42]=U):U=e[42];let K;return e[43]!==v||e[44]!==R||e[45]!==U?(K=s.jsxs(ha,{open:v,onOpenChange:w,children:[R,U]}),e[43]=v,e[44]=R,e[45]=U,e[46]=K):K=e[46],K};function hg(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function fg(t){return t.loadSkills}function xg(t){return t.name}function bg(t){return!$a(t)}function vg(t,e){return t.name.localeCompare(e.name)}function yg(t,e){return t.name.localeCompare(e.name)}const jg=()=>{const{t}=Ze(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l,setSelectedCommand:d}=Ga($s(V=>({selectedCommandName:V.selectedCommandName,getCommandByName:V.getCommandByName,createCommand:V.createCommand,updateCommand:V.updateCommand,commandDraft:V.commandDraft,setCommandDraft:V.setCommandDraft,setSelectedCommand:V.setSelectedCommand}))),c=Js(),h=Ga(V=>Ac(V,c)),p=e?a(e,c):null,f=!!(i&&i.name===e&&!p),[m,u]=o.useState(""),[v,w]=o.useState("user"),[b,k]=o.useState(""),[g,I]=o.useState(""),[C,P]=o.useState(""),[j,T]=o.useState(""),[x,A]=o.useState(!1),[M,S]=o.useState(""),[D,O]=o.useState(!1),F=o.useRef(null),N=JSON.stringify([c,e]),R=o.useRef(null),U=o.useRef(null);o.useEffect(()=>{const V=R.current===N;if(R.current=N,f&&i){const X=i.name||"",$=i.scope||"user",ee=i.description||"",L=i.agent||"",Y=ci(i.model),oe=Y?`${Y.providerID}/${Y.modelID}`:"",de=Y?.variant||"",ue=i.subagent===!0,ce=i.template||"";u(X),w($),k(ee),I(L),P(oe),T(de),A(ue),S(ce),F.current={draftName:X,draftScope:$,description:ee,agent:L,model:oe,variant:de,subagent:ue,template:ce}}else if(p){const X=p.description||"",$=p.agent||"",ee=ci(p.model),L=ee?`${ee.providerID}/${ee.modelID}`:"",Y=ee?.variant||"",oe=p.subagent===!0,de=p.template||"",ue=U.current,ce=[F.current,ue?.identity===N?ue.form:null];if(V&&ce.some(Se=>Se&&Se.description===X&&Se.agent===$&&Se.model===L&&Se.variant===Y&&Se.subagent===oe&&Se.template===de))return;k(X),I($),P(L),T(Y),A(oe),S(de),F.current={draftName:"",draftScope:"user",description:X,agent:$,model:L,variant:Y,subagent:oe,template:de}}},[p,f,e,h,i,N]);const K=o.useCallback(V=>{const X=g.trim(),$=Ln(C.trim()),ee=$?Ic({providerID:$.providerId,modelID:$.modelId,variant:j.trim()||void 0}):null;return{name:V,description:b.trim()||void 0,agent:X===""?null:X,model:ee,subagent:x,template:M.trim(),scope:f?v:void 0}},[g,b,v,f,C,x,M,j]),W=o.useCallback(async()=>{const V=F.current,X=e?.trim();if(f||!V||!X||b.trim()===V.description.trim()&&g.trim()===V.agent.trim()&&C.trim()===V.model.trim()&&j.trim()===V.variant.trim()&&x===V.subagent&&M.trim()===V.template.trim())return Os;if(!M.trim())return us(t("settings.commands.page.toast.templateRequired"));const ee=K(X),L=ci(ee.model),Y={identity:N,form:{...V,description:ee.description||"",agent:ee.agent||"",model:L?`${L.providerID}/${L.modelID}`:"",variant:L?.variant||"",subagent:ee.subagent===!0,template:ee.template||""}};U.current=Y;try{return await r(X,ee,c)?(R.current===N&&(F.current=Y.form),In):us(t("settings.commands.page.toast.updateFailed"))}finally{U.current===Y&&(U.current=null)}},[g,K,b,N,f,C,e,c,x,t,M,r,j]),te=Ja(W),{requestSave:Q}=te,H=async()=>{const V=m.trim().replace(/\s+/g,"-");if(!V){B.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!M.trim()){B.error(t("settings.commands.page.toast.templateRequired"));return}if(h.some(X=>X.name===V)){B.error(t("settings.commands.sidebar.toast.commandExists"));return}O(!0);try{await n(K(V),c)?(l(null),B.success(t("settings.commands.page.toast.created"))):B.error(t("settings.commands.page.toast.createFailed"))}catch(X){console.error("Error creating command:",X),B.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{O(!1)}},_=()=>{l(null),d(null)};return e?s.jsxs(ns,{title:f?t("settings.commands.page.title.new"):`/${e}`,description:t(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),onBlurCapture:te.onBlurCapture,children:[!f&&p&&s.jsx(Po,{legacy:p.legacy===!0,path:p.path}),s.jsxs(qe,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[f&&s.jsxs(Ct,{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(We,{value:m,onChange:V=>u(V.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:v,onValueChange:V=>w(V),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(As,{value:b,onChange:V=>k(V.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(qe,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ct,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(fo,{agentName:g,onChange:V=>{I(V),Q()},className:Ws})}),s.jsx(Ct,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ca,{providerId:Ln(C)?.providerId??"",modelId:Ln(C)?.modelId??"",onChange:(V,X)=>{P(V&&X?`${V}/${X}`:""),Q()},className:Ws})}),s.jsx(Ct,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(We,{value:j,onChange:V=>T(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!C&&!j,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(Ct,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(Ba,{checked:x,onCheckedChange:V=>{A(V),Q()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(qe,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:M,onChange:V=>S(V.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"}),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")]}),f&&s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(G,{onClick:()=>{H()},disabled:D||!m.trim()||!M.trim(),size:"xs",className:"!font-normal",children:t(D?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:_,disabled:D,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},Yi={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},wg=t=>t===!1?{...Yi,oauthEnabled:!1}:t?{oauthEnabled:!0,oauthClientId:t.client_id??"",oauthClientSecret:t.client_secret??"",oauthScope:t.scope??"",oauthRedirectUri:t.redirect_uri??"",oauthCallbackPort:t.callback_port===void 0?"":String(t.callback_port)}:Yi,yl=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":return"warning";default:return"idle"}},jl=t=>{const e=at.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 r;e[1]!==a?(r=Ie("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]=r):r=e[2];let i;return e[3]!==r?(i=s.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},kg=t=>{const e=at.c(124),{onItemSelect:a}=t,{t:n}=Ze(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:d,deleteMcp:c}=Jn($s(Ng)),h=Js();let p;e[0]!==h?(p=Ue=>go(Ue,h),e[0]=h,e[1]=p):p=e[1];const f=Jn(p);let m;e[2]!==h?(m=Ue=>Ue.getStatusForDirectory(h),e[2]=h,e[3]=m):m=e[3];const u=un(m),v=un(Sg),w=un(Cg),[b,k]=o.useState(null),[g,I]=o.useState(!1),[C,P]=o.useState(null),[j,T]=o.useState(null),[x,A]=o.useState(!1);let M;e[4]!==f?(M=f.filter(Ig),e[4]=f,e[5]=M):M=e[5];const S=M;let D;e[6]!==f?(D=f.filter(Pg),e[6]=f,e[7]=D):D=e[7];const O=D;let F,N;e[8]!==d||e[9]!==h?(F=()=>{d({directory:h})},N=[d,h],e[8]=d,e[9]=h,e[10]=F,e[11]=N):(F=e[10],N=e[11]),o.useEffect(F,N);let R;e[12]!==w||e[13]!==x||e[14]!==v||e[15]!==h?(R=()=>{if(x)return;A(!0);const Ue=new Promise(Ag);Promise.all([v({directory:h,silent:!0}),Ue]).then(()=>{const st=w(h);st&&B.error(st)}).finally(()=>{A(!1)})},e[12]=w,e[13]=x,e[14]=v,e[15]=h,e[16]=R):R=e[16];const U=R;let K;e[17]!==f||e[18]!==a||e[19]!==l||e[20]!==i?(K=()=>{let Ue="new-mcp-server",st=1;for(;f.some(ye=>ye.name===Ue);)Ue=`new-mcp-server-${st}`,st++;const ut={name:Ue,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...Yi,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1};l(ut),i(Ue),a?.()},e[17]=f,e[18]=a,e[19]=l,e[20]=i,e[21]=K):K=e[21];const W=K;let te;e[22]!==c||e[23]!==b||e[24]!==h||e[25]!==n?(te=async()=>{if(!b)return;I(!0);const Ue=await c(b.name,h);Ue.ok?Ue.reloadFailed?B.warning(Ue.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:Ue.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):B.success(Ue.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):B.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),I(!1)},e[22]=c,e[23]=b,e[24]=h,e[25]=n,e[26]=te):te=e[26];const Q=te;let H;e[27]!==n?(H=(Ue,st)=>s.jsxs(st,{onClick:ut=>{ut.stopPropagation(),k(Ue)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=H):H=e[28];const _=H;let V;e[29]===Symbol.for("react.memo_cache_sentinel")?(V=Ie("flex h-full flex-col","bg-background"),e[29]=V):V=e[29];let X;e[30]!==n?(X=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=X):X=e[31];let $;e[32]!==X?($=s.jsx("h2",{className:Pn,children:X}),e[32]=X,e[33]=$):$=e[33];let ee;e[34]!==n?(ee=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=ee):ee=e[35];let L;e[36]!==n?(L=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=L):L=e[37];const Y=x&&"animate-spin";let oe;e[38]!==Y?(oe=Ie("h-4 w-4",Y),e[38]=Y,e[39]=oe):oe=e[39];let de;e[40]!==oe?(de=s.jsx(z,{name:"refresh",className:oe}),e[40]=oe,e[41]=de):de=e[41];let ue;e[42]!==U||e[43]!==x||e[44]!==ee||e[45]!==L||e[46]!==de?(ue=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-ring",disabled:x,onClick:U,"aria-label":ee,title:L,children:de}),e[42]=U,e[43]=x,e[44]=ee,e[45]=L,e[46]=de,e[47]=ue):ue=e[47];let ce;e[48]!==$||e[49]!==ue?(ce=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[$,ue]}),e[48]=$,e[49]=ue,e[50]=ce):ce=e[50];let Se;e[51]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(xi,{className:"mb-3"}),e[51]=Se):Se=e[51];let ie;e[52]!==f.length||e[53]!==n?(ie=n("settings.mcp.sidebar.total",{count:f.length}),e[52]=f.length,e[53]=n,e[54]=ie):ie=e[54];let be;e[55]!==ie?(be=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ie}),e[55]=ie,e[56]=be):be=e[56];let ae;e[57]!==n?(ae=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=ae):ae=e[58];let pe;e[59]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[59]=pe):pe=e[59];let je;e[60]!==W||e[61]!==ae?(je=s.jsx(G,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:W,title:ae,children:pe}),e[60]=W,e[61]=ae,e[62]=je):je=e[62];let De;e[63]!==be||e[64]!==je?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,je]}),e[63]=be,e[64]=je,e[65]=De):De=e[65];let me;e[66]!==ce||e[67]!==De?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ce,Se,De]}),e[66]=ce,e[67]=De,e[68]=me):me=e[68];let $e;e[69]!==f.length||e[70]!==u||e[71]!==a||e[72]!==C||e[73]!==S||e[74]!==_||e[75]!==j||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==O?($e=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:f.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[S.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")}),S.map(Ue=>{const st=u[Ue.name],ut=yl(st?.status.status),ye=r===Ue.name,re=mi();return s.jsxs(ha,{open:j===Ue.name,onOpenChange:Te=>T(Te?Ue.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ye?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:re?void 0:Te=>{Te.preventDefault(),T(Ue.name)}}),children:[s.jsxs("button",{onClick:()=>{i(Ue.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(jl,{tone:ut,enabled:Ue.disabled!==!0}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ue.name}),s.jsx("span",{title:Ue.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Ue.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ue.type==="local"?Ue.command?.join(" ")??"":Ue.url??""})]}),s.jsxs(zn,{open:C===Ue.name,onOpenChange:Te=>{Te&&T(null),P(Te?Ue.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:_(Ue,wn)})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:_(Ue,pa)})]},Ue.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(Ue=>{const st=u[Ue.name],ut=yl(st?.status.status),ye=r===Ue.name,re=mi();return s.jsxs(ha,{open:j===Ue.name,onOpenChange:Te=>T(Te?Ue.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ye?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:re?void 0:Te=>{Te.preventDefault(),T(Ue.name)}}),children:[s.jsxs("button",{onClick:()=>{i(Ue.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(jl,{tone:ut,enabled:Ue.disabled!==!0}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ue.name}),s.jsx("span",{title:Ue.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Ue.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ue.type==="local"?Ue.command?.join(" ")??"":Ue.url??""})]}),s.jsxs(zn,{open:C===Ue.name,onOpenChange:Te=>{Te&&T(null),P(Te?Ue.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:_(Ue,wn)})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:_(Ue,pa)})]},Ue.name)})]})]})}),e[69]=f.length,e[70]=u,e[71]=a,e[72]=C,e[73]=S,e[74]=_,e[75]=j,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=O,e[81]=$e):$e=e[81];const Ge=b!==null;let xe;e[82]!==g?(xe=Ue=>{!Ue&&!g&&k(null)},e[82]=g,e[83]=xe):xe=e[83];let Pe;e[84]!==n?(Pe=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Pe):Pe=e[85];let J;e[86]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[86]=Pe,e[87]=J):J=e[87];const se=b?.name||"";let he;e[88]!==n||e[89]!==se?(he=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[88]=n,e[89]=se,e[90]=he):he=e[90];let ve;e[91]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ve):ve=e[91];let Fe;e[92]!==he?(Fe=s.jsxs(Ht,{children:[he," ",ve,"."]}),e[92]=he,e[93]=Fe):Fe=e[93];let Ke;e[94]!==J||e[95]!==Fe?(Ke=s.jsxs(Bt,{children:[J,Fe]}),e[94]=J,e[95]=Fe,e[96]=Ke):Ke=e[96];let Be;e[97]===Symbol.for("react.memo_cache_sentinel")?(Be=()=>k(null),e[97]=Be):Be=e[97];let ze;e[98]!==n?(ze=n("settings.common.actions.cancel"),e[98]=n,e[99]=ze):ze=e[99];let _e;e[100]!==g||e[101]!==ze?(_e=s.jsx(G,{size:"sm",variant:"ghost",onClick:Be,disabled:g,children:ze}),e[100]=g,e[101]=ze,e[102]=_e):_e=e[102];let Me;e[103]!==g||e[104]!==n?(Me=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=Me):Me=e[105];let tt;e[106]!==Q||e[107]!==g||e[108]!==Me?(tt=s.jsx(G,{size:"sm",onClick:Q,disabled:g,children:Me}),e[106]=Q,e[107]=g,e[108]=Me,e[109]=tt):tt=e[109];let pt;e[110]!==_e||e[111]!==tt?(pt=s.jsxs(as,{children:[_e,tt]}),e[110]=_e,e[111]=tt,e[112]=pt):pt=e[112];let ct;e[113]!==Ke||e[114]!==pt?(ct=s.jsxs(Ut,{className:"max-w-md",children:[Ke,pt]}),e[113]=Ke,e[114]=pt,e[115]=ct):ct=e[115];let dt;e[116]!==Ge||e[117]!==xe||e[118]!==ct?(dt=s.jsx(_t,{open:Ge,onOpenChange:xe,children:ct}),e[116]=Ge,e[117]=xe,e[118]=ct,e[119]=dt):dt=e[119];let ht;return e[120]!==me||e[121]!==$e||e[122]!==dt?(ht=s.jsxs("div",{className:V,children:[me,$e,dt]}),e[120]=me,e[121]=$e,e[122]=dt,e[123]=ht):ht=e[123],ht};function Ng(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Sg(t){return t.refresh}function Cg(t){return t.getErrorForDirectory}function Ig(t){return t.scope==="project"}function Pg(t){return t.scope!=="project"}function Ag(t){return setTimeout(t,500)}function qs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Xa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function vn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ri(t,e,a){const n=Eg(a),r=typeof a.url=="string"?a.url.trim():"",i=wl(a,"env","environment"),l=wl(a,"headers"),d=qs(a.oauth)?a.oauth:null,c=ei(d,"client_id","clientId"),h=ei(d,"client_secret","clientSecret"),p=ei(d,"scope"),f=ei(d,"redirect_uri","redirectUri"),m=Tg(d,"callback_port","callbackPort"),u=ei(d,"auth_server_metadata_url","authServerMetadataUrl"),v=a.oauth===!1||a.oauth===null||a.oauth===void 0?!1:!!d&&!!(c||h||p||f||m||u),w=Dg(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:v,oauthClientId:c,oauthClientSecret:h,oauthScope:p,oauthRedirectUri:f,oauthCallbackPort:m,oauthAuthServerMetadataUrl:u,timeoutStartup:w.startup,timeoutCatalog:w.catalog,timeoutExecution:w.execution,codemode:a.codemode===!0?"on":a.codemode===!1?"off":"default",disabled:Mg(a),protocol:Xr.find(b=>b===a.protocol)??"legacy"}}function ei(t,...e){if(!t)return"";for(const a of e){const n=t[a];if(typeof n=="string"&&n.trim())return n.trim()}return""}function Tg(t,...e){if(!t)return"";for(const a of e){const n=oi(t[a]);if(n)return n}return""}function oi(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return String(Math.floor(t));if(typeof t=="string"&&t.trim()){const e=Number(t);if(Number.isFinite(e)&&e>0)return String(Math.floor(e))}return""}function Eg(t){const e=t.command,a=t.args;if(Xa(e)&&Xa(a))return[...e,...a];if(Xa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Xa(a)?[...n,...a]:n}return Xa(a)?a:[]}function wl(t,...e){for(const a of e){const n=t[a];if(!qs(n))continue;const r=Object.entries(n).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function Dg(t){return qs(t.timeout)?{startup:oi(t.timeout.startup),catalog:oi(t.timeout.catalog),execution:oi(t.timeout.execution)}:{startup:"",catalog:"",execution:oi(t.timeout)}}function Mg(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function Rg(t){const e=t.mcpServers;if(qs(e)){const n=Object.keys(e);if(n.length===1){const r=n[0],i=e[r];if(qs(i))return{name:r,entry:i}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const r=t[n];return n!=="mcpServers"&&qs(r)});if(a.length===1){const n=a[0],r=t[n];if(Xc(r))return{name:n,entry:r}}return null}function Xc(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Og(t,e){let a;try{const c=t.trim();if(!c)return vn("No JSON content provided");a=JSON.parse(c)}catch(c){return vn(c instanceof Error?`Invalid JSON: ${c.message}`:"Invalid JSON")}if(!qs(a))return vn("Expected a JSON object, not an array or primitive");const n=a,r=n.mcpServers;if(qs(r)){const c=Object.keys(r);if(c.length===0)return vn("mcpServers object is empty",a);if(c.length>1)return vn("Paste one server at a time. Found "+c.length+" servers in mcpServers",a);const h=c[0],p=r[h];return qs(p)?Ri(h,Oi(p),p):vn("Server entry is not a valid object",a)}const i=n.mcp,l=qs(i)&&qs(i.servers)?i.servers:i;if(qs(l)){const c=Object.keys(l);if(c.length===0)return vn("mcp object is empty",a);if(c.length>1)return vn("Paste one server at a time. Found "+c.length+" servers in mcp",a);const h=c[0],p=l[h];return qs(p)?Ri(h,Oi(p),p):vn("Server entry in mcp is not a valid object",a)}const d=Rg(n);if(d)return Ri(d.name,Oi(d.entry),d.entry);if(Xc(n)){const c=Oi(n),h=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ri(h,c,n)}return vn("No recognizable MCP server configuration found in JSON",a)}function Oi(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 Fg(t,e,a){const n=a?.isNewServer??!1,r=t.name,i=n&&r?r:e.name??"";return{...e,name:i,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:"",oauthCallbackPort:t.type==="remote"?t.oauthCallbackPort:"",oauthAuthServerMetadataUrl:t.type==="remote"?t.oauthAuthServerMetadataUrl:"",timeoutStartup:t.type==="local"?t.timeoutStartup:"",timeoutCatalog:t.timeoutCatalog,timeoutExecution:t.timeoutExecution,codemode:t.codemode,disabled:t.disabled,protocol:t.protocol}}const Lg=(t,e)=>!!e&&t!=="claude-code",Kg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,_g=t=>Kg.exec(t)?.[0]??void 0,bi=t=>t.type!=="external",Fi=t=>t.title??t.key,Ug=(t,e)=>{if(e===void 0)return!1;const a=String(e),n=String(t.value);return t.op==="eq"?a===n:a!==n},zg=(t,e)=>bi(t)?(t.when??[]).every(a=>Ug(a,e[a.key])):!0,Ao=(t,e)=>{const a={},n=[];for(const r of t){if(!zg(r,a))continue;n.push(r);const i=e[r.key];bi(r)&&i!==void 0&&(a[r.key]=i)}return n},$g=t=>{const e={};for(const a of t)switch(a.type){case"external":break;case"boolean":e[a.key]=a.default??!1;break;case"number":case"integer":typeof a.default=="number"&&(e[a.key]=a.default);break;case"multiselect":e[a.key]=a.default??[];break;case"string":e[a.key]=a.default??a.options?.[0]?.value??"";break}return e},ed=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,Bg=(t,e)=>Ao(t,e).find(a=>bi(a)&&a.required===!0&&ed(e[a.key]))??null,Vg=(t,e)=>{const a={};for(const n of Ao(t,e)){if(!bi(n))continue;const r=e[n.key];ed(r)||r===void 0||(a[n.key]=typeof r=="string"?r.trim():r)}return a},kl=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Nl=t=>typeof t=="string"&&t.length>0?t:void 0,Hg=(t,e,a)=>{const n=kl(t)?t:{},r=kl(n.data)?n.data:{};switch(n.name){case"IntegrationOauthAttemptMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"IntegrationOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"IntegrationOauthFailed":return e("settings.providers.page.auth.oauth.error.declined");case"IntegrationValidationFailed":return Nl(r.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return Nl(n.message)??e(a)}},Or={phase:"idle"},qg=1500,ro=({integrationId:t,methods:e,onConnected:a,directory:n,className:r})=>{const{t:i}=Ze(),l=o.useCallback(()=>n?Gs.getScopedSdkClient(n):Gs.getSdkClient(),[n]),[d,c]=o.useState(Or),[h,p]=o.useState({}),[f,m]=o.useState(""),u=o.useRef(null),v=o.useCallback(D=>{u.current=null,l().integration.oauth.cancel({integrationID:t,attemptID:D}).catch(()=>{})},[t,l]);o.useEffect(()=>()=>{const D=u.current;D&&v(D)},[v]);const w=d.phase==="idle"?null:d.methodID,b=d.phase==="connecting"||d.phase==="waiting"||d.phase==="awaitingCode"&&d.submitting,k=async(D,O,F)=>{const N=await za(D);if(N.ok){B.success(i(O));return}console.error("Failed to copy OAuth value:",N.error),B.error(i(F))},g=async()=>{u.current=null,c(Or),B.success(i("settings.providers.page.toast.oauthCompleted")),await a()},I=(D,O,F)=>{u.current=null,console.error("OAuth flow failed:",O),c({phase:"failed",methodID:D,message:Hg(O,i,F)})},C=async(D,O)=>{const F=l();for(;u.current===O;){if(await new Promise(N=>setTimeout(N,qg)),u.current!==O)return;try{const{data:N}=await F.integration.oauth.status({integrationID:t,attemptID:O});if(u.current!==O)return;if(N.status==="complete"){await g();return}if(N.status==="failed"){c({phase:"failed",methodID:D,message:N.message}),u.current=null;return}}catch(N){if(u.current!==O)return;I(D,N,"settings.providers.page.toast.oauthCompleteFailed");return}}},P=async(D,O)=>{c({phase:"connecting",methodID:D.id});let F;try{const{data:N}=await l().integration.oauth.connect({integrationID:t,methodID:D.id,...Object.keys(O).length>0?{answer:O}:{}});F={attemptID:N.attemptID,mode:N.mode,url:N.url,instructions:N.instructions}}catch(N){I(D.id,N,"settings.providers.page.toast.oauthStartFailed");return}if(u.current=F.attemptID,Lg(t,F.url)&&yn(F.url),F.mode==="code"){m(""),c({phase:"awaitingCode",methodID:D.id,attempt:F,submitting:!1});return}c({phase:"waiting",methodID:D.id,attempt:F}),await C(D.id,F.attemptID)},j=D=>{const O=(D.form??[]).filter(bi);if(O.length===0){P(D,{});return}p($g(O)),c({phase:"prompting",methodID:D.id,fields:O,error:null})},T=D=>{if(d.phase!=="prompting")return;const O=Bg(d.fields,h);if(O){c({...d,error:i("settings.providers.page.auth.oauth.promptRequired",{field:Fi(O)})});return}P(D,Vg(d.fields,h))},x=async()=>{if(d.phase!=="awaitingCode")return;const D=f.trim();if(!D)return;const{methodID:O,attempt:F}=d;c({...d,submitting:!0});try{await l().integration.oauth.complete({integrationID:t,attemptID:F.attemptID,code:D}),await g()}catch(N){I(O,N,"settings.providers.page.toast.oauthCompleteFailed")}},A=()=>{(d.phase==="waiting"||d.phase==="awaitingCode")&&v(d.attempt.attemptID),c(Or)},M=D=>{if(D.type==="external")return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Fi(D)}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(D.url)},children:i("settings.providers.page.actions.open")})]},D.key);const O=h[D.key],F=typeof O=="string"?O:"",N=U=>p(K=>({...K,[D.key]:U})),R=D.type==="string"||D.type==="multiselect"?D.options??[]:[];return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Fi(D)}),D.description&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:D.description}),R.length>0?s.jsxs(Tt,{value:F,onValueChange:N,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{children:U=>R.find(K=>K.value===U)?.label??null})}),s.jsx(At,{children:R.map(U=>s.jsx(mt,{value:U.value,children:U.description?`${U.label} · ${U.description}`:U.label},U.value))})]}):D.type==="boolean"?s.jsx("input",{type:"checkbox",checked:O===!0,onChange:U=>N(U.target.checked),"aria-label":Fi(D)}):s.jsx(We,{value:F,onChange:U=>N(U.target.value),placeholder:D.type==="string"?D.placeholder:void 0,className:"max-w-[24rem] text-xs"})]},D.key)},S=D=>{const O=_g(D.instructions);return s.jsxs(s.Fragment,{children:[D.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:D.instructions}),O&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:O,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{k(O,"settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),D.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:D.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(D.url)},children:i("settings.providers.page.actions.open")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{k(D.url,"settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]})};return s.jsx("div",{className:Ie("space-y-4",r),children:e.map(D=>{const O=w===D.id;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:D.label}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>j(D),disabled:b,children:i("settings.providers.page.actions.connect")})]}),O&&d.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Ao(d.fields,h).map(M),d.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{size:"xs",className:"!font-normal",onClick:()=>T(D),children:i("settings.providers.page.actions.continue")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:A,children:i("settings.providers.page.actions.cancel")})]})]}),O&&d.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),O&&d.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[S(d.attempt),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:A,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),O&&d.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[S(d.attempt),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(We,{value:f,onChange:F=>m(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:d.submitting}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{x()},disabled:d.submitting||f.trim().length===0,children:d.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:A,disabled:d.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),O&&d.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.message}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>j(D),children:i("settings.providers.page.actions.tryAgain")})]})]},D.id)})})},Gg=(t,e)=>t.find(a=>a.id.startsWith("mcp_")&&a.metadata?.source==="mcp"&&a.name===e),Wg=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Jg=({serverName:t,directory:e,onConnected:a})=>{const[n,r]=o.useState(null);o.useEffect(()=>{let l=!1;r(null);const d=e?Gs.getScopedSdkClient(e):Gs.getSdkClient();return(async()=>{try{const{data:h}=await d.integration.list();l||r(Gg(h,t)??null)}catch(h){console.error("Failed to load MCP integrations:",h)}})(),()=>{l=!0}},[e,t]);const i=Wg(n??void 0);return!n||i.length===0?null:s.jsx(ro,{integrationId:n.id,methods:i,directory:e,onConnected:a},n.id)},Fr=t=>t===void 0?"":String(t),Lr=t=>{const e=t.trim();if(!e)return null;const a=Number(e);return!Number.isFinite(a)||a<=0?null:a%1e3===0?`${a/1e3}s`:`${a}ms`},Kr={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},Sl={default:"settings.mcp.page.advanced.codemodeOption.default",on:"settings.mcp.page.advanced.codemodeOption.on",off:"settings.mcp.page.advanced.codemodeOption.off"},Qg=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},ti=t=>t?.status.status,_r=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function td(t){const e=[];let a="",n=!1,r=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!r){n=!n;continue}if(l==='"'&&!n){r=!r;continue}if((l===" "||l===" ")&&!n&&!r){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}const Yg=t=>{const e=at.c(27),{value:a,onChange:n,preview:r,onDetectUrl:i}=t;let l;e[0]!==a?(l=()=>a.join(`
5
+ `),e[0]=a,e[1]=l):l=e[1];const[d,c]=o.useState(l),h=o.useRef(a);let p,f;e[2]!==a?(p=()=>{JSON.stringify(h.current)!==JSON.stringify(a)&&(h.current=a,c(a.join(`
6
+ `)))},f=[a],e[2]=a,e[3]=p,e[4]=f):(p=e[3],f=e[4]),o.useEffect(p,f);let m;e[5]!==n||e[6]!==i?(m=j=>{const T=j.split(`
7
+ `).filter(ah);if(i&&T.length===1&&/^https?:\/\/\S+$/i.test(T[0].trim())){i(T[0].trim());return}n(T)},e[5]=n,e[6]=i,e[7]=m):m=e[7];const u=m;let v;e[8]!==n?(v=j=>{const x=j.clipboardData.getData("text").trim();if(!x||x.includes(`
8
+ `)||!/\s/.test(x))return;const A=j.currentTarget;if(A.selectionStart!==0||A.selectionEnd!==A.value.length)return;j.preventDefault();const M=td(x);c(M.join(`
9
+ `)),n(M)},e[8]=n,e[9]=v):v=e[9];const w=v;let b;e[10]!==u?(b=j=>{c(j.target.value),u(j.target.value)},e[10]=u,e[11]=b):b=e[11];let k;e[12]!==u||e[13]!==d?(k=()=>{const j=d.split(`
10
+ `).map(ih).join(`
11
+ `);c(j),u(j)},e[12]=u,e[13]=d,e[14]=k):k=e[14];const g=Math.max(4,a.length+1);let I;e[15]!==w||e[16]!==b||e[17]!==k||e[18]!==g||e[19]!==d?(I=s.jsx(As,{onPaste:w,value:d,onChange:b,onBlur:k,placeholder:`npx
12
12
  -y
13
13
  @modelcontextprotocol/server-postgres
14
- postgresql://user:pass@host/db`,rows:m,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=w,e[16]=b,e[17]=k,e[18]=m,e[19]=d,e[20]=S):S=e[20];let P;e[21]!==r||e[22]!==a?(P=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:r(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(ih)})})]}),e[21]=r,e[22]=a,e[23]=P):P=e[23];let I;return e[24]!==P||e[25]!==S?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[S,P]}),e[24]=P,e[25]=S,e[26]=I):I=e[26],I},Yg=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Nl=({value:t,onChange:e,onCommit:a,keyTransform:n=Yg,keyPlaceholder:r="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:l="Paste .env",pasteTitle:d="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:h,clipboardReadFailed:g,keyLabel:f,valueLabel:p,valuePlaceholder:u,hideValueTitle:v,showValueTitle:w,addVariable:b,plainTextWarning:k,removeVariableAria:m})=>{const[S,P]=o.useState(new Set),I=()=>e([...t,{key:"",value:""}]),j=C=>{e(t.filter((E,O)=>O!==C)),a?.(),P(E=>{const O=new Set(E);return O.delete(C),O})},D=(C,E,O)=>{const F=[...t];F[C]={...F[C],[E]:O},e(F)},x=C=>{P(E=>{const O=new Set(E);return O.has(C)?O.delete(C):O.add(C),O})},A=async()=>{try{const C=await navigator.clipboard.readText(),E=[];for(const F of C.split(`
15
- `)){const N=F.trim();if(!N||N.startsWith("#"))continue;const M=N.indexOf("=");if(M===-1)continue;const U=N.slice(0,M).trim();let K=N.slice(M+1).trim();(K.startsWith('"')&&K.endsWith('"')||K.startsWith("'")&&K.endsWith("'"))&&(K=K.slice(1,-1)),U&&E.push({key:U,value:K})}if(E.length===0){B.error(c);return}const O=[...t];for(const F of E){const N=O.findIndex(M=>M.key===F.key);N!==-1?O[N]=F:O.push(F)}e(O),a?.(),B.success(h(E.length))}catch{B.error(g)}},R=t.some(C=>C.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:f}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:d,children:[s.jsx(z,{name:"clipboard",className:"h-3 w-3"}),l]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((C,E)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:C.key,onChange:O=>D(E,"key",n(O.target.value)),placeholder:r,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(We,{type:S.has(E)?"text":"password",value:C.value,onChange:O=>D(E,"value",O.target.value),placeholder:u,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:()=>x(E),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:S.has(E)?v:w,children:S.has(E)?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>j(E),"aria-label":m,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},E))}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:I,type:"button",children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),b]}),R&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:k})]})},Sl=t=>{const e=at.c(14),{status:a,enabled:n,getStatusLabel:r,variant:i}=t,l=i===void 0?"compact":i;if(!n||!a)return null;let d,c;if(e[0]!==r||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const p={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const u=Ie("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let v;e[5]!==r||e[6]!==a?(v=r(a),e[5]=r,e[6]=a,e[7]=v):v=e[7],c=s.jsxs("span",{className:u,children:["● ",v]});break e}d=Ie("typography-micro font-medium",p.text)}e[0]=r,e[1]=a,e[2]=l,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let h;e[8]!==r||e[9]!==a?(h=r(a),e[8]=r,e[9]=a,e[10]=h):h=e[10];let g;return e[11]!==d||e[12]!==h?(g=s.jsxs("span",{className:d,children:["● ",h]}),e[11]=d,e[12]=h,e[13]=g):g=e[13],g},Zg=(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 a?.trim()||e("settings.mcp.page.status.description.needsAuth");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Xg=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},eh=t=>t==="failed"||t==="needs_auth",th=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},sh=()=>{const{t}=Ze(),e=o.useCallback((ne,we)=>t(ne,we),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:r,setSelectedMcp:i,getMcpByName:l,createMcp:d,updateMcp:c,deleteMcp:h}=Jn($s(ne=>({selectedMcpName:ne.selectedMcpName,mcpDraft:ne.mcpDraft,setMcpDraft:ne.setMcpDraft,setSelectedMcp:ne.setSelectedMcp,getMcpByName:ne.getMcpByName,createMcp:ne.createMcp,updateMcp:ne.updateMcp,deleteMcp:ne.deleteMcp}))),g=Js(),f=un(ne=>ne.getStatusForDirectory(g)),p=un(ne=>ne.getDiagnosticForDirectory(g)),u=un(ne=>ne.refresh),v=un(ne=>ne.connect),w=un(ne=>ne.disconnect),b=un(ne=>ne.testConnection),k=Jn(ne=>go(ne,g)),m=a?l(a,g):null,S=!!(n&&n.name===a&&!m),[P,I]=o.useState(""),[j,D]=o.useState("user"),[x,A]=o.useState("local"),[R,C]=o.useState([]),[E,O]=o.useState(""),[F,N]=o.useState([]),[M,U]=o.useState([]),[K,W]=o.useState(""),[te,Q]=o.useState(""),[H,_]=o.useState(""),[V,X]=o.useState("default"),[$,ee]=o.useState("legacy"),[L,Y]=o.useState(""),[oe,de]=o.useState(Yi),[ge,ce]=o.useState(!0),[Se,ie]=o.useState(!1),[be,ae]=o.useState(!1),[me,je]=o.useState(!1),[De,ue]=o.useState(!1),[$e,Ge]=o.useState(!1),[xe,Pe]=o.useState(!1),[J,se]=o.useState(!1),[he,ve]=o.useState(""),[Fe,Ke]=o.useState(null),Be=o.useMemo(()=>th(a,g),[g,a]),ze=o.useRef(Be),_e=o.useRef(null),Me=JSON.stringify([a,g,S]),tt=o.useRef(Me);tt.current=Me;const pt=o.useRef(null),ct={mcpType:x,command:R,url:E,envEntries:F,headerEntries:M,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ge},dt=o.useRef(ct);dt.current=ct;const ht=o.useCallback(()=>{ve(""),Ke(null),se(!0)},[]),Ue=o.useCallback(async()=>{try{const ne=await navigator.clipboard.readText();ve(ne),Ke(null)}catch{B.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),st=o.useCallback(()=>{const ne=Rg(he,{fallbackName:P});if(!ne.ok){Ke(ne.error);return}const nt=Og(ne,{name:P,scope:j,type:x,command:R,url:E,environment:F,headers:M,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,disabled:!ge,protocol:$,oauthAuthServerMetadataUrl:L},{isNewServer:S});I(nt.name),A(nt.type),C(nt.command??[]),O(nt.url??""),N(nt.environment??[]),U(nt.headers??[]),W(nt.timeoutStartup??""),Q(nt.timeoutCatalog??""),_(nt.timeoutExecution??""),X(nt.codemode??"default"),ce(nt.disabled!==!0),ee(nt.protocol??"legacy"),Y(nt.oauthAuthServerMetadataUrl??""),se(!1),ve(""),Ke(null),B.success(t("settings.mcp.page.toast.configImported"))},[he,P,j,x,R,E,F,M,$,L,K,te,H,V,ge,S,t]);o.useEffect(()=>{if(S&&n){pt.current=null,I(n.name),D(n.scope||"user"),A(n.type),C(n.command),O(n.url),N(n.environment),U(n.headers),W(n.timeoutStartup),Q(n.timeoutCatalog),_(n.timeoutExecution),X(n.codemode),ee(n.protocol),Y(n.oauthAuthServerMetadataUrl),de({oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,oauthCallbackPort:n.oauthCallbackPort}),ce(!n.disabled),Pe(!1),_e.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,timeoutStartup:n.timeoutStartup,timeoutCatalog:n.timeoutCatalog,timeoutExecution:n.timeoutExecution,codemode:n.codemode,protocol:n.protocol,oauthAuthServerMetadataUrl:n.oauthAuthServerMetadataUrl,enabled:!n.disabled};return}if(m){D(m.scope==="project"?"project":"user");const ne=Uo(m.environment),we=m.type==="remote"?m:null,nt=Uo(we?.headers),Rt=m.type,Jt=Rt==="local"?m.command??[]:[],Ce=we?.url??"",He=Fr(m.timeout?.startup),yt=Fr(m.timeout?.catalog),It=Fr(m.timeout?.execution),Qt=Bd(m.codemode),Xt=m.protocol??"legacy",ts=jg(we?.oauth),es=we&&we.oauth?we.oauth.auth_server_metadata_url??"":"",Fs=m.disabled!==!0;de(ts);const Qs=_e.current!==null&&JSON.stringify(_e.current)!==JSON.stringify(dt.current);if(pt.current===Me&&Qs)return;pt.current=Me,A(Rt),C(Jt),O(Ce),N(ne),U(nt),W(He),Q(yt),_(It),X(Qt),ee(Xt),Y(es),ce(Fs),Pe(!1),_e.current={mcpType:Rt,command:Jt,url:Ce,envEntries:ne,headerEntries:nt,timeoutStartup:He,timeoutCatalog:yt,timeoutExecution:It,codemode:Qt,protocol:Xt,oauthAuthServerMetadataUrl:es,enabled:Fs}}},[m,a,g,S,n,Me]);const ut=o.useMemo(()=>{const ne=L.trim();return!ne||Jg(ne)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[L,t]),ye=o.useMemo(()=>{const ne=[];x==="remote"&&M.length>0&&ne.push(`${M.length} ${t("settings.mcp.page.advanced.headers")}`);const we=x==="local"?Lr(K):null;we&&ne.push(t("settings.mcp.page.advanced.summary.startup",{value:we}));const nt=Lr(te);nt&&ne.push(t("settings.mcp.page.advanced.summary.catalog",{value:nt}));const Rt=Lr(H);return Rt&&ne.push(t("settings.mcp.page.advanced.summary.execution",{value:Rt})),V==="on"&&ne.push(t("settings.mcp.page.advanced.summary.codemodeOn")),V==="off"&&ne.push(t("settings.mcp.page.advanced.summary.codemodeOff")),$!=="legacy"&&ne.push(t(Kr[$])),ne.join(" · ")},[V,M.length,x,$,t,te,H,K]),re=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(z,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(z,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Te=o.useCallback(ne=>{A("remote"),O(ne),C([])},[]),Ne=o.useCallback(ne=>{O(ne);const we=ne.trim();we&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(we)&&/\s/.test(we)&&(A("local"),C(Xc(we)),O(""))},[]),Ae=ne=>({name:ne,scope:j,type:x,command:R,url:E,environment:F,headers:M,...oe,oauthAuthServerMetadataUrl:x==="remote"?L:"",protocol:$,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,disabled:!ge}),Le=Ja(async()=>{const ne=_e.current;if(S||!ne||!a||JSON.stringify(ne)===JSON.stringify({mcpType:x,command:R,url:E,envEntries:F,headerEntries:M,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ge}))return Os;if(x==="local"&&R.filter(Boolean).length===0)return hs(t("settings.mcp.page.toast.localCommandRequired"));if(x==="remote"&&!E.trim())return hs(t("settings.mcp.page.toast.remoteUrlRequired"));if(x==="remote"&&ut)return hs(ut);const we=await c(a,Ae(a),g);return we.ok?tt.current!==Me?In:(_e.current={mcpType:x,command:R,url:E,envEntries:F,headerEntries:M,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ge},await u({directory:g,silent:!0}),we.reloadFailed?hs(we.warning||we.message||t("settings.mcp.page.toast.savedReloadFailed")):In):hs(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:Qe}=Le,lt=async()=>{const ne=P.trim();if(!ne){B.error(t("settings.mcp.page.toast.nameRequired"));return}if(k.some(we=>we.name===ne)){B.error(t("settings.mcp.page.toast.serverNameExists"));return}if(x==="local"&&R.filter(Boolean).length===0){B.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(x==="remote"&&!E.trim()){B.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(x==="remote"&&ut){B.error(ut);return}ie(!0);try{const we=await d(Ae(ne),g);we.ok?(r(null),i(ne),await u({directory:g,silent:!0}),we.reloadFailed?B.warning(we.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:we.warning||t("settings.mcp.page.toast.retryRefreshHint")}):B.success(we.message||t("settings.mcp.page.toast.serverCreatedReloading"))):B.error(t("settings.mcp.page.toast.saveFailed"))}catch(we){B.error(we instanceof Error?we.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ie(!1)}},ot=()=>{r(null),i(null)},bt=async()=>{if(!a)return;je(!0);const ne=await h(a,g);ne.ok?(ne.reloadFailed?B.warning(ne.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:ne.warning||t("settings.mcp.page.toast.refreshListIfStale")}):B.success(ne.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),ae(!1)):B.error(t("settings.mcp.page.toast.deleteFailed")),je(!1)},wt=async()=>{if(a)try{await v(a,g),B.success(t("settings.mcp.page.toast.connected"))}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionTestFailed"))}},jt=async()=>{if(a){ue(!0);try{if(ti(f[a])==="connected")await w(a,g),B.success(t("settings.mcp.page.toast.disconnected"));else{await v(a,g),await u({directory:g,silent:!0});const we=un.getState().getStatusForDirectory(g)[a],nt=ti(we);nt==="connected"?B.success(t("settings.mcp.page.toast.connected")):nt==="needs_auth"?B.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):nt==="failed"?B.error(_r(we)||t("settings.mcp.page.toast.connectionFailed")):B.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await u({directory:g,silent:!0})}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ue(!1)}}},vt=o.useCallback(()=>S?(B.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[S,t]),Xe=o.useCallback(async(ne=!1)=>{try{await u({directory:g,silent:ne})}catch(we){ne||B.error(we instanceof Error?we.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[g,u,t]);o.useEffect(()=>{Xe(!0)},[Xe]),o.useEffect(()=>{ze.current=Be,ue(!1),Ge(!1)},[Be]);const kt=o.useCallback(async()=>{if(!(!a||!vt())){if(!ge){B.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Ge(!0);try{const ne=await b(a,g),we=ti(ne.status);ne.warning?B.warning(ne.warning):we==="connected"?B.success(t("settings.mcp.page.toast.connectionTestSucceeded")):we==="needs_auth"?B.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):we==="failed"?B.error(_r(ne.status)||ne.error||t("settings.mcp.page.toast.connectionTestFailed")):ne.error?B.error(ne.error):B.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Ge(!1)}}},[g,ge,vt,a,t,b]);if(!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Re=f[a],Ve=a?p[a]:void 0,Z=Re?ti(Re):Ve?.status,pe=Re?_r(Re):Ve?.error,Oe=ti(Re)==="connected",Ee=Zg(Z,e,pe),Ye=ne=>{switch(ne){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");default:return ne}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:S?t("settings.mcp.page.header.newServer"):a,titleAccessory:S?void 0:s.jsx(Sl,{status:Z,enabled:ge,getStatusLabel:Ye,variant:"pill"}),description:S?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(x==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:S?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{variant:Oe?"outline":"default",size:"xs",className:"!font-normal",onClick:jt,disabled:De||!ge,children:t(De?"settings.mcp.page.actions.working":Oe?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),Oe&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{kt()},disabled:$e||!ge,children:t($e?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:Le.onBlurCapture,children:[!S&&m&&s.jsx(Po,{legacy:m.legacy===!0,path:m.path}),!S&&eh(Z)&&s.jsx(qe,{divider:!1,children:s.jsx("div",{className:Ie("rounded-lg border p-3",Xg(Z)),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:Nt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Sl,{status:Z,enabled:ge,getStatusLabel:Ye})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ee}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:j==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:g??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),Z==="needs_auth"&&a&&s.jsx(Wg,{serverName:a,directory:g,onConnected:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Oe&&s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:$e||!ge,children:t($e?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(qe,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:S?s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:ht,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(z,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[S&&s.jsxs(Ct,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(We,{value:P,onChange:ne=>I(ne.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(Tt,{value:j,onValueChange:ne=>D(ne),children:[s.jsxs(Pt,{size:$t,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(z,{name:j==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(j==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:ge,onChange:ne=>{ce(ne),Qe()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(qe,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(So,{items:re,activeId:x,onSelect:ne=>{A(ne),Qe()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),x==="local"?s.jsx(Qg,{value:R,onChange:C,preview:ne=>t("settings.mcp.page.connection.previewArgs",{count:ne}),onDetectUrl:Te}):s.jsx(We,{value:E,onChange:ne=>Ne(ne.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(x==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),s.jsx(qe,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(kn,{open:xe,onOpenChange:Pe,children:[s.jsxs(Nn,{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")}),ye&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",ye,")"]})]}),xe?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",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:Nt,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Tt,{value:$,onValueChange:ne=>{const we=Xr.find(nt=>nt===ne);we&&(ee(we),Qe())},children:[s.jsx(Pt,{size:$t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.protocol"),children:s.jsx("span",{className:"truncate",children:t(Kr[$])})}),s.jsx(At,{children:Xr.map(ne=>s.jsx(mt,{value:ne,children:t(Kr[ne])},ne))})]})]}),s.jsxs("div",{className:"space-y-2",children:[x==="local"&&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:Nt,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:K,onChange:ne=>W(ne.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),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:Nt,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:te,onChange:ne=>Q(ne.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),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:Nt,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:H,onChange:ne=>_(ne.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),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:Nt,children:t("settings.mcp.page.advanced.codemode")}),s.jsxs(qt,{children:[t("settings.mcp.page.advanced.codemodeHint")," ",t("settings.mcp.page.advanced.codemodeDefaultHint")]})]}),s.jsxs(Tt,{value:V,onValueChange:ne=>{const we=zo.find(nt=>nt===ne);we&&(X(we),Qe())},children:[s.jsx(Pt,{size:$t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.codemode"),children:s.jsx("span",{className:"truncate",children:t(kl[V])})}),s.jsx(At,{children:zo.map(ne=>s.jsx(mt,{value:ne,children:t(kl[ne])},ne))})]})]}),x==="remote"&&s.jsxs("div",{children:[s.jsxs(Cn,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),M.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",M.length,")"]})]}),s.jsx(Nl,{value:M,onChange:U,onCommit:Qe,keyTransform:ne=>ne.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:ne=>t("settings.mcp.page.toast.importedVariablesCount",{count:ne}),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")})]}),x==="remote"&&s.jsxs("div",{children:[s.jsx(Cn,{as:"div",className:"mb-2",children:t("settings.mcp.page.advanced.oauth")}),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:Nt,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.oauthMetadataUrlHint")})]}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx(We,{type:"url",value:L,onChange:ne=>Y(ne.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":ut?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),ut&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:ut})]})]})]})]})})]})}),s.jsx(qe,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:F.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",F.length,")"]}):null,settingsItem:"mcp.environment",children:F.length===0?s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>N([{key:"",value:""}]),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Nl,{value:F,onChange:N,onCommit:Qe,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:ne=>t("settings.mcp.page.toast.importedVariablesCount",{count:ne}),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&&s.jsxs(s.Fragment,{children:[s.jsx(G,{onClick:()=>{lt()},disabled:Se||!P.trim(),size:"xs",className:"!font-normal",children:t(Se?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:ot,disabled:Se,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!S&&s.jsx(G,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ae(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(_t,{open:J,onOpenChange:ne=>{ne||(se(!1),ve(""),Ke(null))},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ht,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:he,onChange:ne=>{ve(ne.target.value),Ke(null)},placeholder:`{
14
+ postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=w,e[16]=b,e[17]=k,e[18]=g,e[19]=d,e[20]=I):I=e[20];let C;e[21]!==r||e[22]!==a?(C=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:r(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(rh)})})]}),e[21]=r,e[22]=a,e[23]=C):C=e[23];let P;return e[24]!==C||e[25]!==I?(P=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[I,C]}),e[24]=C,e[25]=I,e[26]=P):P=e[26],P},Zg=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Cl=({value:t,onChange:e,onCommit:a,keyTransform:n=Zg,keyPlaceholder:r="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:l="Paste .env",pasteTitle:d="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:h,clipboardReadFailed:p,keyLabel:f,valueLabel:m,valuePlaceholder:u,hideValueTitle:v,showValueTitle:w,addVariable:b,plainTextWarning:k,removeVariableAria:g})=>{const[I,C]=o.useState(new Set),P=()=>e([...t,{key:"",value:""}]),j=S=>{e(t.filter((D,O)=>O!==S)),a?.(),C(D=>{const O=new Set(D);return O.delete(S),O})},T=(S,D,O)=>{const F=[...t];F[S]={...F[S],[D]:O},e(F)},x=S=>{C(D=>{const O=new Set(D);return O.has(S)?O.delete(S):O.add(S),O})},A=async()=>{try{const S=await navigator.clipboard.readText(),D=[];for(const F of S.split(`
15
+ `)){const N=F.trim();if(!N||N.startsWith("#"))continue;const R=N.indexOf("=");if(R===-1)continue;const U=N.slice(0,R).trim();let K=N.slice(R+1).trim();(K.startsWith('"')&&K.endsWith('"')||K.startsWith("'")&&K.endsWith("'"))&&(K=K.slice(1,-1)),U&&D.push({key:U,value:K})}if(D.length===0){B.error(c);return}const O=[...t];for(const F of D){const N=O.findIndex(R=>R.key===F.key);N!==-1?O[N]=F:O.push(F)}e(O),a?.(),B.success(h(D.length))}catch{B.error(p)}},M=t.some(S=>S.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:f}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:m})]}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:d,children:[s.jsx(z,{name:"clipboard",className:"h-3 w-3"}),l]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((S,D)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:S.key,onChange:O=>T(D,"key",n(O.target.value)),placeholder:r,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(We,{type:I.has(D)?"text":"password",value:S.value,onChange:O=>T(D,"value",O.target.value),placeholder:u,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:()=>x(D),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:I.has(D)?v:w,children:I.has(D)?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>j(D),"aria-label":g,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},D))}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:P,type:"button",children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),b]}),M&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:k})]})},Il=t=>{const e=at.c(14),{status:a,enabled:n,getStatusLabel:r,variant:i}=t,l=i===void 0?"compact":i;if(!n||!a)return null;let d,c;if(e[0]!==r||e[1]!==a||e[2]!==l){c=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"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const u=Ie("typography-micro font-medium rounded-full px-2 py-0.5",m.text,m.bg);let v;e[5]!==r||e[6]!==a?(v=r(a),e[5]=r,e[6]=a,e[7]=v):v=e[7],c=s.jsxs("span",{className:u,children:["● ",v]});break e}d=Ie("typography-micro font-medium",m.text)}e[0]=r,e[1]=a,e[2]=l,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let h;e[8]!==r||e[9]!==a?(h=r(a),e[8]=r,e[9]=a,e[10]=h):h=e[10];let p;return e[11]!==d||e[12]!==h?(p=s.jsxs("span",{className:d,children:["● ",h]}),e[11]=d,e[12]=h,e[13]=p):p=e[13],p},Xg=(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 a?.trim()||e("settings.mcp.page.status.description.needsAuth");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},eh=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},th=t=>t==="failed"||t==="needs_auth",sh=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},nh=()=>{const{t}=Ze(),e=o.useCallback((ne,we)=>t(ne,we),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:r,setSelectedMcp:i,getMcpByName:l,createMcp:d,updateMcp:c,deleteMcp:h}=Jn($s(ne=>({selectedMcpName:ne.selectedMcpName,mcpDraft:ne.mcpDraft,setMcpDraft:ne.setMcpDraft,setSelectedMcp:ne.setSelectedMcp,getMcpByName:ne.getMcpByName,createMcp:ne.createMcp,updateMcp:ne.updateMcp,deleteMcp:ne.deleteMcp}))),p=Js(),f=un(ne=>ne.getStatusForDirectory(p)),m=un(ne=>ne.getDiagnosticForDirectory(p)),u=un(ne=>ne.refresh),v=un(ne=>ne.connect),w=un(ne=>ne.disconnect),b=un(ne=>ne.testConnection),k=Jn(ne=>go(ne,p)),g=a?l(a,p):null,I=!!(n&&n.name===a&&!g),[C,P]=o.useState(""),[j,T]=o.useState("user"),[x,A]=o.useState("local"),[M,S]=o.useState([]),[D,O]=o.useState(""),[F,N]=o.useState([]),[R,U]=o.useState([]),[K,W]=o.useState(""),[te,Q]=o.useState(""),[H,_]=o.useState(""),[V,X]=o.useState("default"),[$,ee]=o.useState("legacy"),[L,Y]=o.useState(""),[oe,de]=o.useState(Yi),[ue,ce]=o.useState(!0),[Se,ie]=o.useState(!1),[be,ae]=o.useState(!1),[pe,je]=o.useState(!1),[De,me]=o.useState(!1),[$e,Ge]=o.useState(!1),[xe,Pe]=o.useState(!1),[J,se]=o.useState(!1),[he,ve]=o.useState(""),[Fe,Ke]=o.useState(null),Be=o.useMemo(()=>sh(a,p),[p,a]),ze=o.useRef(Be),_e=o.useRef(null),Me=JSON.stringify([a,p,I]),tt=o.useRef(Me);tt.current=Me;const pt=o.useRef(null),ct={mcpType:x,command:M,url:D,envEntries:F,headerEntries:R,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ue},dt=o.useRef(ct);dt.current=ct;const ht=o.useCallback(()=>{ve(""),Ke(null),se(!0)},[]),Ue=o.useCallback(async()=>{try{const ne=await navigator.clipboard.readText();ve(ne),Ke(null)}catch{B.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),st=o.useCallback(()=>{const ne=Og(he,{fallbackName:C});if(!ne.ok){Ke(ne.error);return}const nt=Fg(ne,{name:C,scope:j,type:x,command:M,url:D,environment:F,headers:R,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,disabled:!ue,protocol:$,oauthAuthServerMetadataUrl:L},{isNewServer:I});P(nt.name),A(nt.type),S(nt.command??[]),O(nt.url??""),N(nt.environment??[]),U(nt.headers??[]),W(nt.timeoutStartup??""),Q(nt.timeoutCatalog??""),_(nt.timeoutExecution??""),X(nt.codemode??"default"),ce(nt.disabled!==!0),ee(nt.protocol??"legacy"),Y(nt.oauthAuthServerMetadataUrl??""),se(!1),ve(""),Ke(null),B.success(t("settings.mcp.page.toast.configImported"))},[he,C,j,x,M,D,F,R,$,L,K,te,H,V,ue,I,t]);o.useEffect(()=>{if(I&&n){pt.current=null,P(n.name),T(n.scope||"user"),A(n.type),S(n.command),O(n.url),N(n.environment),U(n.headers),W(n.timeoutStartup),Q(n.timeoutCatalog),_(n.timeoutExecution),X(n.codemode),ee(n.protocol),Y(n.oauthAuthServerMetadataUrl),de({oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,oauthCallbackPort:n.oauthCallbackPort}),ce(!n.disabled),Pe(!1),_e.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,timeoutStartup:n.timeoutStartup,timeoutCatalog:n.timeoutCatalog,timeoutExecution:n.timeoutExecution,codemode:n.codemode,protocol:n.protocol,oauthAuthServerMetadataUrl:n.oauthAuthServerMetadataUrl,enabled:!n.disabled};return}if(g){T(g.scope==="project"?"project":"user");const ne=zo(g.environment),we=g.type==="remote"?g:null,nt=zo(we?.headers),Rt=g.type,Jt=Rt==="local"?g.command??[]:[],Ce=we?.url??"",He=Fr(g.timeout?.startup),yt=Fr(g.timeout?.catalog),It=Fr(g.timeout?.execution),Qt=Hd(g.codemode),Xt=g.protocol??"legacy",ts=wg(we?.oauth),es=we&&we.oauth?we.oauth.auth_server_metadata_url??"":"",Fs=g.disabled!==!0;de(ts);const Qs=_e.current!==null&&JSON.stringify(_e.current)!==JSON.stringify(dt.current);if(pt.current===Me&&Qs)return;pt.current=Me,A(Rt),S(Jt),O(Ce),N(ne),U(nt),W(He),Q(yt),_(It),X(Qt),ee(Xt),Y(es),ce(Fs),Pe(!1),_e.current={mcpType:Rt,command:Jt,url:Ce,envEntries:ne,headerEntries:nt,timeoutStartup:He,timeoutCatalog:yt,timeoutExecution:It,codemode:Qt,protocol:Xt,oauthAuthServerMetadataUrl:es,enabled:Fs}}},[g,a,p,I,n,Me]);const ut=o.useMemo(()=>{const ne=L.trim();return!ne||Qg(ne)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[L,t]),ye=o.useMemo(()=>{const ne=[];x==="remote"&&R.length>0&&ne.push(`${R.length} ${t("settings.mcp.page.advanced.headers")}`);const we=x==="local"?Lr(K):null;we&&ne.push(t("settings.mcp.page.advanced.summary.startup",{value:we}));const nt=Lr(te);nt&&ne.push(t("settings.mcp.page.advanced.summary.catalog",{value:nt}));const Rt=Lr(H);return Rt&&ne.push(t("settings.mcp.page.advanced.summary.execution",{value:Rt})),V==="on"&&ne.push(t("settings.mcp.page.advanced.summary.codemodeOn")),V==="off"&&ne.push(t("settings.mcp.page.advanced.summary.codemodeOff")),$!=="legacy"&&ne.push(t(Kr[$])),ne.join(" · ")},[V,R.length,x,$,t,te,H,K]),re=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(z,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(z,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Te=o.useCallback(ne=>{A("remote"),O(ne),S([])},[]),Ne=o.useCallback(ne=>{O(ne);const we=ne.trim();we&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(we)&&/\s/.test(we)&&(A("local"),S(td(we)),O(""))},[]),Ae=ne=>({name:ne,scope:j,type:x,command:M,url:D,environment:F,headers:R,...oe,oauthAuthServerMetadataUrl:x==="remote"?L:"",protocol:$,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,disabled:!ue}),Le=Ja(async()=>{const ne=_e.current;if(I||!ne||!a||JSON.stringify(ne)===JSON.stringify({mcpType:x,command:M,url:D,envEntries:F,headerEntries:R,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ue}))return Os;if(x==="local"&&M.filter(Boolean).length===0)return us(t("settings.mcp.page.toast.localCommandRequired"));if(x==="remote"&&!D.trim())return us(t("settings.mcp.page.toast.remoteUrlRequired"));if(x==="remote"&&ut)return us(ut);const we=await c(a,Ae(a),p);return we.ok?tt.current!==Me?In:(_e.current={mcpType:x,command:M,url:D,envEntries:F,headerEntries:R,timeoutStartup:K,timeoutCatalog:te,timeoutExecution:H,codemode:V,protocol:$,oauthAuthServerMetadataUrl:x==="remote"?L:"",enabled:ue},await u({directory:p,silent:!0}),we.reloadFailed?us(we.warning||we.message||t("settings.mcp.page.toast.savedReloadFailed")):In):us(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:Qe}=Le,lt=async()=>{const ne=C.trim();if(!ne){B.error(t("settings.mcp.page.toast.nameRequired"));return}if(k.some(we=>we.name===ne)){B.error(t("settings.mcp.page.toast.serverNameExists"));return}if(x==="local"&&M.filter(Boolean).length===0){B.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(x==="remote"&&!D.trim()){B.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(x==="remote"&&ut){B.error(ut);return}ie(!0);try{const we=await d(Ae(ne),p);we.ok?(r(null),i(ne),await u({directory:p,silent:!0}),we.reloadFailed?B.warning(we.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:we.warning||t("settings.mcp.page.toast.retryRefreshHint")}):B.success(we.message||t("settings.mcp.page.toast.serverCreatedReloading"))):B.error(t("settings.mcp.page.toast.saveFailed"))}catch(we){B.error(we instanceof Error?we.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ie(!1)}},ot=()=>{r(null),i(null)},bt=async()=>{if(!a)return;je(!0);const ne=await h(a,p);ne.ok?(ne.reloadFailed?B.warning(ne.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:ne.warning||t("settings.mcp.page.toast.refreshListIfStale")}):B.success(ne.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),ae(!1)):B.error(t("settings.mcp.page.toast.deleteFailed")),je(!1)},wt=async()=>{if(a)try{await v(a,p),B.success(t("settings.mcp.page.toast.connected"))}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionTestFailed"))}},jt=async()=>{if(a){me(!0);try{if(ti(f[a])==="connected")await w(a,p),B.success(t("settings.mcp.page.toast.disconnected"));else{await v(a,p),await u({directory:p,silent:!0});const we=un.getState().getStatusForDirectory(p)[a],nt=ti(we);nt==="connected"?B.success(t("settings.mcp.page.toast.connected")):nt==="needs_auth"?B.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):nt==="failed"?B.error(_r(we)||t("settings.mcp.page.toast.connectionFailed")):B.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await u({directory:p,silent:!0})}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionFailed"))}finally{me(!1)}}},vt=o.useCallback(()=>I?(B.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[I,t]),Xe=o.useCallback(async(ne=!1)=>{try{await u({directory:p,silent:ne})}catch(we){ne||B.error(we instanceof Error?we.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[p,u,t]);o.useEffect(()=>{Xe(!0)},[Xe]),o.useEffect(()=>{ze.current=Be,me(!1),Ge(!1)},[Be]);const kt=o.useCallback(async()=>{if(!(!a||!vt())){if(!ue){B.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Ge(!0);try{const ne=await b(a,p),we=ti(ne.status);ne.warning?B.warning(ne.warning):we==="connected"?B.success(t("settings.mcp.page.toast.connectionTestSucceeded")):we==="needs_auth"?B.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):we==="failed"?B.error(_r(ne.status)||ne.error||t("settings.mcp.page.toast.connectionTestFailed")):ne.error?B.error(ne.error):B.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(ne){B.error(ne instanceof Error?ne.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Ge(!1)}}},[p,ue,vt,a,t,b]);if(!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Re=f[a],Ve=a?m[a]:void 0,Z=Re?ti(Re):Ve?.status,ge=Re?_r(Re):Ve?.error,Oe=ti(Re)==="connected",Ee=Xg(Z,e,ge),Ye=ne=>{switch(ne){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");default:return ne}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:I?t("settings.mcp.page.header.newServer"):a,titleAccessory:I?void 0:s.jsx(Il,{status:Z,enabled:ue,getStatusLabel:Ye,variant:"pill"}),description:I?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(x==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:I?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{variant:Oe?"outline":"default",size:"xs",className:"!font-normal",onClick:jt,disabled:De||!ue,children:t(De?"settings.mcp.page.actions.working":Oe?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),Oe&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{kt()},disabled:$e||!ue,children:t($e?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:Le.onBlurCapture,children:[!I&&g&&s.jsx(Po,{legacy:g.legacy===!0,path:g.path}),!I&&th(Z)&&s.jsx(qe,{divider:!1,children:s.jsx("div",{className:Ie("rounded-lg border p-3",eh(Z)),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:St,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Il,{status:Z,enabled:ue,getStatusLabel:Ye})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ee}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:j==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:p??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),Z==="needs_auth"&&a&&s.jsx(Jg,{serverName:a,directory:p,onConnected:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Oe&&s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:$e||!ue,children:t($e?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(qe,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:I?s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:ht,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(z,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[I&&s.jsxs(Ct,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(We,{value:C,onChange:ne=>P(ne.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(Tt,{value:j,onValueChange:ne=>T(ne),children:[s.jsxs(Pt,{size:$t,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(z,{name:j==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(j==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:ue,onChange:ne=>{ce(ne),Qe()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(qe,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(So,{items:re,activeId:x,onSelect:ne=>{A(ne),Qe()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),x==="local"?s.jsx(Yg,{value:M,onChange:S,preview:ne=>t("settings.mcp.page.connection.previewArgs",{count:ne}),onDetectUrl:Te}):s.jsx(We,{value:D,onChange:ne=>Ne(ne.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(x==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),s.jsx(qe,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(kn,{open:xe,onOpenChange:Pe,children:[s.jsxs(Nn,{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")}),ye&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",ye,")"]})]}),xe?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",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:St,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Tt,{value:$,onValueChange:ne=>{const we=Xr.find(nt=>nt===ne);we&&(ee(we),Qe())},children:[s.jsx(Pt,{size:$t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.protocol"),children:s.jsx("span",{className:"truncate",children:t(Kr[$])})}),s.jsx(At,{children:Xr.map(ne=>s.jsx(mt,{value:ne,children:t(Kr[ne])},ne))})]})]}),s.jsxs("div",{className:"space-y-2",children:[x==="local"&&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:St,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:K,onChange:ne=>W(ne.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),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:St,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:te,onChange:ne=>Q(ne.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),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:St,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:H,onChange:ne=>_(ne.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),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:St,children:t("settings.mcp.page.advanced.codemode")}),s.jsxs(qt,{children:[t("settings.mcp.page.advanced.codemodeHint")," ",t("settings.mcp.page.advanced.codemodeDefaultHint")]})]}),s.jsxs(Tt,{value:V,onValueChange:ne=>{const we=$o.find(nt=>nt===ne);we&&(X(we),Qe())},children:[s.jsx(Pt,{size:$t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.codemode"),children:s.jsx("span",{className:"truncate",children:t(Sl[V])})}),s.jsx(At,{children:$o.map(ne=>s.jsx(mt,{value:ne,children:t(Sl[ne])},ne))})]})]}),x==="remote"&&s.jsxs("div",{children:[s.jsxs(Cn,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),R.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",R.length,")"]})]}),s.jsx(Cl,{value:R,onChange:U,onCommit:Qe,keyTransform:ne=>ne.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:ne=>t("settings.mcp.page.toast.importedVariablesCount",{count:ne}),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")})]}),x==="remote"&&s.jsxs("div",{children:[s.jsx(Cn,{as:"div",className:"mb-2",children:t("settings.mcp.page.advanced.oauth")}),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:St,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(qt,{children:t("settings.mcp.page.advanced.oauthMetadataUrlHint")})]}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx(We,{type:"url",value:L,onChange:ne=>Y(ne.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":ut?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),ut&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:ut})]})]})]})]})})]})}),s.jsx(qe,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:F.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",F.length,")"]}):null,settingsItem:"mcp.environment",children:F.length===0?s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>N([{key:"",value:""}]),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Cl,{value:F,onChange:N,onCommit:Qe,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:ne=>t("settings.mcp.page.toast.importedVariablesCount",{count:ne}),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:[I&&s.jsxs(s.Fragment,{children:[s.jsx(G,{onClick:()=>{lt()},disabled:Se||!C.trim(),size:"xs",className:"!font-normal",children:t(Se?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:ot,disabled:Se,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!I&&s.jsx(G,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ae(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(_t,{open:J,onOpenChange:ne=>{ne||(se(!1),ve(""),Ke(null))},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ht,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:he,onChange:ne=>{ve(ne.target.value),Ke(null)},placeholder:`{
16
16
  "mcpServers": {
17
17
  "postgres": {
18
18
  "command": "npx",
19
19
  "args": ["-y", "@modelcontextprotocol/server-postgres"]
20
20
  }
21
21
  }
22
- }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Fe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Fe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ue,type:"button",children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"outline",onClick:()=>{se(!1),ve(""),Ke(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{onClick:st,disabled:!he.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(_t,{open:be,onOpenChange:ne=>{!ne&&!me&&ae(!1)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Ht,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"outline",onClick:()=>ae(!1),disabled:me,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{variant:"destructive",size:"sm",onClick:bt,disabled:me,children:t(me?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function nh(t){return t.trim().length>0}function ah(t){return t.trimEnd()}function ih(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 rh=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function oh(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 lh=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=Ze(),r=Wt(N=>N.createEntry),i=Wt(N=>N.createFile),[l,d]=o.useState("npm"),[c,h]=o.useState(""),[g,f]=o.useState(""),[p,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(a),[m,S]=o.useState(!1),P=o.useCallback(()=>{h(""),f(""),u(""),w(""),k(a)},[a]);o.useEffect(()=>{t&&(d("npm"),P())},[t,P]);const I=N=>{N!==l&&(d(N),P())},j=o.useMemo(()=>oh(g),[g]),D=!j.ok,x=l==="file"&&p.trim()!==""&&!rh.test(p.trim()),A=(l==="npm"||l==="path")&&c.trim()==="",R=l==="file"&&v.trim()==="",C=l==="file"&&p.trim()==="",E=m||D||l==="npm"&&A||l==="path"&&A||l==="file"&&(C||x||R),O=async()=>{if(!E){S(!0);try{let N;l==="file"?N=await i({fileName:p.trim(),content:v,scope:b}):N=await r({spec:c.trim(),options:j.ok?j.value:void 0,scope:b}),N.ok?(B.success(N.message||n("settings.plugins.toast.created")),N.reloadFailed&&B.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):B.error(N.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{S(!1)}}},F=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(_t,{open:t,onOpenChange:N=>{!N&&m||e(N)},children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Ht,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(So,{items:F,activeId:l,onSelect:N=>I(N),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(We,{id:"plugin-spec",value:c,onChange:N=>h(N.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":A?!1:void 0,disabled:m}),A&&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:g,onChange:N=>f(N.target.value),rows:5,className:"font-mono",hasError:D,disabled:m}),D&&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(We,{id:"plugin-filename",value:p,onChange:N=>u(N.target.value),placeholder:"my-plugin.ts","aria-invalid":x||void 0,disabled:m}),x&&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:N=>w(N.target.value),rows:16,className:"font-mono",disabled:m})]})]}),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(N=>{const M=b===N,U=n(N==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(N),disabled:m,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(xo,{checked:M,onChange:()=>k(N),ariaLabel:U}),s.jsx("span",{className:Ie("typography-ui-label font-normal",M?"text-foreground":"text-foreground/60"),children:U})]},N)})})]})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:m,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(G,{size:"sm",onClick:()=>{O()},disabled:E,children:[m?s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},ch=t=>{const e=at.c(33),{spec:a}=t;let n;e[0]!==a?(n=d=>d.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const r=Wt(n),{t:i}=Ze();if(!r)return null;const l=dh;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let h;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(h=l(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=h):h=e[9],h}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=d):d=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(d,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let d;e[15]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=d):d=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(d,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let d;e[19]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=d):d=e[19];let c;return e[20]!==i?(c=l(d,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let d;e[22]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=l(d,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let d;e[25]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=d):d=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(d,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let d;e[29]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=d):d=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(d,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function dh(t,e){return s.jsxs(nr,{children:[s.jsx(ar,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(bo,{children:e})]})}const uh=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),qa=t=>{const e=t.replace(/\\/g,"/"),a=[],[n,...r]=e.split("/");for(const l of r)if(!(l===""||l===".")){if(l===".."){a.pop();continue}a.push(l)}return`${/^[A-Za-z]:$/.test(n)?`${n.toUpperCase()}/`:"/"}${a.join("/")}`},mh=t=>qa(`${t.replace(/\\/g,"/")}/..`),ph=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function ed(t,e){if(t.startsWith("file://")){const a=ph(t);return a?{kind:"local",path:qa(a)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:qa(`${mh(e)}/${t}`)}:null:uh(t)?{kind:"local",path:qa(t)}:{kind:"package",target:t}}function td(t){return t?{kind:"local",path:qa(t)}:null}const gh=(t,e)=>{if(t.kind==="package")return e.source.kind==="package"&&e.source.target===t.target;if(e.source.kind!=="local")return!1;const a=qa(e.source.path);return a===t.path||a.startsWith(`${t.path}/`)};function sd(t,e){return e.filter(a=>gh(t,a))}function hh(t){const e=t.find(n=>n.state.kind==="failed");if(e&&e.state.kind==="failed")return{kind:"failed",error:e.state.error,ref:e.state.ref};const a=t[0];return a?{kind:"active",version:a.source.kind==="package"?a.source.version:null}:{kind:"notReported"}}function nd(t){const e=t.flatMap(a=>a.source.kind==="package"?[a.source]:[]);return e.some(a=>a.updating)?"updating":e.some(a=>a.outdated)?"available":"none"}function ad(t){const e=at.c(12),a=Wt(fh),n=vo(sa());let r;e:{if(a.kind==="idle"||a.scope!==n){let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={kind:"loading"},e[0]=h):h=e[0],r=h;break e}if(a.kind==="failed"||!t){let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h={kind:"unknown"},e[1]=h):h=e[1],r=h;break e}let i,l,d;if(e[2]!==a.plugins||e[3]!==t){const h=sd(t,a.plugins);i="known",l=hh(h),d=nd(h),e[2]=a.plugins,e[3]=t,e[4]=i,e[5]=l,e[6]=d}else i=e[4],l=e[5],d=e[6];let c;e[7]!==i||e[8]!==l||e[9]!==d||e[10]!==t?(c={kind:i,load:l,update:d,target:t},e[7]=i,e[8]=l,e[9]=d,e[10]=t,e[11]=c):c=e[11],r=c}return r}function fh(t){return t.runtime}function id(t){const e=at.c(4);let a;if(e[0]!==t){const i=vo(sa());a=t?.kind==="package"?Pc(i,t.target):null,e[0]=t,e[1]=a}else a=e[1];const n=a;let r;return e[2]!==n?(r=i=>n?i.packageUpdates[n]??null:null,e[2]=n,e[3]=r):r=e[3],Wt(r)}const Ur=t=>{const e=at.c(28),{target:a}=t,{t:n}=Ze(),r=ad(a),i=id(a);if(r.kind!=="known")return null;let l;e:{if(r.update==="updating"||i?.kind==="running"){let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground"}),e[0]=f):f=e[0];let p;e[1]!==n?(p=n("settings.plugins.update.running"),e[1]=n,e[2]=p):p=e[2];let u;e[3]!==p?(u={icon:f,label:p},e[3]=p,e[4]=u):u=e[4],l=u;break e}if(r.load.kind==="failed"){let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[5]=f):f=e[5];let p;e[6]!==n?(p=n("settings.plugins.status.failed.title"),e[6]=n,e[7]=p):p=e[7];let u;e[8]!==p?(u={icon:f,label:p},e[8]=p,e[9]=u):u=e[9],l=u;break e}if(r.load.kind==="notReported"){let f;e[10]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"time",className:"h-3 w-3 text-muted-foreground"}),e[10]=f):f=e[10];let p;e[11]!==n?(p=n("settings.plugins.status.notReported.title"),e[11]=n,e[12]=p):p=e[12];let u;e[13]!==p?(u={icon:f,label:p},e[13]=p,e[14]=u):u=e[14],l=u;break e}if(r.update==="available"){let f;e[15]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3 text-[var(--status-success)]"}),e[15]=f):f=e[15];let p;e[16]!==n?(p=n("settings.plugins.update.available.title"),e[16]=n,e[17]=p):p=e[17];let u;e[18]!==p?(u={icon:f,label:p},e[18]=p,e[19]=u):u=e[19],l=u;break e}l=null}const d=l;if(!d)return null;let c;e[20]!==d.icon||e[21]!==d.label?(c=s.jsx(ar,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center","aria-label":d.label,children:d.icon})}),e[20]=d.icon,e[21]=d.label,e[22]=c):c=e[22];let h;e[23]!==d.label?(h=s.jsx(bo,{children:d.label}),e[23]=d.label,e[24]=h):h=e[24];let g;return e[25]!==c||e[26]!==h?(g=s.jsxs(nr,{children:[c,h]}),e[25]=c,e[26]=h,e[27]=g):g=e[27],g},rd=t=>{const e=at.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,d=l===void 0?"sidebar":l,c=fs(),h=o.useRef(null),[g,f]=o.useState(!1),[p,u]=o.useState(!1),v=d==="background"||c?"bg-background":"bg-sidebar",w=v==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const E=h.current;if(!E){f(!1),u(!1);return}if(!(E.scrollHeight>E.clientHeight+1)){f(!1),u(!1);return}f(E.scrollTop>1),u(E.scrollTop+E.clientHeight<E.scrollHeight-1)},e[0]=b):b=e[0];const k=b;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{k()},e[1]=m):m=e[1];let S;e[2]!==r?(S=[r,k],e[2]=r,e[3]=S):S=e[3],o.useEffect(m,S);let P,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const E=h.current;if(!E)return;const O=()=>k();return E.addEventListener("scroll",O,{passive:!0}),()=>E.removeEventListener("scroll",O)},I=[k],e[4]=P,e[5]=I):(P=e[4],I=e[5]),o.useEffect(P,I);let j;e[6]!==v||e[7]!==i?(j=Ie("flex h-full flex-col",v,i),e[6]=v,e[7]=i,e[8]=j):j=e[8];let D;e[9]!==r?(D=s.jsx(bs,{ref:h,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=D):D=e[10];let x;e[11]!==w||e[12]!==g?(x=g&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${w} 0%, transparent 100%)`}}),e[11]=w,e[12]=g,e[13]=x):x=e[13];let A;e[14]!==w||e[15]!==p?(A=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${w} 0%, transparent 100%)`}}),e[14]=w,e[15]=p,e[16]=A):A=e[16];let R;e[17]!==A||e[18]!==D||e[19]!==x?(R=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[D,x,A]}),e[17]=A,e[18]=D,e[19]=x,e[20]=R):R=e[20];let C;return e[21]!==n||e[22]!==a||e[23]!==R||e[24]!==j?(C=s.jsxs("div",{className:j,children:[a,R,n]}),e[21]=n,e[22]=a,e[23]=R,e[24]=j,e[25]=C):C=e[25],C},Hi=t=>{const e=at.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:d,className:c}=t,h=r===void 0?!1:r,g=d&&d.length>0,f=h?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==c||e[1]!==f?(p=Ie("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",f,c),e[0]=c,e[1]=f,e[2]=p):p=e[2];let u;e[3]!==a?(u=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=u):u=e[4];let v;e[5]!==l||e[6]!==u?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,u]}),e[5]=l,e[6]=u,e[7]=v):v=e[7];let w;e[8]!==n?(w=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=w):w=e[9];let b;e[10]!==i||e[11]!==v||e[12]!==w?(b=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[v,w]}),e[10]=i,e[11]=v,e[12]=w,e[13]=b):b=e[13];let k;e[14]!==d||e[15]!==g?(k=g&&s.jsxs(zn,{children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:d.map(xh)})]}),e[14]=d,e[15]=g,e[16]=k):k=e[16];let m;e[17]!==b||e[18]!==k?(m=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,k]}),e[17]=b,e[18]=k,e[19]=m):m=e[19];let S;return e[20]!==p||e[21]!==m?(S=s.jsx("div",{className:p,children:m}),e[20]=p,e[21]=m,e[22]=S):S=e[22],S};function xh(t){const e=t.icon;return s.jsxs(wn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:Ie(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(z,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const bh=t=>t.parsedKind==="npm"?"code-box":"folder",vh=t=>{const e=at.c(165),{onItemSelect:a,onAddClick:n}=t,{t:r}=Ze(),{entries:i,files:l,selectedId:d,setSelected:c,deleteEntry:h,deleteFile:g,loadPlugins:f}=Wt($s(yh)),p=Wt(jh),u=Wt(wh),v=Wt(kh),w=Wt(Nh),b=Wt(Sh),k=Wt(Ch),m=Wt(Ih),S=Wt(Ph),P=Wt(Ah);let I;e[0]===Symbol.for("react.memo_cache_sentinel")?(I=vo(sa()),e[0]=I):I=e[0];const j=I,D=b.kind==="failed"&&b.scope===j,x=b.kind==="ready"&&b.scope===j?b.plugins:null;let A;if(e[1]!==i||e[2]!==l){A=new Map;for(const Ce of i)A.set(Ce.id,ed(Ce.spec,Ce.sourcePath));for(const Ce of l)A.set(Ce.id,td(Ce.absolutePath));e[1]=i,e[2]=l,e[3]=A}else A=e[3];const R=A;let C;e[4]!==P||e[5]!==x||e[6]!==R?(C=Ce=>{const He=R.get(Ce);return!x||He?.kind!=="package"||P[Pc(j,He.target)]?.kind==="running"?null:nd(sd(He,x))==="available"?He.target:null},e[4]=P,e[5]=x,e[6]=R,e[7]=C):C=e[7];const E=C,[O,F]=o.useState(null),[N,M]=o.useState(!1),[U,K]=o.useState(!1);let W,te;e[8]!==f?(W=()=>{f()},te=[f],e[8]=f,e[9]=W,e[10]=te):(W=e[9],te=e[10]),o.useEffect(W,te);let Q,H;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{const Ce=()=>K(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Ce),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Ce)},H=[],e[11]=Q,e[12]=H):(Q=e[11],H=e[12]),o.useEffect(Q,H);let _;if(e[13]!==i||e[14]!==E||e[15]!==p){_={userEntries:0,projectEntries:0};for(const Ce of i){const He=p[Ce.spec];(He?.kind==="npm-ok"&&He.hasUpdate||E(Ce.id)!==null)&&(Ce.scope==="user"?_.userEntries=_.userEntries+1:Ce.scope==="project"&&(_.projectEntries=_.projectEntries+1))}e[13]=i,e[14]=E,e[15]=p,e[16]=_}else _=e[16];const V=_;let X;e[17]!==i?(X=i.filter(Th),e[17]=i,e[18]=X):X=e[18];const $=X;let ee;e[19]!==i?(ee=i.filter(Eh),e[19]=i,e[20]=ee):ee=e[20];const L=ee;let Y;e[21]!==l?(Y=l.filter(Dh),e[21]=l,e[22]=Y):Y=e[22];const oe=Y;let de;e[23]!==l?(de=l.filter(Mh),e[23]=l,e[24]=de):de=e[24];const ge=de,ce=i.length+l.length,Se=ce===0;let ie;e[25]!==n?(ie=()=>{n?n():K(!0)},e[25]=n,e[26]=ie):ie=e[26];const be=ie;let ae;e[27]!==a||e[28]!==c?(ae=Ce=>{c(Ce),a?.()},e[27]=a,e[28]=c,e[29]=ae):ae=e[29];const me=ae;let je;e[30]!==i||e[31]!==p||e[32]!==r||e[33]!==w?(je=async Ce=>{const He=i.find(Xt=>Xt.id===Ce);if(!He)return;const yt=p[He.spec];if(!yt||yt.kind!=="npm-ok"||!yt.hasUpdate||!yt.latestVersion)return;const It=yt.latestVersion;(await w(Ce)).ok?B.success(r("settings.plugins.toast.updatedToLatest",{version:It})):B.error(r("settings.plugins.toast.refreshFailed"))},e[30]=i,e[31]=p,e[32]=r,e[33]=w,e[34]=je):je=e[34];const De=je;let ue;e[35]!==r||e[36]!==S?(ue=async(Ce,He)=>{await S(Ce)?B.success(r("settings.plugins.update.toast.done",{name:He})):B.error(r("settings.plugins.update.toast.failed",{name:He}))},e[35]=r,e[36]=S,e[37]=ue):ue=e[37];const $e=ue;let Ge;e[38]!==m||e[39]!==v||e[40]!==r?(Ge=async()=>{B.info(r("settings.plugins.toast.refreshing"));const[Ce,He]=await Promise.all([v({force:!0}),m()]);Ce||B.error(r("settings.plugins.toast.refreshFailed")),He||B.error(r("settings.plugins.toast.checkFailed"))},e[38]=m,e[39]=v,e[40]=r,e[41]=Ge):Ge=e[41];const xe=Ge;let Pe;e[42]!==h||e[43]!==g||e[44]!==O||e[45]!==r?(Pe=async()=>{if(!O)return;M(!0);const Ce=O.kind==="entry"?await h(O.id):await g(O.id);Ce.ok?B.success(Ce.message||r("settings.plugins.sidebar.toast.deleted",{name:O.label})):B.error(r("settings.plugins.sidebar.toast.deleteFailed")),F(null),M(!1)},e[42]=h,e[43]=g,e[44]=O,e[45]=r,e[46]=Pe):Pe=e[46];const J=Pe;let se;e[47]!==$e||e[48]!==me||e[49]!==De||e[50]!==E||e[51]!==p||e[52]!==R||e[53]!==d||e[54]!==r?(se=Ce=>{const He=p[Ce.spec],yt=He?.kind==="npm-ok"&&He.hasUpdate&&!!He.latestVersion,It=E(Ce.id),Qt=[];return yt?Qt.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{De(Ce.id)}}):It&&Qt.push({label:r("settings.plugins.update.action"),icon:"arrow-up-s",onClick:()=>{$e(It,Ce.spec)}}),Qt.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>F({kind:"entry",id:Ce.id,label:Ce.spec})}),s.jsx(Hi,{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:Ce.spec}),s.jsx(Ur,{target:R.get(Ce.id)??null}),s.jsx(ch,{spec:Ce.spec})]}),metadata:Ce.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===Ce.id,onSelect:()=>me(Ce.id),icon:s.jsx(z,{name:bh(Ce),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Qt},Ce.id)},e[47]=$e,e[48]=me,e[49]=De,e[50]=E,e[51]=p,e[52]=R,e[53]=d,e[54]=r,e[55]=se):se=e[55];const he=se;let ve;e[56]!==me||e[57]!==R||e[58]!==d||e[59]!==r?(ve=Ce=>Ce.kind==="package"?s.jsx(Hi,{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:Ce.fileName}),s.jsx(Ur,{target:R.get(Ce.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.package"),selected:!1,onSelect:Rh,icon:s.jsx(z,{name:"folder",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"})},Ce.id):s.jsx(Hi,{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:Ce.fileName}),s.jsx(Ur,{target:R.get(Ce.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.file"),selected:d===Ce.id,onSelect:()=>me(Ce.id),icon:s.jsx(z,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>F({kind:"file",id:Ce.id,label:Ce.fileName})}]},Ce.id),e[56]=me,e[57]=R,e[58]=d,e[59]=r,e[60]=ve):ve=e[60];const Fe=ve;let Ke;e[61]!==r?(Ke=(Ce,He,yt)=>{const It=yt===void 0?0:yt;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:[Ce,It>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(It===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:It})})]}),He]})},e[61]=r,e[62]=Ke):Ke=e[62];const Be=Ke;let ze;e[63]!==r?(ze=r("settings.plugins.sidebar.title"),e[63]=r,e[64]=ze):ze=e[64];let _e;e[65]!==ze?(_e=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:Pn,children:ze})}),e[65]=ze,e[66]=_e):_e=e[66];let Me;e[67]!==r||e[68]!==ce?(Me=r("settings.plugins.sidebar.total",{count:ce}),e[67]=r,e[68]=ce,e[69]=Me):Me=e[69];let tt;e[70]!==D||e[71]!==r?(tt=D?s.jsxs("span",{className:"ml-2 inline-flex items-center gap-1",children:[s.jsx(z,{name:"question",className:"size-3"}),r("settings.plugins.status.sidebar.unavailable")]}):null,e[70]=D,e[71]=r,e[72]=tt):tt=e[72];let pt;e[73]!==Me||e[74]!==tt?(pt=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[Me,tt]}),e[73]=Me,e[74]=tt,e[75]=pt):pt=e[75];let ct;e[76]!==xe?(ct=()=>{xe()},e[76]=xe,e[77]=ct):ct=e[77];const dt=u||k;let ht;e[78]!==r?(ht=r("settings.plugins.sidebar.actions.refresh"),e[78]=r,e[79]=ht):ht=e[79];let Ue;e[80]!==r?(Ue=r("settings.plugins.sidebar.actions.refresh"),e[80]=r,e[81]=Ue):Ue=e[81];const st=u||k?"size-4 animate-spin":"size-4";let ut;e[82]!==st?(ut=s.jsx(z,{name:"refresh",className:st}),e[82]=st,e[83]=ut):ut=e[83];let ye;e[84]!==ct||e[85]!==dt||e[86]!==ht||e[87]!==Ue||e[88]!==ut?(ye=s.jsx(G,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ct,disabled:dt,"aria-label":ht,title:Ue,children:ut}),e[84]=ct,e[85]=dt,e[86]=ht,e[87]=Ue,e[88]=ut,e[89]=ye):ye=e[89];let re;e[90]!==r?(re=r("settings.plugins.sidebar.actions.addTitle"),e[90]=r,e[91]=re):re=e[91];let Te;e[92]!==r?(Te=r("settings.plugins.sidebar.actions.addTitle"),e[92]=r,e[93]=Te):Te=e[93];let Ne;e[94]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(z,{name:"add",className:"size-4"}),e[94]=Ne):Ne=e[94];let Ae;e[95]!==be||e[96]!==re||e[97]!==Te?(Ae=s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:be,"aria-label":re,title:Te,children:Ne}),e[95]=be,e[96]=re,e[97]=Te,e[98]=Ae):Ae=e[98];let q;e[99]!==ye||e[100]!==Ae?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[ye,Ae]}),e[99]=ye,e[100]=Ae,e[101]=q):q=e[101];let Le;e[102]!==pt||e[103]!==q?(Le=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[pt,q]}),e[102]=pt,e[103]=q,e[104]=Le):Le=e[104];let Qe;e[105]!==_e||e[106]!==Le?(Qe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[_e,Le]}),e[105]=_e,e[106]=Le,e[107]=Qe):Qe=e[107];let lt;e[108]!==Se||e[109]!==L||e[110]!==ge||e[111]!==he||e[112]!==Fe||e[113]!==Be||e[114]!==r||e[115]!==V||e[116]!==$||e[117]!==oe?(lt=Se?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&Be(r("settings.plugins.sidebar.group.userEntries"),$.map(he),V.userEntries),oe.length>0&&Be(r("settings.plugins.sidebar.group.userFiles"),oe.map(Fe)),L.length>0&&Be(r("settings.plugins.sidebar.group.projectEntries"),L.map(he),V.projectEntries),ge.length>0&&Be(r("settings.plugins.sidebar.group.projectFiles"),ge.map(Fe))]}),e[108]=Se,e[109]=L,e[110]=ge,e[111]=he,e[112]=Fe,e[113]=Be,e[114]=r,e[115]=V,e[116]=$,e[117]=oe,e[118]=lt):lt=e[118];let ot;e[119]!==Qe||e[120]!==lt?(ot=s.jsx(rd,{variant:"background",header:Qe,children:lt}),e[119]=Qe,e[120]=lt,e[121]=ot):ot=e[121];let bt;e[122]!==U?(bt=s.jsx(lh,{open:U,onOpenChange:K}),e[122]=U,e[123]=bt):bt=e[123];const wt=O!==null;let jt;e[124]!==N?(jt=Ce=>{!Ce&&!N&&F(null)},e[124]=N,e[125]=jt):jt=e[125];let vt;e[126]!==r?(vt=r("settings.plugins.sidebar.deleteDialog.title"),e[126]=r,e[127]=vt):vt=e[127];let Xe;e[128]!==vt?(Xe=s.jsx(Vt,{children:vt}),e[128]=vt,e[129]=Xe):Xe=e[129];const kt=O?.label??"";let Re;e[130]!==r||e[131]!==kt?(Re=r("settings.plugins.sidebar.deleteDialog.description",{name:kt}),e[130]=r,e[131]=kt,e[132]=Re):Re=e[132];let Ve;e[133]!==Re?(Ve=s.jsx(Ht,{children:Re}),e[133]=Re,e[134]=Ve):Ve=e[134];let Z;e[135]!==Xe||e[136]!==Ve?(Z=s.jsxs(Bt,{children:[Xe,Ve]}),e[135]=Xe,e[136]=Ve,e[137]=Z):Z=e[137];let pe;e[138]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>F(null),e[138]=pe):pe=e[138];let Oe;e[139]!==r?(Oe=r("settings.common.actions.cancel"),e[139]=r,e[140]=Oe):Oe=e[140];let Ee;e[141]!==N||e[142]!==Oe?(Ee=s.jsx(G,{size:"sm",variant:"ghost",onClick:pe,disabled:N,children:Oe}),e[141]=N,e[142]=Oe,e[143]=Ee):Ee=e[143];let Ye;e[144]!==N||e[145]!==r?(Ye=r(N?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[144]=N,e[145]=r,e[146]=Ye):Ye=e[146];let ne;e[147]!==J||e[148]!==N||e[149]!==Ye?(ne=s.jsx(G,{size:"sm",variant:"destructive",onClick:J,disabled:N,children:Ye}),e[147]=J,e[148]=N,e[149]=Ye,e[150]=ne):ne=e[150];let we;e[151]!==Ee||e[152]!==ne?(we=s.jsxs(as,{children:[Ee,ne]}),e[151]=Ee,e[152]=ne,e[153]=we):we=e[153];let nt;e[154]!==Z||e[155]!==we?(nt=s.jsxs(Ut,{className:"max-w-md",children:[Z,we]}),e[154]=Z,e[155]=we,e[156]=nt):nt=e[156];let Rt;e[157]!==wt||e[158]!==jt||e[159]!==nt?(Rt=s.jsx(_t,{open:wt,onOpenChange:jt,children:nt}),e[157]=wt,e[158]=jt,e[159]=nt,e[160]=Rt):Rt=e[160];let Jt;return e[161]!==ot||e[162]!==bt||e[163]!==Rt?(Jt=s.jsxs(s.Fragment,{children:[ot,bt,Rt]}),e[161]=ot,e[162]=bt,e[163]=Rt,e[164]=Jt):Jt=e[164],Jt};function yh(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function jh(t){return t.registryInfo}function wh(t){return t.isLoadingRegistry}function kh(t){return t.loadRegistryInfo}function Nh(t){return t.updateToLatest}function Sh(t){return t.runtime}function Ch(t){return t.isCheckingUpdates}function Ih(t){return t.checkUpdates}function Ph(t){return t.updatePackage}function Ah(t){return t.packageUpdates}function Th(t){return t.scope==="user"}function Eh(t){return t.scope==="project"}function Dh(t){return t.scope==="user"}function Mh(t){return t.scope==="project"}function Rh(){}const Oh=({entryId:t,spec:e})=>{const{t:a}=Ze(),n=Wt(f=>f.registryInfo[e]),r=Wt(f=>f.updateToLatest),[i,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const f=n.latestVersion,p=n.currentVersion??"",u=async()=>{l(!0);try{(await r(t)).ok?B.success(a("settings.plugins.toast.updatedToLatest",{version:f})):B.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:f})})]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{u()},disabled:i,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:f})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const d=n.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",h=d?"alert":"error-warning",g=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:h,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:g})]})]})},Cl=t=>{const e=at.c(68),{target:a,name:n}=t,{t:r}=Ze(),i=ad(a),l=id(a),d=Wt(Fh),c=Wt(Lh);if(i.kind==="loading")return null;if(i.kind==="unknown"){let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(z,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=P):P=e[0];let I;e[1]!==r?(I=r("settings.plugins.status.unknown.title"),e[1]=r,e[2]=I):I=e[2];let j;e[3]!==I?(j=s.jsx("p",{className:"typography-label text-foreground",children:I}),e[3]=I,e[4]=j):j=e[4];let D;e[5]!==r?(D=r("settings.plugins.status.unknown.description"),e[5]=r,e[6]=D):D=e[6];let x;e[7]!==D?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:D}),e[7]=D,e[8]=x):x=e[8];let A;e[9]!==j||e[10]!==x?(A=s.jsxs("div",{className:"flex-1 min-w-0",children:[j,x]}),e[9]=j,e[10]=x,e[11]=A):A=e[11];let R;e[12]!==d?(R=()=>{d()},e[12]=d,e[13]=R):R=e[13];let C;e[14]!==r?(C=r("settings.plugins.status.retry"),e[14]=r,e[15]=C):C=e[15];let E;e[16]!==R||e[17]!==C?(E=s.jsx(G,{variant:"outline",size:"sm",onClick:R,children:C}),e[16]=R,e[17]=C,e[18]=E):E=e[18];let O;return e[19]!==A||e[20]!==E?(O=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[P,A,E]}),e[19]=A,e[20]=E,e[21]=O):O=e[21],O}const{load:h,update:g}=i,f=i.target.kind==="package"?i.target.target:null,p=g==="updating"||l?.kind==="running";let u;e[22]!==n||e[23]!==f||e[24]!==r||e[25]!==c?(u=async()=>{if(!f)return;await c(f)?B.success(r("settings.plugins.update.toast.done",{name:n})):B.error(r("settings.plugins.update.toast.failed",{name:n}))},e[22]=n,e[23]=f,e[24]=r,e[25]=c,e[26]=u):u=e[26];const v=u;let w;e:{switch(h.kind){case"active":{let P;e[27]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=P):P=e[27];let I;e[28]!==h.version||e[29]!==r?(I=h.version?r("settings.plugins.status.loadedVersion",{version:h.version}):r("settings.plugins.status.loaded"),e[28]=h.version,e[29]=r,e[30]=I):I=e[30];let j;e[31]!==I?(j=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[P,I]}),e[31]=I,e[32]=j):j=e[32],w=j;break e}case"notReported":{let P;e[33]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(z,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=P):P=e[33];let I;e[34]!==r?(I=r("settings.plugins.status.notReported.title"),e[34]=r,e[35]=I):I=e[35];let j;e[36]!==I?(j=s.jsx("p",{className:"typography-label text-foreground",children:I}),e[36]=I,e[37]=j):j=e[37];let D;e[38]!==r?(D=r("settings.plugins.status.notReported.description"),e[38]=r,e[39]=D):D=e[39];let x;e[40]!==D?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:D}),e[40]=D,e[41]=x):x=e[41];let A;e[42]!==j||e[43]!==x?(A=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[P,s.jsxs("div",{className:"flex-1 min-w-0",children:[j,x]})]}),e[42]=j,e[43]=x,e[44]=A):A=e[44],w=A;break e}case"failed":{let P;e[45]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(z,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=P):P=e[45];let I;e[46]!==r?(I=r("settings.plugins.status.failed.title"),e[46]=r,e[47]=I):I=e[47];let j;e[48]!==I?(j=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:I}),e[48]=I,e[49]=j):j=e[49];let D;e[50]!==h.error?(D=s.jsx("p",{className:"typography-micro font-mono text-foreground mt-1 whitespace-pre-wrap break-words",children:h.error}),e[50]=h.error,e[51]=D):D=e[51];let x;e[52]!==h.ref||e[53]!==r?(x=h.ref?s.jsx("p",{className:"typography-micro text-muted-foreground mt-1",children:r("settings.plugins.status.failed.ref",{ref:h.ref})}):null,e[52]=h.ref,e[53]=r,e[54]=x):x=e[54];let A;e[55]!==j||e[56]!==D||e[57]!==x?(A=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[P,s.jsxs("div",{className:"flex-1 min-w-0",children:[j,D,x]})]}),e[55]=j,e[56]=D,e[57]=x,e[58]=A):A=e[58],w=A;break e}}w=void 0}const b=w,k=f!==null&&(g!=="none"||l!==null);let m;e[59]!==v||e[60]!==p||e[61]!==l||e[62]!==k||e[63]!==r?(m=k?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:r("settings.plugins.update.available.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:r("settings.plugins.update.available.description")}),l?.kind==="failed"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-micro text-[var(--status-error)] mt-2",children:r("settings.plugins.update.failed.title")}),s.jsx("p",{className:"typography-micro font-mono text-foreground mt-0.5 whitespace-pre-wrap break-words",children:l.error})]}):null]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{v()},disabled:p,children:p?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-4 animate-spin"}),r("settings.plugins.update.running")]}):r("settings.plugins.update.action")})]}):null,e[59]=v,e[60]=p,e[61]=l,e[62]=k,e[63]=r,e[64]=m):m=e[64];let S;return e[65]!==b||e[66]!==m?(S=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,m]}),e[65]=b,e[66]=m,e[67]=S):S=e[67],S};function Fh(t){return t.loadRuntime}function Lh(t){return t.updatePackage}function Zi(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 Xi(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Il(t,e){if(t.trim()===e.trim())return!0;const a=Zi(t),n=Zi(e);return a.ok&&n.ok&&Xi(a.value)===Xi(n.value)}function Kh(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Xi(t.options),fileName:"",content:""}}function _h(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Pl=t=>{const e=at.c(4),{scope:a,label:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=Ie("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]=r):r=e[0];let i;return e[1]!==n||e[2]!==a?(i=s.jsx("span",{className:r,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=i):i=e[3],i},Uh=()=>{const t=at.c(147),{t:e}=Ze(),n=rn(zh)?.trim()||sa(),r=Wt($h),i=Wt(Bh),l=r===n&&i===jn(),d=Wt(Vh),c=Wt(Hh),h=Wt(qh),g=Wt(Gh),f=Wt(Wh),p=Wt(Jh),u=Wt(Qh),v=Wt(Yh);let w;t[0]!==c||t[1]!==d?(w=d?c.find(W=>W.id===d)??null:null,t[0]=c,t[1]=d,t[2]=w):w=t[2];const b=w;let k;t[3]!==h||t[4]!==d?(k=d?h.find(W=>W.id===d)??null:null,t[3]=h,t[4]=d,t[5]=k):k=t[5];const m=k;let S;t[6]!==b?(S=b?ed(b.spec,b.sourcePath):null,t[6]=b,t[7]=S):S=t[7];const P=S;let I;t[8]!==m?(I=m?td(m.absolutePath):null,t[8]=m,t[9]=I):I=t[9];const j=I,[D,x]=o.useState(!1);let A;t[10]===Symbol.for("react.memo_cache_sentinel")?(A=new Map,t[10]=A):A=t[10];const R=o.useRef(A),C=o.useRef(null),E=JSON.stringify([n,d]);let O;t[11]!==l||t[12]!==n||t[13]!==E||t[14]!==v||t[15]!==b||t[16]!==m||t[17]!==f||t[18]!==x?(O=()=>{let W=!1;if(!l){C.current=null,f(null);return}const te=(Q,H)=>{if(Wt.getState().selectedId!==Q||sa()!==n)return;const _=C.current,V=Wt.getState().draft,X=_?.id===Q&&_.directory===n&&V!==null&&(V.spec!==_.value.spec||!Il(V.optionsJson,_.value.optionsJson)||V.content!==_.value.content);C.current={id:Q,directory:n,value:H},X||f(H)};return b?(te(b.id,Kh(b)),()=>{W=!0}):m?(x(C.current?.id!==m.id||C.current.directory!==n),(async()=>{const Q=await v(m.id);if(W||sa()!==n)return;x(!1);const H=Q?.content??"";R.current.set(E,H),te(m.id,_h(m,H))})(),()=>{W=!0}):(C.current=null,f(null),()=>{W=!0})},t[11]=l,t[12]=n,t[13]=E,t[14]=v,t[15]=b,t[16]=m,t[17]=f,t[18]=x,t[19]=O):O=t[19];let F;t[20]!==l||t[21]!==n||t[22]!==E||t[23]!==v||t[24]!==b||t[25]!==m||t[26]!==f?(F=[b,m,v,f,l,n,E],t[20]=l,t[21]=n,t[22]=E,t[23]=v,t[24]=b,t[25]=m,t[26]=f,t[27]=F):F=t[27],o.useEffect(O,F);let N;t[28]!==l||t[29]!==n||t[30]!==g||t[31]!==E||t[32]!==b||t[33]!==m||t[34]!==e||t[35]!==p||t[36]!==u?(N=async()=>{if(!g||!l||sa()!==n)return Os;if(b&&g.mode==="entry"){const W=g.spec.trim();if(W===b.spec&&Il(g.optionsJson,Xi(b.options)))return Os;if(!W)return hs(e("settings.plugins.validation.specRequired"));const Q=Zi(g.optionsJson);if(!Q.ok)return hs(e("settings.plugins.page.field.options.invalidJson"));const H=await p(b.id,{spec:W,options:Q.value});return H.ok?H.reloadFailed?hs(H.warning||H.message||e("settings.plugins.toast.reloadFailed")):In:hs(H.message||e("settings.plugins.toast.reloadFailed"))}if(m&&g.mode==="file"){const W=R.current.get(E)??"";if(g.content===W)return Os;const te=await u(m.id,{content:g.content});return te.ok?(R.current.set(E,g.content),te.reloadFailed?hs(te.warning||te.message||e("settings.plugins.toast.reloadFailed")):In):hs(te.message||e("settings.plugins.toast.reloadFailed"))}return Os},t[28]=l,t[29]=n,t[30]=g,t[31]=E,t[32]=b,t[33]=m,t[34]=e,t[35]=p,t[36]=u,t[37]=N):N=t[37];const U=Ja(N);if(!d){let W;t[38]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t[38]=W):W=t[38];let te;t[39]!==e?(te=e("settings.plugins.page.empty.select"),t[39]=e,t[40]=te):te=t[40];let Q;t[41]!==te?(Q=s.jsx("p",{className:"typography-body",children:te}),t[41]=te,t[42]=Q):Q=t[42];let H;t[43]!==e?(H=e("settings.plugins.page.empty.add"),t[43]=e,t[44]=H):H=t[44];let _;t[45]!==H?(_=s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:H}),t[45]=H,t[46]=_):_=t[46];let V;return t[47]!==Q||t[48]!==_?(V=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[W,Q,_]})}),t[47]=Q,t[48]=_,t[49]=V):V=t[49],V}if(b&&g&&g.mode==="entry"){let W;t[50]!==g.optionsJson?(W=Zi(g.optionsJson),t[50]=g.optionsJson,t[51]=W):W=t[51];const Q=W.ok;let H;t[52]!==e?(H=e("settings.plugins.page.header.entry"),t[52]=e,t[53]=H):H=t[53];let _;t[54]!==b.scope||t[55]!==e?(_=b.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[54]=b.scope,t[55]=e,t[56]=_):_=t[56];let V;t[57]!==b.scope||t[58]!==_?(V=s.jsx(Pl,{scope:b.scope,label:_}),t[57]=b.scope,t[58]=_,t[59]=V):V=t[59];const X=U.onBlurCapture;let $;t[60]!==b.spec||t[61]!==P?($=s.jsx(Cl,{target:P,name:b.spec}),t[60]=b.spec,t[61]=P,t[62]=$):$=t[62];let ee;t[63]!==b.id||t[64]!==b.spec?(ee=s.jsx(Oh,{entryId:b.id,spec:b.spec}),t[63]=b.id,t[64]=b.spec,t[65]=ee):ee=t[65];let L;t[66]!==$||t[67]!==ee?(L=s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[$,ee]})}),t[66]=$,t[67]=ee,t[68]=L):L=t[68];let Y;t[69]!==e?(Y=e("settings.plugins.page.field.spec"),t[69]=e,t[70]=Y):Y=t[70];const oe=g.spec;let de;t[71]!==g||t[72]!==f?(de=xe=>f({...g,spec:xe.target.value}),t[71]=g,t[72]=f,t[73]=de):de=t[73];let ge;t[74]!==e?(ge=e("settings.plugins.page.field.spec.placeholder"),t[74]=e,t[75]=ge):ge=t[75];let ce;t[76]!==g.spec||t[77]!==de||t[78]!==ge?(ce=s.jsx(We,{value:oe,onChange:de,placeholder:ge,className:"font-mono typography-meta",spellCheck:!1}),t[76]=g.spec,t[77]=de,t[78]=ge,t[79]=ce):ce=t[79];let Se;t[80]!==Y||t[81]!==ce?(Se=s.jsx(qe,{title:Y,settingsItem:"plugins.spec",children:ce}),t[80]=Y,t[81]=ce,t[82]=Se):Se=t[82];let ie;t[83]!==e?(ie=e("settings.plugins.page.field.options"),t[83]=e,t[84]=ie):ie=t[84];const be=g.optionsJson;let ae;t[85]!==g||t[86]!==f?(ae=xe=>f({...g,optionsJson:xe.target.value}),t[85]=g,t[86]=f,t[87]=ae):ae=t[87];const me=!Q&&"border-[var(--status-error-border)]";let je;t[88]!==me?(je=Ie("font-mono typography-meta min-h-[200px]",me),t[88]=me,t[89]=je):je=t[89];let De;t[90]!==g.optionsJson||t[91]!==ae||t[92]!==je?(De=s.jsx(As,{value:be,onChange:ae,rows:10,className:je,spellCheck:!1,placeholder:"{ }"}),t[90]=g.optionsJson,t[91]=ae,t[92]=je,t[93]=De):De=t[93];let ue;t[94]!==Q||t[95]!==e?(ue=!Q&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[94]=Q,t[95]=e,t[96]=ue):ue=t[96];let $e;t[97]!==ie||t[98]!==De||t[99]!==ue?($e=s.jsxs(qe,{title:ie,settingsItem:"plugins.options",children:[De,ue]}),t[97]=ie,t[98]=De,t[99]=ue,t[100]=$e):$e=t[100];let Ge;return t[101]!==U.onBlurCapture||t[102]!==V||t[103]!==L||t[104]!==Se||t[105]!==$e||t[106]!==H?(Ge=s.jsxs(ns,{title:H,titleAccessory:V,onBlurCapture:X,children:[L,Se,$e]}),t[101]=U.onBlurCapture,t[102]=V,t[103]=L,t[104]=Se,t[105]=$e,t[106]=H,t[107]=Ge):Ge=t[107],Ge}if(m&&g&&g.mode==="file"){let W;t[108]!==e?(W=e("settings.plugins.page.header.file"),t[108]=e,t[109]=W):W=t[109];let te;t[110]!==m.scope||t[111]!==e?(te=m.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[110]=m.scope,t[111]=e,t[112]=te):te=t[112];let Q;t[113]!==m.scope||t[114]!==te?(Q=s.jsx(Pl,{scope:m.scope,label:te}),t[113]=m.scope,t[114]=te,t[115]=Q):Q=t[115];let H;t[116]===Symbol.for("react.memo_cache_sentinel")?(H=Ie("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),t[116]=H):H=t[116];let _;t[117]!==m.fileName?(_=s.jsx("span",{className:H,children:m.fileName}),t[117]=m.fileName,t[118]=_):_=t[118];let V;t[119]!==Q||t[120]!==_?(V=s.jsxs(s.Fragment,{children:[Q,_]}),t[119]=Q,t[120]=_,t[121]=V):V=t[121];const X=U.onBlurCapture;let $;t[122]!==m.fileName||t[123]!==j?($=s.jsx(qe,{divider:!1,children:s.jsx(Cl,{target:j,name:m.fileName})}),t[122]=m.fileName,t[123]=j,t[124]=$):$=t[124];let ee;t[125]!==e?(ee=e("settings.plugins.page.field.content"),t[125]=e,t[126]=ee):ee=t[126];let L;t[127]!==g||t[128]!==f?(L=ce=>f({...g,content:ce.target.value}),t[127]=g,t[128]=f,t[129]=L):L=t[129];let Y;t[130]!==U?(Y=ce=>{ce.key==="Enter"&&(ce.metaKey||ce.ctrlKey)&&(ce.preventDefault(),U.requestSave())},t[130]=U,t[131]=Y):Y=t[131];let oe;t[132]!==g.content||t[133]!==D||t[134]!==L||t[135]!==Y?(oe=s.jsx(As,{value:g.content,onChange:L,onKeyDown:Y,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:D}),t[132]=g.content,t[133]=D,t[134]=L,t[135]=Y,t[136]=oe):oe=t[136];let de;t[137]!==ee||t[138]!==oe?(de=s.jsx(qe,{title:ee,settingsItem:"plugins.content",children:oe}),t[137]=ee,t[138]=oe,t[139]=de):de=t[139];let ge;return t[140]!==U.onBlurCapture||t[141]!==V||t[142]!==$||t[143]!==de||t[144]!==W?(ge=s.jsxs(ns,{title:W,titleAccessory:V,onBlurCapture:X,children:[$,de]}),t[140]=U.onBlurCapture,t[141]=V,t[142]=$,t[143]=de,t[144]=W,t[145]=ge):ge=t[145],ge}let K;return t[146]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(z,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[146]=K):K=t[146],K};function zh(t){return t.getActiveProject()?.path}function $h(t){return t.loadedDirectory}function Bh(t){return t.loadedRuntimeKey}function Vh(t){return t.selectedId}function Hh(t){return t.entries}function qh(t){return t.files}function Gh(t){return t.draft}function Wh(t){return t.setDraft}function Jh(t){return t.updateEntry}function Qh(t){return t.updateFile}function Yh(t){return t.readFile}const Zh="<built-in>",di=t=>t?.path===Zh,oo=t=>!!t&&!di(t)&&t.renamable===!0,Xh=t=>{const e=at.c(157),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[g,f]=o.useState(!1),[p,u]=o.useState(null),{selectedSkillName:v,setSelectedSkill:w,setSkillDraft:b,deleteSkill:k,renameSkill:m,getSkillDetail:S}=nn($s(ef)),P=Js();let I;e[0]!==P?(I=Re=>ho(Re,P),e[0]=P,e[1]=I):I=e[1];const j=nn(I),D=nn(tf);let x,A;e[2]!==D||e[3]!==P?(x=()=>{D(P)},A=[D,P],e[2]=D,e[3]=P,e[4]=x,e[5]=A):(x=e[4],A=e[5]),o.useEffect(x,A);let R;e[6]!==a||e[7]!==w||e[8]!==b||e[9]!==j?(R=()=>{let Re="new-skill",Ve=1;for(;j.some(Z=>Z.name===Re);)Re=`new-skill-${Ve}`,Ve++;b({name:Re,scope:"user",source:"opencode",description:""}),w(Re),a?.()},e[6]=a,e[7]=w,e[8]=b,e[9]=j,e[10]=R):R=e[10];const C=R;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=async Re=>{di(Re)||h(Re)},e[11]=E):E=e[11];const O=E;let F;e[12]!==c||e[13]!==k||e[14]!==P||e[15]!==n?(F=async()=>{if(!c)return;if(di(c)){h(null);return}f(!0),await k(c.name,P)?(B.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),h(null)):B.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),f(!1)},e[12]=c,e[13]=k,e[14]=P,e[15]=n,e[16]=F):F=e[16];const N=F;let M;e[17]!==S||e[18]!==w||e[19]!==b||e[20]!==P||e[21]!==j||e[22]!==n?(M=async Re=>{if(di(Re))return;const Ve=Re.name;let Z=1,pe=`${Ve}-copy`;for(;j.some(Ee=>Ee.name===pe);)Z++,pe=`${Ve}-copy-${Z}`;const Oe=await S(Re.name,P);if(!Oe){B.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:pe,scope:Re.scope||"user",source:Re.source||"opencode",description:(Oe.sources.md.fields.includes("description"),""),instructions:""}),w(pe)},e[17]=S,e[18]=w,e[19]=b,e[20]=P,e[21]=j,e[22]=n,e[23]=M):M=e[23];const U=M;let K;e[24]===Symbol.for("react.memo_cache_sentinel")?(K=Re=>{oo(Re)&&(d(Re.name),i(Re))},e[24]=K):K=e[24];const W=K;let te;e[25]!==r||e[26]!==l||e[27]!==m||e[28]!==w||e[29]!==P||e[30]!==j||e[31]!==n?(te=async()=>{if(!r)return;if(!oo(r)){i(null);return}const Re=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Re){B.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Re===r.name){i(null);return}if(j.some(Z=>Z.name===Re)){B.error(n("settings.skills.page.toast.skillExists"));return}await m(r.name,Re,P)?(B.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Re})),w(Re)):B.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=m,e[28]=w,e[29]=P,e[30]=j,e[31]=n,e[32]=te):te=e[32];const Q=te;let H;e[33]!==j?(H=j.filter(sf),e[33]=j,e[34]=H):H=e[34];const _=H;let V;e[35]!==j?(V=j.filter(nf),e[35]=j,e[36]=V):V=e[36];const X=V;let $;e[37]===Symbol.for("react.memo_cache_sentinel")?($=function(Ve){const Z={},pe=[];for(const Ee of Ve)Ee.group?(Z[Ee.group]||(Z[Ee.group]=[]),Z[Ee.group].push(Ee)):pe.push(Ee);const Oe=Object.keys(Z).sort(af).map(Ee=>({name:Ee,skills:[...Z[Ee]].sort(rf)}));return pe.sort(of),{sortedGroups:Oe,ungrouped:pe}},e[37]=$):$=e[37];const ee=$;let L;e[38]!==_?(L=ee(_),e[38]=_,e[39]=L):L=e[39];const Y=L;let oe;e[40]!==X?(oe=ee(X),e[40]=X,e[41]=oe):oe=e[41];const de=oe;let ge;e[42]===Symbol.for("react.memo_cache_sentinel")?(ge=Ie("flex h-full flex-col","bg-background"),e[42]=ge):ge=e[42];let ce;e[43]!==n?(ce=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ce):ce=e[44];let Se;e[45]!==ce?(Se=s.jsx("h2",{className:`${Pn} mb-3`,children:ce}),e[45]=ce,e[46]=Se):Se=e[46];let ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(xi,{className:"mb-3"}),e[47]=ie):ie=e[47];let be;e[48]!==j.length||e[49]!==n?(be=n("settings.skills.sidebar.total",{count:j.length}),e[48]=j.length,e[49]=n,e[50]=be):be=e[50];let ae;e[51]!==be?(ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:be}),e[51]=be,e[52]=ae):ae=e[52];let me;e[53]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[53]=me):me=e[53];let je;e[54]!==C?(je=s.jsx(G,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:C,children:me}),e[54]=C,e[55]=je):je=e[55];let De;e[56]!==ae||e[57]!==je?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ae,je]}),e[56]=ae,e[57]=je,e[58]=De):De=e[58];let ue;e[59]!==Se||e[60]!==De?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Se,ie,De]}),e[59]=Se,e[60]=De,e[61]=ue):ue=e[61];let $e;e[62]!==Y||e[63]!==de||e[64]!==U||e[65]!==a||e[66]!==p||e[67]!==_||e[68]!==v||e[69]!==w||e[70]!==j.length||e[71]!==n||e[72]!==X?($e=s.jsx(bs,{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(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_.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")}),Y.sortedGroups.map(Re=>{const{name:Ve,skills:Z}=Re;return s.jsx(ao,{label:Ve,count:Z.length,storageKey:"project-skills",children:Z.map(pe=>s.jsx(Li,{skill:pe,isSelected:v===pe.name,onSelect:()=>{w(pe.name),a?.()},onRename:()=>W(pe),onDelete:()=>O(pe),onDuplicate:()=>U(pe),isMenuOpen:p===pe.name,onMenuOpenChange:Oe=>u(Oe?pe.name:null)},pe.name))},Ve)}),Y.ungrouped.map(Re=>s.jsx(Li,{skill:Re,isSelected:v===Re.name,onSelect:()=>{w(Re.name),a?.()},onRename:()=>W(Re),onDelete:()=>O(Re),onDuplicate:()=>U(Re),isMenuOpen:p===Re.name,onMenuOpenChange:Ve=>u(Ve?Re.name:null)},Re.name))]}),X.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Re=>{const{name:Ve,skills:Z}=Re;return s.jsx(ao,{label:Ve,count:Z.length,storageKey:"user-skills",children:Z.map(pe=>s.jsx(Li,{skill:pe,isSelected:v===pe.name,onSelect:()=>{w(pe.name),a?.()},onRename:()=>W(pe),onDelete:()=>O(pe),onDuplicate:()=>U(pe),isMenuOpen:p===pe.name,onMenuOpenChange:Oe=>u(Oe?pe.name:null)},pe.name))},Ve)}),de.ungrouped.map(Re=>s.jsx(Li,{skill:Re,isSelected:v===Re.name,onSelect:()=>{w(Re.name),a?.()},onRename:()=>W(Re),onDelete:()=>O(Re),onDuplicate:()=>U(Re),isMenuOpen:p===Re.name,onMenuOpenChange:Ve=>u(Ve?Re.name:null)},Re.name))]})]})}),e[62]=Y,e[63]=de,e[64]=U,e[65]=a,e[66]=p,e[67]=_,e[68]=v,e[69]=w,e[70]=j.length,e[71]=n,e[72]=X,e[73]=$e):$e=e[73];const Ge=c!==null;let xe;e[74]!==g?(xe=Re=>{!Re&&!g&&h(null)},e[74]=g,e[75]=xe):xe=e[75];let Pe;e[76]!==n?(Pe=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Pe):Pe=e[77];let J;e[78]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[78]=Pe,e[79]=J):J=e[79];const se=c?.name??"";let he;e[80]!==n||e[81]!==se?(he=n("settings.skills.sidebar.deleteDialog.description",{name:se}),e[80]=n,e[81]=se,e[82]=he):he=e[82];let ve;e[83]!==he?(ve=s.jsx(Ht,{children:he}),e[83]=he,e[84]=ve):ve=e[84];let Fe;e[85]!==J||e[86]!==ve?(Fe=s.jsxs(Bt,{children:[J,ve]}),e[85]=J,e[86]=ve,e[87]=Fe):Fe=e[87];let Ke;e[88]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>h(null),e[88]=Ke):Ke=e[88];let Be;e[89]!==n?(Be=n("settings.common.actions.cancel"),e[89]=n,e[90]=Be):Be=e[90];let ze;e[91]!==g||e[92]!==Be?(ze=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ke,disabled:g,children:Be}),e[91]=g,e[92]=Be,e[93]=ze):ze=e[93];let _e;e[94]!==n?(_e=n("settings.common.actions.delete"),e[94]=n,e[95]=_e):_e=e[95];let Me;e[96]!==N||e[97]!==g||e[98]!==_e?(Me=s.jsx(G,{size:"sm",onClick:N,disabled:g,children:_e}),e[96]=N,e[97]=g,e[98]=_e,e[99]=Me):Me=e[99];let tt;e[100]!==ze||e[101]!==Me?(tt=s.jsxs(as,{children:[ze,Me]}),e[100]=ze,e[101]=Me,e[102]=tt):tt=e[102];let pt;e[103]!==Fe||e[104]!==tt?(pt=s.jsxs(Ut,{className:"max-w-md",children:[Fe,tt]}),e[103]=Fe,e[104]=tt,e[105]=pt):pt=e[105];let ct;e[106]!==Ge||e[107]!==xe||e[108]!==pt?(ct=s.jsx(_t,{open:Ge,onOpenChange:xe,children:pt}),e[106]=Ge,e[107]=xe,e[108]=pt,e[109]=ct):ct=e[109];const dt=r!==null;let ht;e[110]===Symbol.for("react.memo_cache_sentinel")?(ht=Re=>!Re&&i(null),e[110]=ht):ht=e[110];let Ue;e[111]!==n?(Ue=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=Ue):Ue=e[112];let st;e[113]!==Ue?(st=s.jsx(Vt,{children:Ue}),e[113]=Ue,e[114]=st):st=e[114];const ut=r?.name??"";let ye;e[115]!==n||e[116]!==ut?(ye=n("settings.skills.sidebar.renameDialog.description",{name:ut}),e[115]=n,e[116]=ut,e[117]=ye):ye=e[117];let re;e[118]!==ye?(re=s.jsx(Ht,{children:ye}),e[118]=ye,e[119]=re):re=e[119];let Te;e[120]!==st||e[121]!==re?(Te=s.jsxs(Bt,{children:[st,re]}),e[120]=st,e[121]=re,e[122]=Te):Te=e[122];let Ne;e[123]===Symbol.for("react.memo_cache_sentinel")?(Ne=Re=>d(Re.target.value),e[123]=Ne):Ne=e[123];let Ae;e[124]!==n?(Ae=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=Ae):Ae=e[125];let q;e[126]!==Q?(q=Re=>{Re.key==="Enter"&&Q()},e[126]=Q,e[127]=q):q=e[127];let Le;e[128]!==l||e[129]!==Ae||e[130]!==q?(Le=s.jsx(We,{value:l,onChange:Ne,placeholder:Ae,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:q}),e[128]=l,e[129]=Ae,e[130]=q,e[131]=Le):Le=e[131];let Qe;e[132]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>i(null),e[132]=Qe):Qe=e[132];let lt;e[133]!==n?(lt=n("settings.common.actions.cancel"),e[133]=n,e[134]=lt):lt=e[134];let ot;e[135]!==lt?(ot=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Qe,children:lt}),e[135]=lt,e[136]=ot):ot=e[136];let bt;e[137]!==n?(bt=n("settings.common.actions.rename"),e[137]=n,e[138]=bt):bt=e[138];let wt;e[139]!==Q||e[140]!==bt?(wt=s.jsx(G,{size:"sm",onClick:Q,children:bt}),e[139]=Q,e[140]=bt,e[141]=wt):wt=e[141];let jt;e[142]!==ot||e[143]!==wt?(jt=s.jsxs(as,{children:[ot,wt]}),e[142]=ot,e[143]=wt,e[144]=jt):jt=e[144];let vt;e[145]!==Te||e[146]!==Le||e[147]!==jt?(vt=s.jsxs(Ut,{children:[Te,Le,jt]}),e[145]=Te,e[146]=Le,e[147]=jt,e[148]=vt):vt=e[148];let Xe;e[149]!==dt||e[150]!==vt?(Xe=s.jsx(_t,{open:dt,onOpenChange:ht,children:vt}),e[149]=dt,e[150]=vt,e[151]=Xe):Xe=e[151];let kt;return e[152]!==ue||e[153]!==$e||e[154]!==ct||e[155]!==Xe?(kt=s.jsxs("div",{className:ge,children:[ue,$e,ct,Xe]}),e[152]=ue,e[153]=$e,e[154]=ct,e[155]=Xe,e[156]=kt):kt=e[156],kt},Li=t=>{const e=at.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:h}=t,{t:g}=Ze();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=mi(),e[0]=f):f=e[0];const p=f;let u;e[1]!==a?(u=di(a),e[1]=a,e[2]=u):u=e[2];const v=u;let w;e[3]!==a?(w=oo(a),e[3]=a,e[4]=w):w=e[4];const b=w,[k,m]=o.useState(!1);let S;e[5]!==b||e[6]!==i||e[7]!==d||e[8]!==l||e[9]!==g?(S=U=>s.jsxs(s.Fragment,{children:[b?s.jsxs(U,{onClick:K=>{K.stopPropagation(),l()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),g("settings.common.actions.rename")]}):null,s.jsxs(U,{onClick:K=>{K.stopPropagation(),d()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),g("settings.common.actions.duplicate")]}),s.jsxs(U,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),g("settings.common.actions.delete")]})]}),e[5]=b,e[6]=i,e[7]=d,e[8]=l,e[9]=g,e[10]=S):S=e[10];const P=S,I=!v&&k,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let D;e[11]!==j?(D=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[11]=j,e[12]=D):D=e[12];let x;e[13]!==v?(x=!p&&!v?U=>{U.preventDefault(),m(!0)}:void 0,e[13]=v,e[14]=x):x=e[14];let A;e[15]!==D||e[16]!==x?(A=s.jsx("div",{className:D,onContextMenu:x}),e[15]=D,e[16]=x,e[17]=A):A=e[17];let R;e[18]!==a.name?(R=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]=R):R=e[19];let C;e[20]!==r||e[21]!==R?(C=s.jsx("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-ring",tabIndex:0,children:R}),e[20]=r,e[21]=R,e[22]=C):C=e[22];let E;e[23]!==v||e[24]!==c||e[25]!==h||e[26]!==P?(E=v?null:s.jsxs(zn,{open:c,onOpenChange:U=>{U&&m(!1),h(U)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:P(wn)})]}),e[23]=v,e[24]=c,e[25]=h,e[26]=P,e[27]=E):E=e[27];let O;e[28]!==C||e[29]!==E?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,E]}),e[28]=C,e[29]=E,e[30]=O):O=e[30];let F;e[31]!==O||e[32]!==A?(F=s.jsx(ga,{render:A,children:O}),e[31]=O,e[32]=A,e[33]=F):F=e[33];let N;e[34]!==v||e[35]!==P?(N=v?null:s.jsx(ma,{className:"w-fit min-w-20",children:P(pa)}),e[34]=v,e[35]=P,e[36]=N):N=e[36];let M;return e[37]!==F||e[38]!==N||e[39]!==I?(M=s.jsxs(ha,{open:I,onOpenChange:m,children:[F,N]}),e[37]=F,e[38]=N,e[39]=I,e[40]=M):M=e[40],M};function ef(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function tf(t){return t.loadSkills}function sf(t){return t.scope==="project"}function nf(t){return t.scope==="user"}function af(t,e){return t.localeCompare(e)}function rf(t,e){return t.name.localeCompare(e.name)}function of(t,e){return t.name.localeCompare(e.name)}const lf=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,cf=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},df=({open:t,onOpenChange:e})=>{const{t:a}=Ze(),n=On(N=>N.scanRepo),r=On(N=>N.loadCatalog),i=On(N=>N.loadSource),l=On(N=>N.setSelectedSource),d=On(N=>N.isScanning),c=oa(N=>N.defaultGitIdentityId),h=oa(N=>N.loadDefaultGitIdentityId),[g,f]=o.useState(""),[p,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(null),[m,S]=o.useState(null),[P,I]=o.useState(!1),[j,D]=o.useState([]),[x,A]=o.useState(null),R=o.useRef(0),C=o.useCallback(N=>{R.current+=1,I(!1),S(null),N?.clearIdentity&&(D([]),A(null))},[]);o.useEffect(()=>{t&&(R.current+=1,f(""),u(""),w(""),S(null),I(!1),D([]),A(null),h(),k(null),(async()=>{const N=await An();k(N?N.skillCatalogs??[]:null)})())},[t,h]);const E=o.useMemo(()=>{const N=p.trim(),M=v.trim();return(b??[]).some(U=>{const K=(U.source||"").trim(),W=(U.subpath||"").trim();return K===N&&W===M})},[b,p,v]),O=async()=>{const N=p.trim();if(!N){B.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}g.trim()||f(cf(N)),I(!1),S(null);const M=R.current+1;R.current=M;const U=await n({source:N,subpath:v.trim()||void 0,gitIdentityId:x||void 0});if(R.current!==M)return;if(!U.ok){if(U.error?.kind==="authRequired"){if(fs()){B.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const W=U.error.identities||[];if(D(W),!x&&W.length>0){const te=c&&c!=="global"&&W.some(Q=>Q.id===c)?c:W[0].id;A(te)}B.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}B.error(U.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const K=U.items?.length||0;if(S(K),K===0){B.error(a("settings.skills.catalog.add.toast.noSkillsFound")),I(!1);return}D([]),I(!0),B.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:K}))},F=async()=>{const N=g.trim(),M=p.trim(),U=v.trim();if(!N){B.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!M){B.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!P){B.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(E){B.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const K={id:lf(),label:N,source:M,...U?{subpath:U}:{},...x?{gitIdentityId:x}:{}};if(b===null){B.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const W=[...b,K];try{if(!(await ft({skillCatalogs:W})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(W),B.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(K.id,{refresh:!0}),l(K.id),e(!1)}catch(te){B.error(te instanceof Error?te.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Ht,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(We,{value:g,onChange:N=>f(N.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(qt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(We,{value:p,onChange:N=>{u(N.target.value),C({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(We,{value:v,onChange:N=>{w(N.target.value),C({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),j.length>0&&!fs()?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:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(qt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Tt,{value:x||"",onValueChange:N=>{A(N),C()},children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{children:j.find(N=>N.id===x)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:j.map(N=>s.jsx(mt,{value:N.id,children:N.name},N.id))})]})]}):null,m!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:m})}):null,E?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(G,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{O()},disabled:d||!p.trim(),children:[s.jsx(z,{name:"git-repository",className:"h-4 w-4"}),a(d?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(G,{size:"sm",onClick:()=>{F()},disabled:!P||E||b===null||!g.trim()||!p.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},uf=t=>{const e=at.c(85),{open:a,onOpenChange:n,conflicts:r,onConfirm:i}=t,{t:l}=Ze();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,h]=o.useState(d);let g,f;e[1]!==r||e[2]!==a?(g=()=>{if(!a)return;const L={};for(const Y of r)L[Y.skillName]="skip";h(L)},f=[a,r],e[1]=r,e[2]=a,e[3]=g,e[4]=f):(g=e[3],f=e[4]),o.useEffect(g,f);let p;e[5]!==r?(p=L=>{const Y={};for(const oe of r)Y[oe.skillName]=L;h(Y)},e[5]=r,e[6]=p):p=e[6];const u=p;let v;e[7]!==r||e[8]!==c?(v=r.length>0&&r.every(L=>c[L.skillName]),e[7]=r,e[8]=c,e[9]=v):v=e[9];const w=v;let b;e[10]!==l?(b=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=b):b=e[11];let k;e[12]!==b?(k=s.jsx(Vt,{children:b}),e[12]=b,e[13]=k):k=e[13];let m;e[14]!==l?(m=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=m):m=e[15];let S;e[16]!==m?(S=s.jsx(Ht,{children:m}),e[16]=m,e[17]=S):S=e[17];let P;e[18]!==k||e[19]!==S?(P=s.jsxs(Bt,{children:[k,S]}),e[18]=k,e[19]=S,e[20]=P):P=e[20];let I;e[21]!==r.length||e[22]!==l?(I=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=I):I=e[23];let j;e[24]!==I?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=j):j=e[25];let D;e[26]!==u?(D=()=>u("skip"),e[26]=u,e[27]=D):D=e[27];let x;e[28]!==l?(x=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=x):x=e[29];let A;e[30]!==D||e[31]!==x?(A=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:D,children:x}),e[30]=D,e[31]=x,e[32]=A):A=e[32];let R;e[33]!==u?(R=()=>u("overwrite"),e[33]=u,e[34]=R):R=e[34];let C;e[35]!==l?(C=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=C):C=e[36];let E;e[37]!==R||e[38]!==C?(E=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:R,children:C}),e[37]=R,e[38]=C,e[39]=E):E=e[39];let O;e[40]!==A||e[41]!==E?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[A,E]}),e[40]=A,e[41]=E,e[42]=O):O=e[42];let F;e[43]!==j||e[44]!==O?(F=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,O]}),e[43]=j,e[44]=O,e[45]=F):F=e[45];let N;if(e[46]!==r||e[47]!==c||e[48]!==l){let L;e[50]!==c||e[51]!==l?(L=Y=>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:Y.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:Y.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:Y.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Tt,{value:c[Y.skillName]||"skip",onValueChange:oe=>h(de=>({...de,[Y.skillName]:oe})),children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[Y.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},Y.skillName),e[50]=c,e[51]=l,e[52]=L):L=e[52],N=r.map(L),e[46]=r,e[47]=c,e[48]=l,e[49]=N}else N=e[49];let M;e[53]!==N?(M=s.jsx("div",{className:"space-y-2",children:N}),e[53]=N,e[54]=M):M=e[54];let U;e[55]!==F||e[56]!==M?(U=s.jsxs("div",{className:"space-y-3",children:[F,M]}),e[55]=F,e[56]=M,e[57]=U):U=e[57];let K;e[58]!==n?(K=()=>n(!1),e[58]=n,e[59]=K):K=e[59];let W;e[60]!==l?(W=l("settings.common.actions.cancel"),e[60]=l,e[61]=W):W=e[61];let te;e[62]!==K||e[63]!==W?(te=s.jsx(G,{size:"sm",variant:"ghost",onClick:K,children:W}),e[62]=K,e[63]=W,e[64]=te):te=e[64];let Q;e[65]!==c||e[66]!==i?(Q=()=>i(c),e[65]=c,e[66]=i,e[67]=Q):Q=e[67];const H=!w;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let V;e[70]!==Q||e[71]!==H||e[72]!==_?(V=s.jsx(G,{size:"sm",onClick:Q,disabled:H,children:_}),e[70]=Q,e[71]=H,e[72]=_,e[73]=V):V=e[73];let X;e[74]!==te||e[75]!==V?(X=s.jsxs(as,{children:[te,V]}),e[74]=te,e[75]=V,e[76]=X):X=e[76];let $;e[77]!==P||e[78]!==U||e[79]!==X?($=s.jsxs(Ut,{className:"max-w-2xl",children:[P,U,X]}),e[77]=P,e[78]=U,e[79]=X,e[80]=$):$=e[80];let ee;return e[81]!==n||e[82]!==a||e[83]!==$?(ee=s.jsx(_t,{open:a,onOpenChange:n,children:$}),e[81]=n,e[82]=a,e[83]=$,e[84]=ee):ee=e[84],ee},To=[{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 ui(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 od(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=To.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const mf=t=>{const e=at.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=Ze(),l=On(pf),d=On(gf),[c,h]=o.useState("user"),[g,f]=o.useState("opencode"),p=rn(hf),u=rn(ff),[v,w]=o.useState(null),[b,k]=o.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[S,P]=o.useState(m),[I,j]=o.useState(null);let D,x;e[1]!==u||e[2]!==a?(D=()=>{a&&(h("user"),f("opencode"),w(u),k(!1),P([]),j(null))},x=[a,u],e[1]=u,e[2]=a,e[3]=D,e[4]=x):(D=e[3],x=e[4]),o.useEffect(D,x);let A;e[5]!==i?(A=Me=>{switch(Me){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=A):A=e[6];const R=A;let C;e[7]!==i?(C=Me=>{switch(Me){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=C):C=e[8];const E=C;let O;e:{if(p.length===0){O=null;break e}if(v&&p.some(Me=>Me.id===v)){O=v;break e}if(u&&p.some(Me=>Me.id===u)){O=u;break e}O=p[0]?.id??null}const F=O;let N;e:{if(c!=="project"){N=null;break e}const Me=F;if(!Me){N=null;break e}let tt;if(e[9]!==Me||e[10]!==p){let ct;e[12]!==Me?(ct=dt=>dt.id===Me,e[12]=Me,e[13]=ct):ct=e[13],tt=p.find(ct),e[9]=Me,e[10]=p,e[11]=tt}else tt=e[11];N=tt?.path??null}const M=N;let U;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(U=async Me=>{const tt=await l({source:Me.source,subpath:Me.subpath,gitIdentityId:r?.gitIdentityId,scope:Me.scope,targetSource:Me.targetSource,selections:[{skillDir:Me.skillDir}],conflictPolicy:"prompt",conflictDecisions:Me.conflictDecisions},{directory:Me.directoryOverride??null});if(tt.ok){B.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(tt.error?.kind==="conflicts"){j({source:Me.source,subpath:Me.subpath,scope:Me.scope,targetSource:Me.targetSource,skillDir:Me.skillDir,directoryOverride:Me.directoryOverride??null}),P(tt.error.conflicts),k(!0);return}if(tt.error?.kind==="authRequired"){B.error(tt.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}B.error(tt.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r?.gitIdentityId,e[16]=n,e[17]=i,e[18]=U):U=e[18];const K=U;if(!r)return null;let W;e[19]!==i?(W=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=W):W=e[20];let te;e[21]!==W?(te=s.jsx(Vt,{children:W}),e[21]=W,e[22]=te):te=e[22];let Q;e[23]!==i?(Q=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=Q):Q=e[24];let H;e[25]!==r.skillName?(H=s.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=H):H=e[26];let _;e[27]!==i?(_=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=_):_=e[28];let V;e[29]!==Q||e[30]!==H||e[31]!==_?(V=s.jsxs(Ht,{children:[Q," ",H," ",_]}),e[29]=Q,e[30]=H,e[31]=_,e[32]=V):V=e[32];let X;e[33]!==te||e[34]!==V?(X=s.jsxs(Bt,{children:[te,V]}),e[33]=te,e[34]=V,e[35]=X):X=e[35];let $;e[36]!==i?($=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=$):$=e[37];let ee;e[38]!==$?(ee=s.jsx("span",{className:"typography-ui-label text-foreground",children:$}),e[38]=$,e[39]=ee):ee=e[39];let L;e[40]!==c||e[41]!==g?(L=ui(c,g),e[40]=c,e[41]=g,e[42]=L):L=e[42];let Y;e[43]===Symbol.for("react.memo_cache_sentinel")?(Y=Me=>{const tt=od(Me);h(tt.scope),f(tt.source==="agents"?"agents":"opencode")},e[43]=Y):Y=e[43];let oe;e[44]!==c?(oe=c==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=oe):oe=e[45];let de;e[46]!==g?(de=g==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=g,e[47]=de):de=e[47];let ge;e[48]!==R||e[49]!==c||e[50]!==g?(ge=R(ui(c,g)),e[48]=R,e[49]=c,e[50]=g,e[51]=ge):ge=e[51];let ce;e[52]!==ge?(ce=s.jsx("span",{children:ge}),e[52]=ge,e[53]=ce):ce=e[53];let Se;e[54]!==oe||e[55]!==de||e[56]!==ce?(Se=s.jsxs(Pt,{className:"w-fit gap-1.5",children:[oe,de,ce]}),e[54]=oe,e[55]=de,e[56]=ce,e[57]=Se):Se=e[57];let ie;e[58]!==E||e[59]!==R?(ie=To.map(Me=>s.jsx(mt,{value:Me.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:[Me.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),Me.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:R(Me.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:E(Me.value)})]})},Me.value)),e[58]=E,e[59]=R,e[60]=ie):ie=e[60];let be;e[61]!==ie?(be=s.jsx(At,{align:"start",children:ie}),e[61]=ie,e[62]=be):be=e[62];let ae;e[63]!==L||e[64]!==Se||e[65]!==be?(ae=s.jsxs(Tt,{value:L,onValueChange:Y,children:[Se,be]}),e[63]=L,e[64]=Se,e[65]=be,e[66]=ae):ae=e[66];let me;e[67]!==ee||e[68]!==ae?(me=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ee,ae]}),e[67]=ee,e[68]=ae,e[69]=me):me=e[69];let je;e[70]!==p||e[71]!==F||e[72]!==c||e[73]!==i?(je=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Tt,{value:F??"",onValueChange:Me=>w(Me),disabled:p.length===1,children:[s.jsx(Pt,{className:"w-fit",children:s.jsx(zt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:p.map(xf)})]})]}),e[70]=p,e[71]=F,e[72]=c,e[73]=i,e[74]=je):je=e[74];let De;e[75]!==r.warnings?(De=r.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=De):De=e[76];let ue;e[77]!==me||e[78]!==je||e[79]!==De?(ue=s.jsxs("div",{className:"mt-2 space-y-3",children:[me,je,De]}),e[77]=me,e[78]=je,e[79]=De,e[80]=ue):ue=e[80];let $e;e[81]!==n?($e=()=>n(!1),e[81]=n,e[82]=$e):$e=e[82];let Ge;e[83]!==i?(Ge=i("settings.common.actions.cancel"),e[83]=i,e[84]=Ge):Ge=e[84];let xe;e[85]!==$e||e[86]!==Ge?(xe=s.jsx(G,{size:"sm",variant:"ghost",onClick:$e,children:Ge}),e[85]=$e,e[86]=Ge,e[87]=xe):xe=e[87];const Pe=d||!r.installable||c==="project"&&!M;let J;e[88]!==M||e[89]!==K||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==g?(J=()=>{K({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:g,skillDir:r.skillDir,directoryOverride:M})},e[88]=M,e[89]=K,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=g,e[95]=J):J=e[95];let se;e[96]!==d||e[97]!==i?(se=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=se):se=e[98];let he;e[99]!==Pe||e[100]!==J||e[101]!==se?(he=s.jsx(G,{size:"sm",disabled:Pe,onClick:J,children:se}),e[99]=Pe,e[100]=J,e[101]=se,e[102]=he):he=e[102];let ve;e[103]!==xe||e[104]!==he?(ve=s.jsxs(as,{children:[xe,he]}),e[103]=xe,e[104]=he,e[105]=ve):ve=e[105];let Fe;e[106]!==X||e[107]!==ue||e[108]!==ve?(Fe=s.jsxs(Ut,{className:"max-w-md",children:[X,ue,ve]}),e[106]=X,e[107]=ue,e[108]=ve,e[109]=Fe):Fe=e[109];let Ke;e[110]!==n||e[111]!==a||e[112]!==Fe?(Ke=s.jsx(_t,{open:a,onOpenChange:n,children:Fe}),e[110]=n,e[111]=a,e[112]=Fe,e[113]=Ke):Ke=e[113];let Be;e[114]!==I||e[115]!==K?(Be=Me=>{I&&(K({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:Me,directoryOverride:I.directoryOverride??null}),k(!1))},e[114]=I,e[115]=K,e[116]=Be):Be=e[116];let ze;e[117]!==S||e[118]!==b||e[119]!==Be?(ze=s.jsx(uf,{open:b,onOpenChange:k,conflicts:S,onConfirm:Be}),e[117]=S,e[118]=b,e[119]=Be,e[120]=ze):ze=e[120];let _e;return e[121]!==Ke||e[122]!==ze?(_e=s.jsxs(s.Fragment,{children:[Ke,ze]}),e[121]=Ke,e[122]=ze,e[123]=_e):_e=e[123],_e};function pf(t){return t.installSkills}function gf(t){return t.isInstalling}function hf(t){return t.projects}function ff(t){return t.activeProjectId}function xf(t){return s.jsx(mt,{value:t.id,children:t.label||t.path},t.id)}const bf=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,vf=t=>{const e=t.trim();return bf.test(e)?`https://github.com/${e}`:null},yf=t=>{const e=vf(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Ki=null;const jf=t=>{const e=yo();return(!Ki||Ki.locale!==e)&&(Ki={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Ki.formatter.format(t)},wf=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 r=Math.floor(n/60);if(r<24)return{key:"common.relative.hoursAgoShort",count:r};const i=Math.floor(r/24);if(i<7)return{key:"common.relative.daysAgoShort",count:i};const l=Math.floor(i/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(i/365)}},kf=t=>{const e=at.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:d}=t,c=a.stars??null;let h,g,f,p,u,v,w,b,k,m;if(e[0]!==n||e[1]!==r||e[2]!==l||e[3]!==i||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==d){const j=a.repoUpdatedAt?wf(a.repoUpdatedAt):null;b="button",k=l,m=n;const D=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==D?(g=Ie("oc-surface-elevated w-full min-h-24 text-left rounded-lg border bg-surface-elevated p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",D),e[19]=D,e[20]=g):g=e[20],u="min-w-0 flex-1 block";let x;e[21]!==a.label?(x=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=x):x=e[22];let A;e[23]!==r||e[24]!==i||e[25]!==d?(A=r?s.jsx(z,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=r,e[24]=i,e[25]=d,e[26]=A):A=e[26],e[27]!==x||e[28]!==A?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,A]}),e[27]=x,e[28]=A,e[29]=v):v=e[29],e[30]!==a.source?(w=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]=w):w=e[31],h="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==d?(f=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:d("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(z,{name:"star",className:"h-3 w-3"}),jf(c)]}),e[32]=c,e[33]=d,e[34]=f):f=e[34],p=j&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:j.key==="common.relative.justNow"?d(j.key):d("settings.skills.catalog.page.source.updated",{time:d(j.key,{count:j.count})})}),e[0]=n,e[1]=r,e[2]=l,e[3]=i,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=d,e[9]=h,e[10]=g,e[11]=f,e[12]=p,e[13]=u,e[14]=v,e[15]=w,e[16]=b,e[17]=k,e[18]=m}else h=e[9],g=e[10],f=e[11],p=e[12],u=e[13],v=e[14],w=e[15],b=e[16],k=e[17],m=e[18];let S;e[35]!==h||e[36]!==f||e[37]!==p?(S=s.jsxs("span",{className:h,children:[f,p]}),e[35]=h,e[36]=f,e[37]=p,e[38]=S):S=e[38];let P;e[39]!==S||e[40]!==u||e[41]!==v||e[42]!==w?(P=s.jsxs("span",{className:u,children:[v,w,S]}),e[39]=S,e[40]=u,e[41]=v,e[42]=w,e[43]=P):P=e[43];let I;return e[44]!==g||e[45]!==P||e[46]!==b||e[47]!==k||e[48]!==m?(I=s.jsx("button",{type:b,onClick:k,"aria-pressed":m,className:g,children:P}),e[44]=g,e[45]=P,e[46]=b,e[47]=k,e[48]=m,e[49]=I):I=e[49],I},Nf=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=Ze(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:d,loadCatalog:c,loadSource:h,isLoadingCatalog:g,isLoadingSource:f,loadedSourceIds:p,lastCatalogError:u}=On($s(K=>({sources:K.sources,itemsBySource:K.itemsBySource,selectedSourceId:K.selectedSourceId,setSelectedSource:K.setSelectedSource,loadCatalog:K.loadCatalog,loadSource:K.loadSource,isLoadingCatalog:K.isLoadingCatalog,isLoadingSource:K.isLoadingSource,loadedSourceIds:K.loadedSourceIds,lastCatalogError:K.lastCatalogError}))),[v,w]=o.useState(""),[b,k]=o.useState(!1),[m,S]=o.useState(!1),[P,I]=o.useState(null),[j,D]=o.useState(!1),[x,A]=o.useState(!1),R=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const K=r.filter(Q=>!p[Q.id]);if(K.length===0)return;let W=!1;return(async()=>{for(const Q of K){if(W)return;await h(Q.id)}})(),()=>{W=!0}},[r,p,h]),o.useEffect(()=>{!l||p[l]||h(l)},[l,p,h]),o.useEffect(()=>{const K=W=>{(W.metaKey||W.ctrlKey)&&W.key.toLowerCase()==="k"&&(W.preventDefault(),R.current?.focus())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[]);const C=v.trim().length>0,E=o.useMemo(()=>C?gi(r.flatMap(K=>i[K.id]||[]),v,K=>[K.skillName,K.frontmatterName,K.description]):l?i[l]||[]:[],[r,i,l,v,C]),O=o.useMemo(()=>r.find(K=>K.id===l)||null,[r,l]),F=!!(l&&l.startsWith("custom:")),N=async()=>{if(!(!l||!F)){D(!0);try{const K=await An();if(!K)return;const te=(K.skillCatalogs??[]).filter(Q=>Q.id!==l);await ft({skillCatalogs:te}),await c({refresh:!0}),A(!1)}finally{D(!1)}}},M=C?n("settings.skills.catalog.page.list.searchTitle"):O?.label??"",U=!C&&l!==null&&!p[l]&&(f||g);return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{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(So,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:K=>e(K),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(z,{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(We,{ref:R,value:v,onChange:K=>w(K.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:Ie("h-8 pl-8 w-full",v&&"pr-8")}),v&&s.jsx("button",{type:"button",onClick:()=>{w(""),R.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(z,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(qe,{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:[r.map(K=>s.jsx(kf,{source:K,isActive:K.id===l,isLoading:f&&!p[K.id],skillsCount:p[K.id]?(i[K.id]||[]).length:null,onSelect:()=>d(K.id),t:n},K.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>k(!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(z,{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")})]})]})]})}),u&&s.jsx(qe,{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:u.message})]})}),s.jsxs(qe,{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:M}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:E.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!C?h(l,{refresh:!0}):c({refresh:!0})},disabled:g||f,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(z,{name:"refresh",className:Ie("h-3.5 w-3.5",(g||f)&&"animate-spin")})}),F&&!C&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>A(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),U||f&&E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(z,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.map(K=>{const W=K.installed?.isInstalled,te=K.installed?.scope,Q=yf(K);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:K.skillName}),W&&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:te||n("settings.skills.catalog.page.badge.unknown")})}),!K.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")})]}),K.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:K.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:[Q?s.jsxs("a",{href:Q,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(z,{name:"github",className:"h-3 w-3 shrink-0"}),K.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:K.repoSource}),K.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:K.skillDir})]})]}),K.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:K.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[Q&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(Q,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"})}),W?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:te||""}),children:s.jsx(z,{name:"check",className:"h-4 w-4"})}):s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",disabled:!K.installable,onClick:()=>{I(K),S(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${K.sourceId}:${K.skillDir}`)})})]})]}),s.jsx(df,{open:b,onOpenChange:k}),s.jsx(mf,{open:m,onOpenChange:S,item:P}),s.jsx(_t,{open:x,onOpenChange:K=>{j||A(K)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ht,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>A(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{N()},disabled:j,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Sf=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Nf,{mode:"external",onModeChange:Ef,showModeTabs:!1}),t[0]=e):e=t[0],e},Cf="SKILL.md",If="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",qi=(t,e)=>{const a=Lm({description:t}).trimEnd(),n=e.trimStart();return`---
22
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Fe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Fe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ue,type:"button",children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"outline",onClick:()=>{se(!1),ve(""),Ke(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{onClick:st,disabled:!he.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(_t,{open:be,onOpenChange:ne=>{!ne&&!pe&&ae(!1)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Ht,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"outline",onClick:()=>ae(!1),disabled:pe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{variant:"destructive",size:"sm",onClick:bt,disabled:pe,children:t(pe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function ah(t){return t.trim().length>0}function ih(t){return t.trimEnd()}function rh(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 oh=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function lh(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 ch=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=Ze(),r=Wt(N=>N.createEntry),i=Wt(N=>N.createFile),[l,d]=o.useState("npm"),[c,h]=o.useState(""),[p,f]=o.useState(""),[m,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(a),[g,I]=o.useState(!1),C=o.useCallback(()=>{h(""),f(""),u(""),w(""),k(a)},[a]);o.useEffect(()=>{t&&(d("npm"),C())},[t,C]);const P=N=>{N!==l&&(d(N),C())},j=o.useMemo(()=>lh(p),[p]),T=!j.ok,x=l==="file"&&m.trim()!==""&&!oh.test(m.trim()),A=(l==="npm"||l==="path")&&c.trim()==="",M=l==="file"&&v.trim()==="",S=l==="file"&&m.trim()==="",D=g||T||l==="npm"&&A||l==="path"&&A||l==="file"&&(S||x||M),O=async()=>{if(!D){I(!0);try{let N;l==="file"?N=await i({fileName:m.trim(),content:v,scope:b}):N=await r({spec:c.trim(),options:j.ok?j.value:void 0,scope:b}),N.ok?(B.success(N.message||n("settings.plugins.toast.created")),N.reloadFailed&&B.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):B.error(N.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{I(!1)}}},F=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(_t,{open:t,onOpenChange:N=>{!N&&g||e(N)},children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Ht,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(So,{items:F,activeId:l,onSelect:N=>P(N),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(We,{id:"plugin-spec",value:c,onChange:N=>h(N.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":A?!1:void 0,disabled:g}),A&&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:p,onChange:N=>f(N.target.value),rows:5,className:"font-mono",hasError:T,disabled:g}),T&&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(We,{id:"plugin-filename",value:m,onChange:N=>u(N.target.value),placeholder:"my-plugin.ts","aria-invalid":x||void 0,disabled:g}),x&&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:N=>w(N.target.value),rows:16,className:"font-mono",disabled:g})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(N=>{const R=b===N,U=n(N==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(N),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(xo,{checked:R,onChange:()=>k(N),ariaLabel:U}),s.jsx("span",{className:Ie("typography-ui-label font-normal",R?"text-foreground":"text-foreground/60"),children:U})]},N)})})]})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(G,{size:"sm",onClick:()=>{O()},disabled:D,children:[g?s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},dh=t=>{const e=at.c(33),{spec:a}=t;let n;e[0]!==a?(n=d=>d.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const r=Wt(n),{t:i}=Ze();if(!r)return null;const l=uh;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let h;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(h=l(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=h):h=e[9],h}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=d):d=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(d,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let d;e[15]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=d):d=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(d,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let d;e[19]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=d):d=e[19];let c;return e[20]!==i?(c=l(d,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let d;e[22]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=l(d,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let d;e[25]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=d):d=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(d,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let d;e[29]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=d):d=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(d,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function uh(t,e){return s.jsxs(nr,{children:[s.jsx(ar,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(bo,{children:e})]})}const mh=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),qa=t=>{const e=t.replace(/\\/g,"/"),a=[],[n,...r]=e.split("/");for(const l of r)if(!(l===""||l===".")){if(l===".."){a.pop();continue}a.push(l)}return`${/^[A-Za-z]:$/.test(n)?`${n.toUpperCase()}/`:"/"}${a.join("/")}`},ph=t=>qa(`${t.replace(/\\/g,"/")}/..`),gh=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function sd(t,e){if(t.startsWith("file://")){const a=gh(t);return a?{kind:"local",path:qa(a)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:qa(`${ph(e)}/${t}`)}:null:mh(t)?{kind:"local",path:qa(t)}:{kind:"package",target:t}}function nd(t){return t?{kind:"local",path:qa(t)}:null}const hh=(t,e)=>{if(t.kind==="package")return e.source.kind==="package"&&e.source.target===t.target;if(e.source.kind!=="local")return!1;const a=qa(e.source.path);return a===t.path||a.startsWith(`${t.path}/`)};function ad(t,e){return e.filter(a=>hh(t,a))}function fh(t){const e=t.find(n=>n.state.kind==="failed");if(e&&e.state.kind==="failed")return{kind:"failed",error:e.state.error,ref:e.state.ref};const a=t[0];return a?{kind:"active",version:a.source.kind==="package"?a.source.version:null}:{kind:"notReported"}}function id(t){const e=t.flatMap(a=>a.source.kind==="package"?[a.source]:[]);return e.some(a=>a.updating)?"updating":e.some(a=>a.outdated)?"available":"none"}function rd(t){const e=at.c(12),a=Wt(xh),n=vo(sa());let r;e:{if(a.kind==="idle"||a.scope!==n){let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={kind:"loading"},e[0]=h):h=e[0],r=h;break e}if(a.kind==="failed"||!t){let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h={kind:"unknown"},e[1]=h):h=e[1],r=h;break e}let i,l,d;if(e[2]!==a.plugins||e[3]!==t){const h=ad(t,a.plugins);i="known",l=fh(h),d=id(h),e[2]=a.plugins,e[3]=t,e[4]=i,e[5]=l,e[6]=d}else i=e[4],l=e[5],d=e[6];let c;e[7]!==i||e[8]!==l||e[9]!==d||e[10]!==t?(c={kind:i,load:l,update:d,target:t},e[7]=i,e[8]=l,e[9]=d,e[10]=t,e[11]=c):c=e[11],r=c}return r}function xh(t){return t.runtime}function od(t){const e=at.c(4);let a;if(e[0]!==t){const i=vo(sa());a=t?.kind==="package"?Tc(i,t.target):null,e[0]=t,e[1]=a}else a=e[1];const n=a;let r;return e[2]!==n?(r=i=>n?i.packageUpdates[n]??null:null,e[2]=n,e[3]=r):r=e[3],Wt(r)}const Ur=t=>{const e=at.c(28),{target:a}=t,{t:n}=Ze(),r=rd(a),i=od(a);if(r.kind!=="known")return null;let l;e:{if(r.update==="updating"||i?.kind==="running"){let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground"}),e[0]=f):f=e[0];let m;e[1]!==n?(m=n("settings.plugins.update.running"),e[1]=n,e[2]=m):m=e[2];let u;e[3]!==m?(u={icon:f,label:m},e[3]=m,e[4]=u):u=e[4],l=u;break e}if(r.load.kind==="failed"){let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[5]=f):f=e[5];let m;e[6]!==n?(m=n("settings.plugins.status.failed.title"),e[6]=n,e[7]=m):m=e[7];let u;e[8]!==m?(u={icon:f,label:m},e[8]=m,e[9]=u):u=e[9],l=u;break e}if(r.load.kind==="notReported"){let f;e[10]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"time",className:"h-3 w-3 text-muted-foreground"}),e[10]=f):f=e[10];let m;e[11]!==n?(m=n("settings.plugins.status.notReported.title"),e[11]=n,e[12]=m):m=e[12];let u;e[13]!==m?(u={icon:f,label:m},e[13]=m,e[14]=u):u=e[14],l=u;break e}if(r.update==="available"){let f;e[15]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3 text-[var(--status-success)]"}),e[15]=f):f=e[15];let m;e[16]!==n?(m=n("settings.plugins.update.available.title"),e[16]=n,e[17]=m):m=e[17];let u;e[18]!==m?(u={icon:f,label:m},e[18]=m,e[19]=u):u=e[19],l=u;break e}l=null}const d=l;if(!d)return null;let c;e[20]!==d.icon||e[21]!==d.label?(c=s.jsx(ar,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center","aria-label":d.label,children:d.icon})}),e[20]=d.icon,e[21]=d.label,e[22]=c):c=e[22];let h;e[23]!==d.label?(h=s.jsx(bo,{children:d.label}),e[23]=d.label,e[24]=h):h=e[24];let p;return e[25]!==c||e[26]!==h?(p=s.jsxs(nr,{children:[c,h]}),e[25]=c,e[26]=h,e[27]=p):p=e[27],p},ld=t=>{const e=at.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,d=l===void 0?"sidebar":l,c=fs(),h=o.useRef(null),[p,f]=o.useState(!1),[m,u]=o.useState(!1),v=d==="background"||c?"bg-background":"bg-sidebar",w=v==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const D=h.current;if(!D){f(!1),u(!1);return}if(!(D.scrollHeight>D.clientHeight+1)){f(!1),u(!1);return}f(D.scrollTop>1),u(D.scrollTop+D.clientHeight<D.scrollHeight-1)},e[0]=b):b=e[0];const k=b;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{k()},e[1]=g):g=e[1];let I;e[2]!==r?(I=[r,k],e[2]=r,e[3]=I):I=e[3],o.useEffect(g,I);let C,P;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const D=h.current;if(!D)return;const O=()=>k();return D.addEventListener("scroll",O,{passive:!0}),()=>D.removeEventListener("scroll",O)},P=[k],e[4]=C,e[5]=P):(C=e[4],P=e[5]),o.useEffect(C,P);let j;e[6]!==v||e[7]!==i?(j=Ie("flex h-full flex-col",v,i),e[6]=v,e[7]=i,e[8]=j):j=e[8];let T;e[9]!==r?(T=s.jsx(bs,{ref:h,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=T):T=e[10];let x;e[11]!==w||e[12]!==p?(x=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${w} 0%, transparent 100%)`}}),e[11]=w,e[12]=p,e[13]=x):x=e[13];let A;e[14]!==w||e[15]!==m?(A=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${w} 0%, transparent 100%)`}}),e[14]=w,e[15]=m,e[16]=A):A=e[16];let M;e[17]!==A||e[18]!==T||e[19]!==x?(M=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[T,x,A]}),e[17]=A,e[18]=T,e[19]=x,e[20]=M):M=e[20];let S;return e[21]!==n||e[22]!==a||e[23]!==M||e[24]!==j?(S=s.jsxs("div",{className:j,children:[a,M,n]}),e[21]=n,e[22]=a,e[23]=M,e[24]=j,e[25]=S):S=e[25],S},Hi=t=>{const e=at.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:d,className:c}=t,h=r===void 0?!1:r,p=d&&d.length>0,f=h?"bg-interactive-selection":"hover:bg-interactive-hover";let m;e[0]!==c||e[1]!==f?(m=Ie("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",f,c),e[0]=c,e[1]=f,e[2]=m):m=e[2];let u;e[3]!==a?(u=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=u):u=e[4];let v;e[5]!==l||e[6]!==u?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,u]}),e[5]=l,e[6]=u,e[7]=v):v=e[7];let w;e[8]!==n?(w=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=w):w=e[9];let b;e[10]!==i||e[11]!==v||e[12]!==w?(b=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[v,w]}),e[10]=i,e[11]=v,e[12]=w,e[13]=b):b=e[13];let k;e[14]!==d||e[15]!==p?(k=p&&s.jsxs(zn,{children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:d.map(bh)})]}),e[14]=d,e[15]=p,e[16]=k):k=e[16];let g;e[17]!==b||e[18]!==k?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,k]}),e[17]=b,e[18]=k,e[19]=g):g=e[19];let I;return e[20]!==m||e[21]!==g?(I=s.jsx("div",{className:m,children:g}),e[20]=m,e[21]=g,e[22]=I):I=e[22],I};function bh(t){const e=t.icon;return s.jsxs(wn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:Ie(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(z,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const vh=t=>t.parsedKind==="npm"?"code-box":"folder",yh=t=>{const e=at.c(165),{onItemSelect:a,onAddClick:n}=t,{t:r}=Ze(),{entries:i,files:l,selectedId:d,setSelected:c,deleteEntry:h,deleteFile:p,loadPlugins:f}=Wt($s(jh)),m=Wt(wh),u=Wt(kh),v=Wt(Nh),w=Wt(Sh),b=Wt(Ch),k=Wt(Ih),g=Wt(Ph),I=Wt(Ah),C=Wt(Th);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=vo(sa()),e[0]=P):P=e[0];const j=P,T=b.kind==="failed"&&b.scope===j,x=b.kind==="ready"&&b.scope===j?b.plugins:null;let A;if(e[1]!==i||e[2]!==l){A=new Map;for(const Ce of i)A.set(Ce.id,sd(Ce.spec,Ce.sourcePath));for(const Ce of l)A.set(Ce.id,nd(Ce.absolutePath));e[1]=i,e[2]=l,e[3]=A}else A=e[3];const M=A;let S;e[4]!==C||e[5]!==x||e[6]!==M?(S=Ce=>{const He=M.get(Ce);return!x||He?.kind!=="package"||C[Tc(j,He.target)]?.kind==="running"?null:id(ad(He,x))==="available"?He.target:null},e[4]=C,e[5]=x,e[6]=M,e[7]=S):S=e[7];const D=S,[O,F]=o.useState(null),[N,R]=o.useState(!1),[U,K]=o.useState(!1);let W,te;e[8]!==f?(W=()=>{f()},te=[f],e[8]=f,e[9]=W,e[10]=te):(W=e[9],te=e[10]),o.useEffect(W,te);let Q,H;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{const Ce=()=>K(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Ce),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Ce)},H=[],e[11]=Q,e[12]=H):(Q=e[11],H=e[12]),o.useEffect(Q,H);let _;if(e[13]!==i||e[14]!==D||e[15]!==m){_={userEntries:0,projectEntries:0};for(const Ce of i){const He=m[Ce.spec];(He?.kind==="npm-ok"&&He.hasUpdate||D(Ce.id)!==null)&&(Ce.scope==="user"?_.userEntries=_.userEntries+1:Ce.scope==="project"&&(_.projectEntries=_.projectEntries+1))}e[13]=i,e[14]=D,e[15]=m,e[16]=_}else _=e[16];const V=_;let X;e[17]!==i?(X=i.filter(Eh),e[17]=i,e[18]=X):X=e[18];const $=X;let ee;e[19]!==i?(ee=i.filter(Dh),e[19]=i,e[20]=ee):ee=e[20];const L=ee;let Y;e[21]!==l?(Y=l.filter(Mh),e[21]=l,e[22]=Y):Y=e[22];const oe=Y;let de;e[23]!==l?(de=l.filter(Rh),e[23]=l,e[24]=de):de=e[24];const ue=de,ce=i.length+l.length,Se=ce===0;let ie;e[25]!==n?(ie=()=>{n?n():K(!0)},e[25]=n,e[26]=ie):ie=e[26];const be=ie;let ae;e[27]!==a||e[28]!==c?(ae=Ce=>{c(Ce),a?.()},e[27]=a,e[28]=c,e[29]=ae):ae=e[29];const pe=ae;let je;e[30]!==i||e[31]!==m||e[32]!==r||e[33]!==w?(je=async Ce=>{const He=i.find(Xt=>Xt.id===Ce);if(!He)return;const yt=m[He.spec];if(!yt||yt.kind!=="npm-ok"||!yt.hasUpdate||!yt.latestVersion)return;const It=yt.latestVersion;(await w(Ce)).ok?B.success(r("settings.plugins.toast.updatedToLatest",{version:It})):B.error(r("settings.plugins.toast.refreshFailed"))},e[30]=i,e[31]=m,e[32]=r,e[33]=w,e[34]=je):je=e[34];const De=je;let me;e[35]!==r||e[36]!==I?(me=async(Ce,He)=>{await I(Ce)?B.success(r("settings.plugins.update.toast.done",{name:He})):B.error(r("settings.plugins.update.toast.failed",{name:He}))},e[35]=r,e[36]=I,e[37]=me):me=e[37];const $e=me;let Ge;e[38]!==g||e[39]!==v||e[40]!==r?(Ge=async()=>{B.info(r("settings.plugins.toast.refreshing"));const[Ce,He]=await Promise.all([v({force:!0}),g()]);Ce||B.error(r("settings.plugins.toast.refreshFailed")),He||B.error(r("settings.plugins.toast.checkFailed"))},e[38]=g,e[39]=v,e[40]=r,e[41]=Ge):Ge=e[41];const xe=Ge;let Pe;e[42]!==h||e[43]!==p||e[44]!==O||e[45]!==r?(Pe=async()=>{if(!O)return;R(!0);const Ce=O.kind==="entry"?await h(O.id):await p(O.id);Ce.ok?B.success(Ce.message||r("settings.plugins.sidebar.toast.deleted",{name:O.label})):B.error(r("settings.plugins.sidebar.toast.deleteFailed")),F(null),R(!1)},e[42]=h,e[43]=p,e[44]=O,e[45]=r,e[46]=Pe):Pe=e[46];const J=Pe;let se;e[47]!==$e||e[48]!==pe||e[49]!==De||e[50]!==D||e[51]!==m||e[52]!==M||e[53]!==d||e[54]!==r?(se=Ce=>{const He=m[Ce.spec],yt=He?.kind==="npm-ok"&&He.hasUpdate&&!!He.latestVersion,It=D(Ce.id),Qt=[];return yt?Qt.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{De(Ce.id)}}):It&&Qt.push({label:r("settings.plugins.update.action"),icon:"arrow-up-s",onClick:()=>{$e(It,Ce.spec)}}),Qt.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>F({kind:"entry",id:Ce.id,label:Ce.spec})}),s.jsx(Hi,{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:Ce.spec}),s.jsx(Ur,{target:M.get(Ce.id)??null}),s.jsx(dh,{spec:Ce.spec})]}),metadata:Ce.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===Ce.id,onSelect:()=>pe(Ce.id),icon:s.jsx(z,{name:vh(Ce),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Qt},Ce.id)},e[47]=$e,e[48]=pe,e[49]=De,e[50]=D,e[51]=m,e[52]=M,e[53]=d,e[54]=r,e[55]=se):se=e[55];const he=se;let ve;e[56]!==pe||e[57]!==M||e[58]!==d||e[59]!==r?(ve=Ce=>Ce.kind==="package"?s.jsx(Hi,{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:Ce.fileName}),s.jsx(Ur,{target:M.get(Ce.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.package"),selected:!1,onSelect:Oh,icon:s.jsx(z,{name:"folder",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"})},Ce.id):s.jsx(Hi,{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:Ce.fileName}),s.jsx(Ur,{target:M.get(Ce.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.file"),selected:d===Ce.id,onSelect:()=>pe(Ce.id),icon:s.jsx(z,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>F({kind:"file",id:Ce.id,label:Ce.fileName})}]},Ce.id),e[56]=pe,e[57]=M,e[58]=d,e[59]=r,e[60]=ve):ve=e[60];const Fe=ve;let Ke;e[61]!==r?(Ke=(Ce,He,yt)=>{const It=yt===void 0?0:yt;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:[Ce,It>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(It===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:It})})]}),He]})},e[61]=r,e[62]=Ke):Ke=e[62];const Be=Ke;let ze;e[63]!==r?(ze=r("settings.plugins.sidebar.title"),e[63]=r,e[64]=ze):ze=e[64];let _e;e[65]!==ze?(_e=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:Pn,children:ze})}),e[65]=ze,e[66]=_e):_e=e[66];let Me;e[67]!==r||e[68]!==ce?(Me=r("settings.plugins.sidebar.total",{count:ce}),e[67]=r,e[68]=ce,e[69]=Me):Me=e[69];let tt;e[70]!==T||e[71]!==r?(tt=T?s.jsxs("span",{className:"ml-2 inline-flex items-center gap-1",children:[s.jsx(z,{name:"question",className:"size-3"}),r("settings.plugins.status.sidebar.unavailable")]}):null,e[70]=T,e[71]=r,e[72]=tt):tt=e[72];let pt;e[73]!==Me||e[74]!==tt?(pt=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[Me,tt]}),e[73]=Me,e[74]=tt,e[75]=pt):pt=e[75];let ct;e[76]!==xe?(ct=()=>{xe()},e[76]=xe,e[77]=ct):ct=e[77];const dt=u||k;let ht;e[78]!==r?(ht=r("settings.plugins.sidebar.actions.refresh"),e[78]=r,e[79]=ht):ht=e[79];let Ue;e[80]!==r?(Ue=r("settings.plugins.sidebar.actions.refresh"),e[80]=r,e[81]=Ue):Ue=e[81];const st=u||k?"size-4 animate-spin":"size-4";let ut;e[82]!==st?(ut=s.jsx(z,{name:"refresh",className:st}),e[82]=st,e[83]=ut):ut=e[83];let ye;e[84]!==ct||e[85]!==dt||e[86]!==ht||e[87]!==Ue||e[88]!==ut?(ye=s.jsx(G,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ct,disabled:dt,"aria-label":ht,title:Ue,children:ut}),e[84]=ct,e[85]=dt,e[86]=ht,e[87]=Ue,e[88]=ut,e[89]=ye):ye=e[89];let re;e[90]!==r?(re=r("settings.plugins.sidebar.actions.addTitle"),e[90]=r,e[91]=re):re=e[91];let Te;e[92]!==r?(Te=r("settings.plugins.sidebar.actions.addTitle"),e[92]=r,e[93]=Te):Te=e[93];let Ne;e[94]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(z,{name:"add",className:"size-4"}),e[94]=Ne):Ne=e[94];let Ae;e[95]!==be||e[96]!==re||e[97]!==Te?(Ae=s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:be,"aria-label":re,title:Te,children:Ne}),e[95]=be,e[96]=re,e[97]=Te,e[98]=Ae):Ae=e[98];let q;e[99]!==ye||e[100]!==Ae?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[ye,Ae]}),e[99]=ye,e[100]=Ae,e[101]=q):q=e[101];let Le;e[102]!==pt||e[103]!==q?(Le=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[pt,q]}),e[102]=pt,e[103]=q,e[104]=Le):Le=e[104];let Qe;e[105]!==_e||e[106]!==Le?(Qe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[_e,Le]}),e[105]=_e,e[106]=Le,e[107]=Qe):Qe=e[107];let lt;e[108]!==Se||e[109]!==L||e[110]!==ue||e[111]!==he||e[112]!==Fe||e[113]!==Be||e[114]!==r||e[115]!==V||e[116]!==$||e[117]!==oe?(lt=Se?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&Be(r("settings.plugins.sidebar.group.userEntries"),$.map(he),V.userEntries),oe.length>0&&Be(r("settings.plugins.sidebar.group.userFiles"),oe.map(Fe)),L.length>0&&Be(r("settings.plugins.sidebar.group.projectEntries"),L.map(he),V.projectEntries),ue.length>0&&Be(r("settings.plugins.sidebar.group.projectFiles"),ue.map(Fe))]}),e[108]=Se,e[109]=L,e[110]=ue,e[111]=he,e[112]=Fe,e[113]=Be,e[114]=r,e[115]=V,e[116]=$,e[117]=oe,e[118]=lt):lt=e[118];let ot;e[119]!==Qe||e[120]!==lt?(ot=s.jsx(ld,{variant:"background",header:Qe,children:lt}),e[119]=Qe,e[120]=lt,e[121]=ot):ot=e[121];let bt;e[122]!==U?(bt=s.jsx(ch,{open:U,onOpenChange:K}),e[122]=U,e[123]=bt):bt=e[123];const wt=O!==null;let jt;e[124]!==N?(jt=Ce=>{!Ce&&!N&&F(null)},e[124]=N,e[125]=jt):jt=e[125];let vt;e[126]!==r?(vt=r("settings.plugins.sidebar.deleteDialog.title"),e[126]=r,e[127]=vt):vt=e[127];let Xe;e[128]!==vt?(Xe=s.jsx(Vt,{children:vt}),e[128]=vt,e[129]=Xe):Xe=e[129];const kt=O?.label??"";let Re;e[130]!==r||e[131]!==kt?(Re=r("settings.plugins.sidebar.deleteDialog.description",{name:kt}),e[130]=r,e[131]=kt,e[132]=Re):Re=e[132];let Ve;e[133]!==Re?(Ve=s.jsx(Ht,{children:Re}),e[133]=Re,e[134]=Ve):Ve=e[134];let Z;e[135]!==Xe||e[136]!==Ve?(Z=s.jsxs(Bt,{children:[Xe,Ve]}),e[135]=Xe,e[136]=Ve,e[137]=Z):Z=e[137];let ge;e[138]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>F(null),e[138]=ge):ge=e[138];let Oe;e[139]!==r?(Oe=r("settings.common.actions.cancel"),e[139]=r,e[140]=Oe):Oe=e[140];let Ee;e[141]!==N||e[142]!==Oe?(Ee=s.jsx(G,{size:"sm",variant:"ghost",onClick:ge,disabled:N,children:Oe}),e[141]=N,e[142]=Oe,e[143]=Ee):Ee=e[143];let Ye;e[144]!==N||e[145]!==r?(Ye=r(N?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[144]=N,e[145]=r,e[146]=Ye):Ye=e[146];let ne;e[147]!==J||e[148]!==N||e[149]!==Ye?(ne=s.jsx(G,{size:"sm",variant:"destructive",onClick:J,disabled:N,children:Ye}),e[147]=J,e[148]=N,e[149]=Ye,e[150]=ne):ne=e[150];let we;e[151]!==Ee||e[152]!==ne?(we=s.jsxs(as,{children:[Ee,ne]}),e[151]=Ee,e[152]=ne,e[153]=we):we=e[153];let nt;e[154]!==Z||e[155]!==we?(nt=s.jsxs(Ut,{className:"max-w-md",children:[Z,we]}),e[154]=Z,e[155]=we,e[156]=nt):nt=e[156];let Rt;e[157]!==wt||e[158]!==jt||e[159]!==nt?(Rt=s.jsx(_t,{open:wt,onOpenChange:jt,children:nt}),e[157]=wt,e[158]=jt,e[159]=nt,e[160]=Rt):Rt=e[160];let Jt;return e[161]!==ot||e[162]!==bt||e[163]!==Rt?(Jt=s.jsxs(s.Fragment,{children:[ot,bt,Rt]}),e[161]=ot,e[162]=bt,e[163]=Rt,e[164]=Jt):Jt=e[164],Jt};function jh(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function wh(t){return t.registryInfo}function kh(t){return t.isLoadingRegistry}function Nh(t){return t.loadRegistryInfo}function Sh(t){return t.updateToLatest}function Ch(t){return t.runtime}function Ih(t){return t.isCheckingUpdates}function Ph(t){return t.checkUpdates}function Ah(t){return t.updatePackage}function Th(t){return t.packageUpdates}function Eh(t){return t.scope==="user"}function Dh(t){return t.scope==="project"}function Mh(t){return t.scope==="user"}function Rh(t){return t.scope==="project"}function Oh(){}const Fh=({entryId:t,spec:e})=>{const{t:a}=Ze(),n=Wt(f=>f.registryInfo[e]),r=Wt(f=>f.updateToLatest),[i,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const f=n.latestVersion,m=n.currentVersion??"",u=async()=>{l(!0);try{(await r(t)).ok?B.success(a("settings.plugins.toast.updatedToLatest",{version:f})):B.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:m,latest:f})})]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{u()},disabled:i,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:f})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const d=n.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",h=d?"alert":"error-warning",p=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:h,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:p})]})]})},Pl=t=>{const e=at.c(68),{target:a,name:n}=t,{t:r}=Ze(),i=rd(a),l=od(a),d=Wt(Lh),c=Wt(Kh);if(i.kind==="loading")return null;if(i.kind==="unknown"){let C;e[0]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(z,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=C):C=e[0];let P;e[1]!==r?(P=r("settings.plugins.status.unknown.title"),e[1]=r,e[2]=P):P=e[2];let j;e[3]!==P?(j=s.jsx("p",{className:"typography-label text-foreground",children:P}),e[3]=P,e[4]=j):j=e[4];let T;e[5]!==r?(T=r("settings.plugins.status.unknown.description"),e[5]=r,e[6]=T):T=e[6];let x;e[7]!==T?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:T}),e[7]=T,e[8]=x):x=e[8];let A;e[9]!==j||e[10]!==x?(A=s.jsxs("div",{className:"flex-1 min-w-0",children:[j,x]}),e[9]=j,e[10]=x,e[11]=A):A=e[11];let M;e[12]!==d?(M=()=>{d()},e[12]=d,e[13]=M):M=e[13];let S;e[14]!==r?(S=r("settings.plugins.status.retry"),e[14]=r,e[15]=S):S=e[15];let D;e[16]!==M||e[17]!==S?(D=s.jsx(G,{variant:"outline",size:"sm",onClick:M,children:S}),e[16]=M,e[17]=S,e[18]=D):D=e[18];let O;return e[19]!==A||e[20]!==D?(O=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[C,A,D]}),e[19]=A,e[20]=D,e[21]=O):O=e[21],O}const{load:h,update:p}=i,f=i.target.kind==="package"?i.target.target:null,m=p==="updating"||l?.kind==="running";let u;e[22]!==n||e[23]!==f||e[24]!==r||e[25]!==c?(u=async()=>{if(!f)return;await c(f)?B.success(r("settings.plugins.update.toast.done",{name:n})):B.error(r("settings.plugins.update.toast.failed",{name:n}))},e[22]=n,e[23]=f,e[24]=r,e[25]=c,e[26]=u):u=e[26];const v=u;let w;e:{switch(h.kind){case"active":{let C;e[27]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=C):C=e[27];let P;e[28]!==h.version||e[29]!==r?(P=h.version?r("settings.plugins.status.loadedVersion",{version:h.version}):r("settings.plugins.status.loaded"),e[28]=h.version,e[29]=r,e[30]=P):P=e[30];let j;e[31]!==P?(j=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[C,P]}),e[31]=P,e[32]=j):j=e[32],w=j;break e}case"notReported":{let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(z,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=C):C=e[33];let P;e[34]!==r?(P=r("settings.plugins.status.notReported.title"),e[34]=r,e[35]=P):P=e[35];let j;e[36]!==P?(j=s.jsx("p",{className:"typography-label text-foreground",children:P}),e[36]=P,e[37]=j):j=e[37];let T;e[38]!==r?(T=r("settings.plugins.status.notReported.description"),e[38]=r,e[39]=T):T=e[39];let x;e[40]!==T?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:T}),e[40]=T,e[41]=x):x=e[41];let A;e[42]!==j||e[43]!==x?(A=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[C,s.jsxs("div",{className:"flex-1 min-w-0",children:[j,x]})]}),e[42]=j,e[43]=x,e[44]=A):A=e[44],w=A;break e}case"failed":{let C;e[45]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(z,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=C):C=e[45];let P;e[46]!==r?(P=r("settings.plugins.status.failed.title"),e[46]=r,e[47]=P):P=e[47];let j;e[48]!==P?(j=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:P}),e[48]=P,e[49]=j):j=e[49];let T;e[50]!==h.error?(T=s.jsx("p",{className:"typography-micro font-mono text-foreground mt-1 whitespace-pre-wrap break-words",children:h.error}),e[50]=h.error,e[51]=T):T=e[51];let x;e[52]!==h.ref||e[53]!==r?(x=h.ref?s.jsx("p",{className:"typography-micro text-muted-foreground mt-1",children:r("settings.plugins.status.failed.ref",{ref:h.ref})}):null,e[52]=h.ref,e[53]=r,e[54]=x):x=e[54];let A;e[55]!==j||e[56]!==T||e[57]!==x?(A=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[C,s.jsxs("div",{className:"flex-1 min-w-0",children:[j,T,x]})]}),e[55]=j,e[56]=T,e[57]=x,e[58]=A):A=e[58],w=A;break e}}w=void 0}const b=w,k=f!==null&&(p!=="none"||l!==null);let g;e[59]!==v||e[60]!==m||e[61]!==l||e[62]!==k||e[63]!==r?(g=k?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:r("settings.plugins.update.available.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:r("settings.plugins.update.available.description")}),l?.kind==="failed"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-micro text-[var(--status-error)] mt-2",children:r("settings.plugins.update.failed.title")}),s.jsx("p",{className:"typography-micro font-mono text-foreground mt-0.5 whitespace-pre-wrap break-words",children:l.error})]}):null]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{v()},disabled:m,children:m?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-4 animate-spin"}),r("settings.plugins.update.running")]}):r("settings.plugins.update.action")})]}):null,e[59]=v,e[60]=m,e[61]=l,e[62]=k,e[63]=r,e[64]=g):g=e[64];let I;return e[65]!==b||e[66]!==g?(I=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,g]}),e[65]=b,e[66]=g,e[67]=I):I=e[67],I};function Lh(t){return t.loadRuntime}function Kh(t){return t.updatePackage}function Zi(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 Xi(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Al(t,e){if(t.trim()===e.trim())return!0;const a=Zi(t),n=Zi(e);return a.ok&&n.ok&&Xi(a.value)===Xi(n.value)}function _h(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Xi(t.options),fileName:"",content:""}}function Uh(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Tl=t=>{const e=at.c(4),{scope:a,label:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=Ie("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]=r):r=e[0];let i;return e[1]!==n||e[2]!==a?(i=s.jsx("span",{className:r,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=i):i=e[3],i},zh=()=>{const t=at.c(147),{t:e}=Ze(),n=rn($h)?.trim()||sa(),r=Wt(Bh),i=Wt(Vh),l=r===n&&i===jn(),d=Wt(Hh),c=Wt(qh),h=Wt(Gh),p=Wt(Wh),f=Wt(Jh),m=Wt(Qh),u=Wt(Yh),v=Wt(Zh);let w;t[0]!==c||t[1]!==d?(w=d?c.find(W=>W.id===d)??null:null,t[0]=c,t[1]=d,t[2]=w):w=t[2];const b=w;let k;t[3]!==h||t[4]!==d?(k=d?h.find(W=>W.id===d)??null:null,t[3]=h,t[4]=d,t[5]=k):k=t[5];const g=k;let I;t[6]!==b?(I=b?sd(b.spec,b.sourcePath):null,t[6]=b,t[7]=I):I=t[7];const C=I;let P;t[8]!==g?(P=g?nd(g.absolutePath):null,t[8]=g,t[9]=P):P=t[9];const j=P,[T,x]=o.useState(!1);let A;t[10]===Symbol.for("react.memo_cache_sentinel")?(A=new Map,t[10]=A):A=t[10];const M=o.useRef(A),S=o.useRef(null),D=JSON.stringify([n,d]);let O;t[11]!==l||t[12]!==n||t[13]!==D||t[14]!==v||t[15]!==b||t[16]!==g||t[17]!==f||t[18]!==x?(O=()=>{let W=!1;if(!l){S.current=null,f(null);return}const te=(Q,H)=>{if(Wt.getState().selectedId!==Q||sa()!==n)return;const _=S.current,V=Wt.getState().draft,X=_?.id===Q&&_.directory===n&&V!==null&&(V.spec!==_.value.spec||!Al(V.optionsJson,_.value.optionsJson)||V.content!==_.value.content);S.current={id:Q,directory:n,value:H},X||f(H)};return b?(te(b.id,_h(b)),()=>{W=!0}):g?(x(S.current?.id!==g.id||S.current.directory!==n),(async()=>{const Q=await v(g.id);if(W||sa()!==n)return;x(!1);const H=Q?.content??"";M.current.set(D,H),te(g.id,Uh(g,H))})(),()=>{W=!0}):(S.current=null,f(null),()=>{W=!0})},t[11]=l,t[12]=n,t[13]=D,t[14]=v,t[15]=b,t[16]=g,t[17]=f,t[18]=x,t[19]=O):O=t[19];let F;t[20]!==l||t[21]!==n||t[22]!==D||t[23]!==v||t[24]!==b||t[25]!==g||t[26]!==f?(F=[b,g,v,f,l,n,D],t[20]=l,t[21]=n,t[22]=D,t[23]=v,t[24]=b,t[25]=g,t[26]=f,t[27]=F):F=t[27],o.useEffect(O,F);let N;t[28]!==l||t[29]!==n||t[30]!==p||t[31]!==D||t[32]!==b||t[33]!==g||t[34]!==e||t[35]!==m||t[36]!==u?(N=async()=>{if(!p||!l||sa()!==n)return Os;if(b&&p.mode==="entry"){const W=p.spec.trim();if(W===b.spec&&Al(p.optionsJson,Xi(b.options)))return Os;if(!W)return us(e("settings.plugins.validation.specRequired"));const Q=Zi(p.optionsJson);if(!Q.ok)return us(e("settings.plugins.page.field.options.invalidJson"));const H=await m(b.id,{spec:W,options:Q.value});return H.ok?H.reloadFailed?us(H.warning||H.message||e("settings.plugins.toast.reloadFailed")):In:us(H.message||e("settings.plugins.toast.reloadFailed"))}if(g&&p.mode==="file"){const W=M.current.get(D)??"";if(p.content===W)return Os;const te=await u(g.id,{content:p.content});return te.ok?(M.current.set(D,p.content),te.reloadFailed?us(te.warning||te.message||e("settings.plugins.toast.reloadFailed")):In):us(te.message||e("settings.plugins.toast.reloadFailed"))}return Os},t[28]=l,t[29]=n,t[30]=p,t[31]=D,t[32]=b,t[33]=g,t[34]=e,t[35]=m,t[36]=u,t[37]=N):N=t[37];const U=Ja(N);if(!d){let W;t[38]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t[38]=W):W=t[38];let te;t[39]!==e?(te=e("settings.plugins.page.empty.select"),t[39]=e,t[40]=te):te=t[40];let Q;t[41]!==te?(Q=s.jsx("p",{className:"typography-body",children:te}),t[41]=te,t[42]=Q):Q=t[42];let H;t[43]!==e?(H=e("settings.plugins.page.empty.add"),t[43]=e,t[44]=H):H=t[44];let _;t[45]!==H?(_=s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:H}),t[45]=H,t[46]=_):_=t[46];let V;return t[47]!==Q||t[48]!==_?(V=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[W,Q,_]})}),t[47]=Q,t[48]=_,t[49]=V):V=t[49],V}if(b&&p&&p.mode==="entry"){let W;t[50]!==p.optionsJson?(W=Zi(p.optionsJson),t[50]=p.optionsJson,t[51]=W):W=t[51];const Q=W.ok;let H;t[52]!==e?(H=e("settings.plugins.page.header.entry"),t[52]=e,t[53]=H):H=t[53];let _;t[54]!==b.scope||t[55]!==e?(_=b.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[54]=b.scope,t[55]=e,t[56]=_):_=t[56];let V;t[57]!==b.scope||t[58]!==_?(V=s.jsx(Tl,{scope:b.scope,label:_}),t[57]=b.scope,t[58]=_,t[59]=V):V=t[59];const X=U.onBlurCapture;let $;t[60]!==b.spec||t[61]!==C?($=s.jsx(Pl,{target:C,name:b.spec}),t[60]=b.spec,t[61]=C,t[62]=$):$=t[62];let ee;t[63]!==b.id||t[64]!==b.spec?(ee=s.jsx(Fh,{entryId:b.id,spec:b.spec}),t[63]=b.id,t[64]=b.spec,t[65]=ee):ee=t[65];let L;t[66]!==$||t[67]!==ee?(L=s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[$,ee]})}),t[66]=$,t[67]=ee,t[68]=L):L=t[68];let Y;t[69]!==e?(Y=e("settings.plugins.page.field.spec"),t[69]=e,t[70]=Y):Y=t[70];const oe=p.spec;let de;t[71]!==p||t[72]!==f?(de=xe=>f({...p,spec:xe.target.value}),t[71]=p,t[72]=f,t[73]=de):de=t[73];let ue;t[74]!==e?(ue=e("settings.plugins.page.field.spec.placeholder"),t[74]=e,t[75]=ue):ue=t[75];let ce;t[76]!==p.spec||t[77]!==de||t[78]!==ue?(ce=s.jsx(We,{value:oe,onChange:de,placeholder:ue,className:"font-mono typography-meta",spellCheck:!1}),t[76]=p.spec,t[77]=de,t[78]=ue,t[79]=ce):ce=t[79];let Se;t[80]!==Y||t[81]!==ce?(Se=s.jsx(qe,{title:Y,settingsItem:"plugins.spec",children:ce}),t[80]=Y,t[81]=ce,t[82]=Se):Se=t[82];let ie;t[83]!==e?(ie=e("settings.plugins.page.field.options"),t[83]=e,t[84]=ie):ie=t[84];const be=p.optionsJson;let ae;t[85]!==p||t[86]!==f?(ae=xe=>f({...p,optionsJson:xe.target.value}),t[85]=p,t[86]=f,t[87]=ae):ae=t[87];const pe=!Q&&"border-[var(--status-error-border)]";let je;t[88]!==pe?(je=Ie("font-mono typography-meta min-h-[200px]",pe),t[88]=pe,t[89]=je):je=t[89];let De;t[90]!==p.optionsJson||t[91]!==ae||t[92]!==je?(De=s.jsx(As,{value:be,onChange:ae,rows:10,className:je,spellCheck:!1,placeholder:"{ }"}),t[90]=p.optionsJson,t[91]=ae,t[92]=je,t[93]=De):De=t[93];let me;t[94]!==Q||t[95]!==e?(me=!Q&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[94]=Q,t[95]=e,t[96]=me):me=t[96];let $e;t[97]!==ie||t[98]!==De||t[99]!==me?($e=s.jsxs(qe,{title:ie,settingsItem:"plugins.options",children:[De,me]}),t[97]=ie,t[98]=De,t[99]=me,t[100]=$e):$e=t[100];let Ge;return t[101]!==U.onBlurCapture||t[102]!==V||t[103]!==L||t[104]!==Se||t[105]!==$e||t[106]!==H?(Ge=s.jsxs(ns,{title:H,titleAccessory:V,onBlurCapture:X,children:[L,Se,$e]}),t[101]=U.onBlurCapture,t[102]=V,t[103]=L,t[104]=Se,t[105]=$e,t[106]=H,t[107]=Ge):Ge=t[107],Ge}if(g&&p&&p.mode==="file"){let W;t[108]!==e?(W=e("settings.plugins.page.header.file"),t[108]=e,t[109]=W):W=t[109];let te;t[110]!==g.scope||t[111]!==e?(te=g.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[110]=g.scope,t[111]=e,t[112]=te):te=t[112];let Q;t[113]!==g.scope||t[114]!==te?(Q=s.jsx(Tl,{scope:g.scope,label:te}),t[113]=g.scope,t[114]=te,t[115]=Q):Q=t[115];let H;t[116]===Symbol.for("react.memo_cache_sentinel")?(H=Ie("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),t[116]=H):H=t[116];let _;t[117]!==g.fileName?(_=s.jsx("span",{className:H,children:g.fileName}),t[117]=g.fileName,t[118]=_):_=t[118];let V;t[119]!==Q||t[120]!==_?(V=s.jsxs(s.Fragment,{children:[Q,_]}),t[119]=Q,t[120]=_,t[121]=V):V=t[121];const X=U.onBlurCapture;let $;t[122]!==g.fileName||t[123]!==j?($=s.jsx(qe,{divider:!1,children:s.jsx(Pl,{target:j,name:g.fileName})}),t[122]=g.fileName,t[123]=j,t[124]=$):$=t[124];let ee;t[125]!==e?(ee=e("settings.plugins.page.field.content"),t[125]=e,t[126]=ee):ee=t[126];let L;t[127]!==p||t[128]!==f?(L=ce=>f({...p,content:ce.target.value}),t[127]=p,t[128]=f,t[129]=L):L=t[129];let Y;t[130]!==U?(Y=ce=>{ce.key==="Enter"&&(ce.metaKey||ce.ctrlKey)&&(ce.preventDefault(),U.requestSave())},t[130]=U,t[131]=Y):Y=t[131];let oe;t[132]!==p.content||t[133]!==T||t[134]!==L||t[135]!==Y?(oe=s.jsx(As,{value:p.content,onChange:L,onKeyDown:Y,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:T}),t[132]=p.content,t[133]=T,t[134]=L,t[135]=Y,t[136]=oe):oe=t[136];let de;t[137]!==ee||t[138]!==oe?(de=s.jsx(qe,{title:ee,settingsItem:"plugins.content",children:oe}),t[137]=ee,t[138]=oe,t[139]=de):de=t[139];let ue;return t[140]!==U.onBlurCapture||t[141]!==V||t[142]!==$||t[143]!==de||t[144]!==W?(ue=s.jsxs(ns,{title:W,titleAccessory:V,onBlurCapture:X,children:[$,de]}),t[140]=U.onBlurCapture,t[141]=V,t[142]=$,t[143]=de,t[144]=W,t[145]=ue):ue=t[145],ue}let K;return t[146]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(z,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[146]=K):K=t[146],K};function $h(t){return t.getActiveProject()?.path}function Bh(t){return t.loadedDirectory}function Vh(t){return t.loadedRuntimeKey}function Hh(t){return t.selectedId}function qh(t){return t.entries}function Gh(t){return t.files}function Wh(t){return t.draft}function Jh(t){return t.setDraft}function Qh(t){return t.updateEntry}function Yh(t){return t.updateFile}function Zh(t){return t.readFile}const Xh="<built-in>",di=t=>t?.path===Xh,oo=t=>!!t&&!di(t)&&t.renamable===!0,ef=t=>{const e=at.c(157),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[p,f]=o.useState(!1),[m,u]=o.useState(null),{selectedSkillName:v,setSelectedSkill:w,setSkillDraft:b,deleteSkill:k,renameSkill:g,getSkillDetail:I}=nn($s(tf)),C=Js();let P;e[0]!==C?(P=Re=>ho(Re,C),e[0]=C,e[1]=P):P=e[1];const j=nn(P),T=nn(sf);let x,A;e[2]!==T||e[3]!==C?(x=()=>{T(C)},A=[T,C],e[2]=T,e[3]=C,e[4]=x,e[5]=A):(x=e[4],A=e[5]),o.useEffect(x,A);let M;e[6]!==a||e[7]!==w||e[8]!==b||e[9]!==j?(M=()=>{let Re="new-skill",Ve=1;for(;j.some(Z=>Z.name===Re);)Re=`new-skill-${Ve}`,Ve++;b({name:Re,scope:"user",source:"opencode",description:""}),w(Re),a?.()},e[6]=a,e[7]=w,e[8]=b,e[9]=j,e[10]=M):M=e[10];const S=M;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=async Re=>{di(Re)||h(Re)},e[11]=D):D=e[11];const O=D;let F;e[12]!==c||e[13]!==k||e[14]!==C||e[15]!==n?(F=async()=>{if(!c)return;if(di(c)){h(null);return}f(!0),await k(c.name,C)?(B.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),h(null)):B.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),f(!1)},e[12]=c,e[13]=k,e[14]=C,e[15]=n,e[16]=F):F=e[16];const N=F;let R;e[17]!==I||e[18]!==w||e[19]!==b||e[20]!==C||e[21]!==j||e[22]!==n?(R=async Re=>{if(di(Re))return;const Ve=Re.name;let Z=1,ge=`${Ve}-copy`;for(;j.some(Ee=>Ee.name===ge);)Z++,ge=`${Ve}-copy-${Z}`;const Oe=await I(Re.name,C);if(!Oe){B.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:ge,scope:Re.scope||"user",source:Re.source||"opencode",description:(Oe.sources.md.fields.includes("description"),""),instructions:""}),w(ge)},e[17]=I,e[18]=w,e[19]=b,e[20]=C,e[21]=j,e[22]=n,e[23]=R):R=e[23];const U=R;let K;e[24]===Symbol.for("react.memo_cache_sentinel")?(K=Re=>{oo(Re)&&(d(Re.name),i(Re))},e[24]=K):K=e[24];const W=K;let te;e[25]!==r||e[26]!==l||e[27]!==g||e[28]!==w||e[29]!==C||e[30]!==j||e[31]!==n?(te=async()=>{if(!r)return;if(!oo(r)){i(null);return}const Re=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Re){B.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Re===r.name){i(null);return}if(j.some(Z=>Z.name===Re)){B.error(n("settings.skills.page.toast.skillExists"));return}await g(r.name,Re,C)?(B.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Re})),w(Re)):B.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=g,e[28]=w,e[29]=C,e[30]=j,e[31]=n,e[32]=te):te=e[32];const Q=te;let H;e[33]!==j?(H=j.filter(nf),e[33]=j,e[34]=H):H=e[34];const _=H;let V;e[35]!==j?(V=j.filter(af),e[35]=j,e[36]=V):V=e[36];const X=V;let $;e[37]===Symbol.for("react.memo_cache_sentinel")?($=function(Ve){const Z={},ge=[];for(const Ee of Ve)Ee.group?(Z[Ee.group]||(Z[Ee.group]=[]),Z[Ee.group].push(Ee)):ge.push(Ee);const Oe=Object.keys(Z).sort(rf).map(Ee=>({name:Ee,skills:[...Z[Ee]].sort(of)}));return ge.sort(lf),{sortedGroups:Oe,ungrouped:ge}},e[37]=$):$=e[37];const ee=$;let L;e[38]!==_?(L=ee(_),e[38]=_,e[39]=L):L=e[39];const Y=L;let oe;e[40]!==X?(oe=ee(X),e[40]=X,e[41]=oe):oe=e[41];const de=oe;let ue;e[42]===Symbol.for("react.memo_cache_sentinel")?(ue=Ie("flex h-full flex-col","bg-background"),e[42]=ue):ue=e[42];let ce;e[43]!==n?(ce=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ce):ce=e[44];let Se;e[45]!==ce?(Se=s.jsx("h2",{className:`${Pn} mb-3`,children:ce}),e[45]=ce,e[46]=Se):Se=e[46];let ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(xi,{className:"mb-3"}),e[47]=ie):ie=e[47];let be;e[48]!==j.length||e[49]!==n?(be=n("settings.skills.sidebar.total",{count:j.length}),e[48]=j.length,e[49]=n,e[50]=be):be=e[50];let ae;e[51]!==be?(ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:be}),e[51]=be,e[52]=ae):ae=e[52];let pe;e[53]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[53]=pe):pe=e[53];let je;e[54]!==S?(je=s.jsx(G,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:S,children:pe}),e[54]=S,e[55]=je):je=e[55];let De;e[56]!==ae||e[57]!==je?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ae,je]}),e[56]=ae,e[57]=je,e[58]=De):De=e[58];let me;e[59]!==Se||e[60]!==De?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Se,ie,De]}),e[59]=Se,e[60]=De,e[61]=me):me=e[61];let $e;e[62]!==Y||e[63]!==de||e[64]!==U||e[65]!==a||e[66]!==m||e[67]!==_||e[68]!==v||e[69]!==w||e[70]!==j.length||e[71]!==n||e[72]!==X?($e=s.jsx(bs,{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(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_.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")}),Y.sortedGroups.map(Re=>{const{name:Ve,skills:Z}=Re;return s.jsx(ao,{label:Ve,count:Z.length,storageKey:"project-skills",children:Z.map(ge=>s.jsx(Li,{skill:ge,isSelected:v===ge.name,onSelect:()=>{w(ge.name),a?.()},onRename:()=>W(ge),onDelete:()=>O(ge),onDuplicate:()=>U(ge),isMenuOpen:m===ge.name,onMenuOpenChange:Oe=>u(Oe?ge.name:null)},ge.name))},Ve)}),Y.ungrouped.map(Re=>s.jsx(Li,{skill:Re,isSelected:v===Re.name,onSelect:()=>{w(Re.name),a?.()},onRename:()=>W(Re),onDelete:()=>O(Re),onDuplicate:()=>U(Re),isMenuOpen:m===Re.name,onMenuOpenChange:Ve=>u(Ve?Re.name:null)},Re.name))]}),X.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Re=>{const{name:Ve,skills:Z}=Re;return s.jsx(ao,{label:Ve,count:Z.length,storageKey:"user-skills",children:Z.map(ge=>s.jsx(Li,{skill:ge,isSelected:v===ge.name,onSelect:()=>{w(ge.name),a?.()},onRename:()=>W(ge),onDelete:()=>O(ge),onDuplicate:()=>U(ge),isMenuOpen:m===ge.name,onMenuOpenChange:Oe=>u(Oe?ge.name:null)},ge.name))},Ve)}),de.ungrouped.map(Re=>s.jsx(Li,{skill:Re,isSelected:v===Re.name,onSelect:()=>{w(Re.name),a?.()},onRename:()=>W(Re),onDelete:()=>O(Re),onDuplicate:()=>U(Re),isMenuOpen:m===Re.name,onMenuOpenChange:Ve=>u(Ve?Re.name:null)},Re.name))]})]})}),e[62]=Y,e[63]=de,e[64]=U,e[65]=a,e[66]=m,e[67]=_,e[68]=v,e[69]=w,e[70]=j.length,e[71]=n,e[72]=X,e[73]=$e):$e=e[73];const Ge=c!==null;let xe;e[74]!==p?(xe=Re=>{!Re&&!p&&h(null)},e[74]=p,e[75]=xe):xe=e[75];let Pe;e[76]!==n?(Pe=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Pe):Pe=e[77];let J;e[78]!==Pe?(J=s.jsx(Vt,{children:Pe}),e[78]=Pe,e[79]=J):J=e[79];const se=c?.name??"";let he;e[80]!==n||e[81]!==se?(he=n("settings.skills.sidebar.deleteDialog.description",{name:se}),e[80]=n,e[81]=se,e[82]=he):he=e[82];let ve;e[83]!==he?(ve=s.jsx(Ht,{children:he}),e[83]=he,e[84]=ve):ve=e[84];let Fe;e[85]!==J||e[86]!==ve?(Fe=s.jsxs(Bt,{children:[J,ve]}),e[85]=J,e[86]=ve,e[87]=Fe):Fe=e[87];let Ke;e[88]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>h(null),e[88]=Ke):Ke=e[88];let Be;e[89]!==n?(Be=n("settings.common.actions.cancel"),e[89]=n,e[90]=Be):Be=e[90];let ze;e[91]!==p||e[92]!==Be?(ze=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ke,disabled:p,children:Be}),e[91]=p,e[92]=Be,e[93]=ze):ze=e[93];let _e;e[94]!==n?(_e=n("settings.common.actions.delete"),e[94]=n,e[95]=_e):_e=e[95];let Me;e[96]!==N||e[97]!==p||e[98]!==_e?(Me=s.jsx(G,{size:"sm",onClick:N,disabled:p,children:_e}),e[96]=N,e[97]=p,e[98]=_e,e[99]=Me):Me=e[99];let tt;e[100]!==ze||e[101]!==Me?(tt=s.jsxs(as,{children:[ze,Me]}),e[100]=ze,e[101]=Me,e[102]=tt):tt=e[102];let pt;e[103]!==Fe||e[104]!==tt?(pt=s.jsxs(Ut,{className:"max-w-md",children:[Fe,tt]}),e[103]=Fe,e[104]=tt,e[105]=pt):pt=e[105];let ct;e[106]!==Ge||e[107]!==xe||e[108]!==pt?(ct=s.jsx(_t,{open:Ge,onOpenChange:xe,children:pt}),e[106]=Ge,e[107]=xe,e[108]=pt,e[109]=ct):ct=e[109];const dt=r!==null;let ht;e[110]===Symbol.for("react.memo_cache_sentinel")?(ht=Re=>!Re&&i(null),e[110]=ht):ht=e[110];let Ue;e[111]!==n?(Ue=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=Ue):Ue=e[112];let st;e[113]!==Ue?(st=s.jsx(Vt,{children:Ue}),e[113]=Ue,e[114]=st):st=e[114];const ut=r?.name??"";let ye;e[115]!==n||e[116]!==ut?(ye=n("settings.skills.sidebar.renameDialog.description",{name:ut}),e[115]=n,e[116]=ut,e[117]=ye):ye=e[117];let re;e[118]!==ye?(re=s.jsx(Ht,{children:ye}),e[118]=ye,e[119]=re):re=e[119];let Te;e[120]!==st||e[121]!==re?(Te=s.jsxs(Bt,{children:[st,re]}),e[120]=st,e[121]=re,e[122]=Te):Te=e[122];let Ne;e[123]===Symbol.for("react.memo_cache_sentinel")?(Ne=Re=>d(Re.target.value),e[123]=Ne):Ne=e[123];let Ae;e[124]!==n?(Ae=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=Ae):Ae=e[125];let q;e[126]!==Q?(q=Re=>{Re.key==="Enter"&&Q()},e[126]=Q,e[127]=q):q=e[127];let Le;e[128]!==l||e[129]!==Ae||e[130]!==q?(Le=s.jsx(We,{value:l,onChange:Ne,placeholder:Ae,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:q}),e[128]=l,e[129]=Ae,e[130]=q,e[131]=Le):Le=e[131];let Qe;e[132]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>i(null),e[132]=Qe):Qe=e[132];let lt;e[133]!==n?(lt=n("settings.common.actions.cancel"),e[133]=n,e[134]=lt):lt=e[134];let ot;e[135]!==lt?(ot=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Qe,children:lt}),e[135]=lt,e[136]=ot):ot=e[136];let bt;e[137]!==n?(bt=n("settings.common.actions.rename"),e[137]=n,e[138]=bt):bt=e[138];let wt;e[139]!==Q||e[140]!==bt?(wt=s.jsx(G,{size:"sm",onClick:Q,children:bt}),e[139]=Q,e[140]=bt,e[141]=wt):wt=e[141];let jt;e[142]!==ot||e[143]!==wt?(jt=s.jsxs(as,{children:[ot,wt]}),e[142]=ot,e[143]=wt,e[144]=jt):jt=e[144];let vt;e[145]!==Te||e[146]!==Le||e[147]!==jt?(vt=s.jsxs(Ut,{children:[Te,Le,jt]}),e[145]=Te,e[146]=Le,e[147]=jt,e[148]=vt):vt=e[148];let Xe;e[149]!==dt||e[150]!==vt?(Xe=s.jsx(_t,{open:dt,onOpenChange:ht,children:vt}),e[149]=dt,e[150]=vt,e[151]=Xe):Xe=e[151];let kt;return e[152]!==me||e[153]!==$e||e[154]!==ct||e[155]!==Xe?(kt=s.jsxs("div",{className:ue,children:[me,$e,ct,Xe]}),e[152]=me,e[153]=$e,e[154]=ct,e[155]=Xe,e[156]=kt):kt=e[156],kt},Li=t=>{const e=at.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:h}=t,{t:p}=Ze();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=mi(),e[0]=f):f=e[0];const m=f;let u;e[1]!==a?(u=di(a),e[1]=a,e[2]=u):u=e[2];const v=u;let w;e[3]!==a?(w=oo(a),e[3]=a,e[4]=w):w=e[4];const b=w,[k,g]=o.useState(!1);let I;e[5]!==b||e[6]!==i||e[7]!==d||e[8]!==l||e[9]!==p?(I=U=>s.jsxs(s.Fragment,{children:[b?s.jsxs(U,{onClick:K=>{K.stopPropagation(),l()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}):null,s.jsxs(U,{onClick:K=>{K.stopPropagation(),d()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),s.jsxs(U,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[5]=b,e[6]=i,e[7]=d,e[8]=l,e[9]=p,e[10]=I):I=e[10];const C=I,P=!v&&k,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let T;e[11]!==j?(T=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[11]=j,e[12]=T):T=e[12];let x;e[13]!==v?(x=!m&&!v?U=>{U.preventDefault(),g(!0)}:void 0,e[13]=v,e[14]=x):x=e[14];let A;e[15]!==T||e[16]!==x?(A=s.jsx("div",{className:T,onContextMenu:x}),e[15]=T,e[16]=x,e[17]=A):A=e[17];let M;e[18]!==a.name?(M=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]=M):M=e[19];let S;e[20]!==r||e[21]!==M?(S=s.jsx("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-ring",tabIndex:0,children:M}),e[20]=r,e[21]=M,e[22]=S):S=e[22];let D;e[23]!==v||e[24]!==c||e[25]!==h||e[26]!==C?(D=v?null:s.jsxs(zn,{open:c,onOpenChange:U=>{U&&g(!1),h(U)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:C(wn)})]}),e[23]=v,e[24]=c,e[25]=h,e[26]=C,e[27]=D):D=e[27];let O;e[28]!==S||e[29]!==D?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[S,D]}),e[28]=S,e[29]=D,e[30]=O):O=e[30];let F;e[31]!==O||e[32]!==A?(F=s.jsx(ga,{render:A,children:O}),e[31]=O,e[32]=A,e[33]=F):F=e[33];let N;e[34]!==v||e[35]!==C?(N=v?null:s.jsx(ma,{className:"w-fit min-w-20",children:C(pa)}),e[34]=v,e[35]=C,e[36]=N):N=e[36];let R;return e[37]!==F||e[38]!==N||e[39]!==P?(R=s.jsxs(ha,{open:P,onOpenChange:g,children:[F,N]}),e[37]=F,e[38]=N,e[39]=P,e[40]=R):R=e[40],R};function tf(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function sf(t){return t.loadSkills}function nf(t){return t.scope==="project"}function af(t){return t.scope==="user"}function rf(t,e){return t.localeCompare(e)}function of(t,e){return t.name.localeCompare(e.name)}function lf(t,e){return t.name.localeCompare(e.name)}const cf=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,df=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},uf=({open:t,onOpenChange:e})=>{const{t:a}=Ze(),n=On(N=>N.scanRepo),r=On(N=>N.loadCatalog),i=On(N=>N.loadSource),l=On(N=>N.setSelectedSource),d=On(N=>N.isScanning),c=oa(N=>N.defaultGitIdentityId),h=oa(N=>N.loadDefaultGitIdentityId),[p,f]=o.useState(""),[m,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(null),[g,I]=o.useState(null),[C,P]=o.useState(!1),[j,T]=o.useState([]),[x,A]=o.useState(null),M=o.useRef(0),S=o.useCallback(N=>{M.current+=1,P(!1),I(null),N?.clearIdentity&&(T([]),A(null))},[]);o.useEffect(()=>{t&&(M.current+=1,f(""),u(""),w(""),I(null),P(!1),T([]),A(null),h(),k(null),(async()=>{const N=await An();k(N?N.skillCatalogs??[]:null)})())},[t,h]);const D=o.useMemo(()=>{const N=m.trim(),R=v.trim();return(b??[]).some(U=>{const K=(U.source||"").trim(),W=(U.subpath||"").trim();return K===N&&W===R})},[b,m,v]),O=async()=>{const N=m.trim();if(!N){B.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||f(df(N)),P(!1),I(null);const R=M.current+1;M.current=R;const U=await n({source:N,subpath:v.trim()||void 0,gitIdentityId:x||void 0});if(M.current!==R)return;if(!U.ok){if(U.error?.kind==="authRequired"){if(fs()){B.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const W=U.error.identities||[];if(T(W),!x&&W.length>0){const te=c&&c!=="global"&&W.some(Q=>Q.id===c)?c:W[0].id;A(te)}B.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}B.error(U.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const K=U.items?.length||0;if(I(K),K===0){B.error(a("settings.skills.catalog.add.toast.noSkillsFound")),P(!1);return}T([]),P(!0),B.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:K}))},F=async()=>{const N=p.trim(),R=m.trim(),U=v.trim();if(!N){B.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!R){B.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!C){B.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(D){B.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const K={id:cf(),label:N,source:R,...U?{subpath:U}:{},...x?{gitIdentityId:x}:{}};if(b===null){B.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const W=[...b,K];try{if(!(await ft({skillCatalogs:W})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(W),B.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(K.id,{refresh:!0}),l(K.id),e(!1)}catch(te){B.error(te instanceof Error?te.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Ht,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(We,{value:p,onChange:N=>f(N.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(qt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(We,{value:m,onChange:N=>{u(N.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(We,{value:v,onChange:N=>{w(N.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),j.length>0&&!fs()?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:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(qt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Tt,{value:x||"",onValueChange:N=>{A(N),S()},children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{children:j.find(N=>N.id===x)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:j.map(N=>s.jsx(mt,{value:N.id,children:N.name},N.id))})]})]}):null,g!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:g})}):null,D?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(G,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{O()},disabled:d||!m.trim(),children:[s.jsx(z,{name:"git-repository",className:"h-4 w-4"}),a(d?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(G,{size:"sm",onClick:()=>{F()},disabled:!C||D||b===null||!p.trim()||!m.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},mf=t=>{const e=at.c(85),{open:a,onOpenChange:n,conflicts:r,onConfirm:i}=t,{t:l}=Ze();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,h]=o.useState(d);let p,f;e[1]!==r||e[2]!==a?(p=()=>{if(!a)return;const L={};for(const Y of r)L[Y.skillName]="skip";h(L)},f=[a,r],e[1]=r,e[2]=a,e[3]=p,e[4]=f):(p=e[3],f=e[4]),o.useEffect(p,f);let m;e[5]!==r?(m=L=>{const Y={};for(const oe of r)Y[oe.skillName]=L;h(Y)},e[5]=r,e[6]=m):m=e[6];const u=m;let v;e[7]!==r||e[8]!==c?(v=r.length>0&&r.every(L=>c[L.skillName]),e[7]=r,e[8]=c,e[9]=v):v=e[9];const w=v;let b;e[10]!==l?(b=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=b):b=e[11];let k;e[12]!==b?(k=s.jsx(Vt,{children:b}),e[12]=b,e[13]=k):k=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let I;e[16]!==g?(I=s.jsx(Ht,{children:g}),e[16]=g,e[17]=I):I=e[17];let C;e[18]!==k||e[19]!==I?(C=s.jsxs(Bt,{children:[k,I]}),e[18]=k,e[19]=I,e[20]=C):C=e[20];let P;e[21]!==r.length||e[22]!==l?(P=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=P):P=e[23];let j;e[24]!==P?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[24]=P,e[25]=j):j=e[25];let T;e[26]!==u?(T=()=>u("skip"),e[26]=u,e[27]=T):T=e[27];let x;e[28]!==l?(x=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=x):x=e[29];let A;e[30]!==T||e[31]!==x?(A=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:x}),e[30]=T,e[31]=x,e[32]=A):A=e[32];let M;e[33]!==u?(M=()=>u("overwrite"),e[33]=u,e[34]=M):M=e[34];let S;e[35]!==l?(S=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=S):S=e[36];let D;e[37]!==M||e[38]!==S?(D=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:M,children:S}),e[37]=M,e[38]=S,e[39]=D):D=e[39];let O;e[40]!==A||e[41]!==D?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[A,D]}),e[40]=A,e[41]=D,e[42]=O):O=e[42];let F;e[43]!==j||e[44]!==O?(F=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,O]}),e[43]=j,e[44]=O,e[45]=F):F=e[45];let N;if(e[46]!==r||e[47]!==c||e[48]!==l){let L;e[50]!==c||e[51]!==l?(L=Y=>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:Y.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:Y.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:Y.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Tt,{value:c[Y.skillName]||"skip",onValueChange:oe=>h(de=>({...de,[Y.skillName]:oe})),children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[Y.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},Y.skillName),e[50]=c,e[51]=l,e[52]=L):L=e[52],N=r.map(L),e[46]=r,e[47]=c,e[48]=l,e[49]=N}else N=e[49];let R;e[53]!==N?(R=s.jsx("div",{className:"space-y-2",children:N}),e[53]=N,e[54]=R):R=e[54];let U;e[55]!==F||e[56]!==R?(U=s.jsxs("div",{className:"space-y-3",children:[F,R]}),e[55]=F,e[56]=R,e[57]=U):U=e[57];let K;e[58]!==n?(K=()=>n(!1),e[58]=n,e[59]=K):K=e[59];let W;e[60]!==l?(W=l("settings.common.actions.cancel"),e[60]=l,e[61]=W):W=e[61];let te;e[62]!==K||e[63]!==W?(te=s.jsx(G,{size:"sm",variant:"ghost",onClick:K,children:W}),e[62]=K,e[63]=W,e[64]=te):te=e[64];let Q;e[65]!==c||e[66]!==i?(Q=()=>i(c),e[65]=c,e[66]=i,e[67]=Q):Q=e[67];const H=!w;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let V;e[70]!==Q||e[71]!==H||e[72]!==_?(V=s.jsx(G,{size:"sm",onClick:Q,disabled:H,children:_}),e[70]=Q,e[71]=H,e[72]=_,e[73]=V):V=e[73];let X;e[74]!==te||e[75]!==V?(X=s.jsxs(as,{children:[te,V]}),e[74]=te,e[75]=V,e[76]=X):X=e[76];let $;e[77]!==C||e[78]!==U||e[79]!==X?($=s.jsxs(Ut,{className:"max-w-2xl",children:[C,U,X]}),e[77]=C,e[78]=U,e[79]=X,e[80]=$):$=e[80];let ee;return e[81]!==n||e[82]!==a||e[83]!==$?(ee=s.jsx(_t,{open:a,onOpenChange:n,children:$}),e[81]=n,e[82]=a,e[83]=$,e[84]=ee):ee=e[84],ee},To=[{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 ui(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 cd(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=To.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const pf=t=>{const e=at.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=Ze(),l=On(gf),d=On(hf),[c,h]=o.useState("user"),[p,f]=o.useState("opencode"),m=rn(ff),u=rn(xf),[v,w]=o.useState(null),[b,k]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[I,C]=o.useState(g),[P,j]=o.useState(null);let T,x;e[1]!==u||e[2]!==a?(T=()=>{a&&(h("user"),f("opencode"),w(u),k(!1),C([]),j(null))},x=[a,u],e[1]=u,e[2]=a,e[3]=T,e[4]=x):(T=e[3],x=e[4]),o.useEffect(T,x);let A;e[5]!==i?(A=Me=>{switch(Me){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=A):A=e[6];const M=A;let S;e[7]!==i?(S=Me=>{switch(Me){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=S):S=e[8];const D=S;let O;e:{if(m.length===0){O=null;break e}if(v&&m.some(Me=>Me.id===v)){O=v;break e}if(u&&m.some(Me=>Me.id===u)){O=u;break e}O=m[0]?.id??null}const F=O;let N;e:{if(c!=="project"){N=null;break e}const Me=F;if(!Me){N=null;break e}let tt;if(e[9]!==Me||e[10]!==m){let ct;e[12]!==Me?(ct=dt=>dt.id===Me,e[12]=Me,e[13]=ct):ct=e[13],tt=m.find(ct),e[9]=Me,e[10]=m,e[11]=tt}else tt=e[11];N=tt?.path??null}const R=N;let U;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(U=async Me=>{const tt=await l({source:Me.source,subpath:Me.subpath,gitIdentityId:r?.gitIdentityId,scope:Me.scope,targetSource:Me.targetSource,selections:[{skillDir:Me.skillDir}],conflictPolicy:"prompt",conflictDecisions:Me.conflictDecisions},{directory:Me.directoryOverride??null});if(tt.ok){B.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(tt.error?.kind==="conflicts"){j({source:Me.source,subpath:Me.subpath,scope:Me.scope,targetSource:Me.targetSource,skillDir:Me.skillDir,directoryOverride:Me.directoryOverride??null}),C(tt.error.conflicts),k(!0);return}if(tt.error?.kind==="authRequired"){B.error(tt.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}B.error(tt.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r?.gitIdentityId,e[16]=n,e[17]=i,e[18]=U):U=e[18];const K=U;if(!r)return null;let W;e[19]!==i?(W=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=W):W=e[20];let te;e[21]!==W?(te=s.jsx(Vt,{children:W}),e[21]=W,e[22]=te):te=e[22];let Q;e[23]!==i?(Q=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=Q):Q=e[24];let H;e[25]!==r.skillName?(H=s.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=H):H=e[26];let _;e[27]!==i?(_=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=_):_=e[28];let V;e[29]!==Q||e[30]!==H||e[31]!==_?(V=s.jsxs(Ht,{children:[Q," ",H," ",_]}),e[29]=Q,e[30]=H,e[31]=_,e[32]=V):V=e[32];let X;e[33]!==te||e[34]!==V?(X=s.jsxs(Bt,{children:[te,V]}),e[33]=te,e[34]=V,e[35]=X):X=e[35];let $;e[36]!==i?($=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=$):$=e[37];let ee;e[38]!==$?(ee=s.jsx("span",{className:"typography-ui-label text-foreground",children:$}),e[38]=$,e[39]=ee):ee=e[39];let L;e[40]!==c||e[41]!==p?(L=ui(c,p),e[40]=c,e[41]=p,e[42]=L):L=e[42];let Y;e[43]===Symbol.for("react.memo_cache_sentinel")?(Y=Me=>{const tt=cd(Me);h(tt.scope),f(tt.source==="agents"?"agents":"opencode")},e[43]=Y):Y=e[43];let oe;e[44]!==c?(oe=c==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=oe):oe=e[45];let de;e[46]!==p?(de=p==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=p,e[47]=de):de=e[47];let ue;e[48]!==M||e[49]!==c||e[50]!==p?(ue=M(ui(c,p)),e[48]=M,e[49]=c,e[50]=p,e[51]=ue):ue=e[51];let ce;e[52]!==ue?(ce=s.jsx("span",{children:ue}),e[52]=ue,e[53]=ce):ce=e[53];let Se;e[54]!==oe||e[55]!==de||e[56]!==ce?(Se=s.jsxs(Pt,{className:"w-fit gap-1.5",children:[oe,de,ce]}),e[54]=oe,e[55]=de,e[56]=ce,e[57]=Se):Se=e[57];let ie;e[58]!==D||e[59]!==M?(ie=To.map(Me=>s.jsx(mt,{value:Me.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:[Me.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),Me.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:M(Me.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:D(Me.value)})]})},Me.value)),e[58]=D,e[59]=M,e[60]=ie):ie=e[60];let be;e[61]!==ie?(be=s.jsx(At,{align:"start",children:ie}),e[61]=ie,e[62]=be):be=e[62];let ae;e[63]!==L||e[64]!==Se||e[65]!==be?(ae=s.jsxs(Tt,{value:L,onValueChange:Y,children:[Se,be]}),e[63]=L,e[64]=Se,e[65]=be,e[66]=ae):ae=e[66];let pe;e[67]!==ee||e[68]!==ae?(pe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ee,ae]}),e[67]=ee,e[68]=ae,e[69]=pe):pe=e[69];let je;e[70]!==m||e[71]!==F||e[72]!==c||e[73]!==i?(je=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),m.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Tt,{value:F??"",onValueChange:Me=>w(Me),disabled:m.length===1,children:[s.jsx(Pt,{className:"w-fit",children:s.jsx(zt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:m.map(bf)})]})]}),e[70]=m,e[71]=F,e[72]=c,e[73]=i,e[74]=je):je=e[74];let De;e[75]!==r.warnings?(De=r.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=De):De=e[76];let me;e[77]!==pe||e[78]!==je||e[79]!==De?(me=s.jsxs("div",{className:"mt-2 space-y-3",children:[pe,je,De]}),e[77]=pe,e[78]=je,e[79]=De,e[80]=me):me=e[80];let $e;e[81]!==n?($e=()=>n(!1),e[81]=n,e[82]=$e):$e=e[82];let Ge;e[83]!==i?(Ge=i("settings.common.actions.cancel"),e[83]=i,e[84]=Ge):Ge=e[84];let xe;e[85]!==$e||e[86]!==Ge?(xe=s.jsx(G,{size:"sm",variant:"ghost",onClick:$e,children:Ge}),e[85]=$e,e[86]=Ge,e[87]=xe):xe=e[87];const Pe=d||!r.installable||c==="project"&&!R;let J;e[88]!==R||e[89]!==K||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==p?(J=()=>{K({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:p,skillDir:r.skillDir,directoryOverride:R})},e[88]=R,e[89]=K,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=p,e[95]=J):J=e[95];let se;e[96]!==d||e[97]!==i?(se=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=se):se=e[98];let he;e[99]!==Pe||e[100]!==J||e[101]!==se?(he=s.jsx(G,{size:"sm",disabled:Pe,onClick:J,children:se}),e[99]=Pe,e[100]=J,e[101]=se,e[102]=he):he=e[102];let ve;e[103]!==xe||e[104]!==he?(ve=s.jsxs(as,{children:[xe,he]}),e[103]=xe,e[104]=he,e[105]=ve):ve=e[105];let Fe;e[106]!==X||e[107]!==me||e[108]!==ve?(Fe=s.jsxs(Ut,{className:"max-w-md",children:[X,me,ve]}),e[106]=X,e[107]=me,e[108]=ve,e[109]=Fe):Fe=e[109];let Ke;e[110]!==n||e[111]!==a||e[112]!==Fe?(Ke=s.jsx(_t,{open:a,onOpenChange:n,children:Fe}),e[110]=n,e[111]=a,e[112]=Fe,e[113]=Ke):Ke=e[113];let Be;e[114]!==P||e[115]!==K?(Be=Me=>{P&&(K({source:P.source,subpath:P.subpath,scope:P.scope,targetSource:P.targetSource,skillDir:P.skillDir,conflictDecisions:Me,directoryOverride:P.directoryOverride??null}),k(!1))},e[114]=P,e[115]=K,e[116]=Be):Be=e[116];let ze;e[117]!==I||e[118]!==b||e[119]!==Be?(ze=s.jsx(mf,{open:b,onOpenChange:k,conflicts:I,onConfirm:Be}),e[117]=I,e[118]=b,e[119]=Be,e[120]=ze):ze=e[120];let _e;return e[121]!==Ke||e[122]!==ze?(_e=s.jsxs(s.Fragment,{children:[Ke,ze]}),e[121]=Ke,e[122]=ze,e[123]=_e):_e=e[123],_e};function gf(t){return t.installSkills}function hf(t){return t.isInstalling}function ff(t){return t.projects}function xf(t){return t.activeProjectId}function bf(t){return s.jsx(mt,{value:t.id,children:t.label||t.path},t.id)}const vf=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,yf=t=>{const e=t.trim();return vf.test(e)?`https://github.com/${e}`:null},jf=t=>{const e=yf(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Ki=null;const wf=t=>{const e=yo();return(!Ki||Ki.locale!==e)&&(Ki={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Ki.formatter.format(t)},kf=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 r=Math.floor(n/60);if(r<24)return{key:"common.relative.hoursAgoShort",count:r};const i=Math.floor(r/24);if(i<7)return{key:"common.relative.daysAgoShort",count:i};const l=Math.floor(i/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(i/365)}},Nf=t=>{const e=at.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:d}=t,c=a.stars??null;let h,p,f,m,u,v,w,b,k,g;if(e[0]!==n||e[1]!==r||e[2]!==l||e[3]!==i||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==d){const j=a.repoUpdatedAt?kf(a.repoUpdatedAt):null;b="button",k=l,g=n;const T=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==T?(p=Ie("oc-surface-elevated w-full min-h-24 text-left rounded-lg border bg-surface-elevated p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",T),e[19]=T,e[20]=p):p=e[20],u="min-w-0 flex-1 block";let x;e[21]!==a.label?(x=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=x):x=e[22];let A;e[23]!==r||e[24]!==i||e[25]!==d?(A=r?s.jsx(z,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=r,e[24]=i,e[25]=d,e[26]=A):A=e[26],e[27]!==x||e[28]!==A?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,A]}),e[27]=x,e[28]=A,e[29]=v):v=e[29],e[30]!==a.source?(w=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]=w):w=e[31],h="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==d?(f=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:d("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(z,{name:"star",className:"h-3 w-3"}),wf(c)]}),e[32]=c,e[33]=d,e[34]=f):f=e[34],m=j&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:j.key==="common.relative.justNow"?d(j.key):d("settings.skills.catalog.page.source.updated",{time:d(j.key,{count:j.count})})}),e[0]=n,e[1]=r,e[2]=l,e[3]=i,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=d,e[9]=h,e[10]=p,e[11]=f,e[12]=m,e[13]=u,e[14]=v,e[15]=w,e[16]=b,e[17]=k,e[18]=g}else h=e[9],p=e[10],f=e[11],m=e[12],u=e[13],v=e[14],w=e[15],b=e[16],k=e[17],g=e[18];let I;e[35]!==h||e[36]!==f||e[37]!==m?(I=s.jsxs("span",{className:h,children:[f,m]}),e[35]=h,e[36]=f,e[37]=m,e[38]=I):I=e[38];let C;e[39]!==I||e[40]!==u||e[41]!==v||e[42]!==w?(C=s.jsxs("span",{className:u,children:[v,w,I]}),e[39]=I,e[40]=u,e[41]=v,e[42]=w,e[43]=C):C=e[43];let P;return e[44]!==p||e[45]!==C||e[46]!==b||e[47]!==k||e[48]!==g?(P=s.jsx("button",{type:b,onClick:k,"aria-pressed":g,className:p,children:C}),e[44]=p,e[45]=C,e[46]=b,e[47]=k,e[48]=g,e[49]=P):P=e[49],P},Sf=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=Ze(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:d,loadCatalog:c,loadSource:h,isLoadingCatalog:p,isLoadingSource:f,loadedSourceIds:m,lastCatalogError:u}=On($s(K=>({sources:K.sources,itemsBySource:K.itemsBySource,selectedSourceId:K.selectedSourceId,setSelectedSource:K.setSelectedSource,loadCatalog:K.loadCatalog,loadSource:K.loadSource,isLoadingCatalog:K.isLoadingCatalog,isLoadingSource:K.isLoadingSource,loadedSourceIds:K.loadedSourceIds,lastCatalogError:K.lastCatalogError}))),[v,w]=o.useState(""),[b,k]=o.useState(!1),[g,I]=o.useState(!1),[C,P]=o.useState(null),[j,T]=o.useState(!1),[x,A]=o.useState(!1),M=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const K=r.filter(Q=>!m[Q.id]);if(K.length===0)return;let W=!1;return(async()=>{for(const Q of K){if(W)return;await h(Q.id)}})(),()=>{W=!0}},[r,m,h]),o.useEffect(()=>{!l||m[l]||h(l)},[l,m,h]),o.useEffect(()=>{const K=W=>{(W.metaKey||W.ctrlKey)&&W.key.toLowerCase()==="k"&&(W.preventDefault(),M.current?.focus())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[]);const S=v.trim().length>0,D=o.useMemo(()=>S?gi(r.flatMap(K=>i[K.id]||[]),v,K=>[K.skillName,K.frontmatterName,K.description]):l?i[l]||[]:[],[r,i,l,v,S]),O=o.useMemo(()=>r.find(K=>K.id===l)||null,[r,l]),F=!!(l&&l.startsWith("custom:")),N=async()=>{if(!(!l||!F)){T(!0);try{const K=await An();if(!K)return;const te=(K.skillCatalogs??[]).filter(Q=>Q.id!==l);await ft({skillCatalogs:te}),await c({refresh:!0}),A(!1)}finally{T(!1)}}},R=S?n("settings.skills.catalog.page.list.searchTitle"):O?.label??"",U=!S&&l!==null&&!m[l]&&(f||p);return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{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(So,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:K=>e(K),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(z,{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(We,{ref:M,value:v,onChange:K=>w(K.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:Ie("h-8 pl-8 w-full",v&&"pr-8")}),v&&s.jsx("button",{type:"button",onClick:()=>{w(""),M.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(z,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(qe,{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:[r.map(K=>s.jsx(Nf,{source:K,isActive:K.id===l,isLoading:f&&!m[K.id],skillsCount:m[K.id]?(i[K.id]||[]).length:null,onSelect:()=>d(K.id),t:n},K.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>k(!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(z,{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")})]})]})]})}),u&&s.jsx(qe,{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:u.message})]})}),s.jsxs(qe,{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:R}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:D.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!S?h(l,{refresh:!0}):c({refresh:!0})},disabled:p||f,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(z,{name:"refresh",className:Ie("h-3.5 w-3.5",(p||f)&&"animate-spin")})}),F&&!S&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>A(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),U||f&&D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(z,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):D.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:D.map(K=>{const W=K.installed?.isInstalled,te=K.installed?.scope,Q=jf(K);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:K.skillName}),W&&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:te||n("settings.skills.catalog.page.badge.unknown")})}),!K.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")})]}),K.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:K.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:[Q?s.jsxs("a",{href:Q,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(z,{name:"github",className:"h-3 w-3 shrink-0"}),K.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:K.repoSource}),K.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:K.skillDir})]})]}),K.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:K.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[Q&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(Q,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"})}),W?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:te||""}),children:s.jsx(z,{name:"check",className:"h-4 w-4"})}):s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",disabled:!K.installable,onClick:()=>{P(K),I(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${K.sourceId}:${K.skillDir}`)})})]})]}),s.jsx(uf,{open:b,onOpenChange:k}),s.jsx(pf,{open:g,onOpenChange:I,item:C}),s.jsx(_t,{open:x,onOpenChange:K=>{j||A(K)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ht,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>A(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{N()},disabled:j,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Cf=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Sf,{mode:"external",onModeChange:Df,showModeTabs:!1}),t[0]=e):e=t[0],e},If="SKILL.md",Pf="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",qi=(t,e)=>{const a=_m({description:t}).trimEnd(),n=e.trimStart();return`---
23
23
  ${a}
24
24
  ---${n?`
25
25
 
26
26
  ${n}`:`
27
- `}`},Pf=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),ld=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=Km(e[1]);if(Pf(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Af=(t,e)=>{const a=ld(t);return qi(e,a.instructions)},Tf=()=>{const{t}=Ze(),{currentTheme:e}=fa(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:d,setSkillDraft:c,setSelectedSkill:h}=nn($s(ye=>({selectedSkillName:ye.selectedSkillName,getSkillByName:ye.getSkillByName,getSkillDetail:ye.getSkillDetail,createSkill:ye.createSkill,updateSkill:ye.updateSkill,skillDraft:ye.skillDraft,setSkillDraft:ye.setSkillDraft,setSelectedSkill:ye.setSelectedSkill}))),g=Js(),f=nn(ye=>ho(ye,g)),p=a?n(a,g):null,u=!!(d&&d.name===a&&!p),v=!!(a&&!p&&!d),w=p?.path==="<built-in>";o.useEffect(()=>{v&&h(null)},[v,h]);const[b,k]=o.useState(""),[m,S]=o.useState("user"),[P,I]=o.useState("opencode"),[j,D]=o.useState(""),[x,A]=o.useState(""),[R,C]=o.useState(()=>qi("","")),[E,O]=o.useState("edit"),[F,N]=o.useState([]),[M,U]=o.useState([]),[K,W]=o.useState(!1),[te,Q]=o.useState(!1),[H,_]=o.useState(""),[V,X]=o.useState(""),[$,ee]=o.useState(!1),[L,Y]=o.useState(""),[oe,de]=o.useState(""),[ge,ce]=o.useState(null),[Se,ie]=o.useState(!1),[be,ae]=o.useState(""),[me,je]=o.useState(null),[De,ue]=o.useState(!1),$e=ge?oe!==be:L.trim()!=="",Ge=o.useCallback(ye=>{switch(ye){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]),xe=o.useCallback(ye=>{switch(ye){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]),Pe=JSON.stringify([g,a,p?.path,u]),J=o.useRef(null),se=o.useRef({key:Pe,markdown:R});se.current={key:Pe,markdown:R};const he=o.useRef("");o.useEffect(()=>{let ye=!1;const re=(Ne,Ae)=>{if(se.current.key!==Pe)return;const q=qi(Ne,Ae),Le=J.current===Pe&&se.current.markdown!==he.current;J.current=Pe,he.current=q,Le||(D(Ne),A(Ae),C(q))};return(async()=>{if(u&&d){Q(!1);const Ne=d.description||"",Ae=d.instructions||"";k(d.name||""),S(d.scope||"user"),I(d.source==="agents"?"agents":"opencode"),re(Ne,Ae),_(""),X(""),N([]),U(d.pendingFiles||[])}else if(a&&p){Q(J.current!==Pe);try{const Ne=await r(a,g);if(!ye&&se.current.key===Pe&&Ne){const Ae=Ne.sources.md,q=Ae.description||"",Le=Ae.instructions||"";re(q,Le),_(q),X(Le),N(Ae.supportingFiles||[])}}catch(Ne){console.error("Failed to load skill details:",Ne)}finally{ye||Q(!1)}}})(),()=>{ye=!0}},[p,u,a,g,f,d,r,Pe]);const ve=fe(ye=>ye.editorFontSize),Fe=o.useMemo(()=>{const ye=[cl(e,{fontSize:ve})],re=$o(Cf);return re&&ye.push(re),ye.push(ul.lineWrapping),ye},[e,ve]),Ke=o.useMemo(()=>{const ye=L.trim()||"supporting-file.md",re=Vd(ye),Te=!!re&&re!=="markdown",Ne=[cl(e,Te?{syntaxColors:!1,fontSize:ve}:{fontSize:ve})],Ae=$o(ye);return Ae&&Ne.push(Ae),Te&&re&&Ne.push(_m({language:re,themeName:e.metadata.id,theme:zm(e)})),Ne.push(ul.lineWrapping),Ne},[e,L,ve]),Be=o.useCallback(ye=>{D(ye),C(re=>Af(re,ye))},[]),ze=o.useCallback(ye=>{C(ye);const re=ld(ye);D(re.description??""),A(re.instructions)},[]),_e=ye=>ye?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ye)||ye.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),Me=o.useCallback(async()=>{const ye=a?.trim();return u||w||!ye||j===H&&x===V?Os:j.trim()?await l(ye,{name:ye,description:j.trim(),instructions:x.trim()||void 0,targetPath:p?.path},g)?(se.current.key===Pe&&(he.current=qi(j,x),_(j),X(x)),In):hs(t("settings.skills.page.toast.updateSkillFailed")):hs(t("settings.skills.page.toast.descriptionRequired"))},[j,x,u,w,H,V,p?.path,a,g,Pe,t,l]),tt=Ja(Me),pt=async()=>{const ye=b.trim().replace(/\s+/g,"-").toLowerCase(),re=_e(ye);if(re){B.error(re);return}if(!j.trim()){B.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f.some(Te=>Te.name===ye)){B.error(t("settings.skills.page.toast.skillExists"));return}W(!0);try{const Te={name:ye,description:j.trim(),instructions:x.trim()||void 0,scope:m,source:P,supportingFiles:M.length>0?M:void 0};await i(Te,g)?(c(null),U([]),h(ye),B.success(t("settings.skills.page.toast.skillCreated"))):B.error(t("settings.skills.page.toast.createSkillFailed"))}catch(Te){console.error("Error creating skill:",Te),B.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{W(!1)}},ct=()=>{c(null),h(null)},dt=()=>{ce(null),Y(""),de(""),ae(""),ee(!0)},ht=async ye=>{if(ce(ye),Y(ye),u){const Te=M.find(Ne=>Ne.path===ye)?.content||"";de(Te),ae(Te),ee(!0);return}if(a){ie(!0),ee(!0);try{const{readSupportingFile:re}=nn.getState(),Te=await re(a,ye,g);de(Te||""),ae(Te||"")}catch{B.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),ae("")}finally{ie(!1)}}},Ue=async()=>{if(!L.trim()){B.error(t("settings.skills.page.toast.fileNameRequired"));return}const ye=L.trim(),re=ge!==null;if(u){if(re)U(Ae=>Ae.map(q=>q.path===ge?{path:ye,content:oe}:q)),B.success(t("settings.skills.page.toast.fileUpdated",{path:ye}));else{if(M.some(Ae=>Ae.path===ye)){B.error(t("settings.skills.page.toast.fileExists"));return}U(Ae=>[...Ae,{path:ye,content:oe}]),B.success(t("settings.skills.page.toast.fileAdded",{path:ye}))}ee(!1),ce(null);return}if(!a){B.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Te}=nn.getState();if(await Te(a,ye,oe,g)){B.success(re?t("settings.skills.page.toast.fileUpdated",{path:ye}):t("settings.skills.page.toast.fileCreated",{path:ye})),ee(!1),ce(null);const Ae=await r(a,g);Ae&&N(Ae.sources.md.supportingFiles||[])}else B.error(t(re?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},st=ye=>{if(u){U(re=>re.filter(Te=>Te.path!==ye)),B.success(t("settings.skills.page.toast.fileRemoved",{path:ye}));return}a&&je(ye)},ut=async()=>{if(!me||!a)return;ue(!0);const{deleteSupportingFile:ye}=nn.getState();if(await ye(a,me,g)){B.success(t("settings.skills.page.toast.fileDeleted",{path:me}));const Te=await r(a,g);Te&&N(Te.sources.md.supportingFiles||[]),je(null)}else B.error(t("settings.skills.page.toast.deleteFileFailed"));ue(!1)};return!a&&!d||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(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):te?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(ns,{title:u?t("settings.skills.page.title.newSkill"):a,description:p?t("settings.skills.page.subtitle.skillLocation",{location:Ge(ui(p.scope,p.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:tt.onBlurCapture,children:[s.jsxs(qe,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[u&&s.jsxs(Ct,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(We,{value:b,onChange:ye=>k(ye.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Tt,{value:ui(m,P),onValueChange:ye=>{const re=od(ye);S(re.scope),I(re.source==="agents"?"agents":"opencode")},children:[s.jsxs(Pt,{size:$t,className:"w-fit gap-1.5",children:[m==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),P==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ge(ui(m,P))})]}),s.jsx(At,{align:"start",children:To.map(ye=>s.jsx(mt,{value:ye.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ye.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ge(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:xe(ye.value)})]})},ye.value))})]})]}),s.jsx(Ot,{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:j,onChange:ye=>Be(ye.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:w})})]}),s.jsx(qe,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Um,{currentMode:E==="preview"?"preview":"edit",onToggle:()=>O(ye=>ye==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:Ie("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",If),onKeyDown:ye=>{ye.key==="Enter"&&(ye.metaKey||ye.ctrlKey)&&(ye.preventDefault(),tt.requestSave())},children:E==="preview"?s.jsx(bs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Hd,{content:R,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(dl,{value:R,onChange:ze,readOnly:w,extensions:Fe,className:"h-full",enableSearch:!0})})}),s.jsx(qe,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:dt,disabled:w,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const ye=u?M:F;return ye.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:ye.map(re=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ht(re.path),children:[s.jsx(z,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:re.path}),u&&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")}),!w&&s.jsx(G,{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:Te=>{Te.stopPropagation(),st(re.path)},children:s.jsx(z,{name:"delete-bin",className:"h-3 w-3"})})]},re.path))})})()}),u&&s.jsx(qe,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{onClick:()=>{pt()},disabled:K||!b.trim()||!j.trim(),size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(G,{variant:"ghost",onClick:ct,disabled:K,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(_t,{open:me!==null,onOpenChange:ye=>{!ye&&!De&&je(null)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.description",{path:me??""})})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>je(null),disabled:De,children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:ut,disabled:De,children:t("settings.common.actions.delete")})]})]})}),s.jsx(_t,{open:$,onOpenChange:ye=>{if(ye){ee(!0);return}if(ge!==null&&oe!==be){Ue();return}ee(!1),ce(null)},children:s.jsxs(Ut,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Bt,{className:"flex-shrink-0",children:[s.jsx(Vt,{children:t(ge?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ht,{children:t(ge?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Se?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:Nt,children:t("settings.skills.page.fileDialog.field.filePath")}),!ge&&s.jsx(qt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(We,{value:L,onChange:ye=>Y(ye.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:ge!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Nt} 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(dl,{value:oe,onChange:de,extensions:Ke,className:"h-full",enableSearch:!0})})]})]}),s.jsx(as,{className:"mt-4",children:ge?s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Se,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{ee(!1),ce(null)},children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Se||!$e,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},Al=t=>{const e=at.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(Sf,{}):s.jsx(Tf,{}),e[0]=n,e[1]=r):r=e[1],r};function Ef(){}const Df=t=>{const e=at.c(38),{onItemSelect:a}=t,{t:n}=Ze(),r=rn(Mf),i=fe(Rf),l=fe(Of),{currentTheme:d}=fa();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[0]=c):c=e[0];const h=c,g=Ff;let f,p;e[1]!==r||e[2]!==i||e[3]!==l?(f=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(D=>D.id===i)||l(r[0].id)},p=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=f,e[5]=p):(f=e[4],p=e[5]),o.useEffect(f,p);let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=Ie("border-b px-3","pt-4 pb-3"),e[6]=u):u=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let w;e[9]!==v?(w=s.jsx("h2",{className:`${Pn} mb-3`,children:v}),e[9]=v,e[10]=w):w=e[10];let b;e[11]!==r.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=n,e[13]=b):b=e[13];let k;e[14]!==b?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=k):k=e[15];let m;e[16]!==n?(m=!h&&s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:g,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(z,{name:"add",className:"size-4"})}),e[16]=n,e[17]=m):m=e[17];let S;e[18]!==k||e[19]!==m?(S=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,m]}),e[18]=k,e[19]=m,e[20]=S):S=e[20];let P;e[21]!==S||e[22]!==w?(P=s.jsxs("div",{className:u,children:[w,S]}),e[21]=S,e[22]=w,e[23]=P):P=e[23];let I;if(e[24]!==d||e[25]!==a||e[26]!==r||e[27]!==i||e[28]!==l){let D;e[30]!==d||e[31]!==a||e[32]!==i||e[33]!==l?(D=x=>{const A=x.id===i,R=x.icon?Gd[x.icon]:null,C=x.color?Wd[x.color]??null:null,E=R?s.jsx(z,{name:R,className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:C?{color:C}:void 0}):s.jsx(z,{name:"folder",className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:C?{color:C}:void 0}),O=x.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:x.iconBackground?{backgroundColor:x.iconBackground}:void 0,children:s.jsx(Jd,{project:x,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:E})}):E;return s.jsx(Hi,{title:x.label||x.path,icon:O,selected:A,onSelect:()=>{l(x.id),a?.()}},x.id)},e[30]=d,e[31]=a,e[32]=i,e[33]=l,e[34]=D):D=e[34],I=r.map(D),e[24]=d,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=I}else I=e[29];let j;return e[35]!==P||e[36]!==I?(j=s.jsx(rd,{variant:"background",header:P,children:I}),e[35]=P,e[36]=I,e[37]=j):j=e[37],j};function Mf(t){return t.projects}function Rf(t){return t.settingsProjectsSelectedId}function Of(t){return t.setSettingsProjectsSelectedId}function Ff(){qd.requestDirectoryDialog()}const Lf=()=>{const t=at.c(30),{t:e}=Ze(),a=rn(Kf),n=rn(_f),r=fe(Uf),i=fe(zf);let l;e:{if(!r){l=null;break e}let b;t[0]!==a||t[1]!==r?(b=a.find(k=>k.id===r)??null,t[0]=a,t[1]=r,t[2]=b):b=t[2],l=b}const d=l;let c,h;t[3]!==a||t[4]!==r||t[5]!==i?(c=()=>{if(a.length===0){i(null);return}r&&a.some(b=>b.id===r)||i(a[0].id)},h=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=c,t[7]=h):(c=t[6],h=t[7]),o.useEffect(c,h);let g;t[8]!==d||t[9]!==n?(g=async b=>{d&&n(d.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultAgent:b.defaultAgent??null,defaultModel:b.defaultModel??null,defaultVariant:b.defaultVariant??null})},t[8]=d,t[9]=n,t[10]=g):g=t[10];const f=g;if(!d){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let k;t[13]!==e?(k=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=k):k=t[14];let m;t[15]!==k?(m=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=m):m=t[16];let S;return t[17]!==b||t[18]!==m?(S=s.jsx(ns,{title:b,showSaveStatus:!0,children:m}),t[17]=b,t[18]=m,t[19]=S):S=t[19],S}let p;t[20]!==d.label||t[21]!==e?(p=d.label??e("settings.projects.page.title.default"),t[20]=d.label,t[21]=e,t[22]=p):p=t[22];const u=p;let v;t[23]!==f||t[24]!==d?(v=s.jsx(Am,{project:d,onIdentitySave:f}),t[23]=f,t[24]=d,t[25]=v):v=t[25];let w;return t[26]!==u||t[27]!==d.path||t[28]!==v?(w=s.jsx(ns,{title:u,description:d.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=u,t[27]=d.path,t[28]=v,t[29]=w):w=t[29],w};function Kf(t){return t.projects}function _f(t){return t.updateProjectMeta}function Uf(t){return t.settingsProjectsSelectedId}function zf(t){return t.setSettingsProjectsSelectedId}const $f=Ts({clientToken:Dt().trim().min(1)}),Bf=Ts({error:Fm("Invalid or expired pairing session")}),Vf=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&Bf.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const a=$f.safeParse(e);return a.success?{kind:"success",token:a.data.clientToken}:{kind:"invalid-response"}};function Hf(t){const e=at.c(42),{t:a}=Ze(),[n,r]=et.useState(null),i=et.useRef(null),l=et.useRef(null);let d,c;e[0]!==t?(d=()=>(l.current=t,r(null),()=>{l.current=null;const N=i.current;i.current=null,N?.(null)}),c=[t],e[0]=t,e[1]=d,e[2]=c):(d=e[1],c=e[2]),et.useEffect(d,c);let h;e[3]!==t?(h=(N,M)=>{const U=M===void 0?"settings.common.actions.saveChanges":M;return!t||l.current!==t||i.current?Promise.resolve(null):new Promise(K=>{i.current=K,r({messageKey:N,actionKey:U})})},e[3]=t,e[4]=h):h=e[4];const g=h;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=N=>{const M=i.current;i.current=null,r(null),M?.(N)},e[5]=f):f=e[5];const p=f,u=n!==null;let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=N=>{N||p(!1)},e[6]=v):v=e[6];let w;e[7]!==a?(w=a("settings.remoteInstances.page.title"),e[7]=a,e[8]=w):w=e[8];let b;e[9]!==w?(b=s.jsx(Vt,{children:w}),e[9]=w,e[10]=b):b=e[10];let k;e[11]!==n||e[12]!==a?(k=n?a(n.messageKey):null,e[11]=n,e[12]=a,e[13]=k):k=e[13];let m;e[14]!==k?(m=s.jsx(Ht,{children:k}),e[14]=k,e[15]=m):m=e[15];let S;e[16]!==b||e[17]!==m?(S=s.jsxs(Bt,{children:[b,m]}),e[16]=b,e[17]=m,e[18]=S):S=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P=()=>p(!1),e[19]=P):P=e[19];let I;e[20]!==a?(I=a("settings.common.actions.cancel"),e[20]=a,e[21]=I):I=e[21];let j;e[22]!==I?(j=s.jsx(G,{variant:"outline",autoFocus:!0,onClick:P,children:I}),e[22]=I,e[23]=j):j=e[23];let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=()=>p(!0),e[24]=D):D=e[24];let x;e[25]!==n||e[26]!==a?(x=n?a(n.actionKey):null,e[25]=n,e[26]=a,e[27]=x):x=e[27];let A;e[28]!==x?(A=s.jsx(G,{onClick:D,children:x}),e[28]=x,e[29]=A):A=e[29];let R;e[30]!==j||e[31]!==A?(R=s.jsxs(as,{children:[j,A]}),e[30]=j,e[31]=A,e[32]=R):R=e[32];let C;e[33]!==S||e[34]!==R?(C=s.jsxs(Ut,{children:[S,R]}),e[33]=S,e[34]=R,e[35]=C):C=e[35];let E;e[36]!==C||e[37]!==u?(E=s.jsx(_t,{open:u,onOpenChange:v,children:C}),e[36]=C,e[37]=u,e[38]=E):E=e[38];const O=E;let F;return e[39]!==g||e[40]!==O?(F={confirm:g,dialog:O},e[39]=g,e[40]=O,e[41]=F):F=e[41],F}const Gi=()=>Math.floor(2e4+Math.random()*3e4),qf=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")},Gf=()=>{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"},Tl=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}},El=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"}},Wf=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Eo=t=>!!(t&&Wf.has(t)),Dl=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Eo(t)?"connecting":"idle",Ml=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"}},Jf=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},Rl={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Qf=t=>t==="noRuntime"?Rl.noRuntime:t==="noOpencode"?Rl.noOpencode:null,Ol=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Eo(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Yf=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}`,Zf=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Gi(),remoteHost:"127.0.0.1",remotePort:80}),Xf=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",tn=t=>{const e=at.c(7),{label:a,hint:n}=t;let r;e[0]!==a?(r=s.jsx("span",{children:a}),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==n?(i=s.jsx(qt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=i):i=e[3];let l;return e[4]!==r||e[5]!==i?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Nt}`,children:[r,i]}),e[4]=r,e[5]=i,e[6]=l):l=e[6],l},ex=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"}},Fl=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},tx=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},sx=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],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${n}] [${r}] ${i}`},lo=(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}),nx=t=>t.trim().toLowerCase()==="authorization",zr=t=>{const e={};for(const a of t){const n=a.name.trim(),r=a.value.trim();n&&r&&!nx(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},ax=t=>Object.entries(t||{}).map(([e,a])=>lo(e,a)),cd=()=>{if(typeof window>"u")return null;const e=hi()||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}},Ll=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},ix=async()=>{const t=Ka(hi())||window.location.origin;if(!ls()||!fi()||(await An())?.desktopLanAccessActive!==!0)return t;const a=await $c(),n=cd();return!a||!n?t:`http://${a}:${n}`},_i=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},rx=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.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}},ox=()=>{const{t}=Ze(),e=fe(T=>T.timeFormatPreference),{clientAuth:a}=jo(),n=ls(),r=Is(T=>T.instances),i=Is(T=>T.statusesById),l=Is(T=>T.importCandidates),d=Is(T=>T.isLoading),c=Is(T=>T.isImportsLoading),h=Is(T=>T.isSaving),g=Is(T=>T.error),f=Is(T=>T.load),p=Is(T=>T.loadImports),u=Is(T=>T.refreshStatuses),v=Is(T=>T.upsertInstance),w=Is(T=>T.createFromCommand),b=Is(T=>T.removeInstance),k=Is(T=>T.connect),m=Is(T=>T.disconnect),S=Is(T=>T.retry),P=fe(T=>T.settingsRemoteInstancesSelectedId),I=fe(T=>T.setSettingsRemoteInstancesSelectedId),{confirm:j,dialog:D}=Hf(P),x=o.useMemo(()=>P&&r.find(T=>T.id===P)||null,[r,P]),[A,R]=o.useState(null),[C,E]=o.useState(!1),[O,F]=o.useState(!1),[N,M]=o.useState(null),[U,K]=o.useState([]),[W,te]=o.useState(null),[Q,H]=o.useState(""),[_,V]=o.useState(!1),[X,$]=o.useState({}),[ee,L]=o.useState(!1),[Y,oe]=o.useState(!1),[de,ge]=o.useState(()=>Date.now()),[ce,Se]=o.useState([]),[ie,be]=o.useState({}),[ae,me]=o.useState("local"),[je,De]=o.useState(!1),[ue,$e]=o.useState(!1),[Ge,xe]=o.useState(""),[Pe,J]=o.useState(""),[se,he]=o.useState(""),[ve,Fe]=o.useState([]),[Ke,Be]=o.useState(""),[ze,_e]=o.useState(null),[Me,tt]=o.useState(!1),[pt,ct]=o.useState(!1),[dt,ht]=o.useState(!1),[Ue,st]=o.useState(null),[ut,ye]=o.useState(""),[re,Te]=o.useState(""),[Ne,Ae]=o.useState(""),[q,Le]=o.useState([]),[Qe,lt]=o.useState([]),[ot,bt]=o.useState([]),[wt,jt]=o.useState(!1),[vt,Xe]=o.useState(""),[kt,Re]=o.useState(null),[Ve,Z]=o.useState(null),[pe,Oe]=o.useState(null),[Ee,Ye]=o.useState(null),[ne,we]=o.useState(!1),[nt,Rt]=o.useState(!1),[Jt,Ce]=o.useState("configure"),[He,yt]=o.useState(!1),[It,Qt]=o.useState("relay"),[Xt,ts]=o.useState(!0),[es,Fs]=o.useState(null),Qs=o.useMemo(()=>Qe.filter(T=>!!T.revokedAt).length,[Qe]),[pn,Ls]=o.useState(!1),[Ks,on]=o.useState("saved"),[Ys,Zs]=o.useState(""),[_s,Tn]=o.useState(""),[Mt,Gt]=o.useState(""),[Kt,Et]=o.useState(!1);o.useEffect(()=>{f(),p()},[f,p]);const is=o.useCallback(async()=>{De(!0),_e(null);try{const T=await Zo();Se(T.hosts||[]),me(T.defaultHostId||"local")}catch(T){_e(T instanceof Error?T.message:String(T))}finally{De(!1)}},[]);o.useEffect(()=>{is()},[is]);const ss=o.useCallback(async(T,le=ae)=>{$e(!0),_e(null);try{return await Xo({hosts:T,defaultHostId:le,initialHostChoiceCompleted:!0}),Se(T),me(le),!0}catch(Je){return _e(Je instanceof Error?Je.message:String(Je)),!1}finally{$e(!1)}},[ae]),lr=o.useCallback(async()=>{const T=el(Pe);if(!T){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=T.persistedUrl,rt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ge.trim()||Za(le),url:le,apiUrl:le,...se.trim()?{clientToken:se.trim()}:{},...zr(ve)?{requestHeaders:zr(ve)}:{}};await ss([rt,...ce],ae)&&(xe(""),J(""),he(""),Fe([]),tt(!1),T.redeemUrl&&_i(T.redeemUrl))},[ae,ve,ce,Ge,se,Pe,ss,t]),cr=o.useCallback(async()=>{_e(null);const T=Wu(Ke);if(!T){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const le=await Ju().catch(()=>""),Je=JSON.stringify({pairingId:T.pairingId,secret:T.secret,clientLabel:T.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Gf(),...le?{dedupeKey:`desktop:${le}`}:{}}),rt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Je};let Ft=null;const xs=async Zt=>{const Cs=await Vf(Zt);switch(Cs.kind){case"success":return Cs.token;case"rejected":Ft=t("desktopHostSwitcher.error.pairingRejected");break;case"http-error":Ft??=t("desktopHostSwitcher.error.pairingFailed",{status:Cs.status});break;case"invalid-response":Ft??=t("desktopHostSwitcher.error.pairingInvalidResponse");break}return null},Xs=[...T.candidates].sort((Zt,Cs)=>(Zt.type==="relay"?1:0)-(Cs.type==="relay"?1:0));let us=null;for(const Zt of Xs){if(Zt.type==="relay"){const Ta=Qu({relayUrl:Zt.relayUrl,serverId:Zt.serverId,hostEncPubJwk:Zt.hostEncPubJwk,...Zt.grant?{grant:Zt.grant}:{}});try{const Ea=await Ta.fetch("/api/client-auth/pairing/redeem",{...rt,signal:AbortSignal.timeout(15e3)}),Da=await xs(Ea);if(Da){us={kind:"relay",relay:{relayUrl:Zt.relayUrl,serverId:Zt.serverId,hostEncPubJwk:Zt.hostEncPubJwk},token:Da};break}}catch{}finally{Ta.close()}continue}const Cs=Ka(Zt.url);if(Cs)try{const Ta=await fetch(`${Cs}/api/client-auth/pairing/redeem`,{...rt,signal:AbortSignal.timeout(15e3)}),Ea=await xs(Ta);if(Ea){us={kind:"direct",url:Cs,token:Ea};break}}catch{}}if(!us){_e(Ft||t("mobile.connect.error.unreachable"));return}const Us=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Dn=T.candidates.find(Zt=>Zt.type==="relay"),fn=us.kind==="relay"?us.relay:Dn?{relayUrl:Dn.relayUrl,serverId:Dn.serverId,hostEncPubJwk:Dn.hostEncPubJwk}:void 0,Pa=T.candidates.filter(Zt=>Zt.type!=="relay").map(Zt=>Ka(Zt.url)).find(Zt=>!!Zt),Aa=us.kind==="direct"?us.url:Pa,{token:Lt}=us,Yt=Aa||(fn?Yu(fn.serverId):null);if(!Yt){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const xn={url:Yt,apiUrl:Aa||void 0,clientToken:Lt,...fn?{relay:fn}:{}},dn=ce.find(Zt=>fn?Zt.relay?.serverId===fn.serverId:!Zt.relay&&Ka(Zt.apiUrl||Zt.url)===Yt);if(dn){const Zt=ce.map(Cs=>Cs.id===dn.id?{...Cs,label:T.label||Cs.label,...xn}:Cs);if(!await ss(Zt,ae))return}else if(!await ss([{id:Us(),label:T.label||Za(Yt),...xn},...ce],ae))return;Be(""),_e(null),ct(!1)},[Ke,ae,ce,ss,t]),dr=o.useCallback(async T=>{const le=ce.filter(rt=>rt.id!==T);await ss(le,ae===T?"local":ae)&&Ue===T&&st(null)},[ae,Ue,ce,ss]),ur=o.useCallback(T=>{st(T.id),ye(T.label),Te(T.apiUrl||T.url),Ae(T.clientToken||""),Le(ax(T.requestHeaders)),_e(null)},[]),vi=o.useCallback(async()=>{if(!Ue)return;const T=el(re);if(!T){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=T.persistedUrl,Je=ce.map(rt=>rt.id===Ue?{...rt,label:ut.trim()||Za(le),url:le,apiUrl:le,clientToken:Ne.trim()||void 0,requestHeaders:zr(q)}:rt);await ss(Je,ae)&&(st(null),T.redeemUrl&&_i(T.redeemUrl))},[ae,q,ut,Ne,re,Ue,ce,ss,t]),mr=o.useCallback(async()=>{const T=_s.trim();if(!T){B.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const le=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await w(le,T,Mt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(le),Ls(!1),Tn(""),Gt(""),B.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Je){B.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Je instanceof Error?Je.message:String(Je)})}},[w,I,_s,Mt,t]),yi=o.useCallback(()=>{Zs(""),on(l.length>0?"saved":"manual"),Ls(!0)},[l.length]),pr=o.useCallback(async T=>{await ss(ce,T)},[ce,ss]);o.useEffect(()=>{if(!n||ce.length===0)return;let T=!1;return Promise.all(ce.map(async le=>{const Je=()=>nm(le.relay,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(le.relay&&!le.apiUrl)return[le.id,await Je()];const rt=Ka(Zu(le));if(!rt)return[le.id,le.relay?await Je():{status:"unreachable",latencyMs:0}];const Ft=await Xu(rt,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ft.status==="unreachable"&&le.relay){const xs=await Je();if(xs.status==="ok")return[le.id,xs]}return[le.id,Ft]})).then(le=>{T||be(Object.fromEntries(le))}),()=>{T=!0}},[ce,n]);const Bs=o.useCallback(async T=>{if(a){T?.silent||jt(!0),T?.silent||Re(null);try{const[le,Je]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);lt(le),Je&&bt(Je)}catch(le){T?.silent||Re(le instanceof Error?le.message:String(le))}finally{T?.silent||jt(!1)}}},[a]),Qa=o.useRef(!1);o.useEffect(()=>{if(!(!nt||Jt!=="result"||!pe)){if(ot.some(T=>T.id===pe)){Qa.current=!0;return}Qa.current&&(Oe(null),Rt(!1),Qe.some(T=>T.pairingId===pe)&&B.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[nt,Jt,pe,ot,Qe,t]);const ji=o.useCallback(async T=>{if(a)try{await a.cancelPairing(T),bt(le=>le.filter(Je=>Je.id!==T)),await Bs({silent:!0})}catch(le){Re(le instanceof Error?le.message:String(le))}},[a,Bs]);o.useEffect(()=>{if(!a)return;Bs();const T=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Bs({silent:!0})},5e3);return()=>window.clearInterval(T)},[a,Bs]);const wi=o.useCallback(async()=>{if(a?.getPairingTransports)try{const rt=await a.getPairingTransports();return{localUrl:rt.local,lanUrl:rt.lan,relayAvailable:rt.relayAvailable}}catch{}const T=cd(),le=T?`http://127.0.0.1:${T}`:Ll(window.location.origin)?window.location.origin:null;let Je=null;try{const rt=Ka(await ix());Je=rt&&!Ll(rt)?rt:null}catch{}return{localUrl:le,lanUrl:Je,relayAvailable:!0}},[a]),gr=o.useCallback(async()=>{Re(null),Z(null),Ye(null),we(!1),Oe(null),Ce("configure"),ts(!0),Rt(!0);const T=await wi();Fs(T),Qt(T.relayAvailable?"relay":T.lanUrl?"lan":"local")},[wi]),hr=o.useCallback(async()=>{if(!(!a?.createPairingSession||!es)){Re(null),yt(!0);try{const T=vt.trim()||void 0;let le,Je,rt=!0;It==="local"?(le=es.localUrl??void 0,Je=!1):It==="lan"?(le=es.lanUrl??void 0,Je=Xt):Xt&&es.lanUrl?(le=es.lanUrl,Je=!0):(rt=!1,Je=!0);const{pairing:Ft,server:xs}=await a.createPairingSession({label:T,allowedClientKinds:["mobile","desktop"],serverUrl:le,includeRelay:Je,includeDirect:rt}),Xs=em({pairingId:Ft.id,secret:Ft.secret,label:xs.label,fingerprint:Ft.fingerprint??void 0,expiresAt:Ft.expiresAt,candidates:xs.candidates}),us=tm(Xs);Z(us),Ye(await Wc.toDataURL(us,{width:1024,margin:2,errorCorrectionLevel:"L"})),we(!1),Qa.current=!1,Oe(Ft.id),Ce("result"),await Bs({silent:!0})}catch(T){Re(T instanceof Error?T.message:String(T))}finally{yt(!1)}}},[a,es,It,Xt,vt,Bs]),ki=o.useCallback(()=>{Ve&&za(Ve).then(T=>{T.ok&&(we(!0),window.setTimeout(()=>we(!1),2e3))})},[Ve]),fr=o.useCallback(async T=>{if(!a)return;const le=T.clientKind==="desktop-local";Re(null);try{if(await a.revokeClient(T.id),le&&ls()){const Je=await Zo();await Xo({hosts:Je.hosts,defaultHostId:Je.defaultHostId,initialHostChoiceCompleted:Je.initialHostChoiceCompleted,localClientToken:null}),lt(rt=>rt.map(Ft=>Ft.id===T.id?{...Ft,revokedAt:new Date().toISOString()}:Ft)),sm({apiBaseUrl:hi(),clientToken:null,runtimeKey:"local"});return}await Bs()}catch(Je){Re(Je instanceof Error?Je.message:String(Je))}},[a,Bs]),xr=o.useCallback(async()=>{if(a){Re(null);try{await a.purgeRevokedClients(),await Bs()}catch(T){Re(T instanceof Error?T.message:String(T))}}},[a,Bs]);o.useEffect(()=>{R(x)},[x]),o.useEffect(()=>{Et(!1)},[P]),o.useEffect(()=>{if(!P)return;const T=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||u()},2e3);return()=>{window.clearInterval(T)}},[u,P]),o.useEffect(()=>{let T=null,le=Date.now();const Je=()=>{const Ft=Date.now();Ft-le>=1e3&&(ge(Ft),le=Ft),T=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(T=requestAnimationFrame(Je));const rt=()=>{document.visibilityState==="visible"&&T===null?T=requestAnimationFrame(Je):document.visibilityState!=="visible"&&T!==null&&(cancelAnimationFrame(T),T=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),T!==null&&cancelAnimationFrame(T)}},[]);const js=P?i[P]:null,ln=js?.phase,ba=ln==="ready",En=ln==="degraded",$n=Eo(ln),cn=ba||($n||En),br=js?Math.max(0,de-js.updatedAtMs):0,va=En&&br>12e3,ya=Dl(ln),Yn=ya==="error"?Jf(js?.detail):null,Ya=Qf(Yn),vr=o.useMemo(()=>!A||!x?!1:JSON.stringify(A)!==JSON.stringify(x),[A,x]),ds=o.useCallback(T=>{R(le=>le&&T(le))},[]),yr=o.useCallback(async()=>{if(!A)return;const T=rx(A);if(!T.sshCommand.trim()){B.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(T.remoteOpenchamber.mode==="external"&&!T.remoteOpenchamber.preferredPort){B.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Et(!0);return}if(T.remoteOpenchamber.mode==="managed"&&T.remoteOpenchamber.bindHost==="0.0.0.0"&&!T.auth.openchamberPassword?.value?.trim()){B.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Et(!0),window.setTimeout(()=>ka.current?.focus(),0);return}if(!(T.localForward.bindHost==="0.0.0.0"&&!await j("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(T.auth.sshPassword?.enabled&&T.auth.sshPassword.value?.trim()&&T.auth.sshPassword.store!=="settings"){const le=await j("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext");if(le===null)return;T.auth.sshPassword.store=le?"settings":"never",le||(T.auth.sshPassword.value=void 0)}if(T.auth.openchamberPassword?.enabled&&T.auth.openchamberPassword.value?.trim()&&T.auth.openchamberPassword.store!=="settings"){const le=await j("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext");if(le===null)return;T.auth.openchamberPassword.store=le?"settings":"never",le||(T.auth.openchamberPassword.value=void 0)}try{await v(T),B.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(le){B.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:le instanceof Error?le.message:String(le)})}}},[j,A,t,v]),ja=o.useCallback(async(T,le)=>{const Je=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await w(Je,`ssh ${le}`,T),I(Je),B.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(rt){return B.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:rt instanceof Error?rt.message:String(rt)}),!1}},[w,I,t]),wa=o.useCallback(()=>{_||(te(null),H(""))},[_]),jr=o.useCallback((T,le)=>{if(Ls(!1),le){te(T),H(Xf(T));return}ja(T,T)},[ja]),Ni=o.useMemo(()=>gi(l,Ys,T=>[T.host,T.sshCommand]),[l,Ys]),wr=o.useCallback(T=>{const le=(T||"").trim();if(!le){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}_i(le)},[t]),Bn=o.useCallback(async()=>{const T=W,le=Q.trim();if(T){if(!le){B.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await ja(T,le)&&(te(null),H(""))}finally{V(!1)}}},[ja,Q,W,t]),gn=o.useCallback(async()=>{if(x)try{await k(x.id);return}catch(T){if(!qf(T)||!await j("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw T;const Je={...x,localForward:{...x.localForward,preferredLocalPort:Gi()}};await v(Je),await k(Je.id),B.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[j,k,x,t,v]),ka=o.useRef(null),Si=o.useRef(null),Na=o.useCallback(async T=>{if(x){if(T==="localPort"){const le={...x,localForward:{...x.localForward,preferredLocalPort:Gi()}};try{await v(le),await k(le.id),B.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Je){B.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Je instanceof Error?Je.message:String(Je)})}return}Et(!0),window.setTimeout(()=>{if(T==="uiPassword"){ka.current?.focus();return}Si.current?.scrollIntoView({block:"center"})},0)}},[k,x,t,v]),Sa=o.useCallback(async T=>(await Qd(T,600)).map(Je=>sx(Je)),[]),kr=o.useCallback(async()=>{if(A){E(!0),F(!0),M(null);try{const T=await Sa(A.id);K(T)}catch(T){K([]),M(T instanceof Error?T.message:String(T))}finally{F(!1)}}},[A,Sa]);o.useEffect(()=>{if(!C||!A)return;let T=!1;const le=async()=>{try{const rt=await Sa(A.id);T||(K(rt),M(null))}catch(rt){T||M(rt instanceof Error?rt.message:String(rt))}};le();const Je=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||le()},1e3);return()=>{T=!0,window.clearInterval(Je)}},[A,C,Sa]);const ke=o.useMemo(()=>U.join(`
28
- `),[U]),Ss=o.useCallback(()=>{if(!ke.trim()){B.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}za(ke).then(T=>{T.ok&&B.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ke,t]),Ca=o.useCallback(async()=>{if(A)try{await Yd(A.id),K([]),B.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(T){B.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:T instanceof Error?T.message:String(T)})}},[A,t]),Ci=o.useCallback(async()=>{if(!js?.localUrl){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const T=js.localUrl.trim();if(!T){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}_i(T)},[js?.localUrl,t]),Ii=o.useCallback(()=>{if(!A)return;if(!cn&&A.remoteOpenchamber.mode==="external"&&!A.remoteOpenchamber.preferredPort){B.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Et(!0);return}if(!cn&&A.remoteOpenchamber.mode==="managed"&&A.remoteOpenchamber.bindHost==="0.0.0.0"&&!A.auth.openchamberPassword?.value?.trim()){B.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Et(!0),window.setTimeout(()=>ka.current?.focus(),0);return}L(!0),(cn?m(A.id):gn()).catch(le=>{const Je=cn?ba?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";B.error(t(Je),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{L(!1)})},[cn,gn,m,A,ba,t]),Pi=o.useCallback(()=>{if(!A||$n)return;oe(!0),(En?m(A.id).then(()=>gn()):S(A.id)).catch(le=>{B.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{oe(!1)})},[gn,m,A,$n,En,S,t]),Ai=t($n?"settings.remoteInstances.page.actions.connecting":En?va?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ti=!ee&&!Y&&(ln==="error"||ln==="idle"||!ln||En&&va)&&!$n,Nr=t(ba?"settings.remoteInstances.sidebar.actions.disconnect":cn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!A)return s.jsxs(ns,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(qe,{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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{gr()},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[Qs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{xr()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,wt&&Qe.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):Qe.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[ot.map(T=>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:T.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),T.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(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ji(T.id)},children:t("settings.common.actions.cancel")})]},`pending-${T.id}`)),Qe.map(T=>{const le=T.clientKind==="desktop-local",Je=T.lastUsedAt?Date.parse(T.lastUsedAt):Number.NaN,rt=!T.revokedAt&&(le||Number.isFinite(Je)&&Date.now()-Je<9e4),Ft=T.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):rt?T.lastTransport==="relay"&&!le?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Je)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Zd(Je,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:Ie("h-2 w-2 shrink-0 rounded-full",T.revokedAt?"bg-muted-foreground/20":rt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:T.label}),Tl(T.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:Tl(T.devicePlatform)}):null,le?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:Ie("typography-micro truncate",rt&&!T.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ft})]})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{fr(T)},disabled:!!T.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},T.id)})]})]}),kt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:kt}):null]}):null,n?s.jsxs(qe,{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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{_e(null),ct(!0)},disabled:ue,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_e(null),tt(!0)},disabled:ue,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:je?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):ce.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):ce.map(T=>{const le=ie[T.id],Je=le?le.status==="ok"?"desktopHostSwitcher.status.connected":le.status==="auth"?"desktopHostSwitcher.status.authRequired":le.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":le.status==="incompatible"?"desktopHostSwitcher.status.incompatible":le.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",rt=le?.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:Ie("h-2 w-2 shrink-0 rounded-full",le?rt?"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:Za(T.label)}),ae===T.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:Ie("typography-micro shrink-0",rt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Je),rt&&typeof le?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(le.latencyMs))}):""]})]}),s.jsx("p",{className:Ie("typography-micro text-muted-foreground truncate",T.apiUrl&&"font-mono"),children:T.relay&&!T.apiUrl?t("mobile.connect.relay.badge"):Za(T.apiUrl||T.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{pr(T.id)},disabled:ue||ae===T.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ae===T.id?s.jsx(z,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"star",className:"h-3.5 w-3.5"})}),T.relay&&!T.apiUrl?null:s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ur(T),disabled:ue,children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{dr(T.id)},disabled:ue,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},T.id)})}),ze&&!pt&&!Me&&!Ue?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ze}):null]}):null,n?s.jsx(_t,{open:Me,onOpenChange:tt,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),lr()},children:[s.jsx(We,{className:"h-8",value:Ge,onChange:T=>xe(T.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ue}),s.jsx(We,{className:"h-8",value:Pe,onChange:T=>J(T.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ue,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(We,{className:"h-8",value:se,onChange:T=>he(T.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ue}),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(Cn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ve.map(T=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:T.name,onChange:le=>Fe(Je=>Je.map(rt=>rt.id===T.id?{...rt,name:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ue}),s.jsx(We,{className:"h-8 font-mono text-xs",value:T.value,onChange:le=>Fe(Je=>Je.map(rt=>rt.id===T.id?{...rt,value:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ue}),s.jsx("button",{type:"button",onClick:()=>Fe(le=>le.filter(Je=>Je.id!==T.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:ue,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},T.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Fe(T=>[...T,lo()]),disabled:ue,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>tt(!1),disabled:ue,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:ue||!Pe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),ze?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null]})]})}):null,n?s.jsx(_t,{open:!!Ue,onOpenChange:T=>{T||st(null)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),vi()},children:[s.jsx(We,{className:"h-8",value:ut,onChange:T=>ye(T.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ue}),s.jsx(We,{className:"h-8",value:re,onChange:T=>Te(T.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ue,autoFocus:!0}),s.jsx(We,{className:"h-8",value:Ne,onChange:T=>Ae(T.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ue}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.headers.description")})]}),q.map(T=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:T.name,onChange:le=>Le(Je=>Je.map(rt=>rt.id===T.id?{...rt,name:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ue}),s.jsx(We,{className:"h-8 font-mono text-xs",value:T.value,onChange:le=>Le(Je=>Je.map(rt=>rt.id===T.id?{...rt,value:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ue}),s.jsx("button",{type:"button",onClick:()=>Le(le=>le.filter(Je=>Je.id!==T.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:ue,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},T.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Le(T=>[...T,lo()]),disabled:ue,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>st(null),disabled:ue,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:ue,children:t("settings.common.actions.saveChanges")})]}),ze?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null]})]})}):null,n?s.jsx(_t,{open:pt,onOpenChange:T=>{dt||ct(T)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":dt,onSubmit:async T=>{if(T.preventDefault(),!(dt||ue)){ht(!0);try{await cr()}catch{_e(t("mobile.connect.error.unreachable"))}finally{ht(!1)}}},children:[s.jsx(We,{className:"h-8",value:Ke,onChange:T=>{Be(T.target.value),_e(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:ue||dt,"aria-describedby":ze?"direct-import-error":void 0,autoFocus:!0}),ze?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ct(!1),disabled:ue||dt,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:ue||dt||!Ke.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(_t,{open:nt,onOpenChange:Rt,children:s.jsxs(Ut,{className:Jt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t(Jt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Ht,{children:t(Jt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),Jt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:T=>{T.preventDefault(),hr()},children:[s.jsx(We,{className:"h-8",value:vt,onChange:T=>Xe(T.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:!!es?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!es?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!es?.localUrl}].map(T=>{const le=It===T.key;return s.jsxs("div",{className:Ie("flex items-start gap-2 py-0.5",T.available?"cursor-pointer":"opacity-45"),onClick:()=>{T.available&&Qt(T.key)},role:"presentation",children:[s.jsx(xo,{checked:le,disabled:!T.available,onChange:()=>Qt(T.key),ariaLabel:T.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:Ie("typography-ui-label font-normal",le?"text-foreground":"text-foreground/70"),children:T.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:T.hint})]})]},T.key)})}),It==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(eo,{checked:Xt,onChange:ts,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,It==="relay"&&es?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(eo,{checked:Xt,onChange:ts,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]}),kt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:kt}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Rt(!1),disabled:He,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:He||!es,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Ee?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Ee,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,Ve?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:Ve}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:ki,children:[s.jsx(z,{name:ne?"check":"file-copy",className:Ie("h-3.5 w-3.5",ne&&"text-[var(--status-success)]")}),t(ne?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(qe,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:r.length}),headerAction:s.jsxs(G,{type:"button",size:"xs",className:"!font-normal",onClick:yi,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):r.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")}):r.map(T=>{const le=i[T.id],Je=T.nickname?.trim()||T.sshParsed?.destination||T.id,rt=le?.phase,Ft=rt==="ready",xs=Dl(rt),Xs=xs==="error"?le?.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 ${Ol(rt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Je})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Ml(xs)),xs==="connecting"?` · ${t(El(rt))}`:"",Ft&&le?.localUrl?` · ${le.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ft?s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>wr(le?.localUrl),children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Ft?m(T.id):k(T.id)).catch(Us=>B.error(t(Ft?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Us instanceof Error?Us.message:String(Us)}))},children:[Ft?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Ft?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>I(T.id),children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(T.id).catch(Us=>B.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Us instanceof Error?Us.message:String(Us)}))},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),Xs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:Xs}):null]},T.id)})}):null,n?s.jsx(_t,{open:pn,onOpenChange:Ls,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Ht,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(mn,{value:Ks,onChange:on,"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")}]}),Ks==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(We,{className:"h-8",value:Ys,onChange:T=>Zs(T.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Ni.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:Ni.map(T=>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:[T.host,T.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:T.sshCommand})]}),s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{jr(T.host,T.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${T.source}:${T.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),mr()},children:[s.jsx(We,{className:"h-8",value:Mt,onChange:T=>Gt(T.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:h}),s.jsx(We,{className:"h-8",value:_s,onChange:T=>Tn(T.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:h,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ls(!1),disabled:h,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:h||!_s.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(_t,{open:!!W,onOpenChange:T=>{T||wa()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),Bn()},children:[s.jsx(We,{value:Q,onChange:T=>H(T.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:wa,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const hn=A.remoteOpenchamber.mode==="managed",Vn=hn&&A.remoteOpenchamber.bindHost==="0.0.0.0",Ia=Vn&&!A.auth.openchamberPassword?.value?.trim(),Sr=A.nickname?.trim()||A.sshParsed?.destination||A.id;return s.jsx(_t,{open:!!A,onOpenChange:T=>{T||I(null)},children:s.jsxs(Ut,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Zr} truncate`,children:Sr}),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 ${Ol(ln)}`}),s.jsx("span",{className:"text-foreground",children:t(Ml(ya))}),ya==="connecting"?s.jsx("span",{children:t(El(ln))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,va?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(qe,{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(G,{type:"button",variant:cn?"outline":"default",size:"xs",className:"!font-normal",onClick:Ii,disabled:ee||Y,children:[cn?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),Nr]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Pi,disabled:!Ti,children:[s.jsx(z,{name:"refresh",className:`h-3.5 w-3.5 ${$n||En&&!va?"animate-spin":""}`}),Ai]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kr()},children:[s.jsx(z,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(G,{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"))&&b(A.id).then(()=>{I(null),B.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(le=>{B.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:le instanceof Error?le.message:String(le)})})},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ya==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),Ya?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(Ya)}):null,Yn&&!Ya?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Na(Yn)},children:t(Yn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Yn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:js.localUrl})]}):null]}),s.jsxs(qe,{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(We,{className:"h-7 md:max-w-xl",value:A.sshCommand,onChange:T=>ds(le=>({...le,sshCommand:T.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(We,{className:"h-7 md:max-w-sm",value:A.nickname||"",onChange:T=>ds(le=>({...le,nickname:T.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(tn,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Tt,{value:A.remoteOpenchamber.mode,onValueChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,mode:T==="external"?"external":"managed"}})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(mt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(kn,{open:Kt,onOpenChange:Et,children:[s.jsxs(Nn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:Ac,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(z,{name:Kt?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Sn,{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(gs,{containerClassName:"w-fit",min:5,max:240,step:1,className:Ie(vs,"tabular-nums"),value:A.connectionTimeoutSec,onValueChange:T=>{ds(le=>({...le,connectionTimeoutSec:Number.isFinite(T)?T:le.connectionTimeoutSec}))}})]}),s.jsxs(qe,{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:Si,children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:A.remoteOpenchamber.preferredPort,onValueChange:T=>{ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,preferredPort:Number.isFinite(T)&&T>0?T:void 0}}))},onClear:()=>{ds(T=>({...T,remoteOpenchamber:{...T.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),hn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Tt,{value:A.remoteOpenchamber.installMethod,onValueChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,installMethod:T==="npm"||T==="bun"?T:"auto"}})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(mt,{value:"bun",children:"bun"}),s.jsx(mt,{value:"npm",children:"npm"})]})]})]}):null,hn?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(tn,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(Ba,{checked:Vn,onCheckedChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,bindHost:T?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),Vn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,hn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(Ba,{checked:A.remoteOpenchamber.keepRunning,onCheckedChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,keepRunning:T}}))})})]}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Tt,{value:A.localForward.bindHost,onValueChange:T=>{T==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ds(le=>({...le,localForward:{...le.localForward,bindHost:T==="localhost"||T==="0.0.0.0"?T:"127.0.0.1"}}))},children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[240px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(mt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(mt,{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(tn,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:A.localForward.preferredLocalPort,onValueChange:T=>{ds(le=>({...le,localForward:{...le.localForward,preferredLocalPort:Number.isFinite(T)&&T>0?T:void 0}}))},onClear:()=>{ds(T=>({...T,localForward:{...T.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ds(T=>({...T,localForward:{...T.localForward,preferredLocalPort:Gi()}})),children:s.jsx(z,{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:`${A.localForward.bindHost}:${A.localForward.preferredLocalPort||"auto"} → ${A.sshParsed?.destination||A.nickname||"remote"}:${A.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(qe,{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(tn,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(We,{className:"h-7 md:max-w-sm",type:"password",value:A.auth.sshPassword?.value||"",onChange:T=>ds(le=>({...le,auth:{...le.auth,sshPassword:{enabled:T.target.value.trim().length>0,value:T.target.value,store:le.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(tn,{label:t(Vn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(hn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(We,{className:Ie("h-7 md:max-w-sm",Ia&&"border-[var(--status-error)]"),type:"password",ref:ka,"aria-invalid":Ia,value:A.auth.openchamberPassword?.value||"",onChange:T=>ds(le=>({...le,auth:{...le.auth,openchamberPassword:{enabled:T.target.value.trim().length>0,value:T.target.value,store:le.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),Ia?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[A.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,A.portForwards.map((T,le)=>{const Je=Lt=>{ds(Yt=>({...Yt,portForwards:Yt.portForwards.map((xn,dn)=>dn===le?Lt(xn):xn)}))},rt=T.type==="remote"?"Local target":"Local listen",Ft=T.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.",xs=T.type==="remote"?"Remote listen":"Remote target",Xs=T.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",us=Fl(T.localHost||"localhost",T.localPort),Us=Fl(T.remoteHost||"localhost",T.remotePort),Dn=T.type==="local"&&typeof T.localPort=="number"&&T.localPort>0,fn=Dn?`http://${tx(T.localHost)}:${T.localPort}`:"",Pa=!!X[T.id],Aa=T.type==="local"?t("settings.remoteInstances.page.forwardType.local"):T.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(kn,{open:Pa,onOpenChange:Lt=>{$(Yt=>({...Yt,[T.id]:Lt}))},className:`${le>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(Nn,{className:"flex items-center gap-2 group",children:[s.jsx(z,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Pa?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Yf(T)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Aa})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ba,{checked:T.enabled,onCheckedChange:Lt=>Je(Yt=>({...Yt,enabled:Lt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(G,{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:()=>ds(Lt=>({...Lt,portForwards:Lt.portForwards.filter(Yt=>Yt.id!==T.id)})),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Sn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(ex(T.type))})]})})}),s.jsxs(Tt,{value:T.type,onValueChange:Lt=>Je(Yt=>({...Yt,type:Lt==="dynamic"||Lt==="remote"?Lt:"local"})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(mt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(mt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:rt,hint:Ft})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:T.localHost||"127.0.0.1",onChange:Lt=>Je(Yt=>({...Yt,localHost:Lt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:T.localPort,onValueChange:Lt=>{Je(Yt=>({...Yt,localPort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{Je(Lt=>({...Lt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),T.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:xs,hint:Xs})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:T.remoteHost||"",onChange:Lt=>Je(Yt=>({...Yt,remoteHost:Lt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:T.remotePort,onValueChange:Lt=>{Je(Yt=>({...Yt,remotePort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{Je(Lt=>({...Lt,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:T.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):T.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Dn?s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(fn).then(Lt=>{Lt||B.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},T.id)}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const T=Zf();ds(le=>({...le,portForwards:[...le.portForwards,T]})),$(le=>({...le,[T.id]:!0}))},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{yr()},disabled:!vr||h,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{za(js.localUrl||"").then(T=>{T.ok&&B.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ci()},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,g?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:g}):null]})}),D,s.jsx(_t,{open:C,onOpenChange:E,children:s.jsxs(Ut,{className:"sm:max-w-2xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ht,{children:A?.nickname?.trim()||A?.sshParsed?.destination||A?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ss,disabled:O||!ke.trim(),children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ca()},disabled:O,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):N?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:N}):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:U.length>0?U.join(`
29
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(_t,{open:!!W,onOpenChange:T=>{T||wa()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),Bn()},children:[s.jsx(We,{value:Q,onChange:T=>H(T.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:wa,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.common.actions.create")})]})]})]})})]})})},lx="__add_provider__",cx=()=>{const t=Gs.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},dx=({onItemSelect:t})=>{const{t:e}=Ze(),a=Js(),n=it(v=>Tc(v,a)),r=it(v=>v.selectedProviderId),i=it(v=>v.setSelectedProvider),l=rn(v=>v.activeProjectId),[d,c]=o.useState({}),h=o.useMemo(()=>a||cx(),[l,a]),g=it(v=>v.loadProviders);o.useEffect(()=>{a&&g({directory:a,source:"settings:providers"})},[g,a]),o.useEffect(()=>{if(n.length===0){c({});return}let v=!1;return(async()=>{const b=n.map(async k=>{try{const m=h?`?directory=${encodeURIComponent(h)}`:"",S=await St(`/api/provider/${encodeURIComponent(k.id)}/source${m}`,{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const P=await S.json().catch(()=>null),I=P?.sources??P?.data?.sources;if(!I||v)return;c(j=>({...j,[k.id]:I}))}catch{}});await Promise.all(b)})(),()=>{v=!0}},[h,n]);const f="bg-background",p=o.useMemo(()=>n.filter(v=>!!d[v.id]?.project?.exists),[n,d]),u=o.useMemo(()=>n.filter(v=>!d[v.id]?.project?.exists),[n,d]);return s.jsxs("div",{className:Ie("flex h-full flex-col",f),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Pn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(xi,{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(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(lx),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"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:[u.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")}),u.map(v=>s.jsx(Kl,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Ie("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),p.map(v=>s.jsx(Kl,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]})]})})]})},Kl=t=>{const e=at.c(17),{provider:a,selectedProviderId:n,onSelect:r}=t,i=Array.isArray(a.models)?a.models.length:0,l=a.id===n,d=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==c?(h=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=h):h=e[1];let g;e[2]!==a.id?(g=s.jsx(na,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=g):g=e[3];const f=a.name||a.id;let p;e[4]!==f?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:f}),e[4]=f,e[5]=p):p=e[5];let u;e[6]!==i?(u=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=u):u=e[7];let v;e[8]!==r||e[9]!==g||e[10]!==p||e[11]!==u?(v=s.jsxs("button",{type:"button",onClick:r,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-ring",tabIndex:0,children:[g,p,u]}),e[8]=r,e[9]=g,e[10]=p,e[11]=u,e[12]=v):v=e[12];let w;return e[13]!==a.id||e[14]!==h||e[15]!==v?(w=s.jsx("div",{className:h,children:v},d),e[13]=a.id,e[14]=h,e[15]=v,e[16]=w):w=e[16],w},ux=t=>t,mx=(t,e,a)=>t&&!e&&!a,ta=(t,e)=>t.find(a=>a.id===e),li=t=>t==="opencode-go"?"opencode":t,_l=(t,e)=>{const a=ta(t,e)?.connections,n=li(e);if(n===e)return a;const r=ta(t,n)?.connections;if(!(!a&&!r))return[...a??[],...r??[]]},Ul=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),px=t=>(t?.methods??[]).find(e=>e.type==="key"),zl=t=>t===void 0||px(t)!==void 0,gx=t=>(t?.connections??[]).filter(e=>e.type==="credential"),$l=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,hx=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),fx=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Do={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},ea="__custom_provider__",xx=/^[a-z0-9][a-z0-9-_]*$/,dd=/^https?:\/\//,bx=/^\{env:([^}]+)\}$/,er=t=>{if(!t)return;if(typeof t.package=="string"&&t.package)return t.package;const e=t.api?.npm;return typeof e=="string"&&e?`aisdk:${e}`:void 0},ud=t=>t.settings&&typeof t.settings=="object"?t.settings:t.options&&typeof t.options=="object"?t.options:{};let vx=0;const tr=()=>`row-${vx++}`,Mo=()=>({row:tr(),id:"",name:"",variants:""});function yx(t,e){switch(t){case"openai-chat":return{settings:{reasoningEffort:e}};case"openai-responses":return{settings:{reasoningEffort:e,reasoningSummary:"auto",include:["reasoning.encrypted_content"]}};case"anthropic-messages":return{settings:{thinking:{type:"adaptive",display:"summarized"},effort:e}}}}function jx(t){const e=t.split(/[,\s]+/).map(a=>a.trim()).filter(Boolean);return e.filter((a,n)=>e.indexOf(a)===n)}function wx(t){return Object.fromEntries((t??[]).map(({id:e,...a})=>[e,a]))}const Ro=()=>({row:tr(),key:"",value:""}),kx=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Mo()],headers:[Ro()]}),md={"@opencode/ai/providers/openai-compatible":"openai-chat","@opencode/ai/providers/openai":"openai-responses","@opencode/ai/providers/anthropic":"anthropic-messages"};function Nx(t){const e=t?md[t]:void 0;if(e)return e;switch(t){case"aisdk:@ai-sdk/openai":case"@ai-sdk/openai":return"openai-responses";case"aisdk:@ai-sdk/anthropic":case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Sx(t){const e=t.trim();if(!e)return{};const n=e.match(bx)?.[1]?.trim();return n?{env:n}:{key:e}}function Cx(t){const e=ud(t),a=typeof e.baseURL=="string"?e.baseURL.trim():"";if(a&&dd.test(a))return!0;const n=new Set([...Object.values(Do),...Object.keys(md)]);return n.has(er(t)??"")?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>!i||typeof i!="object"?!1:n.has(er(i)??""))}function Bl(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&Cx(t):!1}function Vl(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function Hl(t){const e=ud(t),a=typeof e.baseURL=="string"?e.baseURL:"",n=t.headers&&typeof t.headers=="object"?t.headers:e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},r=Object.entries(n).filter(h=>typeof h[0]=="string"&&typeof h[1]=="string").map(([h,g])=>({row:tr(),key:h,value:g})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([h,g])=>{const f=g&&typeof g=="object"?g:{};return{id:h,modelID:typeof f.modelID=="string"?f.modelID:h,name:typeof f.name=="string"?f.name:h,package:typeof f.package=="string"?f.package:void 0,variants:pd.safeParse(f.variants).data}}):[],l=i.length>0?i.map(h=>{const g=typeof h?.modelID=="string"&&h.modelID?h.modelID:typeof h?.id=="string"?h.id:"",f=wx(h?.variants);return{row:tr(),id:g,name:typeof h?.name=="string"?h.name:g,variants:Object.keys(f).join(", "),savedVariants:f}}):[Mo()],d=Array.isArray(t.env)?t.env.find(h=>typeof h=="string"&&h.trim().length>0)?.trim():void 0,c=i.map(h=>er(h)).find(h=>!!h);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:Nx(er(t)??c),baseURL:a,apiKey:d?`{env:${d}}`:"",models:l,headers:r.length>0?r:[Ro()]}}const pd=xa(Ts({id:Dt(),settings:Kn(Dt(),so()).optional(),headers:Kn(Dt(),Dt()).optional(),body:Kn(Dt(),so()).optional()})),Ix=Ts({name:Dt().optional(),package:Dt().optional(),env:xa(Dt()).optional(),settings:Kn(Dt(),so()).optional(),headers:Kn(Dt(),Dt()).optional(),models:Kn(Dt(),Ts({modelID:Dt().optional(),name:Dt().optional(),package:Dt().optional(),variants:pd.optional()})).optional()});function Px(t,e){const a=Array.isArray(t.models)?t.models.map(i=>({...i,variants:void 0})):t.models,n=Hl({...t,models:a});if(!e)return{...n,models:n.models.map(i=>({...i,savedVariants:void 0}))};const r=Hl({...e,id:t.id});return{providerID:t.id,name:e.name?.trim()?r.name:n.name,protocol:e.package?r.protocol:n.protocol,baseURL:r.baseURL||n.baseURL,apiKey:r.apiKey,models:e.models&&Object.keys(e.models).length>0?r.models:n.models.map(i=>({...i,savedVariants:void 0})),headers:r.headers}}function Ax(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:r,key:i}=Sx(t.form.apiKey),l=t.disabledProviders??[],d=t.editingProviderID?.trim(),c=e?xx.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),h=a?void 0:t.t("settings.providers.page.custom.error.name.required"),g=n?dd.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(r||i||d&&t.allowExistingAuth&&d===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),u=l.includes(e),w=c||!!(d&&d===e)?void 0:t.existingProviderIDs.has(e)&&!u?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(R=>{const C=R.id.trim(),E=C?b.has(C)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(C):t.t("settings.providers.page.custom.error.required"),O=R.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:E,name:O}}),m=k.every(R=>!R.id&&!R.name),S=Object.fromEntries(t.form.models.map(R=>{const C=R.id.trim(),E={modelID:C,name:R.name.trim()},O=jx(R.variants);return(O.length>0||R.savedVariants!==void 0)&&(E.variants=O.map(F=>({id:F,...R.savedVariants?.[F]??yx(t.form.protocol,F)}))),[C,E]})),P=new Set,I=t.form.headers.map(R=>{const C=R.key.trim(),E=R.value.trim();if(!C&&!E)return{};const O=C?P.has(C.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void P.add(C.toLowerCase()):t.t("settings.providers.page.custom.error.required"),F=E?void 0:t.t("settings.providers.page.custom.error.required");return{key:O,value:F}}),j=I.every(R=>!R.key&&!R.value),D=Object.fromEntries(t.form.headers.map(R=>({key:R.key.trim(),value:R.value.trim()})).filter(R=>R.key&&R.value).map(R=>[R.key,R.value])),x={providerID:c??w,name:h,baseURL:g,apiKey:p};return!c&&!w&&!h&&!g&&!p&&m&&j?{err:x,models:k,headers:I,result:{providerID:e,name:a,apiKey:i,config:Tx({protocol:t.form.protocol,name:a,env:r,baseURL:n,headers:D,models:S})}}:{err:x,models:k,headers:I}}function Tx(t){const e={package:Do[t.protocol],name:t.name,settings:{baseURL:t.baseURL},models:t.models};return t.env&&(e.env=[t.env]),Object.keys(t.headers).length>0&&(e.headers=t.headers),e}function Ex(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function Dx(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const ql=t=>{const e=at.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:d,authFailureHint:c,onSubmit:h,onCancel:g,onDisconnect:f}=t;let p;e[0]!==n?(p=n===void 0?[]:n,e[0]=n,e[1]=p):p=e[1];const u=p,v=r===void 0?!1:r,w=i===void 0?"create":i,b=d===void 0?!1:d,k=c===void 0?null:c,{t:m}=Ze(),S=w==="edit";let P;e[2]!==l?(P=()=>l??kx(),e[2]=l,e[3]=P):P=e[3];const[I,j]=o.useState(P);let D;e[4]===Symbol.for("react.memo_cache_sentinel")?(D={},e[4]=D):D=e[4];const[x,A]=o.useState(D);let R;e[5]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[5]=R):R=e[5];const[C,E]=o.useState(R);let O;e[6]===Symbol.for("react.memo_cache_sentinel")?(O=[],e[6]=O):O=e[6];const[F,N]=o.useState(O),M=o.useRef(null);let U,K;e[7]!==l||e[8]!==S?(U=()=>{l&&(S&&M.current===l.providerID||(M.current=S?l.providerID:null,j(l),A({}),E([]),N([])))},K=[l,S],e[7]=l,e[8]=S,e[9]=U,e[10]=K):(U=e[9],K=e[10]),o.useEffect(U,K);let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=(Mt,Gt)=>{j(Kt=>({...Kt,[Mt]:Gt})),A(Kt=>({...Kt,[Mt]:void 0}))},e[11]=W):W=e[11];const te=W;let Q;e[12]===Symbol.for("react.memo_cache_sentinel")?(Q=(Mt,Gt,Kt)=>{j(Et=>({...Et,models:Et.models.map((is,ss)=>ss===Mt?{...is,[Gt]:Kt}:is)})),E(Et=>{const is=[...Et];return is[Mt]={...is[Mt]??{},[Gt]:void 0},is})},e[12]=Q):Q=e[12];const H=Q;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(Mt,Gt,Kt)=>{j(Et=>({...Et,headers:Et.headers.map((is,ss)=>ss===Mt?{...is,[Gt]:Kt}:is)})),N(Et=>{const is=[...Et];return is[Mt]={...is[Mt]??{},[Gt]:void 0},is})},e[13]=_):_=e[13];const V=_;let X;e[14]!==b||e[15]!==v||e[16]!==u||e[17]!==a||e[18]!==I||e[19]!==S||e[20]!==h||e[21]!==m?(X=async Mt=>{if(Mt.preventDefault(),v)return;const Gt=Ax({form:I,t:((Kt,Et)=>m(Kt,Et)),existingProviderIDs:a,disabledProviders:u,editingProviderID:S?I.providerID:void 0,allowExistingAuth:S&&b});A(Gt.err),E(Gt.models),N(Gt.headers),Gt.result&&await h(Gt.result)},e[14]=b,e[15]=v,e[16]=u,e[17]=a,e[18]=I,e[19]=S,e[20]=h,e[21]=m,e[22]=X):X=e[22];const $=X;let ee;e[23]!==S||e[24]!==m?(ee=m(S?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=S,e[24]=m,e[25]=ee):ee=e[25];let L;e[26]!==m?(L=m("settings.providers.page.custom.description"),e[26]=m,e[27]=L):L=e[27];let Y;e[28]!==L?(Y=s.jsx("p",{className:ys,children:L}),e[28]=L,e[29]=Y):Y=e[29];let oe;e[30]!==k?(oe=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=oe):oe=e[31];let de;e[32]!==m?(de=m("settings.providers.page.custom.field.providerID.label"),e[32]=m,e[33]=de):de=e[33];let ge;e[34]!==m?(ge=m("settings.providers.page.custom.field.providerID.info"),e[34]=m,e[35]=ge):ge=e[35];const ce=I.providerID;let Se;e[36]===Symbol.for("react.memo_cache_sentinel")?(Se=Mt=>te("providerID",Mt.target.value),e[36]=Se):Se=e[36];let ie;e[37]!==m?(ie=m("settings.providers.page.custom.field.providerID.placeholder"),e[37]=m,e[38]=ie):ie=e[38];const be=!S,ae=S||v,me=!!x.providerID;let je;e[39]!==m?(je=m("settings.providers.page.custom.field.providerID.label"),e[39]=m,e[40]=je):je=e[40];let De;e[41]!==I.providerID||e[42]!==ie||e[43]!==be||e[44]!==ae||e[45]!==me||e[46]!==je?(De=s.jsx(We,{value:ce,onChange:Se,placeholder:ie,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:be,disabled:ae,"aria-invalid":me,"aria-label":je}),e[41]=I.providerID,e[42]=ie,e[43]=be,e[44]=ae,e[45]=me,e[46]=je,e[47]=De):De=e[47];let ue;e[48]!==x.providerID?(ue=x.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.providerID}):null,e[48]=x.providerID,e[49]=ue):ue=e[49];let $e;e[50]!==de||e[51]!==ge||e[52]!==De||e[53]!==ue?($e=s.jsxs(Ot,{label:de,info:ge,children:[De,ue]}),e[50]=de,e[51]=ge,e[52]=De,e[53]=ue,e[54]=$e):$e=e[54];let Ge;e[55]!==m?(Ge=m("settings.providers.page.custom.field.protocol.label"),e[55]=m,e[56]=Ge):Ge=e[56];let xe;e[57]!==m?(xe=m("settings.providers.page.custom.field.protocol.info"),e[57]=m,e[58]=xe):xe=e[58];const Pe=I.protocol;let J;e[59]===Symbol.for("react.memo_cache_sentinel")?(J=Mt=>{Mt in Do&&j(Gt=>({...Gt,protocol:Mt,models:Gt.models.map(Mx)}))},e[59]=J):J=e[59];let se;e[60]!==m?(se=m("settings.providers.page.custom.field.protocol.label"),e[60]=m,e[61]=se):se=e[61];let he;e[62]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx(zt,{}),e[62]=he):he=e[62];let ve;e[63]!==se?(ve=s.jsx(Pt,{"aria-label":se,className:"w-full",children:he}),e[63]=se,e[64]=ve):ve=e[64];let Fe;e[65]!==m?(Fe=m("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=m,e[66]=Fe):Fe=e[66];let Ke;e[67]!==Fe?(Ke=s.jsx(mt,{value:"openai-chat",children:Fe}),e[67]=Fe,e[68]=Ke):Ke=e[68];let Be;e[69]!==m?(Be=m("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=m,e[70]=Be):Be=e[70];let ze;e[71]!==Be?(ze=s.jsx(mt,{value:"openai-responses",children:Be}),e[71]=Be,e[72]=ze):ze=e[72];let _e;e[73]!==m?(_e=m("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=m,e[74]=_e):_e=e[74];let Me;e[75]!==_e?(Me=s.jsx(mt,{value:"anthropic-messages",children:_e}),e[75]=_e,e[76]=Me):Me=e[76];let tt;e[77]!==Ke||e[78]!==ze||e[79]!==Me?(tt=s.jsxs(At,{children:[Ke,ze,Me]}),e[77]=Ke,e[78]=ze,e[79]=Me,e[80]=tt):tt=e[80];let pt;e[81]!==v||e[82]!==I.protocol||e[83]!==ve||e[84]!==tt?(pt=s.jsxs(Tt,{value:Pe,onValueChange:J,disabled:v,children:[ve,tt]}),e[81]=v,e[82]=I.protocol,e[83]=ve,e[84]=tt,e[85]=pt):pt=e[85];let ct;e[86]!==Ge||e[87]!==xe||e[88]!==pt?(ct=s.jsx(Ot,{label:Ge,info:xe,children:pt}),e[86]=Ge,e[87]=xe,e[88]=pt,e[89]=ct):ct=e[89];let dt;e[90]!==m?(dt=m("settings.providers.page.custom.field.name.label"),e[90]=m,e[91]=dt):dt=e[91];let ht;e[92]!==m?(ht=m("settings.providers.page.custom.field.name.info"),e[92]=m,e[93]=ht):ht=e[93];const Ue=I.name;let st;e[94]===Symbol.for("react.memo_cache_sentinel")?(st=Mt=>te("name",Mt.target.value),e[94]=st):st=e[94];let ut;e[95]!==m?(ut=m("settings.providers.page.custom.field.name.placeholder"),e[95]=m,e[96]=ut):ut=e[96];const ye=!!x.name;let re;e[97]!==m?(re=m("settings.providers.page.custom.field.name.label"),e[97]=m,e[98]=re):re=e[98];let Te;e[99]!==I.name||e[100]!==ut||e[101]!==ye||e[102]!==re?(Te=s.jsx(We,{value:Ue,onChange:st,placeholder:ut,className:"h-8 rounded-md px-3","aria-invalid":ye,"aria-label":re}),e[99]=I.name,e[100]=ut,e[101]=ye,e[102]=re,e[103]=Te):Te=e[103];let Ne;e[104]!==x.name?(Ne=x.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.name}):null,e[104]=x.name,e[105]=Ne):Ne=e[105];let Ae;e[106]!==dt||e[107]!==ht||e[108]!==Te||e[109]!==Ne?(Ae=s.jsxs(Ot,{label:dt,info:ht,children:[Te,Ne]}),e[106]=dt,e[107]=ht,e[108]=Te,e[109]=Ne,e[110]=Ae):Ae=e[110];let q;e[111]!==m?(q=m("settings.providers.page.custom.field.baseURL.label"),e[111]=m,e[112]=q):q=e[112];let Le;e[113]!==m?(Le=m("settings.providers.page.custom.field.baseURL.info"),e[113]=m,e[114]=Le):Le=e[114];const Qe=I.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=Mt=>te("baseURL",Mt.target.value),e[115]=lt):lt=e[115];let ot;e[116]!==m?(ot=m("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=m,e[117]=ot):ot=e[117];const bt=!!x.baseURL;let wt;e[118]!==m?(wt=m("settings.providers.page.custom.field.baseURL.label"),e[118]=m,e[119]=wt):wt=e[119];let jt;e[120]!==I.baseURL||e[121]!==ot||e[122]!==bt||e[123]!==wt?(jt=s.jsx(We,{value:Qe,onChange:lt,placeholder:ot,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":bt,"aria-label":wt}),e[120]=I.baseURL,e[121]=ot,e[122]=bt,e[123]=wt,e[124]=jt):jt=e[124];let vt;e[125]!==x.baseURL?(vt=x.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.baseURL}):null,e[125]=x.baseURL,e[126]=vt):vt=e[126];let Xe;e[127]!==q||e[128]!==Le||e[129]!==jt||e[130]!==vt?(Xe=s.jsxs(Ot,{label:q,info:Le,children:[jt,vt]}),e[127]=q,e[128]=Le,e[129]=jt,e[130]=vt,e[131]=Xe):Xe=e[131];let kt;e[132]!==m?(kt=m("settings.providers.page.custom.field.apiKey.label"),e[132]=m,e[133]=kt):kt=e[133];let Re;e[134]!==b||e[135]!==S||e[136]!==m?(Re=m(S&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=S,e[136]=m,e[137]=Re):Re=e[137];const Ve=I.apiKey;let Z;e[138]===Symbol.for("react.memo_cache_sentinel")?(Z=Mt=>te("apiKey",Mt.target.value),e[138]=Z):Z=e[138];let pe;e[139]!==b||e[140]!==S||e[141]!==m?(pe=m(S&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=S,e[141]=m,e[142]=pe):pe=e[142];const Oe=!!x.apiKey;let Ee;e[143]!==m?(Ee=m("settings.providers.page.custom.field.apiKey.label"),e[143]=m,e[144]=Ee):Ee=e[144];let Ye;e[145]!==I.apiKey||e[146]!==pe||e[147]!==Oe||e[148]!==Ee?(Ye=s.jsx(We,{type:"password",value:Ve,onChange:Z,placeholder:pe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Oe,"aria-label":Ee}),e[145]=I.apiKey,e[146]=pe,e[147]=Oe,e[148]=Ee,e[149]=Ye):Ye=e[149];let ne;e[150]!==x.apiKey?(ne=x.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.apiKey}):null,e[150]=x.apiKey,e[151]=ne):ne=e[151];let we;e[152]!==kt||e[153]!==Re||e[154]!==Ye||e[155]!==ne?(we=s.jsxs(Ot,{label:kt,info:Re,children:[Ye,ne]}),e[152]=kt,e[153]=Re,e[154]=Ye,e[155]=ne,e[156]=we):we=e[156];let nt;e[157]!==ee||e[158]!==Y||e[159]!==oe||e[160]!==$e||e[161]!==ct||e[162]!==Ae||e[163]!==Xe||e[164]!==we?(nt=s.jsxs(qe,{title:ee,divider:!1,settingsItem:"providers.custom",contentClassName:Rs,children:[Y,oe,$e,ct,Ae,Xe,we]}),e[157]=ee,e[158]=Y,e[159]=oe,e[160]=$e,e[161]=ct,e[162]=Ae,e[163]=Xe,e[164]=we,e[165]=nt):nt=e[165];let Rt;e[166]!==m?(Rt=m("settings.providers.page.custom.models.title"),e[166]=m,e[167]=Rt):Rt=e[167];let Jt;if(e[168]!==I.models||e[169]!==C||e[170]!==m){let Mt;e[172]!==I.models.length||e[173]!==C||e[174]!==m?(Mt=(Gt,Kt)=>s.jsx("div",{className:`${Ps} 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:Nt,children:m("settings.providers.page.custom.models.idLabel")}),s.jsx(We,{value:Gt.id,onChange:Et=>H(Kt,"id",Et.target.value),placeholder:m("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.models.idLabel")}),C[Kt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:C[Kt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:m("settings.providers.page.custom.models.nameLabel")}),s.jsx(We,{value:Gt.name,onChange:Et=>H(Kt,"name",Et.target.value),placeholder:m("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":m("settings.providers.page.custom.models.nameLabel")}),C[Kt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:C[Kt]?.name}):null]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Nt,children:m("settings.providers.page.custom.models.variantsLabel")}),s.jsx(qt,{children:m("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(We,{value:Gt.variants,onChange:Et=>H(Kt,"variants",Et.target.value),placeholder:m("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.models.variantsLabel")})]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:ps,disabled:I.models.length<=1,onClick:()=>{I.models.length<=1||(j(Et=>({...Et,models:Et.models.filter((is,ss)=>ss!==Kt)})),E(Et=>Et.filter((is,ss)=>ss!==Kt)))},"aria-label":m("settings.providers.page.custom.models.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Gt.row),e[172]=I.models.length,e[173]=C,e[174]=m,e[175]=Mt):Mt=e[175],Jt=I.models.map(Mt),e[168]=I.models,e[169]=C,e[170]=m,e[171]=Jt}else Jt=e[171];let Ce;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>{j(Rx),E(Ox)},e[176]=Ce):Ce=e[176];let He;e[177]!==m?(He=m("settings.providers.page.custom.models.add"),e[177]=m,e[178]=He):He=e[178];let yt;e[179]!==He?(yt=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ce,children:He}),e[179]=He,e[180]=yt):yt=e[180];let It;e[181]!==Rt||e[182]!==Jt||e[183]!==yt?(It=s.jsxs(qe,{title:Rt,contentClassName:Rs,children:[Jt,yt]}),e[181]=Rt,e[182]=Jt,e[183]=yt,e[184]=It):It=e[184];let Qt;e[185]!==m?(Qt=m("settings.providers.page.custom.headers.title"),e[185]=m,e[186]=Qt):Qt=e[186];let Xt;e[187]!==m?(Xt=m("settings.providers.page.custom.headers.description"),e[187]=m,e[188]=Xt):Xt=e[188];let ts;e[189]!==Xt?(ts=s.jsx("p",{className:ys,children:Xt}),e[189]=Xt,e[190]=ts):ts=e[190];let es;if(e[191]!==I.headers||e[192]!==F||e[193]!==m){let Mt;e[195]!==I.headers.length||e[196]!==F||e[197]!==m?(Mt=(Gt,Kt)=>s.jsx("div",{className:`${Ps} 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:Nt,children:m("settings.providers.page.custom.headers.keyLabel")}),s.jsx(We,{value:Gt.key,onChange:Et=>V(Kt,"key",Et.target.value),placeholder:m("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.keyLabel")}),F[Kt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:F[Kt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:m("settings.providers.page.custom.headers.valueLabel")}),s.jsx(We,{value:Gt.value,onChange:Et=>V(Kt,"value",Et.target.value),placeholder:m("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.valueLabel")}),F[Kt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:F[Kt]?.value}):null]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:ps,disabled:I.headers.length<=1,onClick:()=>{I.headers.length<=1||(j(Et=>({...Et,headers:Et.headers.filter((is,ss)=>ss!==Kt)})),N(Et=>Et.filter((is,ss)=>ss!==Kt)))},"aria-label":m("settings.providers.page.custom.headers.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Gt.row),e[195]=I.headers.length,e[196]=F,e[197]=m,e[198]=Mt):Mt=e[198],es=I.headers.map(Mt),e[191]=I.headers,e[192]=F,e[193]=m,e[194]=es}else es=e[194];let Fs;e[199]===Symbol.for("react.memo_cache_sentinel")?(Fs=()=>{j(Fx),N(Lx)},e[199]=Fs):Fs=e[199];let Qs;e[200]!==m?(Qs=m("settings.providers.page.custom.headers.add"),e[200]=m,e[201]=Qs):Qs=e[201];let pn;e[202]!==Qs?(pn=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Fs,children:Qs}),e[202]=Qs,e[203]=pn):pn=e[203];let Ls;e[204]!==Qt||e[205]!==ts||e[206]!==es||e[207]!==pn?(Ls=s.jsxs(qe,{title:Qt,contentClassName:Rs,children:[ts,es,pn]}),e[204]=Qt,e[205]=ts,e[206]=es,e[207]=pn,e[208]=Ls):Ls=e[208];let Ks;e[209]!==v||e[210]!==g||e[211]!==m?(Ks=g?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:g,disabled:v,children:m("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=g,e[211]=m,e[212]=Ks):Ks=e[212];let on;e[213]!==v||e[214]!==f||e[215]!==m?(on=f?s.jsx(G,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{f()},disabled:v,children:m("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=f,e[215]=m,e[216]=on):on=e[216];let Ys;e[217]!==v||e[218]!==S||e[219]!==m?(Ys=m(v?"settings.providers.page.actions.saving":S?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=v,e[218]=S,e[219]=m,e[220]=Ys):Ys=e[220];let Zs;e[221]!==v||e[222]!==Ys?(Zs=s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:Ys}),e[221]=v,e[222]=Ys,e[223]=Zs):Zs=e[223];let _s;e[224]!==Ks||e[225]!==on||e[226]!==Zs?(_s=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Ks,on,Zs]}),e[224]=Ks,e[225]=on,e[226]=Zs,e[227]=_s):_s=e[227];let Tn;return e[228]!==$||e[229]!==nt||e[230]!==It||e[231]!==Ls||e[232]!==_s?(Tn=s.jsxs("form",{onSubmit:$,className:"space-y-0",children:[nt,It,Ls,_s]}),e[228]=$,e[229]=nt,e[230]=It,e[231]=Ls,e[232]=_s,e[233]=Tn):Tn=e[233],Tn};function Mx(t){return t.savedVariants?{...t,savedVariants:{}}:t}function Rx(t){return{...t,models:[...t.models,Mo()]}}function Ox(t){return[...t,{}]}function Fx(t){return{...t,headers:[...t.headers,Ro()]}}function Lx(t){return[...t,{}]}const Kx=t=>new Intl.NumberFormat(yo(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Gl=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Kx(t);return e.endsWith(".0")?e.slice(0,-2):e},si="__add_provider__",gd=t=>typeof t=="object"&&t!==null,_x=t=>{if(typeof t=="string")return{id:t};if(!gd(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}},Ux=t=>{let e=[];Array.isArray(t)?e=t:gd(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(r=>_x(r)).filter(r=>!!r),n=new Set;return a.filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))},zx=Dt(),Wl=t=>zx.safeParse(t?.settings?.apiKey).data??null,$x=()=>{const{t}=Ze(),e=Js(),a=it(re=>Tc(re,e)),n=it(re=>re.selectedProviderId),r=it(re=>re.setSelectedProvider),i=it(re=>re.getModelMetadata),l=fe(re=>re.hiddenModels),d=fe(re=>re.toggleHiddenModel),c=fe(re=>re.hideAllModels),h=fe(re=>re.showAllModels),[g,f]=o.useState(null),[p,u]=o.useState(!1),[v,w]=o.useState({}),[b,k]=o.useState(null),[m,S]=o.useState(""),[P,I]=o.useState([]),[j,D]=o.useState(!1),[x,A]=o.useState(null),[R,C]=o.useState(""),[E,O]=o.useState(""),[F,N]=o.useState(!1),[M,U]=o.useState({}),[K,W]=o.useState({}),[te,Q]=o.useState(0),[H,_]=o.useState(0),[V,X]=o.useState(!1),[$,ee]=o.useState(null),[L,Y]=o.useState(null),[oe,de]=o.useState(null),[ge,ce]=o.useState(null),[Se,ie]=o.useState(null),[be,ae]=o.useState(null),me=n===si,je=me&&R===ea,De=!!(L&&n&&L===n&&!me);o.useEffect(()=>{!n&&a.length>0&&r(a[0].id)},[a,n,r]),o.useEffect(()=>{if(!n)return;let re=!0;return(async()=>{u(!0);try{const{data:Ne}=await Gs.getSdkClient().integration.list();if(!re)return;f(Ne)}catch(Ne){if(!re)return;console.error("Failed to load provider integrations:",Ne),B.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{re&&u(!1)}})(),()=>{re=!1}},[n,H,t]),o.useEffect(()=>{if(!ux(me))return;let re=!0;return(async()=>{D(!0),A(null);try{const[{data:Ne},Ae]=await Promise.all([Gs.getSdkClient().integration.list(),eu(Gs.getDirectory()??null).catch(()=>null)]);if(!re)return;const q=new Set((Ae??[]).map(Le=>Le.id));I(Ux(Ne.filter(Le=>!Le.id.startsWith("mcp_")&&!q.has(Le.id)&&Le.connections.length===0)))}catch(Ne){if(!re)return;console.error("Failed to load available providers:",Ne),A(t("settings.providers.page.state.unableToLoadProviderList"))}finally{re&&D(!1)}})(),()=>{re=!1}},[me,t]);const ue=o.useMemo(()=>new Set(a.map(re=>re.id)),[a]),$e=o.useMemo(()=>P.filter(re=>!ue.has(re.id)).sort((re,Te)=>{const Ne=(re.name||re.id).toLowerCase(),Ae=(Te.name||Te.id).toLowerCase();return Ne.localeCompare(Ae)}),[P,ue]);o.useEffect(()=>{n===si&&R&&R!==ea&&!$e.some(re=>re.id===R)&&C("")},[n,R,$e]),o.useEffect(()=>{if(n===si){X(!0),ee(null),Y(null),de(null),ce(null),ie(null);return}X(!1),ee(null),L&&L!==n&&(Y(null),de(null),ce(null),ie(null))},[n,L]),o.useEffect(()=>{if(!n||n===si)return;const re=M[n];if(!re||g===null)return;const Te=a.find(q=>q.id===n),Ne=$l({connections:_l(g,n),optionsApiKey:Wl(Te)}),Ae=!!(Te&&Bl(Te,re));fx({hasCredentials:Ne,userDismissed:$===n,isEditableCustomProvider:Ae})&&X(!0)},[n,M,a,g,$]),o.useEffect(()=>{if(!n||n===si)return;let re=!1;return(async()=>{try{const Ne=e?`?directory=${encodeURIComponent(e)}`:"",Ae=await St(`/api/provider/${encodeURIComponent(n)}/source${Ne}`,{method:"GET",headers:{Accept:"application/json"}}),q=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(q?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Le=q?.sources??q?.data?.sources;!re&&Le&&(U(Qe=>({...Qe,[n]:Le})),W(Qe=>({...Qe,[n]:Ix.safeParse(q?.config??q?.data?.config).data??null})))}catch(Ne){re||console.error("Failed to load provider sources:",Ne)}})(),()=>{re=!0}},[n,te,e,t]);const Ge=o.useCallback(()=>{Q(re=>re+1)},[]),xe=o.useCallback(()=>{_(re=>re+1)},[]),Pe=o.useCallback(re=>{f(Te=>(Te??[]).map(Ne=>Ne.id===re&&Ne.connections.length===0?{...Ne,connections:[{type:"credential",id:`pending:${re}`,label:re,method:"key"}]}:Ne)),ee(null),X(!1),r(re),Ge(),xe()},[xe,Ge,r]),J=a.find(re=>re.id===n),se=n?M[n]:void 0,he=async re=>{const Te=v[re]?.trim()??"";if(!Te){B.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ne=`api:${re}`;k(Ne);try{await Gs.getSdkClient().integration.connect.key({integrationID:re,key:Te}),B.success(t("settings.providers.page.toast.apiKeySaved")),w(Ae=>({...Ae,[re]:""})),Pe(re)}catch(Ae){console.error("Failed to save API key:",Ae),B.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},ve=async re=>{const Te=`custom:${re.providerID}`;k(Te),ae(re.providerID),ie(null);try{const Ne=Ex(re);Ne&&await Gs.getSdkClient().integration.connect.key(Ne);const Ae=Dx(re,{scope:L?ge??Vl(M[L]):"user"}),q=await St(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ae)}),Le=await q.json().catch(()=>null);if(!q.ok)throw Ne&&ie(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(Le?.error||t("settings.providers.page.toast.customProviderSaveFailed"));B.success(t("settings.providers.page.toast.customProviderSaved",{provider:re.name})),C(""),Y(null),de(null),ce(null),ie(null),ae(null),Pe(re.providerID)}catch(Ne){console.error("Failed to save custom provider:",Ne),B.error(Ne instanceof Error&&Ne.message?Ne.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},Fe=re=>{X(!1),Pe(re)},Ke=async re=>{const Te=`disconnect:${re}`;k(Te);try{const Ne=gx(ta(g??[],re)),Ae=Gs.getSdkClient();for(const q of Ne)await Ae.credential.remove({credentialID:q.id});B.success(t("settings.providers.page.toast.providerDisconnected")),ee(null),Ge(),xe()}catch(Ne){console.error("Failed to disconnect provider:",Ne),B.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},Be=async re=>{re&&(await Ke(re),Y(null),de(null),ce(null),ie(null),ae(null),C(""))};if(!me&&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(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(me)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(qe,{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")}),j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):x?s.jsx("p",{className:"typography-meta text-muted-foreground",children:x}):s.jsxs(zn,{open:F,onOpenChange:re=>{N(re),re||O("")},children:[s.jsx(Un,{asChild:!0,children:s.jsxs("button",{type:"button",className:Ws,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R&&R!==ea?s.jsx(na,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:Ie("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R===ea?t("settings.providers.page.custom.optionLabel"):R?$e.find(re=>re.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(_n,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:re=>re.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:re=>re.stopPropagation(),children:[s.jsx(z,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:E,onChange:re=>O(re.target.value),onKeyDown:re=>re.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(bs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const re=t("settings.providers.page.custom.optionLabel"),Te=Xd([re,"other","custom"],E),Ne=gi($e,E,Ae=>[Ae.name||Ae.id,Ae.id]);return Ne.length===0&&!Te?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:[Ne.map(Ae=>s.jsxs(wn,{onSelect:()=>{C(Ae.id),N(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(na,{providerId:Ae.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ae.name||Ae.id})]}),R===Ae.id&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ae.id)),Te?s.jsxs(wn,{onSelect:()=>{C(ea),N(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(z,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re})]}),R===ea&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ea):null]})})()})]})]})]})}),je?s.jsx(ql,{mode:"create",existingProviderIDs:ue,busy:b?.startsWith("custom:")??!1,authFailureHint:Se,onCancel:()=>{C(""),ie(null),ae(null)},onDisconnect:Se&&be?()=>{Be(be)}:void 0,onSubmit:ve}):R?s.jsx(qe,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const re=ta(g??[],R),Te=Ul(ta(g??[],li(R))),Ne=zl(re);return s.jsxs(s.Fragment,{children:[Ne?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(qt,{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(We,{type:"password",value:v[R]??"",onChange:Ae=>w(q=>({...q,[R]:Ae.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>he(R),disabled:b===`api:${R}`,children:b===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Te.length>0?s.jsx(ro,{integrationId:li(R),methods:Te,onConnected:()=>Fe(R),className:Ie(Ne&&"border-t border-[var(--surface-subtle)] pt-2")},R):null]})})()})}):null]});if(!J)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ze=Array.isArray(J.models)?J.models:[],_e=ta(g??[],J.id),Me=Ul(ta(g??[],li(J.id))),tt=zl(_e),pt=g!==null,ct=!!se,dt=ct&&Bl(J,se),ht=$l({connections:_l(g??[],J.id),optionsApiKey:Wl(J)}),Ue=mx(pt,ht,dt),st=hx({modelCount:ze.length,integrationsLoaded:pt,hasCredentials:ht,isEditableCustomProvider:dt}),ut=!tt&&Me.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),ye=gi(ze,m,re=>[typeof re?.name=="string"?re.name:"",typeof re?.id=="string"?re.id:""]);return De&&dt&&oe?s.jsx(ns,{title:J.name||J.id,titleLeading:s.jsx(na,{providerId:J.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:J.id}),showSaveStatus:!1,children:s.jsx(ql,{mode:"edit",existingProviderIDs:ue,initialValues:oe,allowExistingAuth:ht||!ct,busy:b?.startsWith("custom:")??!1,authFailureHint:Se,onCancel:()=>{Y(null),de(null),ce(null),ie(null),ae(null)},onDisconnect:()=>{Be(J.id)},onSubmit:ve})}):s.jsxs(ns,{title:J.name||J.id,titleLeading:s.jsx(na,{providerId:J.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:J.id}),showSaveStatus:!1,children:[s.jsx(qe,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[dt?s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ie(null),de(Px(J,K[J.id]??null)),ce(Vl(se)),Y(J.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const re=!V;X(re),ee(re?null:J.id)},children:t(V?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:V?p?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:[tt?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(qt,{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(We,{type:"password",value:v[J.id]??"",onChange:re=>w(Te=>({...Te,[J.id]:re.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>he(J.id),disabled:b===`api:${J.id}`,children:b===`api:${J.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Me.length>0&&s.jsx(ro,{integrationId:li(J.id),methods:Me,onConnected:()=>Fe(J.id),className:Ie(tt&&"border-t border-[var(--surface-subtle)] pt-2")},J.id)]}):Ue?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(qt,{children:ut})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(qt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(qe,{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:ht||se?.user.exists||se?.project.exists||se?.custom?.exists?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ht?t("settings.providers.page.connectionDetails.source.authCredentials"):null,se?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,se?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,se?.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(G,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>Ke(J.id),disabled:b===`disconnect:${J.id}`,children:b===`disconnect:${J.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),st?s.jsxs(qe,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",ze.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const re=ze.map(Te=>typeof Te?.id=="string"?Te.id:"").filter(Te=>Te.length>0);c(J.id,re)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>h(J.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(z,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(We,{value:m,onChange:re=>S(re.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ye.map(re=>{const Te=typeof re?.id=="string"?re.id:"",Ne=typeof re?.name=="string"?re.name:Te,Ae=Te?i(J.id,Te):void 0,q=l.some(ot=>ot.providerID===J.id&&ot.modelID===Te),Le=Gl(Ae?.limit?.context),Qe=Gl(Ae?.limit?.output),lt=[];return Ae?.tool_call&&lt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ae?.reasoning&&lt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ae?.attachment&&lt.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:Ie("flex items-center gap-3",q&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ne}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Le||Qe)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Le?`${Le} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Le&&Qe?" · ":"",Qe?`${Qe} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),lt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:lt.map(({key:ot,icon:bt,label:wt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:wt,"aria-label":wt,children:s.jsx(z,{name:bt,className:"h-3 w-3"})},ot))}),s.jsx("button",{type:"button",onClick:()=>d(J.id,Te),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(q?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(q?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:q?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},Te)})})]}):null]})},Bx=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)},Vx=t=>{const e=at.c(75),{onItemSelect:a}=t,{t:n}=Ze(),r=rs(Hx),i=rs(qx),l=rs(Gx),d=rs(Wx),c=rs(Jx),h=rs(Qx),g=rs(Yx),f=rs(Zx);let p,u;e[0]!==f?(p=()=>{f()},u=[f],e[0]=f,e[1]=p,e[2]=u):(p=e[1],u=e[2]),o.useEffect(p,u);const v=Xx;let w;e[3]!==g?(w=Y=>{Y!=="usage"&&Y!=="remaining"||(g(Y),v({usageDisplayMode:Y}))},e[3]=g,e[4]=w):w=e[4];const b=w;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=Ie("flex h-full flex-col","bg-background"),e[5]=k):k=e[5];let m;e[6]!==n?(m=n("settings.usage.sidebar.title"),e[6]=n,e[7]=m):m=e[7];let S;e[8]!==m?(S=s.jsx("h2",{className:`${Pn} mb-3`,children:m}),e[8]=m,e[9]=S):S=e[9];let P;e[10]!==n?(P=n("settings.usage.sidebar.total",{count:Ji.length}),e[10]=n,e[11]=P):P=e[11];let I;e[12]!==P?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[12]=P,e[13]=I):I=e[13];let j;e[14]!==d?(j=()=>d(),e[14]=d,e[15]=j):j=e[15];let D;e[16]!==n?(D=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=D):D=e[17];let x;e[18]!==n?(x=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=x):x=e[19];const A=c&&"animate-spin";let R;e[20]!==A?(R=Ie("h-3.5 w-3.5",A),e[20]=A,e[21]=R):R=e[21];let C;e[22]!==R?(C=s.jsx(z,{name:"refresh",className:R}),e[22]=R,e[23]=C):C=e[23];let E;e[24]!==c||e[25]!==D||e[26]!==x||e[27]!==C||e[28]!==j?(E=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:j,"aria-label":D,title:x,disabled:c,children:C})}),e[24]=c,e[25]=D,e[26]=x,e[27]=C,e[28]=j,e[29]=E):E=e[29];let O;e[30]!==E||e[31]!==I?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,E]}),e[30]=E,e[31]=I,e[32]=O):O=e[32];let F;e[33]!==n?(F=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=F):F=e[34];let N;e[35]!==F?(N=s.jsx("span",{className:"typography-micro text-muted-foreground",children:F}),e[35]=F,e[36]=N):N=e[36];let M;e[37]!==n?(M=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=M):M=e[38];let U;e[39]!==M?(U=s.jsx(Pt,{className:"w-fit",children:s.jsx(zt,{placeholder:M})}),e[39]=M,e[40]=U):U=e[40];let K;e[41]!==n?(K=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=K):K=e[42];let W;e[43]!==K?(W=s.jsx(mt,{value:"usage",children:K}),e[43]=K,e[44]=W):W=e[44];let te;e[45]!==n?(te=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=te):te=e[46];let Q;e[47]!==te?(Q=s.jsx(mt,{value:"remaining",children:te}),e[47]=te,e[48]=Q):Q=e[48];let H;e[49]!==W||e[50]!==Q?(H=s.jsxs(At,{children:[W,Q]}),e[49]=W,e[50]=Q,e[51]=H):H=e[51];let _;e[52]!==b||e[53]!==U||e[54]!==H||e[55]!==h?(_=s.jsxs(Tt,{value:h,onValueChange:b,children:[U,H]}),e[52]=b,e[53]=U,e[54]=H,e[55]=h,e[56]=_):_=e[56];let V;e[57]!==N||e[58]!==_?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[N,_]}),e[57]=N,e[58]=_,e[59]=V):V=e[59];let X;e[60]!==O||e[61]!==V||e[62]!==S?(X=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[S,O,V]}),e[60]=O,e[61]=V,e[62]=S,e[63]=X):X=e[63];let $;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?($=Ji.map(Y=>{const oe=r.find(be=>be.providerId===Y.id),de=Bx(oe?.usage),ge=Ec(de),ce=Y.id===i,Se=oe?.configured,ie=Se?ge==="critical"?{backgroundColor:"var(--status-error)"}:ge==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ce?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(Y.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-ring",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ie}),s.jsx(na,{providerId:Y.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:Y.name}),Se===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},Y.id)}),e[64]=a,e[65]=r,e[66]=i,e[67]=l,e[68]=n,e[69]=$):$=e[69];let ee;e[70]!==$?(ee=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:$}),e[70]=$,e[71]=ee):ee=e[71];let L;return e[72]!==X||e[73]!==ee?(L=s.jsxs("div",{className:k,children:[X,ee]}),e[72]=X,e[73]=ee,e[74]=L):L=e[74],L};function Hx(t){return t.results}function qx(t){return t.selectedProviderId}function Gx(t){return t.setSelectedProvider}function Wx(t){return t.fetchAllQuotas}function Jx(t){return t.isLoading}function Qx(t){return t.displayMode}function Yx(t){return t.setDisplayMode}function Zx(t){return t.loadSettings}async function Xx(t){try{await ft(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const eb=t=>{const e=at.c(17),{percent:a,tonePercent:n,className:r}=t;let i;e[0]!==a?(i=tu(a)??0,e[0]=a,e[1]=i):i=e[1];const l=i,d=n??a;let c;e[2]!==d?(c=Ec(d),e[2]=d,e[3]=c):c=e[3];const h=c;let g;e[4]!==h?(g=h==="critical"?{backgroundColor:"var(--status-error)"}:h==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=h,e[5]=g):g=e[5];const f=g;let p;e[6]!==r?(p=Ie("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=p):p=e[7];const u=`${l}%`;let v;e[8]!==f||e[9]!==u?(v={...f,width:u},e[8]=f,e[9]=u,e[10]=v):v=e[10];let w;e[11]!==l||e[12]!==v?(w=s.jsx("div",{className:"h-full transition-all duration-300",style:v,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=v,e[13]=w):w=e[13];let b;return e[14]!==p||e[15]!==w?(b=s.jsx("div",{className:p,children:w}),e[14]=p,e[15]=w,e[16]=b):b=e[16],b},$r=t=>{const e=at.c(37),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:d}=t,c=i===void 0?!1:i,h=l===void 0?!1:l,g=rs(tb),f=fe(sb),p=g==="remaining"?n.remainingPercent:n.usedPercent,u=p!==null,v=g==="remaining"?"remaining":"used";let w;e[0]!==p||e[1]!==n.valueLabel?(w=su(n.valueLabel,p),e[0]=p,e[1]=n.valueLabel,e[2]=w):w=e[2];const b=w,k=n.resetAfterFormatted??n.resetAtFormatted;let m;e[3]!==k||e[4]!==f||e[5]!==n.resetAt?(m=nu(n.resetAt,k,f),e[3]=k,e[4]=f,e[5]=n.resetAt,e[6]=m):m=e[6];const S=m,P=S?`Resets ${S}`:"";let I;e[7]!==a?(I=au(a),e[7]=a,e[8]=I):I=e[8];const j=I;let D;e[9]!==d||e[10]!==c||e[11]!==h?(D=c&&s.jsx(eo,{checked:h,onChange:U=>d?.(U),ariaLabel:"Show in dropdown"}),e[9]=d,e[10]=c,e[11]=h,e[12]=D):D=e[12];let x;e[13]!==j?(x=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j}),e[13]=j,e[14]=x):x=e[14];let A;e[15]!==r?(A=r&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[15]=r,e[16]=A):A=e[16];let R;e[17]!==x||e[18]!==A?(R=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[x,A]}),e[17]=x,e[18]=A,e[19]=R):R=e[19];let C;e[20]!==R||e[21]!==D?(C=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[D,R]}),e[20]=R,e[21]=D,e[22]=C):C=e[22];const E=b==="-"?"":b;let O;e[23]!==E?(O=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:E}),e[23]=E,e[24]=O):O=e[24];let F;e[25]!==C||e[26]!==O?(F=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[C,O]}),e[25]=C,e[26]=O,e[27]=F):F=e[27];let N;e[28]!==v||e[29]!==p||e[30]!==u||e[31]!==P||e[32]!==n.usedPercent?(N=u?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(eb,{percent:p,tonePercent:n.usedPercent,className:"h-1.5"}),s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:P}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]})]}):P?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:P}):null,e[28]=v,e[29]=p,e[30]=u,e[31]=P,e[32]=n.usedPercent,e[33]=N):N=e[33];let M;return e[34]!==F||e[35]!==N?(M=s.jsxs("div",{className:"py-3",children:[F,N]}),e[34]=F,e[35]=N,e[36]=M):M=e[36],M};function tb(t){return t.displayMode}function sb(t){return t.timeFormatPreference}const nb=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,ab=({providerId:t,providerName:e})=>{const{t:a}=Ze(),[n,r]=o.useState(null),[i,l]=o.useState({}),[d,c]=o.useState(!1),h=`/api/quota/credentials/${t}`;o.useEffect(()=>{St(h).then(async p=>{if(!p.ok)throw new Error;const u=await p.json();r(u),l({})}).catch(()=>r({configured:!1}))},[h]);const g=async(p,u,v)=>{c(!0);try{const w=await St(p,{method:u,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error(b?.error);b?.configured!==void 0&&r(b),l({}),B.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(w){B.error(w instanceof Error&&w.message?w.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},f=(p,u,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[u,s.jsx(We,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[p]??"",onChange:w=>l(b=>({...b,[p]:w.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==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:nb})]}),t==="ollama-cloud"&&f("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&f("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("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(G,{size:"xs",disabled:d,onClick:()=>g(h,"PUT",i),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(G,{variant:"outline",size:"xs",disabled:d,onClick:()=>g(`${h}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(G,{variant:"outline",size:"xs",disabled:d,onClick:()=>g(`${h}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(G,{variant:"destructive",size:"xs",disabled:d,onClick:()=>g(h,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Jl=(t,e)=>{if(!t)return"-";try{return Dc(t,e,{fallback:"-"})}catch{return"-"}},ib=()=>{const{t}=Ze(),e=fe(M=>M.timeFormatPreference),a=rs(M=>M.results),n=rs(M=>M.selectedProviderId),r=rs(M=>M.setSelectedProvider),i=rs(M=>M.loadSettings),l=rs(M=>M.fetchAllQuotas),d=rs(M=>M.isLoading),c=rs(M=>M.lastUpdated),h=rs(M=>M.refreshErrors),g=rs(M=>M.dropdownProviderIds),f=rs(M=>M.setDropdownProviderIds),p=rs(M=>M.selectedModels),u=rs(M=>M.toggleModelSelected),v=rs(M=>M.applyDefaultSelections);iu(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const M=a.find(U=>U.configured)?.providerId;r(M??Ji[0]?.id??null)},[a,n,r]);const w=a.find(M=>M.providerId===n)??null,k=Ji.find(M=>M.id===n)?.name??n??t("settings.usage.sidebar.title"),m=w?.usage,S=n?h[n]:void 0,P=S?m?t("header.services.usageRefreshFailedStale",{error:S}):S:w?.configured&&!w.ok?w.error:null,I=n?g.includes(n):!1,j=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",D=o.useCallback(M=>{if(!n)return;const U=M?Array.from(new Set([...g,n])):g.filter(K=>K!==n);f(U),ft({usageDropdownProviders:U})},[g,n,f]),x=o.useMemo(()=>m?.models?Object.entries(m.models).map(([M,U])=>({name:M,windows:U})).filter(M=>Object.keys(M.windows.windows).length>0):[],[m?.models]);o.useEffect(()=>{n&&x.length>0&&v(n,x.map(M=>M.name))},[n,x,v]);const A=o.useMemo(()=>!n||x.length===0?new Map:ru(x,M=>M.name,n),[x,n]),R=o.useMemo(()=>{if(!n)return[];const M=lu(n);return ou(M)},[n]),[C,E]=o.useState(()=>({})),O=o.useCallback(M=>{E(U=>({...U,[M]:!U[M]}))},[]),F=o.useCallback(M=>{if(!n)return;u(n,M);const U=p[n]??[],W=U.includes(M)?U.filter(Q=>Q!==M):[...U,M],te={...p,[n]:W};ft({usageSelectedModels:te})},[n,p,u]),N=n?p[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(na,{providerId:n,className:"h-5 w-5 shrink-0"}),description:d?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):w?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:w.planLabel,time:Jl(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Jl(c,e)}),showSaveStatus:!0,children:[s.jsx(qe,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:I,onChange:D,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!w&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),P&&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:P})]}),w&&!w.configured&&!j&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(ab,{providerId:n,providerName:k}),m?.windows&&Object.keys(m.windows).length>0&&s.jsx(qe,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(m.windows).map(([M,U])=>s.jsx($r,{title:M,window:U},M))})}),x.length>0&&s.jsxs(qe,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[R.map(M=>{const U=A.get(M.id)??[];if(U.length===0)return null;const K=C[M.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!K,onOpenChange:()=>O(M.id),children:[s.jsxs(Nn,{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:M.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",U.length,")"]})]}),K?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:U.map(W=>{const te=Object.entries(W.windows.windows);if(te.length===0)return null;const[Q,H]=te[0],_=N.includes(W.name);return s.jsx($r,{title:Q,subtitle:Bo(W.name),window:H,showToggle:!0,toggleEnabled:_,onToggle:()=>F(W.name)},W.name)})})})]})},M.id)}),(()=>{const M=A.get(null)??[];if(M.length===0)return null;const U=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!U,onOpenChange:()=>O("other"),children:[s.jsxs(Nn,{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:["(",M.length,")"]})]}),U?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(K=>{const W=Object.entries(K.windows.windows);if(W.length===0)return null;const[te,Q]=W[0],H=N.includes(K.name);return s.jsx($r,{title:te,subtitle:Bo(K.name),window:Q,showToggle:!0,toggleEnabled:H,onToggle:()=>F(K.name)},K.name)})})})]})})})()]}),w?.configured&&m&&Object.keys(m.windows??{}).length===0&&x.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")})})},rb="git.commit.generate",co=Om(t=>({selectedPromptId:rb,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),ob=t=>{const e=at.c(24),{onItemSelect:a}=t,{t:n}=Ze(),r=co(lb),i=co(cb);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 d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={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]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=h):h=e[3];let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=[l,d,c,h,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=g):g=e[4];const f=g;let p;e[5]!==n?(p=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=p):p=e[6];let u;e[7]!==p?(u=s.jsx("h2",{className:Pn,children:p}),e[7]=p,e[8]=u):u=e[8];let v;e[9]!==n?(v=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=v):v=e[10];let w;e[11]!==v?(w=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:v}),e[11]=v,e[12]=w):w=e[12];let b;e[13]!==u||e[14]!==w?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[u,w]}),e[13]=u,e[14]=w,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==r||e[18]!==i||e[19]!==n?(k=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:f.map(S=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(S.groupKey)}),S.items.map(P=>{const I=r===P.id;return s.jsx("button",{type:"button",onClick:()=>{i(P.id),a?.()},className:Ie("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",I?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(P.titleKey)})},P.id)})]},S.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=k):k=e[20];let m;return e[21]!==b||e[22]!==k?(m=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,k]}),e[21]=b,e[22]=k,e[23]=m):m=e[23],m};function lb(t){return t.selectedPromptId}function cb(t){return t.setSelectedPromptId}const Ql={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Yl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Br=t=>t.endsWith(".visible"),db=()=>{const{t}=Ze(),e=o.useCallback(j=>t(j),[t]),a=co(j=>j.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[d,c]=o.useState({}),[h,g]=o.useState({}),[f,p]=o.useState({}),[u,v]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{r(!0);try{const x=await mu();if(!j)return;l(x)}catch(x){console.warn("Failed to load magic prompts:",x),B.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&r(!1)}})(),()=>{j=!1}},[t]);const w=Ql[a]??Ql["git.commit.generate"],b=o.useCallback(j=>Yl(i,j)?i[j]:Pr(j),[i]),k=o.useCallback(j=>d[j]??b(j),[d,b]),m=o.useCallback((j,D)=>{c(x=>x[j]===D?x:{...x,[j]:D})},[]),S=o.useCallback(async j=>{const D=k(j);if(Br(j)&&D.trim().length===0){B.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}g(x=>({...x,[j]:!0}));try{const x=D===Pr(j)?await Vo(j):await cu(j,D);l(x.overrides),B.success(t("settings.magicPrompts.page.toast.saved"))}catch(x){const A=x instanceof Error?x.message:String(x);B.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:A})}finally{g(x=>({...x,[j]:!1}))}},[k,t]),P=o.useCallback(async j=>{p(D=>({...D,[j]:!0}));try{const D=await Vo(j);l(D.overrides),c(x=>({...x,[j]:Pr(j)})),B.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(D){const x=D instanceof Error?D.message:String(D);B.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:x})}finally{p(D=>({...D,[j]:!1}))}},[t]),I=o.useCallback(async()=>{v(!0);try{const j=await du();l(j.overrides),c({}),B.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const D=j instanceof Error?j.message:String(j);B.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:D})}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(ns,{title:e(w.titleKey),titleAccessory:s.jsx(qt,{contentClassName:"max-w-xs",children:e(w.descriptionKey)}),headerEnd:s.jsx(G,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{I()},disabled:u||Object.keys(i).length===0,children:t(u?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:w.blocks.map((j,D)=>{const x=uu(j.id),A=b(j.id),R=k(j.id),C=Yl(i,j.id),E=R!==A,O=Br(j.id)&&R.trim().length===0,F=h[j.id]===!0,N=f[j.id]===!0;return s.jsxs(qe,{title:e(j.titleKey),info:x.description,description:x.placeholders&&x.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${x.placeholders.map(M=>`{{${M.key}}}`).join(", ")}`:void 0,divider:D>0,settingsItem:Br(j.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:R,onChange:M=>m(j.id,M.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(E?"settings.magicPrompts.page.status.unsavedChanges":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"outline",size:"sm",onClick:()=>{P(j.id)},disabled:!C||F||N,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(G,{size:"sm",onClick:()=>{S(j.id)},disabled:!E||F||N||O,children:t(F?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})})},ub=t=>{const e=at.c(89),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(null),[c,h]=o.useState(null),{selectedSnippetName:g,snippets:f,setSelectedSnippet:p,setSnippetDraft:u,deleteSnippet:v,loadSnippets:w}=Qi($s(mb));let b,k;e[0]!==w?(b=()=>{w()},k=[w],e[0]=w,e[1]=b,e[2]=k):(b=e[1],k=e[2]),o.useEffect(b,k);let m;e[3]!==a||e[4]!==p||e[5]!==u||e[6]!==f?(m=async()=>{const ae=new Set(f.map(pb));let me="new-snippet",je=1;for(;ae.has(me);)me=`new-snippet-${je++}`;u({name:me,scope:"global"}),p(me),a?.()},e[3]=a,e[4]=p,e[5]=u,e[6]=f,e[7]=m):m=e[7];const S=m;let P;e[8]!==r||e[9]!==v||e[10]!==n?(P=async()=>{if(!r)return;await v(r.name)?(B.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):B.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=v,e[10]=n,e[11]=P):P=e[11];const I=P;let j;e[12]!==f?(j=[...f].sort(gb),e[12]=f,e[13]=j):j=e[13];const D=j;let x;e[14]===Symbol.for("react.memo_cache_sentinel")?(x=Ie("flex h-full flex-col","bg-background"),e[14]=x):x=e[14];let A;e[15]!==n?(A=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=A):A=e[16];let R;e[17]!==A?(R=s.jsx("h2",{className:`${Pn} mb-3`,children:A}),e[17]=A,e[18]=R):R=e[18];let C;e[19]!==f.length||e[20]!==n?(C=n("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=n,e[21]=C):C=e[21];let E;e[22]!==C?(E=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[22]=C,e[23]=E):E=e[23];let O;e[24]!==n?(O=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=O):O=e[25];let F;e[26]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[26]=F):F=e[26];let N;e[27]!==S||e[28]!==O?(N=s.jsx(G,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:S,"aria-label":O,children:F}),e[27]=S,e[28]=O,e[29]=N):N=e[29];let M;e[30]!==E||e[31]!==N?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,N]}),e[30]=E,e[31]=N,e[32]=M):M=e[32];let U;e[33]!==M||e[34]!==R?(U=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[R,M]}),e[33]=M,e[34]=R,e[35]=U):U=e[35];let K;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==g||e[40]!==p||e[41]!==D||e[42]!==n){let ae;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==g||e[48]!==p||e[49]!==n?(ae=me=>s.jsxs(ha,{open:c===me.name,onOpenChange:je=>h(je?me.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g===me.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je=>{je.preventDefault(),h(me.name)}}),children:[s.jsxs("button",{onClick:()=>{p(me.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",me.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.${me.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:me.description||me.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(zn,{open:l===me.name,onOpenChange:je=>{je&&h(null),d(je?me.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{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:me.name}),children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:s.jsxs(wn,{onClick:je=>{je.stopPropagation(),i(me)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:s.jsxs(pa,{onClick:je=>{je.stopPropagation(),i(me)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${me.source}:${me.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=g,e[48]=p,e[49]=n,e[50]=ae):ae=e[50],K=D.map(ae),e[36]=a,e[37]=l,e[38]=c,e[39]=g,e[40]=p,e[41]=D,e[42]=n,e[43]=K}else K=e[43];let W;e[51]!==K?(W=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:K}),e[51]=K,e[52]=W):W=e[52];const te=r!==null;let Q;e[53]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>{ae||i(null)},e[53]=Q):Q=e[53];let H;e[54]!==n?(H=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=H):H=e[55];let _;e[56]!==H?(_=s.jsx(Vt,{children:H}),e[56]=H,e[57]=_):_=e[57];const V=r?.name??"";let X;e[58]!==n||e[59]!==V?(X=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=X):X=e[60];let $;e[61]!==X?($=s.jsx(Ht,{children:X}),e[61]=X,e[62]=$):$=e[62];let ee;e[63]!==_||e[64]!==$?(ee=s.jsxs(Bt,{children:[_,$]}),e[63]=_,e[64]=$,e[65]=ee):ee=e[65];let L;e[66]===Symbol.for("react.memo_cache_sentinel")?(L=()=>i(null),e[66]=L):L=e[66];let Y;e[67]!==n?(Y=n("settings.common.actions.cancel"),e[67]=n,e[68]=Y):Y=e[68];let oe;e[69]!==Y?(oe=s.jsx(G,{size:"sm",variant:"ghost",onClick:L,children:Y}),e[69]=Y,e[70]=oe):oe=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let ge;e[73]!==I||e[74]!==de?(ge=s.jsx(G,{size:"sm",onClick:I,children:de}),e[73]=I,e[74]=de,e[75]=ge):ge=e[75];let ce;e[76]!==oe||e[77]!==ge?(ce=s.jsxs(as,{children:[oe,ge]}),e[76]=oe,e[77]=ge,e[78]=ce):ce=e[78];let Se;e[79]!==ee||e[80]!==ce?(Se=s.jsxs(Ut,{className:"max-w-md",children:[ee,ce]}),e[79]=ee,e[80]=ce,e[81]=Se):Se=e[81];let ie;e[82]!==te||e[83]!==Se?(ie=s.jsx(_t,{open:te,onOpenChange:Q,children:Se}),e[82]=te,e[83]=Se,e[84]=ie):ie=e[84];let be;return e[85]!==U||e[86]!==W||e[87]!==ie?(be=s.jsxs("div",{className:x,children:[U,W,ie]}),e[85]=U,e[86]=W,e[87]=ie,e[88]=be):be=e[88],be};function mb(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function pb(t){return t.name}function gb(t,e){return t.name.localeCompare(e.name)}const hb=()=>{const{t}=Ze(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=Qi($s(x=>({selectedSnippetName:x.selectedSnippetName,snippets:x.snippets,snippetDraft:x.snippetDraft,setSnippetDraft:x.setSnippetDraft,updateSnippet:x.updateSnippet,createSnippet:x.createSnippet}))),d=o.useMemo(()=>e?a.find(x=>x.name===e||x.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!d),[h,g]=o.useState(""),[f,p]=o.useState("global"),[u,v]=o.useState(""),[w,b]=o.useState(""),[k,m]=o.useState(""),[S,P]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(c&&n){const x={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};g(x.draftName),p(x.draftScope),v(x.description),b(x.aliases),m(x.content),I.current=x}else if(d){const x={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};v(x.description),b(x.aliases),m(x.content),I.current=x}},[d,c,e,n]);const j=o.useMemo(()=>{const x=I.current;return x?c&&h!==x.draftName||c&&f!==x.draftScope?!0:u!==x.description||w!==x.aliases||k!==x.content:!1},[w,k,u,h,f,c]),D=async()=>{const x=c?h.trim().replace(/\s+/g,"-"):e?.trim();if(!x){B.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){B.error(t("settings.snippets.page.toast.contentRequired"));return}const A=w.split(",").map(R=>R.trim()).filter(Boolean);P(!0);try{if(!(c?await l(x,k,{aliases:A,description:u,scope:f}):await i(x,{content:k,aliases:A,description:u}))){B.error(t("settings.snippets.page.toast.saveFailed"));return}B.success(t("settings.snippets.page.toast.saved")),c&&r(null)}finally{P(!1)}};return e?s.jsxs(ns,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:d?d.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(qe,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Ct,{label:"#",children:[s.jsx(We,{value:h,onChange:x=>g(x.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Tt,{value:f,onValueChange:x=>p(x),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(mt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Ot,{label:t("settings.common.field.description"),children:s.jsx(We,{value:u,onChange:x=>v(x.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Ot,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(We,{value:w,onChange:x=>b(x.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(qe,{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(qt,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:k,onChange:x=>m(x.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(G,{onClick:D,disabled:S||!j,size:"xs",className:"!font-normal",children:t(S?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},hd=()=>{const{t}=Ze(),e=it(f=>f.settingsGitmojiEnabled),a=it(f=>f.setSettingsGitmojiEnabled),n=am(),r=fe(f=>f.gitChangesViewMode),i=fe(f=>f.setGitChangesViewMode),[l,d]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const p=await An();p&&(p.gitmojiEnabled!==void 0&&a(p.gitmojiEnabled),p.gitChangesViewMode!==void 0&&i(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{d(!1)}})()},[i,a]);const h=o.useCallback(async f=>{a(f);try{await ft({gitmojiEnabled:f})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),g=o.useCallback(f=>{f!==r&&(i(f),ft({gitChangesViewMode:f}))},[r,i]);return l?null:s.jsx(qe,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:cs,children:[s.jsx(ws,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(sn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(f=>s.jsx(ks,{selected:r===f.id,onSelect:()=>{g(f.id)},label:f.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:f.label})},f.id))})}),s.jsx(gt,{settingsItem:"git.gitmoji",checked:e,onChange:f=>{h(f)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(gt,{settingsItem:"git.gitignored-files",checked:n,onChange:im,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Zl=[{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)"}],fb=[{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"}],xb=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:r}=Ze(),i=oa($=>$.getProfileById),l=oa($=>$.createProfile),d=oa($=>$.updateProfile),c=oa($=>$.deleteProfile),h=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),g=a==="new"||n!=null,f=a==="global",[p,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(""),[m,S]=o.useState("ssh"),[P,I]=o.useState(""),[j,D]=o.useState(!1),[x,A]=o.useState(""),[R,C]=o.useState(""),[E,O]=o.useState("keyword"),[F,N]=o.useState("branch"),[M,U]=o.useState(!1),[K,W]=o.useState(!1),[te,Q]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const $=n.host.split("/"),ee=$.length>=3?$[$.length-1]:n.host;u(ee),w(n.username),k(""),S("token"),I(""),D(!1),A(""),C(n.host),O("string"),N("code")}else if(g)u(""),w(""),k(""),S("ssh"),I(""),D(!1),A(""),C(""),O("keyword"),N("branch");else if(h)u(h.name),w(h.userName),k(h.userEmail),S(h.authType||"ssh"),I(h.sshKey||""),D(h.signCommits===!0),A(h.signingKey||""),C(h.host||""),O(h.color||"keyword"),N(h.icon||"branch");else if(f){const $=i("global");$&&(u($.name),w($.userName),k($.userEmail),S($.authType||"ssh"),I($.sshKey||""),D(!1),A(""),C($.host||""),O($.color||"keyword"),N($.icon||"branch"))}}},[t,a,h,g,n,f,i]);const H=async()=>{if(!v.trim()||!b.trim()){B.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(m==="token"&&!R.trim()){B.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!x.trim()){B.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}U(!0);try{const $={name:p.trim()||v.trim(),userName:v.trim(),userEmail:b.trim(),authType:m,sshKey:m==="ssh"&&P.trim()||null,signCommits:j,signingKey:x.trim()||null,host:m==="token"&&R.trim()||null,color:E,icon:F};let ee;if(g)ee=await l($);else if(a)ee=await d(a,$);else return;ee?(B.success(r(g?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):B.error(r(g?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch($){console.error("Error saving profile:",$),B.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{U(!1)}},_=async()=>{if(!(!a||g)){Q(!0);try{await c(a)?(B.success(r("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):B.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch($){console.error("Error deleting profile:",$),B.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{Q(!1)}}},V=o.useMemo(()=>Zl.find(ee=>ee.key===E)?.cssVar||"var(--syntax-keyword)",[E]),X=n?r("settings.gitIdentities.editor.title.importCredential"):g?r("settings.gitIdentities.editor.title.newIdentity"):f?r("settings.gitIdentities.editor.title.globalIdentity"):h?.name||r("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:X}),s.jsx(Ht,{children:r(f?"settings.gitIdentities.editor.description.globalReadOnly":g?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!f&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Nt} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(We,{value:p,onChange:$=>u($.target.value),placeholder:r("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:r("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Zl.map($=>s.jsx("button",{type:"button",onClick:()=>O($.key),className:Ie("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",E===$.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:$.cssVar},title:$.label},$.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:fb.map($=>{const ee=$.Icon;return s.jsx("button",{type:"button",onClick:()=>N($.key),className:Ie("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",F===$.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:$.label,children:s.jsx(z,{name:ee,className:"w-3.5 h-3.5",style:{color:F===$.key?V:"var(--surface-muted-foreground)"}})},$.key)})})]})]}),!f&&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:Nt,children:r("settings.gitIdentities.editor.field.userName")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(We,{value:v,onChange:$=>w($.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!f,readOnly:f,disabled:f,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:Nt,children:r("settings.gitIdentities.editor.field.emailAddress")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(We,{type:"email",value:b,onChange:$=>k($.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!f,readOnly:f,disabled:f,className:"h-8"})]})]}),!f&&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:r("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="ssh",onClick:()=>S("ssh"),children:[s.jsx(z,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="token",onClick:()=>S("token"),children:[s.jsx(z,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),m==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Nt,children:r("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(We,{value:P,onChange:$=>I($.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(gt,{checked:j,onChange:D,label:r("settings.gitIdentities.editor.field.signCommits"),info:r("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:r("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:Nt,children:r("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(We,{value:x,onChange:$=>A($.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]}),m==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Nt,children:r("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(We,{value:R,onChange:$=>C($.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(as,{className:"gap-2",children:[!f&&!g&&s.jsxs(G,{variant:"outline",size:"sm",onClick:()=>W(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(z,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),s.jsx(G,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(f?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!f&&s.jsx(G,{size:"sm",onClick:H,disabled:M,children:r(M?"settings.common.actions.saving":g?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(_t,{open:K,onOpenChange:$=>{te||W($)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:r("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ht,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:h?.name||p})})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"ghost",onClick:()=>W(!1),disabled:te,children:r("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:te,children:r("settings.common.actions.delete")})]})]})})]})},bb={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},vb={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},yb=()=>{const t=at.c(112),{t:e}=Ze(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:h,setDefaultGitIdentityId:g,getUnimportedCredentials:f}=oa($s(wb)),[p,u]=o.useState(!1),[v,w]=o.useState(null),[b,k]=o.useState(null),[m,S]=o.useState(null),[P,I]=o.useState(!1);let j,D;t[0]!==h||t[1]!==c||t[2]!==d||t[3]!==l?(j=()=>{l(),d(),c(),h()},D=[l,d,c,h],t[0]=h,t[1]=c,t[2]=d,t[3]=l,t[4]=j,t[5]=D):(j=t[4],D=t[5]),o.useEffect(j,D);let x,A,R,C,E,O,F,N,M,U,K,W,te,Q;if(t[6]!==r||t[7]!==m||t[8]!==i||t[9]!==f||t[10]!==n||t[11]!==a||t[12]!==g||t[13]!==e){const Pe=f();let J;t[28]===Symbol.for("react.memo_cache_sentinel")?(J=(_e,Me)=>{w(_e),k(Me??null),u(!0)},t[28]=J):J=t[28];const se=J;let he;t[29]!==r||t[30]!==g||t[31]!==e?(he=async _e=>{const Me=r===_e?null:_e;if(!await g(Me)){B.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}B.success(e(Me?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=g,t[31]=e,t[32]=he):he=t[32];const ve=he;let Fe;t[33]!==m||t[34]!==i||t[35]!==e?(Fe=async()=>{if(!m)return;I(!0),await i(m.id)?(B.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:m.name})),S(null)):B.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=m,t[34]=i,t[35]=e,t[36]=Fe):Fe=t[36],R=Fe,A=ns,t[37]!==e?(E=e("settings.page.git.title"),t[37]=e,t[38]=E):E=t[38],O=!0,x=qe,t[39]!==e?(W=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=W):W=t[40],te=!1;let Ke,Be;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>se("new"),Be=s.jsx(z,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ke,t[42]=Be):(Ke=t[41],Be=t[42]);let ze;t[43]!==e?(ze=e("settings.common.badge.new"),t[43]=e,t[44]=ze):ze=t[44],t[45]!==ze?(Q=s.jsxs(G,{size:"sm",variant:"outline",onClick:Ke,children:[Be," ",ze]}),t[45]=ze,t[46]=Q):Q=t[46],C="git.identities",F="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",N=n&&s.jsx(Xl,{profile:n,isDefault:r==="global",onEdit:()=>se("global"),onToggleDefault:()=>ve("global"),isReadOnly:!0,hasBorder:a.length>0||Pe.length>0}),M=a.map((_e,Me)=>s.jsx(Xl,{profile:_e,isDefault:r===_e.id,onEdit:()=>se(_e.id),onToggleDefault:()=>ve(_e.id),onDelete:()=>S(_e),hasBorder:Me<a.length-1||Pe.length>0},_e.id)),U=!n&&a.length===0&&Pe.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),K=Pe.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")})}),Pe.map((_e,Me)=>s.jsx(jb,{credential:_e,onImport:()=>se("new",{host:_e.host,username:_e.username}),hasBorder:Me<Pe.length-1},`${_e.host}-${_e.username}`))]}),t[6]=r,t[7]=m,t[8]=i,t[9]=f,t[10]=n,t[11]=a,t[12]=g,t[13]=e,t[14]=x,t[15]=A,t[16]=R,t[17]=C,t[18]=E,t[19]=O,t[20]=F,t[21]=N,t[22]=M,t[23]=U,t[24]=K,t[25]=W,t[26]=te,t[27]=Q}else x=t[14],A=t[15],R=t[16],C=t[17],E=t[18],O=t[19],F=t[20],N=t[21],M=t[22],U=t[23],K=t[24],W=t[25],te=t[26],Q=t[27];let H;t[47]!==F||t[48]!==N||t[49]!==M||t[50]!==U||t[51]!==K?(H=s.jsxs("div",{className:F,children:[N,M,U,K]}),t[47]=F,t[48]=N,t[49]=M,t[50]=U,t[51]=K,t[52]=H):H=t[52];let _;t[53]!==x||t[54]!==C||t[55]!==H||t[56]!==W||t[57]!==te||t[58]!==Q?(_=s.jsx(x,{title:W,divider:te,headerAction:Q,settingsItem:C,children:H}),t[53]=x,t[54]=C,t[55]=H,t[56]=W,t[57]=te,t[58]=Q,t[59]=_):_=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(hd,{}),t[60]=V):V=t[60];let X;t[61]!==A||t[62]!==E||t[63]!==O||t[64]!==_?(X=s.jsxs(A,{title:E,showSaveStatus:O,children:[_,V]}),t[61]=A,t[62]=E,t[63]=O,t[64]=_,t[65]=X):X=t[65];let $;t[66]!==b||t[67]!==p||t[68]!==v?($=s.jsx(xb,{open:p,onOpenChange:u,profileId:v,importData:b}),t[66]=b,t[67]=p,t[68]=v,t[69]=$):$=t[69];const ee=m!==null;let L;t[70]!==P?(L=Pe=>{P||Pe||S(null)},t[70]=P,t[71]=L):L=t[71];let Y;t[72]!==e?(Y=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=Y):Y=t[73];let oe;t[74]!==Y?(oe=s.jsx(Vt,{children:Y}),t[74]=Y,t[75]=oe):oe=t[75];const de=m?.name??"";let ge;t[76]!==e||t[77]!==de?(ge=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=ge):ge=t[78];let ce;t[79]!==ge?(ce=s.jsx(Ht,{children:ge}),t[79]=ge,t[80]=ce):ce=t[80];let Se;t[81]!==oe||t[82]!==ce?(Se=s.jsxs(Bt,{children:[oe,ce]}),t[81]=oe,t[82]=ce,t[83]=Se):Se=t[83];let ie;t[84]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>S(null),t[84]=ie):ie=t[84];let be;t[85]!==e?(be=e("settings.common.actions.cancel"),t[85]=e,t[86]=be):be=t[86];let ae;t[87]!==P||t[88]!==be?(ae=s.jsx(G,{variant:"ghost",onClick:ie,disabled:P,children:be}),t[87]=P,t[88]=be,t[89]=ae):ae=t[89];let me;t[90]!==R?(me=()=>{R()},t[90]=R,t[91]=me):me=t[91];let je;t[92]!==e?(je=e("settings.common.actions.delete"),t[92]=e,t[93]=je):je=t[93];let De;t[94]!==P||t[95]!==me||t[96]!==je?(De=s.jsx(G,{size:"sm",variant:"destructive",onClick:me,disabled:P,children:je}),t[94]=P,t[95]=me,t[96]=je,t[97]=De):De=t[97];let ue;t[98]!==ae||t[99]!==De?(ue=s.jsxs(as,{children:[ae,De]}),t[98]=ae,t[99]=De,t[100]=ue):ue=t[100];let $e;t[101]!==Se||t[102]!==ue?($e=s.jsxs(Ut,{className:"max-w-md",children:[Se,ue]}),t[101]=Se,t[102]=ue,t[103]=$e):$e=t[103];let Ge;t[104]!==ee||t[105]!==L||t[106]!==$e?(Ge=s.jsx(_t,{open:ee,onOpenChange:L,children:$e}),t[104]=ee,t[105]=L,t[106]=$e,t[107]=Ge):Ge=t[107];let xe;return t[108]!==X||t[109]!==$||t[110]!==Ge?(xe=s.jsxs(s.Fragment,{children:[X,$,Ge]}),t[108]=X,t[109]=$,t[110]=Ge,t[111]=xe):xe=t[111],xe},Xl=t=>{const e=at.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:d,hasBorder:c}=t,{t:h}=Ze(),[g,f]=o.useState(!1),p=bb[a.icon||"branch"]||"git-branch",u=vb[a.color||""],v=a.authType||"ssh";let w;e[0]!==r?(w=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),r()))},e[0]=r,e[1]=w):w=e[1];const b=w;let k;e[2]!==n||e[3]!==d||e[4]!==l||e[5]!==i||e[6]!==h?(k=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:V=>{V.stopPropagation(),i()},children:h(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&l&&s.jsxs(_,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[2]=n,e[3]=d,e[4]=l,e[5]=i,e[6]=h,e[7]=k):k=e[7];const m=k,S=c&&"border-b border-[var(--surface-subtle)]";let P;e[8]!==S?(P=Ie("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",S),e[8]=S,e[9]=P):P=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=_=>{_.preventDefault(),f(!0)},e[10]=I):I=e[10];let j;e[11]!==b||e[12]!==r||e[13]!==P?(j=s.jsx("div",{className:P,onClick:r,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:I}),e[11]=b,e[12]=r,e[13]=P,e[14]=j):j=e[14];let D;e[15]!==u?(D={color:u},e[15]=u,e[16]=D):D=e[16];let x;e[17]!==p||e[18]!==D?(x=s.jsx(z,{name:p,className:"w-4 h-4 shrink-0",style:D}),e[17]=p,e[18]=D,e[19]=x):x=e[19];let A;e[20]!==a.name?(A=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=A):A=e[21];let R;e[22]!==v?(R=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]=R):R=e[23];let C;e[24]!==n||e[25]!==h?(C=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:h("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=h,e[26]=C):C=e[26];let E;e[27]!==d||e[28]!==h?(E=d&&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:h("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=h,e[29]=E):E=e[29];let O;e[30]!==R||e[31]!==C||e[32]!==E||e[33]!==A?(O=s.jsxs("div",{className:"flex items-center gap-1.5",children:[A,R,C,E]}),e[30]=R,e[31]=C,e[32]=E,e[33]=A,e[34]=O):O=e[34];const F=v==="token"&&a.host?a.host:a.userEmail;let N;e[35]!==F?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:F}),e[35]=F,e[36]=N):N=e[36];let M;e[37]!==O||e[38]!==N?(M=s.jsxs("div",{className:"min-w-0",children:[O,N]}),e[37]=O,e[38]=N,e[39]=M):M=e[39];let U;e[40]!==M||e[41]!==x?(U=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[x,M]}),e[40]=M,e[41]=x,e[42]=U):U=e[42];let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:kb,children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=K):K=e[43];let W;e[44]!==m?(W=s.jsxs(zn,{children:[K,s.jsx(_n,{align:"end",className:"w-fit min-w-28",children:m(wn)})]}),e[44]=m,e[45]=W):W=e[45];let te;e[46]!==U||e[47]!==W||e[48]!==j?(te=s.jsxs(ga,{render:j,children:[U,W]}),e[46]=U,e[47]=W,e[48]=j,e[49]=te):te=e[49];let Q;e[50]!==m?(Q=s.jsx(ma,{className:"w-fit min-w-28",children:m(pa)}),e[50]=m,e[51]=Q):Q=e[51];let H;return e[52]!==g||e[53]!==te||e[54]!==Q?(H=s.jsxs(ha,{open:g,onOpenChange:f,children:[te,Q]}),e[52]=g,e[53]=te,e[54]=Q,e[55]=H):H=e[55],H},jb=t=>{const e=at.c(21),{credential:a,onImport:n,hasBorder:r}=t,{t:i}=Ze();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const d=l,c=d.length>=3?d[d.length-1]:a.host,h=a.host.includes("/"),g=r&&"border-b border-[var(--surface-subtle)]";let f;e[2]!==g?(f=Ie("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",g),e[2]=g,e[3]=f):f=e[3];let p;e[4]!==c?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=p):p=e[5];const u=h?a.host:a.username;let v;e[6]!==u?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:u}),e[6]=u,e[7]=v):v=e[7];let w;e[8]!==p||e[9]!==v?(w=s.jsxs("div",{className:"min-w-0",children:[p,v]}),e[8]=p,e[9]=v,e[10]=w):w=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(z,{name:"download",className:"h-3 w-3"}),e[11]=b):b=e[11];let k;e[12]!==i?(k=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=k):k=e[13];let m;e[14]!==n||e[15]!==k?(m=s.jsxs(G,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[b,k]}),e[14]=n,e[15]=k,e[16]=m):m=e[16];let S;return e[17]!==m||e[18]!==f||e[19]!==w?(S=s.jsxs("div",{className:f,children:[w,m]}),e[17]=m,e[18]=f,e[19]=w,e[20]=S):S=e[20],S};function wb(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 kb(t){return t.stopPropagation()}const fd=({guest:t})=>{const{t:e}=Ze(),a=t.integration,n=Dr(L=>L.byId[t.id]),r=Dr(L=>L.setStatus),i=o.useMemo(()=>Mc(t.id,t.icon,Bc().authenticatedAsset),[t.id,t.icon]),l=Dr(L=>L.refresh),[d,c]=o.useState(!1),[h,g]=o.useState(!1),[f,p]=o.useState(!1),[u,v]=o.useState(""),[w,b]=o.useState(""),[k,m]=o.useState(""),[S,P]=o.useState(""),[I,j]=o.useState({}),[D,x]=o.useState(!1),A=o.useRef(null),[R]=o.useState(jn),C=o.useRef(!0),E=()=>C.current&&jn()===R,O=o.useCallback(()=>{A.current!=null&&(window.clearInterval(A.current),A.current=null),p(!1)},[]);if(o.useEffect(()=>(C.current=!0,l(t.id),()=>{C.current=!1,O()}),[t.id,l,O]),o.useEffect(()=>{n&&j(n.settings)},[n]),!a)return null;const F=a.auth,N=F==="token"&&a.token?.scheme==="basic",M=!!n?.connection.connected,U=n?.connection.account.trim()||"",K=f?e("settings.integrations.guests.status.waiting"):M?U||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),W=f?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":M?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",te=f||d,Q=a.name,H=async()=>{if(!E())return!1;const L=u.trim();if(!L)return n?.hasClient?!0:(B.error(e("settings.integrations.guests.toast.clientRequired")),!1);os("saving");const Y=await Jm(t.id,L,w.trim()||void 0);return E()?Y?(r(t.id,Y),b(""),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.saveFailed",{name:Q})),!1):!1},_=async(L=I)=>{if(!E())return!1;const Y=n?.settings??{};if((a.settings??[]).every(ce=>(L[ce.id]??"").trim()===(Y[ce.id]??"")))return!0;os("saving");const ge=await $m(t.id,L);return E()?ge?(r(t.id,ge),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.saveFailed",{name:Q})),!1):!1},V=async()=>{if(!E())return!1;const L=k.trim();if(!L)return M?!0:(B.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const Y=S.trim();if(N&&!Y)return B.error(e("settings.integrations.guests.toast.usernameRequired")),!1;os("saving");const oe=await Wm(t.id,L,N?Y:void 0);return E()?oe?(r(t.id,oe),m(""),P(""),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},X=async()=>{if(!E())return;O(),g(!0);const L=n?.connection??{connected:!1,account:""};try{if(F==="token"){if(await V()){if((a.settings??[]).length>0&&!await _()||!E())return;B.success(e("settings.integrations.guests.toast.connected",{name:Q}))}return}if(F==="oauth"&&!n?.hasClient&&!await H())return;const Y=await Vm(t.id);if(!E())return;if(!Y){B.error(e("settings.integrations.guests.toast.startFailed",{name:Q}));return}p(!0),c(!0),yn(Y);const oe=Date.now()+Hm;A.current=window.setInterval(()=>{(async()=>{if(!E()){O();return}if(Date.now()>oe){O(),B.error(e("settings.integrations.guests.toast.authorizationFailed",{name:Q}));return}const de=await l(t.id);E()&&de&&qm(L,de.connection)&&(O(),B.success(e("settings.integrations.guests.toast.connected",{name:Q})),ls()&&Vc())})()},Gm)}catch(Y){if(!E())return;console.error("Failed to start guest connect:",Y),B.error(e("settings.integrations.guests.toast.startFailed",{name:Q})),O()}finally{E()&&g(!1)}},$=async()=>{if(E()){g(!0);try{O();const L=await Bm(t.id);if(!E())return;if(!L){B.error(e("settings.integrations.guests.toast.disconnectFailed",{name:Q}));return}r(t.id,L),B.success(e("settings.integrations.guests.toast.disconnected",{name:Q}))}catch(L){if(!E())return;console.error("Failed to disconnect guest:",L),B.error(e("settings.integrations.guests.toast.disconnectFailed",{name:Q}))}finally{E()&&g(!1)}}},ee=async()=>{const L=n?.redirectUri??"";!L||!(await za(L)).ok||(x(!0),window.setTimeout(()=>x(!1),1500))};return s.jsx(kn,{open:te,onOpenChange:L=>{if(f){c(!0);return}c(L)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Nn,{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(Rc,{icon:Oc(t.icon),iconSrc:i,className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:Q}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:a.description})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",W),children:K}),s.jsx(z,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",te&&"rotate-180")})]}),s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[F==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Ot,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:u,onChange:L=>v(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}),s.jsx(Ot,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(We,{type:"password",value:w,onChange:L=>b(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})})]}):null,N?s.jsx(Ot,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:S,onChange:L=>P(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,F==="token"?s.jsx(Ot,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(We,{type:"password",value:k,onChange:L=>m(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,(a.settings??[]).map(L=>s.jsx(Ot,{label:L.label,controlClassName:"w-full max-w-none",children:s.jsx(We,{value:I[L.id]??"",onChange:Y=>{j(oe=>({...oe,[L.id]:Y.target.value}))},onBlur:()=>{_()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})},L.id)),F==="oauth"?s.jsxs(Ot,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(We,{value:n?.redirectUri??"",readOnly:!0,className:"h-8 min-w-0 flex-1 rounded-md px-3"}),s.jsx(G,{type:"button",size:"sm",variant:"outline",disabled:!n?.redirectUri,onClick:()=>{ee()},children:e(D?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:M?s.jsx(G,{type:"button",size:"sm",variant:"destructive",disabled:h,onClick:()=>{$()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(G,{type:"button",size:"sm",disabled:h||f,onClick:()=>{X()},children:[h?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},Nb=t=>{const e=at.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:r}=Ze(),i=Hs(Sb),l=Hs(Cb);let d;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0],o.useEffect(Ib,d),fs()||Hc())return null;let c,h,g,f,p,u,v,w;if(e[1]!==n||e[2]!==i||e[3]!==l||e[4]!==r){w=Symbol.for("react.early_return_sentinel");e:{const k=i.filter(Pb);if(k.length===0){w=null;break e}c=qe,e[13]!==r?(h=r("settings.integrations.guests.title"),e[13]=r,e[14]=h):h=e[14],e[15]!==r?(g=r("settings.integrations.guests.info"),e[15]=r,e[16]=g):g=e[16],f=n,p="integrations.guests",u="space-y-3";let m;e[17]!==l?(m=S=>s.jsx(fd,{guest:S},`${l}:${S.id}`),e[17]=l,e[18]=m):m=e[18],v=k.map(m)}e[1]=n,e[2]=i,e[3]=l,e[4]=r,e[5]=c,e[6]=h,e[7]=g,e[8]=f,e[9]=p,e[10]=u,e[11]=v,e[12]=w}else c=e[5],h=e[6],g=e[7],f=e[8],p=e[9],u=e[10],v=e[11],w=e[12];if(w!==Symbol.for("react.early_return_sentinel"))return w;let b;return e[19]!==c||e[20]!==h||e[21]!==g||e[22]!==f||e[23]!==p||e[24]!==u||e[25]!==v?(b=s.jsx(c,{title:h,info:g,divider:f,settingsItem:p,contentClassName:u,children:v}),e[19]=c,e[20]=h,e[21]=g,e[22]=f,e[23]=p,e[24]=u,e[25]=v,e[26]=b):b=e[26],b};function Sb(t){return t.guests}function Cb(t){return t.runtimeKey}function Ib(){Fn()}function Pb(t){return t.source!=="bundled"&&t.integration&&wo(t)}const Ab=({embedded:t=!1})=>{const{t:e}=Ze(),{isMobile:a}=Qn(),n=Va()?.github,r=Gn(N=>N.status),i=Gn(N=>N.isLoading),l=Gn(N=>N.hasChecked),d=Gn(N=>N.refreshStatus),c=Gn(N=>N.setStatus),h=o.useCallback(async N=>{await yn(N)},[]),[g,f]=o.useState(!1),[p,u]=o.useState(null),[v,w]=o.useState(null),b=o.useRef(null),k=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),w(null)},[]);o.useEffect(()=>((async()=>{try{l||await d(n)}catch(N){console.warn("Failed to load GitHub auth status:",N)}})(),()=>{k()}),[l,d,n,k]);const m=o.useCallback(async()=>{f(!0);try{const N=n?await n.authStart():await(async()=>{const U=await St("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),K=await U.json().catch(()=>null);if(!U.ok||!K||!("deviceCode"in K))throw new Error(K?.error||U.statusText);return K})();u(N),w(Math.max(1,N.interval)*1e3);const M=N.verificationUriComplete||N.verificationUri;h(M)}catch(N){console.error("Failed to start GitHub connect:",N),B.error(e("settings.github.page.toast.startConnectFailed"))}finally{f(!1)}},[h,n,e]),S=o.useCallback(async N=>{if(n)return n.authComplete(N);const M=await St("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:N})}),U=await M.json().catch(()=>null);if(!M.ok||!U)throw new Error(U?.error||M.statusText);return U},[n]);o.useEffect(()=>{if(!(!p?.deviceCode||!v)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const N=await S(p.deviceCode);if(N.connected){B.success(e("settings.github.page.toast.connected")),u(null),k(),await d(n,{force:!0});return}N.status==="slow_down"&&w(M=>M?M+5e3:5e3),(N.status==="expired_token"||N.status==="access_denied")&&(B.error(N.error||e("settings.github.page.toast.authorizationFailed")),u(null),k())}catch(N){console.warn("GitHub polling failed:",N)}})()},v),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[p,v,S,d,n,k,e]);const P=o.useCallback(async N=>{f(!0);try{if(n)await n.authSetGhCliDisabled(N);else{const M=await St("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:N})}),U=await M.json().catch(()=>null);if(!M.ok)throw new Error(U?.error||M.statusText)}B.success(e(N?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await d(n,{force:!0})}catch(M){console.error("Failed to update gh CLI setting:",M),B.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{f(!1)}},[d,n,e]),I=o.useCallback(async()=>{f(!0);try{if(k(),u(null),n)await n.authDisconnect();else{const N=await St("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!N.ok)throw new Error(N.statusText)}B.success(e("settings.github.page.toast.disconnected")),await d(n,{force:!0})}catch(N){console.error("Failed to disconnect GitHub:",N),B.error(e("settings.github.page.toast.disconnectFailed"))}finally{f(!1)}},[d,n,k,e]),j=o.useCallback(async N=>{if(N){f(!0);try{const M=n?await n.authActivate(N):await(async()=>{const U=await St("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:N})}),K=await U.json().catch(()=>null);if(!U.ok||!K)throw new Error(K?.error||U.statusText);return K})();c(M),B.success(e("settings.github.page.toast.accountSwitched"))}catch(M){console.error("Failed to switch GitHub account:",M),B.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{f(!1)}}},[n,c,e]);if(i&&!l)return null;const D=!!r?.connected,x=r?.user,R=(r?.accounts??[]).filter(N=>!N.current),C=r?.ghCli??null,E=C?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),O=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[D?s.jsxs("div",{className:Ie("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Ie("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[x?.avatarUrl?s.jsx("img",{src:x.avatarUrl,alt:x.login?e("settings.github.page.avatarAlt.withLogin",{login:x.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:x?.name?.trim()||x?.login||"GitHub"}),s.jsxs("div",{className:Ie("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:x?.login||e("settings.github.page.label.unknownUser")}),x?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),x?.email&&s.jsx("span",{children:x.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:E})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:r.scope})}),C?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),C?.active?s.jsx(G,{size:"sm",variant:"outline",onClick:()=>P(!0),disabled:g,className:Ie(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(G,{size:"sm",variant:"outline",onClick:I,disabled:g,className:Ie("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(G,{size:"sm",variant:"default",onClick:m,disabled:g,children:e("settings.github.page.actions.connect")})]}),R.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:R.map(N=>{const M=N.user,U=N.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[M?.avatarUrl?s.jsx("img",{src:M.avatarUrl,alt:M.login?e("settings.github.page.avatarAlt.withLogin",{login:M.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:M?.name?.trim()||M?.login||"GitHub"}),M?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:M.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:U})]})]})]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>j(N.id),disabled:g,children:e("settings.github.page.actions.switchTo")})]},N.id)})})]})]}),D&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(G,{size:"sm",variant:"outline",onClick:m,disabled:g,className:Ie(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),p&&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(Cn,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:p.userCode}),s.jsx(G,{size:"sm",asChild:!0,children:s.jsx("a",{href:p.verificationUriComplete||p.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(G,{size:"sm",variant:"ghost",disabled:g,onClick:()=>{k(),u(null)},children:e("settings.common.actions.cancel")})]})]})]}),F=C?.available&&!C?.active&&(!C.user||C.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:Ie("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Ie("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[C.user?.avatarUrl?s.jsx("img",{src:C.user.avatarUrl,alt:C.user.login?e("settings.github.page.avatarAlt.withLogin",{login:C.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!C.disabled&&C.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:C.user.name?.trim()||C.user.login||"GitHub"}),!C.disabled&&C.user?.login&&s.jsxs("div",{className:Ie("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:C.user.login}),C.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),C.user.email&&s.jsx("span",{children:C.user.email})]}),s.jsx("div",{className:Ie("typography-meta text-muted-foreground",C.disabled?"opacity-60":void 0),children:C.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>P(!C.disabled),disabled:g,className:Ie(a?"w-full":void 0),children:C.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[O,F?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Cn,{children:e("settings.github.page.ghCli.title")}),F]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:O}),F?s.jsx(qe,{title:e("settings.github.page.ghCli.title"),children:F}):null]})},Tb=()=>{const t=at.c(37),{t:e}=Ze(),a=Gn(Eb),n=Gn(Db),r=Gn(Mb),[i,l]=o.useState(!1),d=a?.connected===!0;let c;t[0]!==d||t[1]!==r||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!r?e("common.loading"):d?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=d,t[1]=r,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const h=c,g=d?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let f;t[6]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=f):f=t[6];let p;t[7]!==e?(p=e("settings.integrations.github.title"),t[7]=e,t[8]=p):p=t[8];let u;t[9]!==p?(u=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:p}),t[9]=p,t[10]=u):u=t[10];let v;t[11]!==e?(v=e("settings.integrations.github.description"),t[11]=e,t[12]=v):v=t[12];let w;t[13]!==v?(w=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:v}),t[13]=v,t[14]=w):w=t[14];let b;t[15]!==u||t[16]!==w?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[u,w]}),t[15]=u,t[16]=w,t[17]=b):b=t[17];let k;t[18]!==g?(k=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",g),t[18]=g,t[19]=k):k=t[19];let m;t[20]!==h||t[21]!==k?(m=s.jsx("span",{"aria-live":"polite",className:k,children:h}),t[20]=h,t[21]=k,t[22]=m):m=t[22];const S=i&&"rotate-180";let P;t[23]!==S?(P=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",S),t[23]=S,t[24]=P):P=t[24];let I;t[25]!==P?(I=s.jsx(z,{name:"arrow-down-s",className:P}),t[25]=P,t[26]=I):I=t[26];let j;t[27]!==I||t[28]!==b||t[29]!==m?(j=s.jsxs(Nn,{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:[f,b,m,I]}),t[27]=I,t[28]=b,t[29]=m,t[30]=j):j=t[30];let D;t[31]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(Ab,{embedded:!0})}),t[31]=D):D=t[31];let x;t[32]!==j?(x=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[j,D]}),t[32]=j,t[33]=x):x=t[33];let A;return t[34]!==i||t[35]!==x?(A=s.jsx(kn,{open:i,onOpenChange:l,children:x}),t[34]=i,t[35]=x,t[36]=A):A=t[36],A};function Eb(t){return t.status}function Db(t){return t.isLoading}function Mb(t){return t.hasChecked}const Ui="__none__",zi="__inherit__";function Rb({linear:t,connected:e,organizationId:a}){const{t:n}=Ze(),r=rn(b=>b.projects),[i,l]=o.useState(null),[d,c]=o.useState(!1),[h,g]=o.useState(!1),f=o.useCallback(async()=>{if(!e){l(null),c(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){l(null),c(!1);return}l(b),c(!1)}catch(b){console.error("Failed to load Linear mapping:",b),c(!0)}},[e,t]);o.useEffect(()=>{f()},[f,a]);const p=o.useCallback(async b=>{const k={};for(const m of b.teams??[])m.projectPath&&(k[m.id]=m.projectPath);g(!0),os("saving");try{const m=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(m.connected===!1){l(null),os("error");return}l(m),c(!1),os("saved")}catch(m){console.error("Failed to save Linear mapping:",m),os("error")}finally{g(!1)}},[t]);if(!e)return null;if(d&&!i)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!i)return null;const u=b=>r.find(m=>m.path===b)?.label?.trim()||b,v=b=>!b||b===Ui?n("settings.integrations.linear.mapping.defaultProject.placeholder"):u(b),w=b=>!b||b===zi?n("settings.integrations.linear.mapping.teams.useDefault"):u(b);return s.jsxs("div",{className:Rs,children:[r.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ct,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Tt,{value:i.defaultProjectPath||Ui,disabled:h||r.length===0,onValueChange:b=>{p({...i,defaultProjectPath:b===Ui?null:b})},children:[s.jsx(Pt,{size:$t,className:an,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(zt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:v})}),s.jsxs(At,{children:[s.jsx(mt,{value:Ui,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),i.defaultProjectPath&&!r.some(b=>b.path===i.defaultProjectPath)?s.jsx(mt,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,r.map(b=>s.jsx(mt,{value:b.path,children:u(b.path)},b.id))]})]})}),s.jsx(ws,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(i.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Rs,children:(i.teams??[]).map(b=>s.jsx(Ct,{label:`${b.key} · ${b.name}`,children:s.jsxs(Tt,{value:b.projectPath||zi,disabled:h||r.length===0,onValueChange:k=>{p({...i,teams:(i.teams??[]).map(m=>m.id===b.id?{...m,projectPath:k===zi?null:k}:m)})},children:[s.jsx(Pt,{size:$t,className:an,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(zt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:w})}),s.jsxs(At,{children:[s.jsx(mt,{value:zi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!r.some(k=>k.path===b.projectPath)?s.jsx(mt,{value:b.projectPath,children:b.projectPath}):null,r.map(k=>s.jsx(mt,{value:k.path,children:u(k.path)},k.id))]})]})},b.id))})})]})}function Ob({linear:t,connected:e}){const{t:a}=Ze(),[n,r]=o.useState(null),[i,l]=o.useState(!1),[d,c]=o.useState(!1);o.useEffect(()=>{if(!e){r(null),l(!1);return}let g=!1;return t.preferencesGet().then(f=>{g||(r(f.sessionComments),l(!1))}).catch(()=>{g||l(!0)}),()=>{g=!0}},[e,t]);const h=o.useCallback(async g=>{const f=n;r(g),c(!0);try{const p=await t.preferencesSet({sessionComments:g});r(p.sessionComments),os("saved")}catch{r(f),os("error")}finally{c(!1)}},[n,t]);return e?i?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Rs,children:s.jsx(Ct,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(Ba,{checked:n===!0,disabled:n===null||d,onCheckedChange:g=>{h(g)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Fb=3*6e4,Lb=1500;function ec(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Kb(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const _b=()=>{const{t}=Ze(),e=Va()?.linear,a=Ma(C=>C.status),n=Ma(C=>C.isLoading),r=Ma(C=>C.hasChecked),i=Ma(C=>C.refreshStatus),l=Ma(C=>C.setStatus),[d,c]=o.useState(!1),[h,g]=o.useState(!1),[f,p]=o.useState(!1),u=o.useRef(null),v=o.useCallback(()=>{u.current!=null&&(window.clearInterval(u.current),u.current=null),g(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{v()}},[r,i,e,v]);const w=o.useCallback(async()=>{if(!e)return;v(),c(!0);const C=ec(Ma.getState().status);try{const E=await e.authStart(ls()?"desktop":"web");g(!0),p(!0),yn(E.authorizationUrl);const O=Date.now()+Fb;u.current=window.setInterval(()=>{(async()=>{if(Date.now()>O){v(),B.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const F=await i(e,{force:!0});Kb(C,ec(F))&&(v(),B.success(t("settings.integrations.linear.toast.connected")),Vc())})()},Lb)}catch(E){console.error("Failed to start Linear connect:",E),B.error(t("settings.integrations.linear.toast.startConnectFailed")),v()}finally{c(!1)}},[i,e,v,t]),b=o.useCallback(async C=>{if(!(!e||!C)){c(!0);try{const E=await e.authActivate(C);l(E),B.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(E){console.error("Failed to switch Linear workspace:",E),B.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),k=o.useCallback(async()=>{if(e){c(!0);try{v(),await e.authDisconnect(),B.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(C){console.error("Failed to disconnect Linear:",C),B.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[i,e,v,t]);if(!e)return null;const m=!!a?.connected,S=a?.user,P=a?.organization,j=(a?.workspaces??[]).filter(C=>!C.current),D=S?.displayName?.trim()||S?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),x=h?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):m?P?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),A=h?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",R=h||f;return s.jsx(kn,{open:R,onOpenChange:C=>{if(h){p(!0);return}p(C)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Nn,{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(z,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",A),children:x}),s.jsx(z,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",R&&"rotate-180")})]}),s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[m?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[S?.avatarUrl?s.jsx("img",{src:S.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:D}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:D}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[P?.name,S?.email].filter(Boolean).join(" · ")})]})]}):h?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,m?s.jsxs(s.Fragment,{children:[s.jsx(Rb,{linear:e,connected:m,organizationId:P?.id??null}),s.jsx(Ob,{linear:e,connected:m}),j.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:j.map(C=>{const E=C.user,O=C.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:O}),E?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:E.email}):null]}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(C.id)},disabled:d,children:t("settings.integrations.linear.actions.switchTo")})]},C.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{w()},disabled:d||h,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(G,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},disabled:d,children:t("settings.integrations.linear.actions.disconnect")})]})]}):h?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",disabled:d,onClick:v,children:t("settings.common.actions.cancel")})]}):s.jsxs(G,{type:"button",size:"sm",variant:"default",onClick:()=>{w()},disabled:d||n&&!r,children:[d?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Ub=()=>{const t=at.c(23),{t:e}=Ze();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=fs(),t[0]=a):a=t[0];const n=!a,r=!!Va()?.linear,i=Hs(zb),l=Hs($b);let d,c,h,g,f,p;if(t[1]!==i||t[2]!==l||t[3]!==e){const w=!fs()&&!Hc()?i.filter(Bb):[];c=n||r||w.length>0,d=ns,t[10]!==e?(h=e("settings.page.integrations.title"),t[10]=e,t[11]=h):h=t[11],t[12]!==e?(g=e("settings.page.integrations.description"),t[12]=e,t[13]=g):g=t[13],f=!0,p=c?s.jsxs(qe,{title:e("settings.integrations.firstParty.title"),info:e("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[n?s.jsx(Tb,{}):null,r?s.jsx(_b,{}):null,w.map(b=>s.jsx(fd,{guest:b},`${l}:${b.id}`))]}):null,t[1]=i,t[2]=l,t[3]=e,t[4]=d,t[5]=c,t[6]=h,t[7]=g,t[8]=f,t[9]=p}else d=t[4],c=t[5],h=t[6],g=t[7],f=t[8],p=t[9];let u;t[14]!==c?(u=s.jsx(Nb,{divider:c}),t[14]=c,t[15]=u):u=t[15];let v;return t[16]!==d||t[17]!==h||t[18]!==g||t[19]!==f||t[20]!==p||t[21]!==u?(v=s.jsxs(d,{title:h,description:g,showSaveStatus:f,children:[p,u]}),t[16]=d,t[17]=h,t[18]=g,t[19]=f,t[20]=p,t[21]=u,t[22]=v):v=t[22],v};function zb(t){return t.guests}function $b(t){return t.runtimeKey}function Bb(t){return t.source==="bundled"&&t.integration&&wo(t)}const La="__default__",Vb=500,Hb=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),qb=(t,e)=>{const a=at.c(9),n=it(Jb);let r;e:{if(!t||!e){let c;a[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],a[0]=c):c=a[0],r=c;break e}let i;if(a[1]!==e||a[2]!==t||a[3]!==n){let c;a[5]!==t?(c=g=>g.id===t,a[5]=t,a[6]=c):c=a[6],i=n.find(c)?.models.find(g=>g.id===e),a[1]=e,a[2]=t,a[3]=n,a[4]=i}else i=a[4];const l=i;let d;a[7]!==l?(d=l?.variants?Object.keys(l.variants):[],a[7]=l,a[8]=d):d=a[8],r=d}return r},xd=t=>{const e=at.c(33),{providerID:a,modelID:n,value:r,onChange:i,ariaLabel:l,className:d}=t,{t:c}=Ze(),h=qb(a,n);let g;e[0]!==c?(g=A=>A===La?c("settings.routing.thinking.default"):A.charAt(0).toUpperCase()+A.slice(1),e[0]=c,e[1]=g):g=e[1];const f=g,p=r??La;let u;e[2]!==i?(u=A=>i(A===La?null:A),e[2]=i,e[3]=u):u=e[3];const v=h.length===0;let w;e[4]!==d?(w=Ie(an,d),e[4]=d,e[5]=w):w=e[5];const b=r??La;let k;e[6]!==f||e[7]!==b?(k=f(b),e[6]=f,e[7]=b,e[8]=k):k=e[8];let m;e[9]!==k?(m=s.jsx(zt,{children:k}),e[9]=k,e[10]=m):m=e[10];let S;e[11]!==l||e[12]!==w||e[13]!==m?(S=s.jsx(Pt,{size:$t,className:w,"aria-label":l,children:m}),e[11]=l,e[12]=w,e[13]=m,e[14]=S):S=e[14];let P;e[15]!==f?(P=f(La),e[15]=f,e[16]=P):P=e[16];let I;e[17]!==P?(I=s.jsx(mt,{value:La,children:P}),e[17]=P,e[18]=I):I=e[18];let j;if(e[19]!==f||e[20]!==h){let A;e[22]!==f?(A=R=>s.jsx(mt,{value:R,children:f(R)},R),e[22]=f,e[23]=A):A=e[23],j=h.map(A),e[19]=f,e[20]=h,e[21]=j}else j=e[21];let D;e[24]!==I||e[25]!==j?(D=s.jsxs(At,{children:[I,j]}),e[24]=I,e[25]=j,e[26]=D):D=e[26];let x;return e[27]!==D||e[28]!==p||e[29]!==u||e[30]!==v||e[31]!==S?(x=s.jsxs(Tt,{value:p,onValueChange:u,disabled:v,children:[S,D]}),e[27]=D,e[28]=p,e[29]=u,e[30]=v,e[31]=S,e[32]=x):x=e[32],x},Gb=t=>{const e=at.c(49),{category:a,expanded:n,onToggle:r,onChange:i,onReset:l,onRemove:d}=t,{t:c}=Ze();let h;e[0]!==a.model||e[1]!==a.variant||e[2]!==c?(h=a.model?`${a.model.modelID}${a.variant?` / ${a.variant}`:""}`:c("settings.routing.model.useFallback"),e[0]=a.model,e[1]=a.variant,e[2]=c,e[3]=h):h=e[3];const g=h;let f;e[4]!==a.agent||e[5]!==g?(f=[g,a.agent].filter(Boolean),e[4]=a.agent,e[5]=g,e[6]=f):f=e[6];const p=f.join(" · "),u=!a.enabled&&"opacity-60";let v;e[7]!==u?(v=Ie("py-1",u),e[7]=u,e[8]=v):v=e[8];const w=n?"arrow-down-s":"arrow-right-s";let b;e[9]!==w?(b=s.jsx(z,{name:w,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[9]=w,e[10]=b):b=e[10];const k=a.name||a.id;let m;e[11]!==k?(m=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:k}),e[11]=k,e[12]=m):m=e[12];let S;e[13]!==p?(S=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:p}),e[13]=p,e[14]=S):S=e[14];let P;e[15]!==n||e[16]!==r||e[17]!==b||e[18]!==m||e[19]!==S?(P=s.jsxs("button",{type:"button",onClick:r,"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1.5 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[b,m,S]}),e[15]=n,e[16]=r,e[17]=b,e[18]=m,e[19]=S,e[20]=P):P=e[20];const I=a.enabled;let j;e[21]!==i?(j=E=>i({enabled:E}),e[21]=i,e[22]=j):j=e[22];let D;e[23]!==a.name||e[24]!==c?(D=c("settings.routing.category.enabledAria",{name:a.name}),e[23]=a.name,e[24]=c,e[25]=D):D=e[25];let x;e[26]!==a.enabled||e[27]!==j||e[28]!==D?(x=s.jsx(Ba,{checked:I,onCheckedChange:j,"aria-label":D}),e[26]=a.enabled,e[27]=j,e[28]=D,e[29]=x):x=e[29];let A;e[30]!==P||e[31]!==x?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[P,x]}),e[30]=P,e[31]=x,e[32]=A):A=e[32];let R;e[33]!==a.agent||e[34]!==a.description||e[35]!==a.model?.modelID||e[36]!==a.model?.providerID||e[37]!==a.name||e[38]!==a.variant||e[39]!==n||e[40]!==i||e[41]!==d||e[42]!==l||e[43]!==c?(R=n?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(Rn,{children:[s.jsx(Ot,{label:c("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(We,{value:a.name,onChange:E=>i({name:E.target.value}),"aria-label":c("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(Ot,{label:c("settings.routing.category.agent"),info:c("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(fo,{agentName:a.agent??"",onChange:E=>i({agent:E||null}),filter:Qb,className:Ie(Ws,"w-full")})}),s.jsx(Ot,{label:c("settings.routing.category.model"),info:c("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(ca,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(E,O)=>i({model:{providerID:E,modelID:O},variant:null}),className:Ie(Ws,"w-full"),placeholder:c("settings.routing.model.useFallback")})}),s.jsx(Ot,{label:c("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(xd,{providerID:a.model?.providerID,modelID:a.model?.modelID,value:a.variant,onChange:E=>i({variant:E}),ariaLabel:c("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(Ot,{label:c("settings.routing.category.description"),info:c("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(As,{value:a.description,onChange:E=>i({description:E.target.value}),"aria-label":c("settings.routing.category.description"),rows:5,maxLength:2e3,className:"w-full"})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l?s.jsx(G,{size:"sm",variant:"outline",onClick:l,children:c("settings.routing.category.reset")}):null,s.jsx(G,{size:"sm",variant:"ghost",onClick:d,children:c("settings.routing.category.remove")})]})]}):null,e[33]=a.agent,e[34]=a.description,e[35]=a.model?.modelID,e[36]=a.model?.providerID,e[37]=a.name,e[38]=a.variant,e[39]=n,e[40]=i,e[41]=d,e[42]=l,e[43]=c,e[44]=R):R=e[44];let C;return e[45]!==A||e[46]!==R||e[47]!==v?(C=s.jsxs("div",{className:v,children:[A,R]}),e[45]=A,e[46]=R,e[47]=v,e[48]=C):C=e[48],C},Wb=()=>{const{t}=Ze(),e=en(L=>L.available),a=en(L=>L.autoReady),n=en(L=>L.tokenPresent),r=en(L=>L.jevSource),i=en(L=>L.config),l=en(L=>L.builtins),d=en(L=>L.loaded),c=en(L=>L.loadError),h=en(L=>L.load),g=en(L=>L.saveConfig),f=en(L=>L.setToken),p=en(L=>L.clearToken),[u,v]=o.useState(i),[w,b]=o.useState(""),[k,m]=o.useState(!1),[S,P]=o.useState(null),[I,j]=o.useState(""),[D,x]=o.useState(null),A=o.useRef(null),R=o.useRef(null),C=o.useRef(Promise.resolve()),E=o.useRef(0);o.useEffect(()=>{h()},[h]),o.useEffect(()=>{!A.current&&E.current===0&&v(i)},[i]);const O=o.useCallback(()=>{const L=A.current;if(!L||(A.current=null,L.runtimeKey!==jn()))return C.current;E.current+=1,os("saving");const Y=C.current.then(async()=>{try{if(L.runtimeKey!==jn()){os("saved");return}await g(L.config),os("saved")}catch{os("error")}finally{E.current-=1}});return C.current=Y,Y},[g]);o.useEffect(()=>()=>{R.current&&clearTimeout(R.current),O()},[O]);const F=it(L=>L.settingsDefaultModel),N=it(L=>L.settingsDefaultVariant),M=o.useRef(!1);o.useEffect(()=>{if(M.current||!d||!i||i.fallback)return;const L=Ln(F);!L||qc(L.providerId,L.modelId)||(M.current=!0,U(Y=>Y.fallback?Y:{...Y,fallback:{model:{providerID:L.providerId,modelID:L.modelId},variant:N??null}}))},[d,i,F,N]);const U=o.useCallback(L=>{v(Y=>{if(!Y)return Y;const oe=L(Y);return A.current={config:oe,runtimeKey:jn()},R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,O()},Vb),oe})},[O]),K=o.useCallback((L,Y)=>{U(oe=>({...oe,categories:oe.categories.map(de=>de.id===L?{...de,...Y}:de)}))},[U]),W=async()=>{const L=w.trim();if(L){m(!0),P(null);try{await f(L),b("")}catch(Y){P(Y instanceof Error?Y.message:String(Y))}finally{m(!1)}}},te=async()=>{m(!0),P(null);try{await p()}catch(L){P(L instanceof Error?L.message:String(L))}finally{m(!1)}},Q=()=>{const L=I.trim();if(!L||!u)return;const Y=Hb(L)||`category-${Date.now()}`;let oe=Y,de=2;for(;u.categories.some(ge=>ge.id===oe);)oe=`${Y}-${de++}`;U(ge=>({...ge,categories:[...ge.categories,{id:oe,builtin:!1,enabled:!0,name:L,description:"",model:null,variant:null,agent:null}]})),j(""),x(oe)},H=L=>{const Y=l.find(oe=>oe.id===L);Y&&K(L,{name:Y.name,description:Y.description,model:null,variant:null,agent:null,enabled:!0})},_=L=>{const Y=l.find(oe=>oe.id===L);Y&&U(oe=>({...oe,categories:[...oe.categories,{id:L,builtin:!0,enabled:!0,name:Y.name,description:Y.description,model:null,variant:null,agent:null}]}))},V=L=>{U(Y=>({...Y,categories:Y.categories.filter(oe=>oe.id!==L)}))},X=u?.categories.filter(L=>L.enabled).length??0,$=l.filter(L=>!u?.categories.some(Y=>Y.id===L.id)),ee=u?.enabled?u.fallback?X<2?t("settings.routing.status.tooFewCategories"):t(a?"settings.routing.status.ready":"settings.routing.status.notReady"):t("settings.routing.status.noFallback"):t("settings.routing.status.disabled");return s.jsxs(ns,{title:t("settings.page.routing.title"),description:t("settings.page.routing.description"),showSaveStatus:!0,children:[c?s.jsx("p",{className:Vi,children:t("settings.routing.loadError",{error:c})}):null,!d||!u?null:e?s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:t("settings.routing.access.title"),divider:!1,children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.access.intro")}),s.jsx("p",{className:ys,children:r==="typesafe"?t("settings.routing.access.usingKey"):s.jsxs(s.Fragment,{children:[s.jsx("strong",{className:"font-semibold",children:t("settings.routing.access.usingFree")})," ",t("settings.routing.access.usingFreeDetails")]})}),s.jsx(Ct,{settingsItem:"routing.token",label:t("settings.routing.token.label"),info:t("settings.routing.token.info"),children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(We,{type:"password",autoComplete:"off",value:w,onChange:L=>b(L.target.value),onKeyDown:L=>{L.key==="Enter"&&W()},placeholder:t(n?"settings.routing.token.replacePlaceholder":"settings.routing.token.placeholder"),"aria-label":t("settings.routing.token.label"),className:"h-8 rounded-md px-3 min-w-0 flex-1",disabled:k}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>{W()},disabled:k||w.trim().length===0,children:t("settings.routing.token.save")}),n?s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{te()},disabled:k,children:t("settings.routing.token.remove")}):null]})}),S?s.jsx("p",{className:Vi,children:S}):null]})}),s.jsx(qe,{title:t("settings.routing.auto.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"routing.enabled",checked:u.enabled,onChange:L=>U(Y=>({...Y,enabled:L})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:ys,children:ee}),s.jsx(Ct,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(ca,{providerId:u.fallback?.model.providerID??"",modelId:u.fallback?.model.modelID??"",onChange:(L,Y)=>U(oe=>({...oe,fallback:{model:{providerID:L,modelID:Y},variant:null}})),className:Ws,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(Ct,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(xd,{providerID:u.fallback?.model.providerID,modelID:u.fallback?.model.modelID,value:u.fallback?.variant??null,onChange:L=>U(Y=>Y.fallback?{...Y,fallback:{...Y.fallback,variant:L}}:Y),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(qe,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:u.categories.map(L=>s.jsx(Gb,{category:L,expanded:D===L.id,onToggle:()=>x(Y=>Y===L.id?null:L.id),onChange:Y=>K(L.id,Y),onReset:L.builtin?()=>H(L.id):null,onRemove:()=>V(L.id)},L.id))}),$.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:$.map(L=>s.jsx(G,{size:"sm",variant:"outline",onClick:()=>_(L.id),children:t("settings.routing.category.restore",{name:L.name})},L.id))}):null,s.jsx(Ct,{label:t("settings.routing.categories.addLabel"),settingsItem:"routing.add-category",children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(We,{value:I,onChange:L=>j(L.target.value),onKeyDown:L=>{L.key==="Enter"&&Q()},placeholder:t("settings.routing.categories.addPlaceholder"),"aria-label":t("settings.routing.categories.addLabel"),className:"h-8 rounded-md px-3 min-w-0 flex-1",maxLength:60}),s.jsx(G,{size:"sm",variant:"outline",onClick:Q,disabled:I.trim().length===0,children:t("settings.routing.categories.add")})]})})]})}),s.jsx(qe,{title:t("settings.routing.safety.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.safety.description")}),s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"routing.safety-enabled",checked:u.safetyNet.enabled,onChange:L=>U(Y=>({...Y,safetyNet:{...Y.safetyNet,enabled:L}})),label:t("settings.routing.safety.enable"),ariaLabel:t("settings.routing.safety.enable"),info:t("settings.routing.safety.enableInfo")})})]})})]}):s.jsx("p",{className:Vi,children:t("settings.routing.unavailable")})]})};function Jb(t){return t.providers}function Qb(t){return Fc(t.mode)}const Yb={prompt:{icon:"chat-1",titleKey:"settings.extensions.capability.prompt",detailKey:"settings.extensions.capability.prompt.detail"},sessions:{icon:"git-branch",titleKey:"settings.extensions.capability.sessions",detailKey:"settings.extensions.capability.sessions.detail"},files:{icon:"file-text",titleKey:"settings.extensions.capability.files",detailKey:"settings.extensions.capability.files.detail"},model:{icon:"sparkling",titleKey:"settings.extensions.capability.model",detailKey:"settings.extensions.capability.model.detail"},conversation:{icon:"chat-history",titleKey:"settings.extensions.capability.conversation",detailKey:"settings.extensions.capability.conversation.detail"},filesystem:{icon:"hard-drive-2",titleKey:"settings.extensions.capability.filesystem",detailKey:"settings.extensions.capability.filesystem.detail"},service:{icon:"terminal",titleKey:"settings.extensions.capability.service",detailKey:"settings.extensions.capability.service.detail"},network:{icon:"plug",titleKey:"settings.extensions.capability.network",detailKey:"settings.extensions.capability.network.detail"}},Zb=t=>{const e=at.c(73),{guest:a,busy:n,onApprove:r,onDecline:i,onDismiss:l}=t,{t:d}=Ze();let c;e[0]!==a?.capabilities.requested?(c=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=c):c=e[1];const h=c;let g;e[2]!==a?.filesystem?(g=a?.filesystem??[],e[2]=a?.filesystem,e[3]=g):g=e[3];const f=g;let p;e[4]!==a?.service?.permissions?.exec?(p=a?.service?.permissions?.exec??[],e[4]=a?.service?.permissions?.exec,e[5]=p):p=e[5];const u=p;let v;e[6]!==a?.service?.permissions?.sockets?(v=a?.service?.permissions?.sockets??[],e[6]=a?.service?.permissions?.sockets,e[7]=v):v=e[7];const w=v,b=a?.service;let k;e[8]!==b?(k=Lc(b,"browser"),e[8]=b,e[9]=k):k=e[9];const m=k,S=a?.integration?.apiOrigin??null,P=a!==null;let I;e[10]!==n||e[11]!==l?(I=X=>{!X&&!n&&l()},e[10]=n,e[11]=l,e[12]=I):I=e[12];const j=a?.name??"";let D;e[13]!==d||e[14]!==j?(D=d("settings.extensions.dialog.approveTitle",{name:j}),e[13]=d,e[14]=j,e[15]=D):D=e[15];let x;e[16]!==D?(x=s.jsx(Vt,{children:D}),e[16]=D,e[17]=x):x=e[17];const A=a?.name??"",R=a?.version?`v${a.version}`:"";let C;e[18]!==d||e[19]!==A||e[20]!==R?(C=d("settings.extensions.dialog.approveDescription",{name:A,version:R}),e[18]=d,e[19]=A,e[20]=R,e[21]=C):C=e[21];let E;e[22]!==C?(E=s.jsx(Ht,{children:C}),e[22]=C,e[23]=E):E=e[23];let O;e[24]!==x||e[25]!==E?(O=s.jsxs(Bt,{children:[x,E]}),e[24]=x,e[25]=E,e[26]=O):O=e[26];let F;if(e[27]!==S||e[28]!==f||e[29]!==m||e[30]!==h||e[31]!==u||e[32]!==w||e[33]!==d){let X;e[35]!==S||e[36]!==f||e[37]!==m||e[38]!==u||e[39]!==w||e[40]!==d?(X=$=>{const ee=Yb[$];return s.jsxs("li",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-md bg-[var(--surface-muted)]",children:s.jsx(z,{name:ee.icon,className:"size-4 text-foreground"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:d(ee.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:d(ee.detailKey)}),$==="filesystem"&&f.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:f.map(Xb)}):null,$==="network"&&S?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:S})]}):null,$==="service"&&u.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:u.join(", ")})]}):null,$==="service"&&w.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:w.join(", ")})]}):null,$==="service"&&m?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:d("settings.extensions.capability.service.providesBrowser")}):null]})]},$)},e[35]=S,e[36]=f,e[37]=m,e[38]=u,e[39]=w,e[40]=d,e[41]=X):X=e[41],F=h.map(X),e[27]=S,e[28]=f,e[29]=m,e[30]=h,e[31]=u,e[32]=w,e[33]=d,e[34]=F}else F=e[34];let N;e[42]!==F?(N=s.jsx("ul",{className:"space-y-3",children:F}),e[42]=F,e[43]=N):N=e[43];let M;e[44]!==a||e[45]!==i?(M=()=>a&&i(a),e[44]=a,e[45]=i,e[46]=M):M=e[46];let U;e[47]!==d?(U=d("settings.extensions.dialog.decline"),e[47]=d,e[48]=U):U=e[48];let K;e[49]!==n||e[50]!==M||e[51]!==U?(K=s.jsx(G,{size:"sm",variant:"ghost",disabled:n,onClick:M,children:U}),e[49]=n,e[50]=M,e[51]=U,e[52]=K):K=e[52];let W;e[53]!==a||e[54]!==r?(W=()=>a&&r(a),e[53]=a,e[54]=r,e[55]=W):W=e[55];let te;e[56]!==d?(te=d("settings.extensions.dialog.approve"),e[56]=d,e[57]=te):te=e[57];let Q;e[58]!==n||e[59]!==W||e[60]!==te?(Q=s.jsx(G,{size:"sm",disabled:n,onClick:W,children:te}),e[58]=n,e[59]=W,e[60]=te,e[61]=Q):Q=e[61];let H;e[62]!==K||e[63]!==Q?(H=s.jsxs(as,{children:[K,Q]}),e[62]=K,e[63]=Q,e[64]=H):H=e[64];let _;e[65]!==O||e[66]!==N||e[67]!==H?(_=s.jsxs(Ut,{className:"max-w-md",children:[O,N,H]}),e[65]=O,e[66]=N,e[67]=H,e[68]=_):_=e[68];let V;return e[69]!==_||e[70]!==P||e[71]!==I?(V=s.jsx(_t,{open:P,onOpenChange:I,children:_}),e[69]=_,e[70]=P,e[71]=I,e[72]=V):V=e[72],V};function Xb(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const ev=t=>{if(t.source!=="git"||!t.origin?.url)return null;const e=t.origin.url.trim(),a=/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?([A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+):([^\s]+)$/.exec(e);try{const n=new URL(a?`ssh://${a[1]}/${a[2]}`:e);if(n.protocol!=="https:"&&n.protocol!=="ssh:")return null;const r=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return r.username="",r.password="",r.search="",r.hash="",r.pathname=r.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),r.pathname==="/"?null:r.href}catch{return null}},tv=Ts({error:Io(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","extract-failed","too-large"]),required:Dt().trim().min(1).max(64).optional(),id:Dt().trim().min(1).max(128).optional()}),sv=t=>{const e=t.trim();if(!e)return{ok:!1,code:"invalid-path"};if(e.slice(0,8).toLowerCase()==="https://")return{ok:!0,request:{url:e}};if(e.slice(0,6).toLowerCase()==="ssh://"||/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?[A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+:[^\s]+$/.test(e))return{ok:!0,request:{url:e}};const a=/^[a-zA-Z]:[\\/]/.test(e);return/^[a-z][a-z0-9+.-]*:/i.test(e)&&!a?{ok:!1,code:"invalid-url"}:e.startsWith("/")||a||e.startsWith("\\\\")?{ok:!0,request:{path:e}}:{ok:!1,code:"invalid-path"}},bd=async t=>{try{const e=tv.safeParse(JSON.parse(await t.text()));return e.success?e.data.error==="host-too-old"&&e.data.required&&e.data.id?{code:"host-too-old",required:e.data.required,id:e.data.id}:e.data.error==="host-too-old"&&e.data.required?{code:"host-too-old",required:e.data.required}:e.data.id?{code:e.data.error,id:e.data.id}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},vd=async(t,e)=>{if(!t.ok)return{ok:!1,...await bd(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:Kc(a);return n?{ok:!0,guest:n,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},nv=async(t,e={})=>{const a=sv(t);if(!a.ok)return a;const n={...a.request};e.replace&&(n.replace=!0),"url"in n&&e.gitIdentityId&&(n.gitIdentityId=e.gitIdentityId);try{const r=await St("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await vd(r,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},av=async(t,e={})=>{try{const a=await St("/api/guests/upload",{method:"POST",query:{replace:e.replace?"true":void 0,name:t.name||void 0},headers:{"Content-Type":"application/octet-stream",Accept:"application/json"},body:t});return await vd(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},iv=async t=>{try{const e=await St(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await bd(e)).code}}catch{return{ok:!1,code:"failed"}}},rv=async(t,e)=>{try{return(await St(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},ov=async(t,e)=>{try{return(await St(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},Vr=(t,e)=>{const a=`${t.method} ${t.path}`;return t.kind==="network"?`${a}: ${e("settings.extensions.request.noResponse")}`:t.kind==="invalid-response"?`${a}: ${e("settings.extensions.request.invalidResponse",{status:t.status})}`:`${a}: HTTP ${t.status}`},lv=Ts({updates:Kn(Dt().min(1),pu)}),cv=Ts({error:Io(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found"]),required:Dt().trim().min(1).max(64).optional()}),tc=async t=>{try{const e=await St("/api/guests/updates/check",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({force:t})});if(!e.ok)return{ok:!1};const a=lv.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},dv=async t=>{try{const e=cv.safeParse(JSON.parse(await t.text()));return e.success?e.data.required?{code:e.data.error,required:e.data.required}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},uv=async t=>{try{const e=await St(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await dv(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=Kc(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},mv=t=>t==="invalid-path"?"settings.extensions.toast.invalidPath":t==="invalid-url"?"settings.extensions.toast.invalidUrl":t==="not-found"?"settings.extensions.toast.notFound":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="reserved-id"?"settings.extensions.toast.reservedId":t==="id-taken"?"settings.extensions.toast.idTaken":t==="already-installed"?"settings.extensions.toast.alreadyInstalled":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="host-too-old"?"settings.extensions.toast.hostTooOld":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="extract-failed"?"settings.extensions.toast.extractFailed":t==="too-large"?"settings.extensions.toast.zipTooLarge":"settings.extensions.toast.failed",sc=t=>t.name.toLowerCase().endsWith(".zip"),pv=t=>t==="not-git"?"settings.extensions.toast.notGit":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="swap-failed"?"settings.extensions.toast.swapFailed":t==="not-found"?"settings.extensions.toast.notFound":"settings.extensions.toast.updateFailed",gv=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",hv=t=>{const e=(t.service?.socketBindings??[]).map(r=>r.resolved?`${r.id}=${r.resolved}`:`${r.id}?`),a=(t.service?.permissions?.sockets??[]).filter(r=>!(t.service?.socketBindings??[]).some(i=>i.id===r));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},fv=t=>{const e=at.c(27),{guest:a,binding:n,busy:r,onSaved:i}=t,{t:l}=Ze(),[d,c]=o.useState(n.override??n.resolved??""),[h,g]=o.useState(!1),[f,p]=o.useState(!n.resolved);let u;e[0]!==n.override||e[1]!==n.resolved?(u=()=>{c(n.override??n.resolved??""),n.resolved||p(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=u):u=e[2];let v;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(v=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=v):v=e[6],o.useEffect(u,v);let w;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==i||e[11]!==l?(w=async P=>{g(!0);const I=await Qm(a.id,n.id,P);if(g(!1),!I){B.error(l("settings.extensions.toast.socketSaveFailed"));return}B.success(l("settings.extensions.toast.socketSaved",{name:a.name})),p(!1),await i()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=i,e[11]=l,e[12]=w):w=e[12];const b=w;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&p(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const m=k;let S;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==r||e[20]!==m||e[21]!==f||e[22]!==b||e[23]!==h||e[24]!==l||e[25]!==d?(S=s.jsx("div",{className:"space-y-1",children:f?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(We,{value:d,onChange:P=>c(P.target.value),placeholder:l("settings.extensions.service.socket.path",{id:n.id}),"aria-label":l("settings.extensions.service.socket.path.aria",{id:n.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:r||h,autoFocus:!0}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(d.trim()||null)},children:l("settings.extensions.service.socket.save")}),n.override?s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.clear.aria",{id:n.id}),onClick:()=>{b(null)},children:l("settings.extensions.service.socket.clear")}):null,n.resolved?s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.cancel.aria",{id:n.id}),onClick:m,children:l("settings.extensions.service.socket.cancel")}):null]}):s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx("div",{className:"typography-meta min-w-0 flex-1 truncate text-muted-foreground",children:n.resolved?l("settings.extensions.service.socket.resolved",{path:n.resolved}):l("settings.extensions.service.socket.unresolved")}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:ps,disabled:r||h,"aria-label":l("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>p(!0),children:s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=n.id,e[17]=n.override,e[18]=n.resolved,e[19]=r,e[20]=m,e[21]=f,e[22]=b,e[23]=h,e[24]=l,e[25]=d,e[26]=S):S=e[26],S},xv=t=>{const e=at.c(143),{guest:a,busy:n,onReview:r,onRemove:i,onSetEnabled:l,onUpdate:d}=t,{t:c}=Ze(),[h,g]=o.useState(!1),f=a.enabled!==!1;let p;e[0]!==a?(p=to(a),e[0]=a,e[1]=p):p=e[1];const u=p;let v,w,b,k,m,S,P,I,j,D,x,A,R,C;if(e[2]!==f||e[3]!==a||e[4]!==u||e[5]!==h||e[6]!==c){const V=hv(a);b=!!(a.source&&a.source!=="bundled");const X=a.source==="bundled";let $;e[21]!==a?($=ev(a),e[21]=a,e[22]=$):$=e[22],k=$,C=a.source==="git"?a.update:void 0;let ee;e[23]!==a.icon||e[24]!==a.id?(ee=Mc(a.id,a.icon,Bc().authenticatedAsset),e[23]=a.icon,e[24]=a.id,e[25]=ee):ee=e[25];const L=ee;let Y;e[26]!==X||e[27]!==a.source||e[28]!==c?(Y=X?null:c(gv(a.source)),e[26]=X,e[27]=a.source,e[28]=c,e[29]=Y):Y=e[29];const oe=a.version?`v${a.version}`:null;let de;e[30]!==a.entry||e[31]!==c?(de=a.entry?null:c("settings.extensions.source.noPanel"),e[30]=a.entry,e[31]=c,e[32]=de):de=e[32];let ge;e[33]!==Y||e[34]!==oe||e[35]!==de?(ge=[Y,oe,de].filter(Boolean),e[33]=Y,e[34]=oe,e[35]=de,e[36]=ge):ge=e[36];const ce=ge.join(" · "),Se=a.path||a.id;let ie;e[37]!==f||e[38]!==u||e[39]!==c?(ie=c(u?"settings.extensions.status.needsApproval":f?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[37]=f,e[38]=u,e[39]=c,e[40]=ie):ie=e[40];const be=ie,ae=u?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":f?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";w=kn,R=h,m=g,x="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let me;e[41]!==a.icon?(me=Oc(a.icon),e[41]=a.icon,e[42]=me):me=e[42];let je;e[43]!==L||e[44]!==me?(je=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Rc,{icon:me,iconSrc:L,className:"size-5 text-foreground"})}),e[43]=L,e[44]=me,e[45]=je):je=e[45];let De;e[46]!==a.name?(De=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[46]=a.name,e[47]=De):De=e[47];let ue;e[48]!==ce?(ue=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:ce}),e[48]=ce,e[49]=ue):ue=e[49];let $e;e[50]!==De||e[51]!==ue?($e=s.jsxs("div",{className:"min-w-0 flex-1",children:[De,ue]}),e[50]=De,e[51]=ue,e[52]=$e):$e=e[52];let Ge;e[53]!==X||e[54]!==c?(Ge=X?s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c("settings.extensions.source.bundled")}):null,e[53]=X,e[54]=c,e[55]=Ge):Ge=e[55];let xe;e[56]!==c||e[57]!==C?(xe=C?s.jsx("span",{className:"max-w-40 shrink-0 truncate rounded-full bg-[var(--status-info)]/15 px-2 py-0.5 text-[10px] font-medium text-[var(--status-info)]",children:c("settings.extensions.update.badge",{version:C.version})}):null,e[56]=c,e[57]=C,e[58]=xe):xe=e[58];let Pe;e[59]!==ae?(Pe=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ae),e[59]=ae,e[60]=Pe):Pe=e[60];let J;e[61]!==be||e[62]!==Pe?(J=s.jsx("span",{"aria-live":"polite",className:Pe,children:be}),e[61]=be,e[62]=Pe,e[63]=J):J=e[63];const se=h&&"rotate-180";let he;e[64]!==se?(he=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",se),e[64]=se,e[65]=he):he=e[65];let ve;e[66]!==he?(ve=s.jsx(z,{name:"arrow-down-s",className:he}),e[66]=he,e[67]=ve):ve=e[67],e[68]!==je||e[69]!==$e||e[70]!==Ge||e[71]!==xe||e[72]!==J||e[73]!==ve?(A=s.jsxs(Nn,{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:[je,$e,Ge,xe,J,ve]}),e[68]=je,e[69]=$e,e[70]=Ge,e[71]=xe,e[72]=J,e[73]=ve,e[74]=A):A=e[74],v=Sn,D="border-t border-[var(--interactive-border)] px-4 py-4",S="space-y-3",e[75]!==Se?(P=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:Se,children:Se}),e[75]=Se,e[76]=P):P=e[76],e[77]!==X||e[78]!==c?(I=X?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[77]=X,e[78]=c,e[79]=I):I=e[79],j=V?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:c("settings.extensions.service.permissions",{list:V})}):null,e[2]=f,e[3]=a,e[4]=u,e[5]=h,e[6]=c,e[7]=v,e[8]=w,e[9]=b,e[10]=k,e[11]=m,e[12]=S,e[13]=P,e[14]=I,e[15]=j,e[16]=D,e[17]=x,e[18]=A,e[19]=R,e[20]=C}else v=e[7],w=e[8],b=e[9],k=e[10],m=e[11],S=e[12],P=e[13],I=e[14],j=e[15],D=e[16],x=e[17],A=e[18],R=e[19],C=e[20];let E;e[80]!==a.service||e[81]!==c?(E=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.service.warning")}):null,e[80]=a.service,e[81]=c,e[82]=E):E=e[82];let O;e[83]!==n||e[84]!==f||e[85]!==a?(O=f?(a.service?.socketBindings??[]).map(V=>s.jsx(fv,{guest:a,binding:V,busy:n,onSaved:Fn},V.id)):null,e[83]=n,e[84]=f,e[85]=a,e[86]=O):O=e[86];let F;e[87]!==n||e[88]!==a||e[89]!==d||e[90]!==c||e[91]!==C?(F=C?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:C.version}),onClick:()=>{d(a)},children:c("settings.extensions.update.action")}):null,e[87]=n,e[88]=a,e[89]=d,e[90]=c,e[91]=C,e[92]=F):F=e[92];let N;e[93]!==n||e[94]!==a||e[95]!==u||e[96]!==r||e[97]!==c?(N=u?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.review.aria",{name:a.name}),onClick:()=>r(a),children:c("settings.extensions.review")}):null,e[93]=n,e[94]=a,e[95]=u,e[96]=r,e[97]=c,e[98]=N):N=e[98];let M;e[99]!==n||e[100]!==f||e[101]!==a.id||e[102]!==a.name||e[103]!==l||e[104]!==c?(M=f?s.jsx(G,{type:"button",size:"sm",variant:"outline",disabled:n,"aria-label":c("settings.extensions.actions.disable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!1)},children:c("settings.extensions.actions.disable")}):s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.actions.enable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!0)},children:c("settings.extensions.actions.enable")}),e[99]=n,e[100]=f,e[101]=a.id,e[102]=a.name,e[103]=l,e[104]=c,e[105]=M):M=e[105];let U;e[106]!==n||e[107]!==b||e[108]!==a.id||e[109]!==a.name||e[110]!==i||e[111]!==c?(U=b?s.jsx(G,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":c("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{i(a.id,a.name)},children:c("settings.extensions.remove")}):null,e[106]=n,e[107]=b,e[108]=a.id,e[109]=a.name,e[110]=i,e[111]=c,e[112]=U):U=e[112];let K;e[113]!==k||e[114]!==c?(K=k?s.jsxs(G,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{yn(k)},children:[s.jsx(z,{name:"external-link",className:"size-4"}),c("settings.extensions.actions.openSource")]}):null,e[113]=k,e[114]=c,e[115]=K):K=e[115];let W;e[116]!==F||e[117]!==N||e[118]!==M||e[119]!==U||e[120]!==K?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[F,N,M,U,K]}),e[116]=F,e[117]=N,e[118]=M,e[119]=U,e[120]=K,e[121]=W):W=e[121];let te;e[122]!==E||e[123]!==O||e[124]!==W||e[125]!==S||e[126]!==P||e[127]!==I||e[128]!==j?(te=s.jsxs("div",{className:S,children:[P,I,j,E,O,W]}),e[122]=E,e[123]=O,e[124]=W,e[125]=S,e[126]=P,e[127]=I,e[128]=j,e[129]=te):te=e[129];let Q;e[130]!==v||e[131]!==te||e[132]!==D?(Q=s.jsx(v,{className:D,children:te}),e[130]=v,e[131]=te,e[132]=D,e[133]=Q):Q=e[133];let H;e[134]!==Q||e[135]!==x||e[136]!==A?(H=s.jsxs("div",{className:x,children:[A,Q]}),e[134]=Q,e[135]=x,e[136]=A,e[137]=H):H=e[137];let _;return e[138]!==w||e[139]!==m||e[140]!==H||e[141]!==R?(_=s.jsx(w,{open:R,onOpenChange:m,children:H}),e[138]=w,e[139]=m,e[140]=H,e[141]=R,e[142]=_):_=e[142],_},bv=()=>{const t=at.c(174),{t:e}=Ze(),a=Hs(vv),n=Hs(yv),r=Hs(jv),i=Hs(wv),[l,d]=o.useState(null),[c,h]=o.useState(!1),[g,f]=o.useState("global"),p=n==="unsupported",[u,v]=o.useState(""),[w,b]=o.useState(!1),[k,m]=o.useState(!1),S=o.useRef(!1),[P,I]=o.useState(null),[j,D]=o.useState(null),[x,A]=o.useState(!1),R=o.useRef(0),C=o.useRef(null);let E;t[0]===Symbol.for("react.memo_cache_sentinel")?(E=rm(),t[0]=E):E=t[0];const O=E;let F;t[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],t[1]=F):F=t[1],o.useEffect(kv,F);let N,M;t[2]!==i||t[3]!==p?(N=()=>{let Ce=!1;if(d(null),h(!1),f("global"),I(null),D(null),S.current=!1,!p)return Promise.all([gu(),hu()]).then(He=>{const[yt,It]=He;Ce||d({runtimeKey:i,profiles:yt,global:It})}).catch(()=>{Ce||h(!0)}),()=>{Ce=!0}},M=[i,p],t[2]=i,t[3]=p,t[4]=N,t[5]=M):(N=t[4],M=t[5]),o.useEffect(N,M);const U=l?.runtimeKey===i?l:null;let K;t[6]!==e?(K=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=K):K=t[7];const W=U?.global?.userName??"",te=U?.global?.userEmail??"";let Q;t[8]!==K||t[9]!==W||t[10]!==te?(Q={id:"global",name:K,userName:W,userEmail:te,icon:"fingerprint",color:"info"},t[8]=K,t[9]=W,t[10]=te,t[11]=Q):Q=t[11];let H;t[12]!==U?.profiles||t[13]!==Q?(H=[Q,...U?.profiles.filter(Nv)??[]],t[12]=U?.profiles,t[13]=Q,t[14]=H):H=t[14];const _=H;let V;t[15]!==_||t[16]!==g?(V=_.find(Ce=>Ce.id===g)??_[0],t[15]=_,t[16]=g,t[17]=V):V=t[17];const X=V;let $,ee;t[18]!==n?($=()=>{if(n!=="ready"||S.current)return;S.current=!0;const Ce=Hs.getState().runtimeKey;tc(!1).then(He=>{He.ok&&Hs.getState().applyUpdates(He.updates,Ce)})},ee=[n],t[18]=n,t[19]=$,t[20]=ee):($=t[19],ee=t[20]),o.useEffect($,ee);let L;t[21]!==e?(L=async()=>{m(!0);const Ce=Hs.getState().runtimeKey,He=await tc(!0);if(m(!1),!He.ok){B.error(e("settings.extensions.toast.checkFailed"));return}Hs.getState().applyUpdates(He.updates,Ce),Object.keys(He.updates).length===0&&B.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=L):L=t[22];const Y=L;let oe;t[23]!==e?(oe=async Ce=>{b(!0);const He=await uv(Ce.id);if(b(!1),!He.ok){B.error(He.code==="host-too-old"&&He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e(pv(He.code)));return}Mr(Ce.id),B.success(e("settings.extensions.toast.updated",{name:He.guest.name,version:He.guest.version??""})),await Fn(),to(He.guest)&&D(He.guest)},t[23]=e,t[24]=oe):oe=t[24];const de=oe;let ge;if(t[25]!==a||t[26]!==e){const Ce=async(He,yt,It)=>{const Qt=It===void 0?{}:It;if(!He.ok){if(Qt.allowConflictDialog!==!1&&(He.code==="id-taken"||He.code==="already-installed")){const Xt=He.id?a.find(ts=>ts.id===He.id):void 0;return I({source:yt,name:Xt?.name??He.id??(yt.kind==="file"?yt.file.name:yt.input)}),!1}return He.code==="host-too-old"?B.error(He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e("settings.extensions.toast.failed"),{description:He.diagnostic?Vr(He.diagnostic,e):void 0}):B.error(e(mv(He.code)),{description:He.diagnostic?Vr(He.diagnostic,e):void 0}),!1}return v(""),I(null),B.success(He.replaced?e("settings.extensions.toast.reinstalled",{name:He.guest.name}):e("settings.extensions.toast.added",{name:He.guest.name})),await Fn(),to(He.guest)&&D(He.guest),!0};ge=async(He,yt)=>{const It=yt===void 0?{}:yt,Qt=jn();He.kind==="input"&&v(He.input),b(!0);const Xt=He.kind==="file"?await av(He.file,It):await nv(He.input,{...It,gitIdentityId:He.gitIdentityId});b(!1),jn()===Qt&&await Ce(Xt,He,{allowConflictDialog:!It.replace})},t[25]=a,t[26]=e,t[27]=ge}else ge=t[27];const ce=ge;let Se;t[28]!==u||t[29]!==ce||t[30]!==X||t[31]!==e?(Se=async()=>{const Ce=u.trim();if(!Ce){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"input",input:Ce,gitIdentityId:X.id})},t[28]=u,t[29]=ce,t[30]=X,t[31]=e,t[32]=Se):Se=t[32];const ie=Se;let be;t[33]!==ce?(be=async()=>{if(!O)return;const Ce=await om("");Ce.success&&Ce.path&&await ce({kind:"input",input:Ce.path})},t[33]=ce,t[34]=be):be=t[34];const ae=be;let me;t[35]!==ce?(me=async()=>{if(!O){C.current?.click();return}const Ce=await No({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Ce.success&&Ce.path&&await ce({kind:"input",input:Ce.path})},t[35]=ce,t[36]=me):me=t[36];const je=me;let De;t[37]!==ce||t[38]!==e?(De=async Ce=>{const He=Ce.target.files?.[0]??null;if(Ce.target.value="",!!He){if(!sc(He)){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"file",file:He})}},t[37]=ce,t[38]=e,t[39]=De):De=t[39];const ue=De;let $e;t[40]!==w?($e=Ce=>{w||(Ce.preventDefault(),R.current=R.current+1,A(!0))},t[40]=w,t[41]=$e):$e=t[41];const Ge=$e;let xe;t[42]!==w?(xe=Ce=>{w||(Ce.preventDefault(),Ce.dataTransfer.dropEffect="copy")},t[42]=w,t[43]=xe):xe=t[43];const Pe=xe;let J;t[44]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{R.current=Math.max(0,R.current-1),R.current===0&&A(!1)},t[44]=J):J=t[44];const se=J;let he;t[45]!==w||t[46]!==ce||t[47]!==e?(he=async Ce=>{if(Ce.preventDefault(),R.current=0,A(!1),w)return;const He=Ce.dataTransfer.items[0],yt=He?.getAsFile()??null,Qt=(He?.webkitGetAsEntry()??null)?.isDirectory===!0,Xt=yt!==null&&!Qt&&sc(yt),ts=yt&&O?lm(yt):null;if(ts&&(Qt||Xt)){await ce({kind:"input",input:ts});return}if(Qt){B.error(e(O?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!yt||!Xt){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"file",file:yt})},t[45]=w,t[46]=ce,t[47]=e,t[48]=he):he=t[48];const ve=he;let Fe;t[49]!==P||t[50]!==ce?(Fe=async()=>{P&&await ce(P.source,{replace:!0})},t[49]=P,t[50]=ce,t[51]=Fe):Fe=t[51];const Ke=Fe;let Be;t[52]!==e?(Be=async(Ce,He)=>{b(!0);const yt=await iv(Ce);if(b(!1),!yt.ok){B.error(e("settings.extensions.toast.removeFailed"));return}Mr(Ce),B.success(e("settings.extensions.toast.removed",{name:He})),await Fn()},t[52]=e,t[53]=Be):Be=t[53];const ze=Be;let _e;t[54]!==e?(_e=async Ce=>{b(!0);const He=await ov(Ce.id,Ce.capabilities.requested);if(b(!1),!He){B.error(e("settings.extensions.toast.approveFailed"));return}D(null),B.success(e("settings.extensions.toast.approved",{name:Ce.name})),await Fn()},t[54]=e,t[55]=_e):_e=t[55];const Me=_e;let tt;t[56]!==ze?(tt=async Ce=>{D(null),await ze(Ce.id,Ce.name)},t[56]=ze,t[57]=tt):tt=t[57];const pt=tt;let ct;t[58]!==e?(ct=async(Ce,He,yt)=>{b(!0);const It=await rv(Ce,yt);if(b(!1),!It){B.error(e("settings.extensions.toast.enabledFailed"));return}yt||Mr(Ce),B.success(yt?e("settings.extensions.toast.enabled",{name:He}):e("settings.extensions.toast.disabled",{name:He})),await Fn()},t[58]=e,t[59]=ct):ct=t[59];const dt=ct;let ht;t[60]!==e?(ht=e("settings.page.extensions.title"),t[60]=e,t[61]=ht):ht=t[61];let Ue;t[62]!==e?(Ue=e("settings.page.extensions.description"),t[62]=e,t[63]=Ue):Ue=t[63];let st;t[64]!==ie||t[65]!==ae||t[66]!==je||t[67]!==w||t[68]!==x||t[69]!==_||t[70]!==l||t[71]!==c||t[72]!==u||t[73]!==Ge||t[74]!==Pe||t[75]!==ve||t[76]!==ue||t[77]!==X||t[78]!==e||t[79]!==p?(st=p?null:s.jsxs(qe,{title:e("settings.extensions.add.action"),info:e("settings.extensions.add.info"),children:[s.jsx(Ot,{label:e("settings.extensions.add.label"),info:e(O?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:Ie("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",x&&"border-primary bg-primary/5"),onDragEnter:Ge,onDragOver:Pe,onDragLeave:se,onDrop:Ce=>{ve(Ce)},children:[x?s.jsx("span",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-md bg-background/80 typography-ui-label text-primary",children:e("settings.extensions.add.drop.active")}):null,s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center",children:[s.jsx(We,{value:u,onChange:Ce=>v(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"&&(Ce.preventDefault(),ie())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:Ie("h-8 min-w-0 flex-1 rounded-md pl-3",O?"pr-14":"pr-8"),disabled:w}),s.jsx("input",{ref:C,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Ce=>{ue(Ce)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[O?s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:w,onClick:()=>{ae()},children:s.jsx(z,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseZip"),"aria-label":e("settings.extensions.add.browseZip.aria"),disabled:w,onClick:()=>{je()},children:s.jsx(z,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(Tm,{activeProfile:X,identities:_,onSelect:Ce=>f(Ce.id),isApplying:w||!l&&!c,iconOnly:!0})}),s.jsxs(G,{type:"button",size:"sm",disabled:w,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{ie()},children:[s.jsx(z,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),c?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[64]=ie,t[65]=ae,t[66]=je,t[67]=w,t[68]=x,t[69]=_,t[70]=l,t[71]=c,t[72]=u,t[73]=Ge,t[74]=Pe,t[75]=ve,t[76]=ue,t[77]=X,t[78]=e,t[79]=p,t[80]=st):st=t[80];let ut;t[81]!==e?(ut=e("settings.extensions.section.installed"),t[81]=e,t[82]=ut):ut=t[82];let ye;t[83]!==w||t[84]!==Y||t[85]!==k||t[86]!==n||t[87]!==e||t[88]!==p?(ye=p?null:s.jsxs(G,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:w||k||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{Y()},children:[s.jsx(z,{name:"refresh",className:Ie("h-4 w-4",k&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[83]=w,t[84]=Y,t[85]=k,t[86]=n,t[87]=e,t[88]=p,t[89]=ye):ye=t[89];let re;t[90]!==r||t[91]!==n||t[92]!==e?(re=n==="error"||r?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),r?`
30
- ${Vr(r,e)}`:""]}):null,t[90]=r,t[91]=n,t[92]=e,t[93]=re):re=t[93];let Te;t[94]!==e||t[95]!==p?(Te=p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[94]=e,t[95]=p,t[96]=Te):Te=t[96];let Ne;t[97]!==a.length||t[98]!==n||t[99]!==e?(Ne=n==="ready"&&a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[97]=a.length,t[98]=n,t[99]=e,t[100]=Ne):Ne=t[100];let Ae;if(t[101]!==w||t[102]!==a||t[103]!==ze||t[104]!==dt||t[105]!==de){let Ce;t[107]!==w||t[108]!==ze||t[109]!==dt||t[110]!==de?(Ce=He=>s.jsx(xv,{guest:He,busy:w,onReview:D,onRemove:ze,onSetEnabled:dt,onUpdate:de},He.id),t[107]=w,t[108]=ze,t[109]=dt,t[110]=de,t[111]=Ce):Ce=t[111],Ae=a.map(Ce),t[101]=w,t[102]=a,t[103]=ze,t[104]=dt,t[105]=de,t[106]=Ae}else Ae=t[106];let q;t[112]!==ut||t[113]!==ye||t[114]!==re||t[115]!==Te||t[116]!==Ne||t[117]!==Ae?(q=s.jsxs(qe,{title:ut,contentClassName:"space-y-3",headerAction:ye,children:[re,Te,Ne,Ae]}),t[112]=ut,t[113]=ye,t[114]=re,t[115]=Te,t[116]=Ne,t[117]=Ae,t[118]=q):q=t[118];let Le;t[119]!==Me?(Le=Ce=>{Me(Ce)},t[119]=Me,t[120]=Le):Le=t[120];let Qe;t[121]!==pt?(Qe=Ce=>{pt(Ce)},t[121]=pt,t[122]=Qe):Qe=t[122];let lt;t[123]===Symbol.for("react.memo_cache_sentinel")?(lt=()=>D(null),t[123]=lt):lt=t[123];let ot;t[124]!==j||t[125]!==w||t[126]!==Le||t[127]!==Qe?(ot=s.jsx(Zb,{guest:j,busy:w,onApprove:Le,onDecline:Qe,onDismiss:lt}),t[124]=j,t[125]=w,t[126]=Le,t[127]=Qe,t[128]=ot):ot=t[128];const bt=P!==null;let wt;t[129]!==w?(wt=Ce=>{!Ce&&!w&&I(null)},t[129]=w,t[130]=wt):wt=t[130];let jt;t[131]!==e?(jt=e("settings.extensions.dialog.reinstallTitle"),t[131]=e,t[132]=jt):jt=t[132];let vt;t[133]!==jt?(vt=s.jsx(Vt,{children:jt}),t[133]=jt,t[134]=vt):vt=t[134];const Xe=P?.name??"";let kt;t[135]!==e||t[136]!==Xe?(kt=e("settings.extensions.dialog.reinstallDescription",{name:Xe}),t[135]=e,t[136]=Xe,t[137]=kt):kt=t[137];let Re;t[138]!==kt?(Re=s.jsx(Ht,{children:kt}),t[138]=kt,t[139]=Re):Re=t[139];let Ve;t[140]!==vt||t[141]!==Re?(Ve=s.jsxs(Bt,{children:[vt,Re]}),t[140]=vt,t[141]=Re,t[142]=Ve):Ve=t[142];let Z;t[143]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>I(null),t[143]=Z):Z=t[143];let pe;t[144]!==e?(pe=e("settings.common.actions.cancel"),t[144]=e,t[145]=pe):pe=t[145];let Oe;t[146]!==w||t[147]!==pe?(Oe=s.jsx(G,{size:"sm",variant:"ghost",disabled:w,onClick:Z,children:pe}),t[146]=w,t[147]=pe,t[148]=Oe):Oe=t[148];let Ee;t[149]!==Ke?(Ee=()=>{Ke()},t[149]=Ke,t[150]=Ee):Ee=t[150];let Ye;t[151]!==e?(Ye=e("settings.extensions.dialog.reinstall"),t[151]=e,t[152]=Ye):Ye=t[152];let ne;t[153]!==w||t[154]!==Ee||t[155]!==Ye?(ne=s.jsx(G,{size:"sm",disabled:w,onClick:Ee,children:Ye}),t[153]=w,t[154]=Ee,t[155]=Ye,t[156]=ne):ne=t[156];let we;t[157]!==Oe||t[158]!==ne?(we=s.jsxs(as,{children:[Oe,ne]}),t[157]=Oe,t[158]=ne,t[159]=we):we=t[159];let nt;t[160]!==Ve||t[161]!==we?(nt=s.jsxs(Ut,{className:"max-w-md",children:[Ve,we]}),t[160]=Ve,t[161]=we,t[162]=nt):nt=t[162];let Rt;t[163]!==bt||t[164]!==wt||t[165]!==nt?(Rt=s.jsx(_t,{open:bt,onOpenChange:wt,children:nt}),t[163]=bt,t[164]=wt,t[165]=nt,t[166]=Rt):Rt=t[166];let Jt;return t[167]!==ht||t[168]!==Ue||t[169]!==st||t[170]!==q||t[171]!==ot||t[172]!==Rt?(Jt=s.jsxs(ns,{title:ht,description:Ue,children:[st,q,ot,Rt]}),t[167]=ht,t[168]=Ue,t[169]=st,t[170]=q,t[171]=ot,t[172]=Rt,t[173]=Jt):Jt=t[173],Jt};function vv(t){return t.guests}function yv(t){return t.status}function jv(t){return t.failure}function wv(t){return t.runtimeKey}function kv(){Fn()}function Nv(t){return t.id!=="global"}const zs=ia,Sv=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=fu(e),n=(je,De)=>t.colors[je]??De,r=je=>je!=="transparent"&&(Vs(je,"#000000")!==1||Vs(je,"#ffffff")!==1),i=(je,De)=>{const ue=n(je,De);return r(ue)?ue:De},l=n("chat.list.background",n("editor.background",a.colors.surface.background)),d=n("interactive-session.foreground",n("foreground",n("editor.foreground",a.colors.surface.foreground))),h=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([je])=>t.colors[je]),g=h?n(h[0],a.colors.surface.elevated):a.colors.surface.elevated,f=aa(d,g,l),p=h?n(h[1],f):f,u=n("sideBar.background",n("panel.background",a.colors.surface.muted)),v=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),w=n("textBlockQuote.background",u),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),m=n("button.hoverBackground",k),S=t.colors["button.background"]?n("button.foreground",Ms(k,l)):Ms(k,l),P=zs(k,.5),j=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(je=>je&&r(je))||zs(d,e?.25:.2),D=n("toolbar.hoverBackground",n("list.hoverBackground",a.colors.interactive.hover)),x=n("toolbar.activeBackground",D),R=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([je])=>t.colors[je]),C=R.find(([je])=>[l,u,g].every(De=>{const ue=Vs(n(je,""),De,l);return ue===null||ue>1.01}))??R[0],E=C?n(C[0],a.colors.interactive.selection):a.colors.interactive.selection,O=C?n(C[1],d):d,F=n("focusBorder",n("inputOption.activeBorder",k)),N=F,M=n("editorCursor.foreground",a.colors.interactive.cursor),U=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),K=i("editorError.background",zs(U,e?.16:.12)),W=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),te=i("editorWarning.background",zs(W,e?.16:.12)),Q=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),H=zs(Q,e?.16:.12),_=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),V=i("editorInfo.background",zs(_,e?.16:.12)),X=n("editorLineNumber.foreground",v),$=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),ee=n("terminal.ansiBlue",k),L=n("terminal.ansiYellow",a.colors.syntax.base.number),Y=n("terminal.ansiCyan",a.colors.syntax.base.function),oe=n("terminal.ansiMagenta",d),de=n("terminal.ansiYellow",a.colors.syntax.base.type),ge=n("chat.requestBorder",j),ce=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",H)),Se=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",K)),ie=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",Q)),be=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",U)),ae=n("gitDecoration.modifiedResourceForeground",_),me=n("chat.requestBubbleBackground",n("chat.requestBackground",g));return{...a,metadata:{...a.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:e?"dark":"light",tags:["vscode","auto"]},colors:{...a.colors,primary:{base:k,hover:m,active:m,foreground:S,muted:P},surface:{background:l,foreground:d,muted:u,mutedForeground:v,elevated:g,elevatedForeground:p,overlay:b,subtle:w},interactive:{border:j,borderHover:n("toolbar.hoverOutline",j),borderFocus:F,selection:E,selectionForeground:O,focus:F,focusRing:N,cursor:M,hover:D,active:x},status:{error:U,errorForeground:Ms(U,l),errorBackground:K,errorBorder:zs(U,e?.45:.35),warning:W,warningForeground:Ms(W,l),warningBackground:te,warningBorder:zs(W,e?.45:.35),success:Q,successForeground:Ms(Q,l),successBackground:H,successBorder:zs(Q,e?.45:.35),info:_,infoForeground:Ms(_,l),infoBackground:V,infoBorder:zs(_,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:ie,diffAddedBackground:ce,diffRemoved:be,diffRemovedBackground:Se,diffModified:ae,diffModifiedBackground:zs(ae,e?.16:.12),lineNumber:n("editorLineNumber.foreground",v),lineNumberActive:n("editorLineNumber.activeForeground",d)},base:{background:n("editor.background",l),foreground:n("editor.foreground",d),comment:X,keyword:ee,string:$,number:L,function:Y,variable:oe,type:de,operator:k}},tools:{border:ge,icon:n("icon.foreground",v),title:d,description:zs(v,.8),edit:{added:ie,addedBackground:ce,removed:be,removedBackground:Se,modified:ae,modifiedBackground:zs(ae,e?.16:.12),lineNumber:X}},chat:{background:l,userMessage:d,userMessageBackground:me,assistantMessage:d,assistantMessageBackground:l,timestamp:v,divider:j,typing:n("chat.thinkingShimmer",v),avatarBackground:n("chat.avatarBackground",l),avatarForeground:n("chat.avatarForeground",d),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",S),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",m),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",P)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",m),inlineCode:n("textPreformat.foreground",$),inlineCodeBackground:n("textPreformat.background",n("editor.background",l)),blockquote:d,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",j),listMarker:zs(k,.6)}}}},Hr=.075;function Cv(t,e,a){const{surface:n,primary:r,status:i,interactive:l}=t.colors,d=n.background,c=t.metadata.variant==="dark",h=Ms(n.muted,d),g=[d,n.muted,n.elevated,Ns(l.selection,n.muted,1,d)].filter(k=>Ms(k,d)===h),f=k=>g.reduce((m,S)=>aa(m,S,d),k),p=k=>[d,n.muted].every(m=>(Vs(k,m,d)??0)>=3),u=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder,e["inputOption.activeBorder"],a.function,a.keyword].filter(k=>k!==void 0),v=f(u.find(p)??r.base);v!==r.base&&(r.base=v,r.foreground=Ms(v,d),r.hover=Ns(n.foreground,v,.08,d),r.active=Ns(n.foreground,v,.16,d),r.muted=ia(v,.5),!e.focusBorder&&!e["inputOption.activeBorder"]&&(l.focus=v,l.focusRing=v,l.borderFocus=v),t.colors.markdown&&(e["textLink.foreground"]||(t.colors.markdown.link=v),e["textLink.activeForeground"]||(t.colors.markdown.linkHover=r.hover),t.colors.markdown.listMarker=ia(v,.6))),g.some(k=>(Vs(l.focusRing,k,d)??0)<1.1)&&(l.focus=r.base,l.focusRing=r.base,l.borderFocus=r.base);const w=(k,m,S)=>g.every(P=>(Ho(k,m,P,d)??0)>=S);let b=f(i.info);if(!w(b,r.base,Hr)){const k=P=>w(P,r.base,Hr)&&[i.error,i.warning,i.success].every(I=>w(P,I,.1));let S=[e["notificationsInfoIcon.foreground"],e["editorInfo.foreground"],e["terminal.ansiCyan"],e["terminal.ansiBlue"],e["terminal.ansiMagenta"],e["textLink.foreground"],a.function,a.type].filter(P=>P!==void 0).map(f).find(k);if(!S){const P=Ns(b,d,1,d),j=[P,f(Ns(P,d,.5,d))].flatMap(D=>[.12,.18].flatMap(x=>[0,60,-60,90,-90,120,-120,180].map(A=>f(xu(D,A,x)))));if(S=j.find(k),!S){const D=x=>Math.min(...[i.error,i.warning,i.success].map(A=>Ho(x,A,n.muted,d)??0));S=j.filter(x=>w(x,r.base,Hr)).sort((x,A)=>D(A)-D(x))[0]}}S&&(b=S)}if(b!==i.info&&(i.info=b,i.infoForeground=Ms(b,d),i.infoBackground=ia(b,c?.16:.12),i.infoBorder=ia(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((Vs(k,d,d)??1)<1.1){const m=Ns(k,d,1,d);let P=(Vs(m,"#000000")??1)<(Vs(d,"#000000")??1)?"#000000":"#ffffff",I=m;((Vs(P,d,d)??1)<1.1||(Vs(m,d,d)??1)<1.01)&&(I=d,P=n.foreground);let j=0,D=1;for(let A=0;A<16;A++){const R=(j+D)/2,C=Ns(P,I,R,d);(Vs(C,d,d)??1)>=1.1?D=R:j=R}const x=Ns(P,I,D,d);(Vs(n.foreground,x,d)??0)>=4.5&&(t.colors.chat.userMessageBackground=x)}}}const sr=Dt().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),Oo=Ts({foreground:sr.optional()}),yd=Ts({scope:no([Dt(),xa(Dt())]).optional(),settings:Oo}),Iv=Ts({name:Dt().trim().min(1).max(160).optional(),author:Dt().max(160).optional(),description:Dt().max(1024).optional(),type:Io(["light","dark","hc","hc-black","hc-light"]).optional(),include:Dt().optional(),colors:Kn(Dt(),sr.nullable()).default({}),tokenColors:no([xa(yd),Dt()]).optional(),semanticHighlighting:Co().optional(),semanticTokenColors:Kn(Dt(),no([sr,Oo])).optional()});function Pv(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(r=>({scope:r.trim(),color:e.settings.foreground}))))}function Av(t,e){for(const a of e){let n,r=-1;for(const i of t)!i.color||!i.scope||(a===i.scope||a.startsWith(`${i.scope}.`))&&i.scope.length>=r&&(n=i.color,r=i.scope.length);if(n)return n}}function Tv(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const r=sr.safeParse(n);if(r.success)return r.data;const i=Oo.safeParse(n);if(i.success&&i.data.foreground)return i.data.foreground}}function Ev(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function Dv(t,e,a,n){const r=Ms(a,a);if(e.some(c=>Ms(c,a)!==r))return t;let i=t;for(const c of e)i=aa(i,c,a);let l=0,d=1;for(let c=0;c<16;c++){const h=(l+d)/2,g=ia(i,h);e.every(f=>(Vs(g,f,a)??0)>=n)?d=h:l=h}return ia(i,d)}function jd(t,e){if(new TextEncoder().encode(t).byteLength>_c)throw new ra("size");let a;try{a=Iv.parse(JSON.parse(Ym(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ra("invalid")}const n=xa(yd).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ra("include");const r={};for(const[A,R]of Object.entries(a.colors))R!==null&&(r[A]=R);const i={...r},l=r["editor.background"];if(!l)throw new ra("background");const d=a.type?["dark","hc","hc-black"].includes(a.type):Ms(l,"#ffffff")==="#ffffff",c=d?"dark":"light",h=Ns(l,d?"#000000":"#ffffff",1),g=Pv(n.data),f=n.data.filter(A=>!A.scope&&A.settings.foreground).at(-1)?.settings.foreground,p=r["editor.foreground"]??f??r.foreground??Ms(h,h),u=r["chat.list.background"]??h,v=r["interactive-session.foreground"]??r.foreground??p;r["editor.background"]=h,r["editor.foreground"]=p,r.foreground??=v,r["sideBar.background"]??=r["panel.background"]??Ns(v,u,.03,u),!r["editorWidget.background"]&&!r["dropdown.background"]&&!r["input.background"]&&(r["editorWidget.background"]=Ns(v,u,.04,u),r["editorWidget.foreground"]=aa(v,r["editorWidget.background"],u)),r.descriptionForeground??=aa(Ns(v,u,.6,u),u),r["widget.border"]??=r["input.border"]??r["panel.border"]??Ns(v,u,.15,u),r["toolbar.hoverBackground"]??=r["list.hoverBackground"]??Ns(v,u,.08,u),r["toolbar.activeBackground"]??=Ns(v,u,.12,u),!r["list.activeSelectionBackground"]&&!r["editor.selectionBackground"]&&(r["list.activeSelectionBackground"]=Ns(v,u,.16,u),r["list.activeSelectionForeground"]=aa(v,r["list.activeSelectionBackground"],u)),r["button.background"]||(r["button.background"]=r["textLink.foreground"]??r.focusBorder??v,r["button.foreground"]=Ms(r["button.background"],u)),r.focusBorder??=r["button.background"],r["editorCursor.foreground"]??=p;const w=a.type?.startsWith("hc")??!1;w&&r.contrastBorder&&(r["widget.border"]=r.contrastBorder);const k=Sv({kind:d&&w?"high-contrast":c,colors:r});if(w)k.colors.interactive.focusRing=r.focusBorder;else{const{surface:A,interactive:R}=k.colors,C=Dv(R.border,[A.background,A.muted,A.elevated],A.background,d?1.15:1.2);R.border=C,r["toolbar.hoverOutline"]||(R.borderHover=C),k.colors.tools&&!r["chat.requestBorder"]&&(k.colors.tools.border=C),k.colors.chat&&(k.colors.chat.divider=C),k.colors.markdown&&!r["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=C)}const m=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},S=(A,R,C)=>Tv(m,A)??Av(g,R)??C,P={background:h,foreground:p,comment:S(["comment"],["comment","comment.line","comment.block"],aa(Ns(p,h,.6,h),h)),keyword:S(["keyword"],["keyword","storage","keyword.control","storage.type"],p),string:S(["string"],["string","string.quoted","string.template"],p),number:S(["number"],["constant.numeric"],p),function:S(["function"],["entity.name.function","support.function"],p),variable:S(["variable"],["variable.other.readwrite","variable"],p),type:S(["type"],["entity.name.type","support.type","support.class"],p),operator:S(["operator"],["keyword.operator"],p)},I=S(["class"],["entity.name.type.class","entity.name.class"],P.type),j=S(["property"],["variable.other.property","support.type.property-name"],P.variable),D={base:P,tokens:{className:I,interface:S(["interface"],["entity.name.type.interface"],P.type),enum:S(["enum"],["entity.name.type.enum"],I),method:S(["method"],["entity.name.function.method"],P.function),variableProperty:j,parameter:S(["parameter"],["variable.parameter"],P.variable),constant:S(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],P.number),boolean:S([],["constant.language.boolean","constant.language"],P.number),punctuation:S([],["punctuation","punctuation.separator"],P.operator),stringEscape:S([],["constant.character.escape"],P.string),commentDoc:S([],["comment.block.documentation","comment.documentation"],P.comment),keywordImport:S([],["keyword.control.import","keyword.import"],P.keyword),tag:S([],["entity.name.tag"],P.keyword),tagAttribute:S([],["entity.other.attribute-name"],j)},highlights:k.colors.syntax.highlights},x=Ev(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return Cv(k,i,P),bu({metadata:{id:`vscode-import-${c}`,name:x,variant:c,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...k.colors,syntax:D,pr:{open:k.colors.status.success,draft:k.colors.surface.mutedForeground,blocked:k.colors.status.warning,merged:I,closed:k.colors.status.error}}})}const Mv=Ts({namespace:Dt(),name:Dt(),version:Dt(),label:Dt(),icon:Dt().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Rv(t,e){const a=await St("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!a.ok)throw new Error("catalog");return Ts({items:xa(Mv).max(24)}).parse(await a.json()).items}async function Ov(t,e){const a=await St("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!a.ok)throw new Error("catalog");const{items:n}=Ts({items:xa(Ts({path:Dt(),name:Dt(),text:Dt(),error:Co()})).max(40)}).parse(await a.json());return n.map((r,i)=>{const l=`${i}:${r.path}`;try{if(r.error)throw new Error("invalid");const d=jd(r.text,r.path);return d.metadata.name=r.name,d.metadata.author=t.namespace,{status:"ready",key:l,name:r.name,definition:d,theme:vu(d)}}catch{return{status:"invalid",key:l,name:r.name}}})}function Fv(t){const e=at.c(3),{extension:a}=t,[n,r]=o.useState(!1);let i;return e[0]!==a.icon||e[1]!==n?(i=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>r(!0)}):s.jsx(z,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=i):i=e[2],i}function Lv(t){const e=at.c(93),{pickFile:a,fileBusy:n,onClose:r}=t,{t:i}=Ze(),l=fe(Uv),{isMobile:d}=Qn(),c=l||d,{importTheme:h}=fa(),[g,f]=o.useState("");let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={step:"search",status:"idle",results:[]},e[0]=p):p=e[0];const[u,v]=o.useState(p);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=new Set,e[1]=w):w=e[1];const[b,k]=o.useState(w);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[2]=m):m=e[2];const[S,P]=o.useState(m),[I,j]=o.useState(!1),[D,x]=o.useState(null),A=o.useRef(null);let R,C;e[3]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const $=new AbortController;A.current=$;const ee=rr(()=>$.abort());return()=>{ee(),$.abort()}},C=[],e[3]=R,e[4]=C):(R=e[3],C=e[4]),o.useEffect(R,C);let E,O;e[5]!==g||e[6]!==u.step?(E=()=>{if(u.step!=="search")return;const $=new AbortController,ee=g.trim(),L=setTimeout(async()=>{if(!ee){v({step:"search",status:"idle",results:[]});return}v({step:"search",status:"loading",results:[]});try{const Y=await Rv(ee,$.signal);$.signal.aborted||v({step:"search",status:"ready",results:Y})}catch{$.signal.aborted||v({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(L),$.abort()}},O=[g,u.step],e[5]=g,e[6]=u.step,e[7]=E,e[8]=O):(E=e[7],O=e[8]),o.useEffect(E,O);let F,N;if(e[9]!==n||e[10]!==h||e[11]!==c||e[12]!==a||e[13]!==g||e[14]!==D||e[15]!==S||e[16]!==I||e[17]!==b||e[18]!==u.extension||e[19]!==u.results||e[20]!==u.status||e[21]!==u.step||e[22]!==u.variants||e[23]!==i){const $=async ae=>{const me=A.current?.signal;if(me){v({step:"package",status:"loading",extension:ae}),P(new Set),x(null),k(new Set);try{const je=await Ov(ae,me);me.aborted||v({step:"variants",extension:ae,variants:je})}catch{me.aborted||v({step:"package",status:"error",extension:ae})}}};let ee;e[26]!==h||e[27]!==S||e[28]!==I||e[29]!==b||e[30]!==u.step||e[31]!==u.variants||e[32]!==i?(ee=async()=>{if(u.step!=="variants"||I)return;const ae=A.current?.signal;if(!ae)return;j(!0),x(null);let me=!1;for(const je of u.variants){if(ae.aborted)break;if(!(je.status!=="ready"||!b.has(je.key)||S.has(je.key)))try{if(await h(je.definition,{activate:!1}),ae.aborted)break;P(De=>new Set(De).add(je.key)),k(De=>{const ue=new Set(De);return ue.delete(je.key),ue})}catch{me=!0}}ae.aborted||(j(!1),x(me?"partial":null),me?Ha.error(i("settings.themeImport.partialError")):Ha.success(i("settings.themeImport.complete")))},e[26]=h,e[27]=S,e[28]=I,e[29]=b,e[30]=u.step,e[31]=u.variants,e[32]=i,e[33]=ee):ee=e[33];const L=ee;let Y,oe;e[34]!==S||e[35]!==b||e[36]!==u.step||e[37]!==u.variants?(Y=u.step==="variants"?u.variants.filter(ae=>ae.status==="ready"&&!S.has(ae.key)):[],oe=Y.length>0&&Y.every(ae=>b.has(ae.key)),e[34]=S,e[35]=b,e[36]=u.step,e[37]=u.variants,e[38]=Y,e[39]=oe):(Y=e[38],oe=e[39]);const de=oe;let ge;e[40]!==n||e[41]!==L||e[42]!==I||e[43]!==b||e[44]!==u.step||e[45]!==i?(ge=u.step==="variants"&&s.jsx(G,{disabled:!b.size||I||n,onClick:()=>{L()},children:i(I?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=L,e[42]=I,e[43]=b,e[44]=u.step,e[45]=i,e[46]=ge):ge=e[46];const ce=I||n;let Se;e[47]!==i?(Se=i("settings.themeImport.chooseFile"),e[47]=i,e[48]=Se):Se=e[48];let ie;e[49]!==a||e[50]!==ce||e[51]!==Se?(ie=s.jsx(G,{variant:"outline",className:"self-start",disabled:ce,onClick:a,children:Se}),e[49]=a,e[50]=ce,e[51]=Se,e[52]=ie):ie=e[52];let be;e[53]!==ge||e[54]!==ie?(be=s.jsxs(s.Fragment,{children:[ge,ie]}),e[53]=ge,e[54]=ie,e[55]=be):be=e[55],F=be,N=s.jsx(s.Fragment,{children:u.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(We,{autoFocus:!0,"aria-label":i("settings.themeImport.search"),placeholder:i("settings.themeImport.search"),value:g,maxLength:160,onChange:ae=>f(ae.target.value)}),s.jsxs("div",{className:c?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[u.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:i("common.loading")}),u.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}),u.status==="ready"&&!u.results.length&&s.jsx("p",{className:"text-muted-foreground",children:i("settings.themeImport.empty")}),u.results.map(ae=>s.jsxs(G,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{$(ae)},children:[s.jsx(Fv,{extension:ae}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ae.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ae.namespace})]})]},`${ae.namespace}.${ae.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(G,{variant:"ghost",size:"sm",className:"justify-start",disabled:I||u.step==="package"&&u.status==="loading",onClick:()=>v({step:"search",status:"idle",results:[]}),children:[s.jsx(z,{name:"arrow-left",className:"size-4"}),i("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:u.extension.label}),D==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.partialError")}),u.step==="package"?u.status==="loading"?s.jsx("p",{role:"status",children:i("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[u.variants.length>1&&s.jsx(G,{variant:"ghost",size:"sm",className:"self-start",disabled:I||n||!Y.length,onClick:()=>k(de?new Set:new Set(Y.map(_v))),children:i(de?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:c?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:u.variants.map(ae=>s.jsxs("div",{className:"flex items-center gap-3",children:[ae.status==="ready"&&s.jsxs("div",{"aria-hidden":"true",className:"flex w-20 shrink-0 items-center gap-2 rounded px-2 py-3",style:{backgroundColor:ae.theme.colors.surface.background,color:ae.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ae.theme.colors.syntax.base.keyword,ae.theme.colors.syntax.base.string,ae.theme.colors.syntax.base.function].map(Kv)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[S.has(ae.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(z,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ae.name})]}):s.jsx(gt,{checked:b.has(ae.key),disabled:ae.status!=="ready"||I||n,label:ae.name,onChange:me=>k(je=>{const De=new Set(je);return me?De.add(ae.key):De.delete(ae.key),De})}),s.jsx("p",{className:S.has(ae.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ae.status!=="ready"?i("settings.themeImport.error.invalid"):S.has(ae.key)?i("settings.themeImport.installed"):i(ae.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ae.key))})]})]})}),e[9]=n,e[10]=h,e[11]=c,e[12]=a,e[13]=g,e[14]=D,e[15]=S,e[16]=I,e[17]=b,e[18]=u.extension,e[19]=u.results,e[20]=u.status,e[21]=u.step,e[22]=u.variants,e[23]=i,e[24]=F,e[25]=N}else F=e[24],N=e[25];const M=N;if(c){let $;e[56]!==i?($=i("settings.themeImport.catalogTitle"),e[56]=i,e[57]=$):$=e[57];let ee;e[58]!==F?(ee=s.jsx("div",{className:"flex flex-col gap-2",children:F}),e[58]=F,e[59]=ee):ee=e[59];let L;e[60]!==i?(L=i("settings.themeImport.catalogHint"),e[60]=i,e[61]=L):L=e[61];let Y;e[62]!==L?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:L}),e[62]=L,e[63]=Y):Y=e[63];let oe;e[64]!==M||e[65]!==Y?(oe=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[Y,M]}),e[64]=M,e[65]=Y,e[66]=oe):oe=e[66];let de;return e[67]!==r||e[68]!==ee||e[69]!==oe||e[70]!==$?(de=s.jsx(Uc,{open:!0,title:$,onClose:r,footer:ee,children:oe}),e[67]=r,e[68]=ee,e[69]=oe,e[70]=$,e[71]=de):de=e[71],de}let U;e[72]!==r?(U=$=>{$||r()},e[72]=r,e[73]=U):U=e[73];let K;e[74]===Symbol.for("react.memo_cache_sentinel")?(K={forceRender:!0},e[74]=K):K=e[74];let W;e[75]!==i?(W=i("settings.themeImport.catalogTitle"),e[75]=i,e[76]=W):W=e[76];let te;e[77]!==W?(te=s.jsx(Vt,{children:W}),e[77]=W,e[78]=te):te=e[78];let Q;e[79]!==i?(Q=i("settings.themeImport.catalogHint"),e[79]=i,e[80]=Q):Q=e[80];let H;e[81]!==Q?(H=s.jsx(Ht,{children:Q}),e[81]=Q,e[82]=H):H=e[82];let _;e[83]!==te||e[84]!==H?(_=s.jsxs(Bt,{children:[te,H]}),e[83]=te,e[84]=H,e[85]=_):_=e[85];let V;e[86]!==F||e[87]!==M||e[88]!==_?(V=s.jsxs(Ut,{className:"max-w-lg",backdropProps:K,children:[_,M,F]}),e[86]=F,e[87]=M,e[88]=_,e[89]=V):V=e[89];let X;return e[90]!==V||e[91]!==U?(X=s.jsx(_t,{open:!0,onOpenChange:U,children:V}),e[90]=V,e[91]=U,e[92]=X):X=e[92],X}function Kv(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function _v(t){return t.key}function Uv(t){return t.isMobile}function zv(){const{t}=Ze(),{importTheme:e,customThemesLoading:a}=fa(),n=jo(),[r,i]=o.useState(!1),l=o.useCallback(()=>i(!1),[]),d=o.useRef(null),c=o.useRef(0),h=o.useRef(null),[g,f]=o.useState(!1);o.useEffect(()=>rr(()=>{c.current+=1,i(!1)}),[]);const p=async(w,b)=>{f(!0);try{if(w.size>_c)throw new ra("size");const k=await w.text();if(b.key!==jn()||b.generation!==c.current)throw new ra("connection");const m=await e(jd(k,w.name));Ha.success(t("settings.themeImport.success",{name:m.metadata.name})),i(!1)}catch(k){const m=k instanceof ra?k.code:"invalid";Ha.error(t(`settings.themeImport.error.${m}`))}finally{f(!1)}},u=async()=>{if(g)return;const w={key:jn(),generation:c.current};if(h.current=w,!n.themeFiles){d.current?.click();return}f(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const k=b.file;await p({name:k.name,size:k.size,text:async()=>k.text},w)}return}d.current?.click()}catch{Ha.error(t("settings.themeImport.error.invalid"))}finally{f(!1)}},v=async w=>{const b=w.target.files?.[0];w.target.value="",b&&!g&&h.current&&await p(b,h.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(G,{variant:"outline",size:"sm",disabled:g||a,onClick:()=>i(!0),children:[s.jsx(z,{name:g?"loader":"add",className:g?"size-3.5 animate-spin":"size-3.5"}),t(g?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(qt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:d,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:v}),r&&s.jsx(Lv,{pickFile:()=>{u()},fileBusy:g,onClose:l})]})}const nc=(t,e,a)=>{const n=t?.querySelector("[cmdk-list]"),r=t?.querySelector(`[cmdk-item][data-value="${CSS.escape(e)}"]`);if(!n||!r)return;const i=n.getBoundingClientRect(),l=n.offsetHeight>0?i.height/n.offsetHeight:1;if(l<=0)return;const d=r.getBoundingClientRect(),c=(d.top-i.top)/l+n.scrollTop,h=d.height/l;a?.onlyIfHidden&&c>=n.scrollTop&&c+h<=n.scrollTop+n.clientHeight||(n.scrollTop=Math.max(0,c-(n.clientHeight-h)/2))};function ac({options:t,value:e,onValueChange:a,placeholder:n,ariaLabel:r}){const{t:i}=Ze(),{deleteImportedTheme:l,customThemeIds:d}=fa(),{isMobile:c}=Qn(),[h,g]=o.useState(!1),[f,p]=o.useState(""),[u,v]=o.useState(void 0),[w,b]=o.useState(null),k=o.useRef(null),m=o.useRef(null),[S,P]=o.useState(null),[I,j]=o.useState(null),D=o.useCallback(M=>{const U=M instanceof HTMLElement?M:null,K=U?.closest('[data-slot="dialog-content"], [role="dialog"]');P(K instanceof HTMLElement?K:null),j(U?.closest("main")??null)},[]);o.useEffect(()=>{if(h)return yu.suspend()},[h]);const x=o.useRef(e);x.current=e;const A=o.useCallback(M=>{M&&nc(M,x.current)},[]),R=t.find(M=>M.id===e),C=o.useMemo(()=>h?gi(t,f,M=>[M.label]):t,[h,t,f]),E=M=>{a(M),g(!1)},O=async M=>{if(!w){b(M.id);try{await l(M.id),k.current?.focus()}catch{Ha.error(i("settings.themeImport.deleteError"))}finally{b(null)}}},F=M=>{if(!d.includes(M.id))return null;const U=w===M.id;return s.jsx(G,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:U,"aria-label":i("settings.themeImport.delete",{name:M.label}),onPointerDown:K=>K.stopPropagation(),onClick:K=>{K.stopPropagation(),O(M)},children:s.jsx(z,{name:U?"loader":"delete-bin",className:U?"size-4 animate-spin":"size-4"})})},N=s.jsx("div",{role:"status",className:"px-3 py-6 text-center typography-ui-label text-muted-foreground",children:i("settings.openchamber.visual.field.noThemesFound")});return c?s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button","aria-label":r,"aria-haspopup":"dialog",className:Ie(Ws,!R&&"text-muted-foreground"),onClick:()=>{p(""),g(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R?.label??n}),s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(Uc,{open:h,title:r,onClose:()=>g(!1),children:s.jsxs("div",{className:"flex flex-col gap-2 px-3 pb-4 pt-1",children:[s.jsx(We,{value:f,onChange:M=>p(M.target.value),placeholder:i("settings.openchamber.visual.field.searchThemes"),"aria-label":i("settings.openchamber.visual.field.searchThemes"),className:"h-9"}),s.jsx("div",{className:"flex flex-col",role:"listbox","aria-label":r,children:C.length===0?N:C.map(M=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{type:"button",role:"option","aria-selected":M.id===e,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]",onClick:()=>E(M.id),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M.label}),M.id===e?s.jsx(z,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),F(M)]},M.id))})]})})]}):s.jsxs(Zm,{open:h,onOpenChange:M=>{p(""),v(M?e:void 0),g(M)},onOpenChangeComplete:M=>{if(!M){m.current?.focus();return}k.current?.focus(),nc(k.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs(Xm,{ref:m,"aria-label":r,"aria-haspopup":"dialog",className:Ie(Ws,!R&&"text-muted-foreground"),onPointerDownCapture:M=>D(M.currentTarget),onFocusCapture:M=>D(M.currentTarget),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R?.label??n}),s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(ep,{container:S??void 0,children:s.jsx(tp,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:I??void 0,className:"z-[120]",children:s.jsx(sp,{role:"dialog","aria-label":r,className:Ie(Iu,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(ju,{ref:A,className:"min-h-0 flex-1",shouldFilter:!1,value:u,onValueChange:v,children:[s.jsx(wu,{ref:k,"aria-label":i("settings.openchamber.visual.field.searchThemes"),placeholder:i("settings.openchamber.visual.field.searchThemes"),value:f,onValueChange:p,onKeyDown:M=>{if(ku(M)){M.stopPropagation();return}Nu(M,U=>{M.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:U,bubbles:!0,cancelable:!0}))})}}),s.jsx(Su,{label:r,className:"max-h-[20rem] p-1",children:C.length===0?N:C.map(M=>s.jsxs(Cu,{value:M.id,onSelect:E,"aria-current":M.id===e?!0:void 0,className:"max-w-full typography-ui-label",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M.label}),M.id===e?s.jsx(z,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,F(M)]},M.id))})]})})})})]})}const $v=[{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"}],Bv=[{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"}],Vv=[{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"}],ni="OpenChamber - AI Coding Assistant",ic=[{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"}],rc=[{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"}],qr=t=>t==="portrait"||t==="landscape"?t:"system",Hv=[{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"}],qv=[{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"}],oc=[{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"}],Gv=[{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"}],lc=[{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"}],cc=[{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"}],Wv=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Jv=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],Qv=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],Yv=t=>t==="markdown"?"markdown":"plain",Zv=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Xv=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],or=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=Ze(),l=o.useCallback(y=>i(y),[i]),{isMobile:d}=Qn(),{terminal:c}=jo(),{browserTab:h}=Em(),g=cm(),f=fe(y=>y.showReasoningTraces),p=fe(y=>y.sessionRecapEnabled),u=fe(y=>y.sessionSuggestionEnabled),v=fe(y=>y.setSessionRecapEnabled),w=fe(y=>y.setSessionSuggestionEnabled),b=fe(y=>y.sessionGoalEnabled),k=fe(y=>y.setSessionGoalEnabled),m=fe(y=>y.sessionGoalDefaultBudgetEnabled),S=fe(y=>y.setSessionGoalDefaultBudgetEnabled),P=fe(y=>y.sessionGoalDefaultBudget),I=fe(y=>y.setSessionGoalDefaultBudget),j=fe(y=>y.setShowReasoningTraces),D=fe(y=>y.streamingAutoFollowEnabled),x=fe(y=>y.setStreamingAutoFollowEnabled),A=fe(y=>y.collapsibleThinkingBlocks),R=fe(y=>y.setCollapsibleThinkingBlocks),C=tl(y=>y.animatedActivityIndicators),E=tl(y=>y.setAnimatedActivityIndicators),O=fe(y=>y.mermaidRenderingMode),F=fe(y=>y.setMermaidRenderingMode),N=fe(y=>y.userMessageRenderingMode),M=fe(y=>y.setUserMessageRenderingMode),U=fe(y=>y.collapsibleUserMessages),K=fe(y=>y.setCollapsibleUserMessages),W=fe(y=>y.stickyUserHeader),te=fe(y=>y.promptNavigatorEnabled),Q=fe(y=>y.setStickyUserHeader),H=fe(y=>y.setPromptNavigatorEnabled),_=fe(y=>y.autoSaveEnabled),V=fe(y=>y.setAutoSaveEnabled),X=fe(y=>y.wideChatLayoutEnabled),$=fe(y=>y.setWideChatLayoutEnabled),ee=fe(y=>y.codeBlockLineWrap),L=fe(y=>y.setCodeBlockLineWrap),Y=fe(y=>y.chatRenderMode),oe=fe(y=>y.setChatRenderMode),de=fe(y=>y.activityRenderMode),ge=fe(y=>y.setActivityRenderMode),ce=fe(y=>y.fontSize),Se=fe(y=>y.setFontSize),ie=fe(y=>y.terminalFontSize),be=fe(y=>y.setTerminalFontSize),ae=fe(y=>y.terminalShell),me=fe(y=>y.setTerminalShell),je=fe(y=>y.terminalLoginShells),De=fe(y=>y.setTerminalLoginShells),ue=fe(y=>y.editorFontSize),$e=fe(y=>y.setEditorFontSize),Ge=fe(y=>y.uiFont),xe=fe(y=>y.setUiFont),Pe=fe(y=>y.monoFont),J=fe(y=>y.setMonoFont),se=fe(y=>y.padding),he=fe(y=>y.setPadding),ve=fe(y=>y.inputBarOffset),Fe=fe(y=>y.setInputBarOffset),Ke=fe(y=>y.mobileKeyboardMode),Be=fe(y=>y.setMobileKeyboardMode),ze=fe(y=>y.diffLayoutPreference),_e=fe(y=>y.setDiffLayoutPreference),Me=fe(y=>y.showTerminalQuickKeysOnDesktop),tt=fe(y=>y.sessionTabsEnabled),pt=fe(y=>y.setSessionTabsEnabled),ct=fe(y=>y.setShowTerminalQuickKeysOnDesktop),dt=fe(y=>y.fileEditorKeymap),ht=fe(y=>y.setFileEditorKeymap),Ue=sl(y=>y.followUpBehavior),st=sl(y=>y.setFollowUpBehavior),ut=Di(y=>y.scope),ye=Di(y=>y.entryLimit),re=Di(y=>y.applyScope),Te=Di(y=>y.applyEntryLimit),Ne=fe(y=>y.persistChatDraft),Ae=fe(y=>y.setPersistChatDraft),q=fe(y=>y.inputSpellcheckEnabled),Le=fe(y=>y.setInputSpellcheckEnabled),Qe=fe(y=>y.largeTextPasteBehavior),lt=fe(y=>y.setLargeTextPasteBehavior),ot=fe(y=>y.enterToSend),bt=fe(y=>y.setEnterToSend),wt=fe(y=>y.enterToSendConfigured),jt=fe(y=>y.setEnterToSendConfigured),vt=wt?ot:!d,Xe=fe(y=>y.showToolFileIcons),kt=fe(y=>y.setShowToolFileIcons),Re=fe(y=>y.showTurnChangedFiles),Ve=fe(y=>y.setShowTurnChangedFiles),Z=fe(y=>y.showExpandedBashTools),pe=fe(y=>y.setShowExpandedBashTools),Oe=fe(y=>y.showExpandedEditTools),Ee=fe(y=>y.setShowExpandedEditTools),Ye=fe(y=>y.timeFormatPreference),ne=fe(y=>y.setTimeFormatPreference),we=fe(y=>y.weekStartPreference),nt=fe(y=>y.setWeekStartPreference),Rt=fe(y=>y.showSplitAssistantMessageActions),Jt=fe(y=>y.setShowSplitAssistantMessageActions),Ce=fe(y=>y.allowPromptingSubagentSessions),He=fe(y=>y.setAllowPromptingSubagentSessions),yt=fe(y=>y.draftStartersVisible),It=fe(y=>y.setDraftStartersVisible),Qt=it(y=>y.settingsMessageStreamTransport),Xt=it(y=>y.setSettingsMessageStreamTransport),ts=Qt,es=it(y=>y.settingsDefaultFileViewerPreview),Fs=it(y=>y.setSettingsDefaultFileViewerPreview),Qs=fe(y=>y.isSettingsDialogOpen),{themeMode:pn,setThemeMode:Ls,availableThemes:Ks,customThemesLoading:on,reloadCustomThemes:Ys,lightThemeId:Zs,darkThemeId:_s,setLightThemePreference:Tn,setDarkThemePreference:Mt}=fa(),[Gt,Kt]=o.useState(!1),Et=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),is=fe(y=>y.dockBadgeEnabled),ss=fe(y=>y.setDockBadgeEnabled),lr=fe(y=>y.alwaysShowScrollbars===!0),cr=fe(y=>y.setAlwaysShowScrollbars),dr=dm(),ur=fe(y=>y.desktopWindowControlsPosition),vi=fe(y=>y.setDesktopWindowControlsPosition),mr=fe(y=>y.desktopWindowControlsStyle),yi=fe(y=>y.setDesktopWindowControlsStyle),[pr,Bs]=o.useState(0),Qa=fe(y=>y.reportUsage),ji=fe(y=>y.setReportUsage),wi=o.useCallback(y=>{ji(y),ft({reportUsage:y})},[ji]),gr=o.useCallback(y=>{vi(y),ft({desktopWindowControlsPosition:y})},[vi]),hr=o.useCallback(y=>{yi(y),ft({desktopWindowControlsStyle:y})},[yi]),ki=(Qs||d||fs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!ki)return;let y=null,xt=Date.now();const ms=()=>{const bn=Date.now();bn-xt>=420&&(Bs(Zn=>(Zn+1)%24),xt=bn),y=requestAnimationFrame(ms)};(typeof document>"u"||document.visibilityState==="visible")&&(y=requestAnimationFrame(ms));const Es=()=>{document.visibilityState==="visible"&&y===null?y=requestAnimationFrame(ms):document.visibilityState!=="visible"&&y!==null&&(cancelAnimationFrame(y),y=null)};return document.addEventListener("visibilitychange",Es),()=>{document.removeEventListener("visibilitychange",Es),y!==null&&cancelAnimationFrame(y)}},[ki]);const fr=o.useCallback(y=>{M(y),ft({userMessageRenderingMode:y})},[M]),xr=o.useCallback(y=>{Q(y),ft({stickyUserHeader:y})},[Q]),js=o.useCallback(y=>{H(y),ft({promptNavigatorEnabled:y})},[H]),ln=o.useCallback(y=>{It(y),ft({draftStartersVisible:y})},[It]),ba=o.useCallback(y=>{K(y),ft({collapsibleUserMessages:y})},[K]),En=o.useCallback(y=>{$(y),ft({wideChatLayoutEnabled:y})},[$]),$n=o.useCallback(y=>{Jt(y),ft({showSplitAssistantMessageActions:y})},[Jt]),Ko=o.useCallback(y=>{Le(y),ft({inputSpellcheckEnabled:y})},[Le]),cn=o.useCallback(y=>{bt(y),jt(!0),ft({enterToSend:y,enterToSendConfigured:!0})},[bt,jt]),br=o.useCallback(y=>{oe(y),ft({chatRenderMode:y})},[oe]),va=o.useCallback(y=>{Xt(y),ft({messageStreamTransport:y})},[Xt]),ya=o.useCallback(y=>{re(y),ft({inputHistoryScope:y})},[re]),Yn=o.useCallback(y=>{const xt=Math.round(y);um(xt)&&(Te(xt),ft({inputHistoryLimit:xt}))},[Te]),Ya=o.useCallback(y=>{ge(y),ft({activityRenderMode:y})},[ge]),vr=o.useCallback(y=>{F(y),ft({mermaidRenderingMode:y})},[F]),ds=o.useCallback(y=>{kt(y),ft({showToolFileIcons:y})},[kt]),yr=o.useCallback(y=>{Ve(y),ft({showTurnChangedFiles:y})},[Ve]),ja=o.useCallback(y=>{Fs(y),ft({defaultFileViewerPreview:y}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:y}}))},[Fs]),wa=o.useCallback(y=>{pe(y),ft({showExpandedBashTools:y})},[pe]),jr=o.useCallback(y=>{Ee(y),ft({showExpandedEditTools:y})},[Ee]),Ni=o.useCallback(y=>{ne(y),ft({timeFormatPreference:y})},[ne]),wr=o.useCallback(y=>{nt(y),ft({weekStartPreference:y})},[nt]),Bn=o.useMemo(()=>Ks.filter(y=>y.metadata.variant==="light").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ks]),gn=o.useMemo(()=>Ks.filter(y=>y.metadata.variant==="dark").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ks]),ka=o.useMemo(()=>Bn.find(y=>y.metadata.id===Zs)??Bn[0],[Bn,Zs]),Si=o.useMemo(()=>gn.find(y=>y.metadata.id===_s)??gn[0],[gn,_s]),Na=o.useCallback((y,xt)=>{const ms=xt==="dark"?" Dark":" Light";return y.endsWith(ms)?y.slice(0,-ms.length):y},[]),Sa=o.useMemo(()=>Bn.map(y=>({id:y.metadata.id,label:Na(y.metadata.name,"light")})),[Bn,Na]),kr=o.useMemo(()=>gn.map(y=>({id:y.metadata.id,label:Na(y.metadata.name,"dark")})),[gn,Na]),ke=y=>y==="enterToSend"&&d?!1:t?t.includes(y):!0,Ss=fs(),Ca=ke("theme")&&!Ss,Ci=ke("windowControlsPosition")&&dr,Ii=ke("theme")||ke("timeFormat")||ke("weekStart"),Pi=Ss?Ii:ke("theme")||Ci||ke("pwaInstallName")||ke("pwaOrientation")||ke("timeFormat")||ke("weekStart"),Ai=ke("fontSize")||ke("terminalFontSize")||ke("editorFontSize")||ke("spacing")||ke("scrollbars")&&!Ca||ke("inputBarOffset")&&d,Ti=ke("terminalQuickKeys")&&!d||(ke("terminalShell")||ke("terminalLoginShell"))&&!Ss||ke("fileEditorKeymap")||ke("autoSaveEnabled")||ke("sessionTabs")&&!Ss&&!d,Nr=ke("mermaidRendering")||ke("sessionGoal")&&!Ss||ke("userMessageRendering")||ke("chatRenderMode")||ke("messageTransport")||ke("activityRenderMode")||ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("codeBlockLineWrap")||ke("splitAssistantMessageActions")||ke("subagentReadOnlyBanner")||ke("diffLayout")||ke("dotfiles")||ke("fileViewerPreview")||ke("reasoning")||ke("followUpBehavior")||ke("inputHistoryScope")||ke("inputHistoryLimit")||ke("persistDraft")||ke("largeTextPaste")||ke("showToolFileIcons")||ke("expandedTools")||!d&&ke("inputSpellcheck")||ke("enterToSend"),hn=ke("chatRenderMode")||ke("activityRenderMode"),Vn=ke("messageTransport"),Ia=ke("userMessageRendering")||ke("mermaidRendering")||ke("diffLayout")&&!Ss||ke("followUpBehavior")||ke("inputHistoryScope")||ke("inputHistoryLimit"),Sr=ke("sessionAssist")||ke("sessionGoal")&&!Ss||ke("subagentReadOnlyBanner")||ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("codeBlockLineWrap")||ke("splitAssistantMessageActions")||ke("dotfiles")||ke("fileViewerPreview")||ke("persistDraft")||ke("largeTextPaste")||ke("showToolFileIcons")||ke("showTurnChangedFiles")||!d&&ke("inputSpellcheck")||ke("enterToSend")||ke("reasoning")||ke("expandedTools"),T=Pi||Ai||Ti,le=ke("pwaInstallName")&&da()&&h&&!ls()&&!Ss,Je=ke("pwaOrientation")&&da()&&!ls()&&!Ss,rt=ke("mobileKeyboardMode")&&da()&&!ls()&&!Ss&&mm(),Ft=(ke("terminalShell")||ke("terminalLoginShell"))&&!Ss,[xs,Xs]=o.useState([]),[us,Us]=o.useState(0);o.useEffect(()=>rr(()=>{Xs([]),Us(y=>y+1)}),[]),o.useEffect(()=>{let y=!1;if(!(!Ft||!c.listShells))return c.listShells().then(xt=>{y||Xs(xt)}).catch(()=>{y||Xs([])}),()=>{y=!0}},[Ft,c,us]);const Dn=o.useMemo(()=>{const y=xs.filter(xt=>xt.id!=="auto");return ae==="auto"||y.some(xt=>xt.id===ae)?y:[{id:ae,name:ae,supportsLogin:!1},...y]},[xs,ae]),fn=xs.find(y=>y.id===ae)?.supportsLogin===!0,Pa=je.includes(ae),Aa=y=>{De(y?[...je.filter(xt=>xt!==ae),ae]:je.filter(xt=>xt!==ae))},[Lt,Yt]=o.useState(""),[xn,dn]=o.useState("system"),Zt=o.useMemo(()=>{const y=lc.find(xt=>xt.id===Ye);return l(y?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Ye,l]),Cs=o.useMemo(()=>{const y=cc.find(xt=>xt.id===we);return l(y?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[we,l]),Ta=o.useMemo(()=>{const y=ic.find(xt=>xt.id===xn);return y?l(y.labelKey):void 0},[xn,l]),Ea=o.useMemo(()=>{const y=rc.find(xt=>xt.id===Ke);return y?l(y.labelKey):void 0},[Ke,l]),Da=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,Es=y.trim().replace(/\s+/g," ").slice(0,64);if(await ft({pwaAppName:Es}),typeof xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const bn=xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Es);Yt(bn);return}Yt(Es||ni),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),_o=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,ms=qr(y);if(await ft({pwaOrientation:ms}),typeof xt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Es=xt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ms);dn(Es);return}dn(ms),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!le&&!Je&&!rt)return;let y=!1;return(async()=>{try{const ms=await An();if(!ms){y||Yt(ni);return}const bn=(ms.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Zn=qr(ms.pwaOrientation),Ei=ol(ms.mobileKeyboardMode);y||(le&&Yt(bn||ni),Je&&dn(Zn),rt&&Be(Ei))}catch{y||(le&&Yt(ni),Je&&dn("system"),rt&&Be("native"))}})(),()=>{y=!0}},[Be,rt,le,Je]);const Cr=ke("scrollbars")?s.jsx(gt,{checked:lr,onChange:cr,label:i("settings.openchamber.visual.field.alwaysShowScrollbars"),info:i("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Pi&&s.jsxs("div",{className:"space-y-0",children:[Ca&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Rn,{children:[s.jsx("div",{className:Rs,children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.colorMode"),children:$v.map(y=>s.jsx(ks,{selected:pn===y.value,onSelect:()=>Ls(y.value),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.value))})}),s.jsxs("div",{className:Rs,children:[s.jsx(Ot,{label:i("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(ac,{options:Sa,value:ka?.metadata.id??"",onValueChange:Tn,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Ot,{label:i("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(ac,{options:kr,value:Si?.metadata.id??"",onValueChange:Mt,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectDarkThemeAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:on||Gt,onClick:()=>{const y=Date.now();Kt(!0),Ys().finally(()=>{const xt=Date.now()-y;if(xt<500){window.setTimeout(()=>{Kt(!1)},500-xt);return}Kt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(z,{name:"restart",className:Ie("h-3.5 w-3.5",Gt&&"animate-spin")}),i(Gt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(qt,{children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(zv,{})]})]}),Et&&s.jsx(Wa,{settingsItem:"appearance.dock-badge",children:s.jsx(gt,{checked:is,onChange:ss,label:i("settings.openchamber.visual.field.dockBadge"),info:i("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:i("settings.openchamber.visual.field.dockBadge")})}),Cr&&s.jsx(Wa,{children:Cr})]}),Ci&&s.jsx(qe,{title:i("settings.openchamber.desktopNetwork.field.windowControls"),info:i("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Ca,children:s.jsxs(Rn,{children:[s.jsx(Ot,{label:i("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(mn,{value:ur,options:Zv.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:gr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Ot,{label:i("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(mn,{value:mr,options:Xv.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:hr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ii&&s.jsx(qe,{title:i("settings.openchamber.visual.section.localization"),children:s.jsxs(Rn,{children:[s.jsx(Ot,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Tt,{value:e,onValueChange:y=>n(y),children:[s.jsx(Pt,{"aria-label":i("settings.appearance.language.select"),size:$t,className:Ra,children:s.jsx(zt,{children:r(e)})}),s.jsx(At,{children:a.map(y=>s.jsx(mt,{value:y,children:r(y)},y))})]})}),(ke("timeFormat")||ke("weekStart"))&&s.jsxs("div",{className:Rs,children:[ke("timeFormat")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Tt,{value:Ye,onValueChange:y=>Ni(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),size:$t,className:Ra,children:s.jsx(zt,{children:Zt})}),s.jsx(At,{children:lc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})}),ke("weekStart")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Tt,{value:we,onValueChange:y=>wr(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),size:$t,className:Ra,children:s.jsx(zt,{children:Cs})}),s.jsx(At,{children:cc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})})]})]})}),(le||Je||rt)&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.appInstall"),contentClassName:Rs,children:[le&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.installAppName"),info:i("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Ps,children:[s.jsx(We,{value:Lt,onChange:y=>{Yt(y.target.value)},onBlur:()=>{Da(Lt)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),Da(Lt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Yt(ni),Da("")},className:ps,"aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),Je&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.installOrientation"),description:i("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Ps,children:[s.jsxs(Tt,{value:xn,onValueChange:y=>{const xt=qr(y);dn(xt),_o(xt)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:$t,className:qo,children:s.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ta})}),s.jsx(At,{children:ic.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{dn("system"),_o("system")},disabled:xn==="system",className:ps,"aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),rt&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.mobileKeyboardMode"),info:i("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Ps,children:[s.jsxs(Tt,{value:Ke,onValueChange:y=>{const xt=ol(y);Be(xt),ft({mobileKeyboardMode:xt})},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:$t,className:qo,children:s.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ea})}),s.jsx(At,{children:rc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Be("native"),ft({mobileKeyboardMode:"native"})},disabled:Ke==="native",className:ps,"aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Ai&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.densityAndType"),contentClassName:Rs,children:[ke("fontSize")&&!d||ke("terminalFontSize")?s.jsxs(Rn,{children:[ke("fontSize")&&!d&&s.jsxs(Ot,{label:i("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Tt,{value:Ge,onValueChange:y=>xe(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),size:$t,className:Ra,children:s.jsx(zt,{children:nl.find(y=>y.id===Ge)?.label})}),s.jsx(At,{children:nl.map(y=>s.jsx(mt,{value:y.id,children:s.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(al),disabled:Ge===al,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),ke("terminalFontSize")&&s.jsxs(Ot,{label:i("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Tt,{value:Pe,onValueChange:y=>J(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),size:$t,className:Ra,children:s.jsx(zt,{children:il.find(y=>y.id===Pe)?.label})}),s.jsx(At,{children:il.map(y=>s.jsx(mt,{value:y.id,children:s.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>J(rl),disabled:Pe===rl,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ke("fontSize")&&!d||ke("terminalFontSize")||ke("editorFontSize")?s.jsxs(Rn,{children:[ke("fontSize")&&!d&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:ce,onValueChange:Se,min:50,max:200,step:5,className:vs,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Se(100),disabled:ce===100,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("terminalFontSize")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:ie,onValueChange:be,min:9,max:52,step:1,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(13),disabled:ie===13,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("editorFontSize")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:ue,onValueChange:$e,min:9,max:32,step:1,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>$e(13),disabled:ue===13,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ke("spacing")||ke("inputBarOffset")&&d?s.jsxs(Rn,{children:[ke("spacing")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:se,onValueChange:he,min:50,max:200,step:5,className:vs}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(100),disabled:se===100,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("inputBarOffset")&&d&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.inputBarOffset"),info:i("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:ve,onValueChange:Fe,min:0,max:100,step:5,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Fe(0),disabled:ve===0,className:ps,"aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!Ca&&Cr]}),ke("animatedActivityIndicators")&&s.jsx(qe,{title:i("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:cs,children:s.jsx(gt,{checked:C,onChange:E,label:i("settings.openchamber.visual.field.animatedActivityIndicators"),ariaLabel:i("settings.openchamber.visual.field.animatedActivityIndicatorsAria"),info:i("settings.openchamber.visual.field.animatedActivityIndicatorsInfo"),settingsItem:"appearance.animated-activity-indicators"})}),Ti&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ke("fileEditorKeymap")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(y=>s.jsx(ks,{selected:dt===y,onSelect:()=>ht(y),label:i(`settings.openchamber.visual.option.fileEditorKeymap.${y}`),ariaLabel:i(`settings.openchamber.visual.option.fileEditorKeymap.${y}`)},y))})}),s.jsxs("div",{className:cs,children:[ke("autoSaveEnabled")&&s.jsx(gt,{checked:_,onChange:V,label:i("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:i("settings.openchamber.visual.field.autoSaveEnabledAria"),info:i("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Ft&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.terminalShell"),info:i("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Tt,{value:ae,onValueChange:y=>{pm(y)&&me(y)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.terminalShellAria"),size:$t,className:Ra,children:s.jsx(zt,{})}),s.jsxs(At,{children:[s.jsx(mt,{value:"auto",children:i("settings.openchamber.visual.option.terminalShell.auto")}),Dn.map(y=>s.jsx(mt,{value:y.id,children:y.name},y.id))]})]})}),Ft&&fn&&s.jsx(gt,{checked:Pa,onChange:Aa,label:i("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:i("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ke("terminalQuickKeys")&&!d&&s.jsx(gt,{checked:Me,onChange:ct,label:i("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:ua("ctrl"),alt:ua("alt")})})]}),ke("sessionTabs")&&!Ss&&!d&&s.jsx(ws,{title:i("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(gt,{checked:tt,onChange:pt,label:i("settings.openchamber.visual.field.sessionTabs"),ariaLabel:i("settings.openchamber.visual.field.sessionTabsAria"),info:i("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Nr&&s.jsxs(s.Fragment,{children:[hn&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.chatDisplay"),divider:T,contentClassName:"space-y-6",children:[ke("chatRenderMode")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:qv.map(y=>{const xt=Y===y.id,ms=pr%12;return s.jsxs("button",{type:"button",onClick:()=>br(y.id),"aria-pressed":xt,className:Ie("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",xt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:Ie("typography-ui-label",xt?"text-inherit":"text-muted-foreground"),children:l(y.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:y.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Es=>{const bn=Es*3+1,Zn=ms-bn+1,Ei=Zn<=0?0:Zn===1?42:Zn===2?68:92,Rd=Ei>0;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Rd?"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:`${Ei}%`}})]},Es)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Es=>{const bn=ms>=(Es+1)*3;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",bn?"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%"}})]},Es)})})})]},y.id)})})}),ke("activityRenderMode")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),children:Gv.map(y=>s.jsx(ks,{selected:de===y.id,onSelect:()=>Ya(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(y.labelKey)})},y.id))})})]}),Vn&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.messageStreamTransport"),divider:hn||T,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(mn,{value:ts,options:oc.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:va,"aria-label":i("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const y=oc.find(xt=>xt.id===ts);return y?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(y.descriptionKey)}):null})()]}),Ia&&s.jsx(qe,{title:i("settings.openchamber.visual.section.chatMessageOptions"),divider:hn||Vn||T,children:s.jsxs(Rn,{className:"lg:gap-y-6",children:[ke("userMessageRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),children:Hv.map(y=>s.jsx(ks,{selected:Yv(N)===y.id,onSelect:()=>fr(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(y.labelKey)})},y.id))})}),ke("mermaidRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),children:Vv.map(y=>s.jsx(ks,{selected:O===y.id,onSelect:()=>vr(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(y.labelKey)})},y.id))})}),ke("diffLayout")&&!Ss&&s.jsx(ws,{title:i("settings.openchamber.visual.section.diffLayout"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),children:Bv.map(y=>s.jsx(ks,{selected:ze===y.id,onSelect:()=>_e(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(y.labelKey)})},y.id))})}),ke("followUpBehavior")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),children:Wv.map(y=>s.jsx(ks,{selected:Ue===y.id,onSelect:()=>st(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(y.labelKey)})},y.id))})}),ke("inputHistoryScope")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.inputHistoryScope"),info:i("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.inputHistoryScopeAria"),children:Qv.map(y=>s.jsx(ks,{selected:ut===y.id,onSelect:()=>ya(y.id),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.id))})}),ke("inputHistoryLimit")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.inputHistoryLimit"),description:i("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Ps,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:Oa,children:[s.jsx(gs,{value:ye,onValueChange:Yn,min:hm,max:gm,step:1,className:vs,deferExternalValueWhileFocused:!0,"aria-label":i("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Fa,children:i("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),Sr&&s.jsxs(s.Fragment,{children:[ke("expandedTools")&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:hn||Vn||Ia||T,contentClassName:cs,children:[s.jsx(gt,{checked:Z,onChange:wa,label:i("settings.openchamber.visual.field.bash"),ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:Oe,onChange:jr,label:i("settings.openchamber.visual.field.editTools"),ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(qe,{title:i("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:cs,children:[s.jsx(gt,{checked:yt,onChange:ln,label:i("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:i("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ke("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:p,onChange:v,label:i("settings.openchamber.visual.field.sessionRecap"),ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:u,onChange:w,label:i("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ke("subagentReadOnlyBanner")&&s.jsx(gt,{checked:Ce,onChange:He,label:i("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ke("sessionGoal")&&!Ss&&s.jsxs(qe,{title:i("settings.openchamber.visual.goal.sectionTitle"),info:i("settings.openchamber.visual.goal.description"),contentClassName:cs,children:[s.jsx(gt,{checked:b,onChange:k,label:i("settings.openchamber.visual.field.sessionGoal"),ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(gt,{checked:m,onChange:S,disabled:!b,label:i("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),b&&m?s.jsx(gs,{value:P,onValueChange:y=>{typeof y=="number"&&Number.isFinite(y)&&y>0&&I(Math.floor(y))},min:1e3,max:1e8,step:5e4}):null]})]}),ke("reasoning")&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:cs,children:[s.jsx(gt,{checked:f,onChange:j,label:i("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),f&&s.jsx(gt,{checked:A,onChange:R,label:i("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(qe,{title:i("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:cs,children:s.jsx(gt,{checked:D,onChange:x,label:i("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:i("settings.openchamber.visual.field.streamingAutoFollowAria"),info:i("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("splitAssistantMessageActions")||ke("codeBlockLineWrap"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:cs,children:[ke("collapsibleUserMessages")&&s.jsx(gt,{checked:U,onChange:ba,label:i("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ke("stickyUserHeader")&&s.jsx(gt,{checked:W,onChange:xr,label:i("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ke("promptNavigatorEnabled")&&s.jsx(gt,{checked:te,onChange:js,label:i("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ke("wideChatLayout")&&s.jsx(gt,{checked:X,onChange:En,label:i("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ke("splitAssistantMessageActions")&&s.jsx(gt,{checked:Rt,onChange:$n,label:i("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ke("codeBlockLineWrap")&&s.jsx(gt,{checked:ee,onChange:L,label:i("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ke("showToolFileIcons")||ke("showTurnChangedFiles")||ke("dotfiles")&&!fs()||ke("fileViewerPreview"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:cs,children:[ke("showToolFileIcons")&&s.jsx(gt,{checked:Xe,onChange:ds,label:i("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ke("showTurnChangedFiles")&&s.jsx(gt,{checked:Re,onChange:yr,label:i("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ke("dotfiles")&&!fs()&&s.jsx(gt,{checked:g,onChange:fm,label:i("settings.openchamber.visual.field.showDotfiles"),ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ke("fileViewerPreview")&&s.jsx(gt,{checked:es,onChange:ja,label:i("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ke("persistDraft")||ke("largeTextPaste")||!d&&ke("inputSpellcheck")||ke("enterToSend"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ke("persistDraft")||!d&&ke("inputSpellcheck"))&&s.jsxs("div",{className:cs,children:[ke("persistDraft")&&s.jsx(gt,{checked:Ne,onChange:Ae,label:i("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!d&&ke("inputSpellcheck")&&s.jsx(gt,{checked:q,onChange:Ko,label:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ke("largeTextPaste")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.largeTextPaste"),info:i("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.field.largeTextPasteAria"),children:Jv.map(y=>s.jsx(ks,{selected:Qe===y.id,onSelect:()=>lt(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(y.labelKey)})},y.id))})}),ke("enterToSend")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.enterToSend"),info:i("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(sn,{"aria-label":i("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(ks,{selected:vt,onSelect:()=>cn(!0),label:i("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(ks,{selected:!vt,onSelect:()=>cn(!1),label:i("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ke("reportUsage")&&s.jsx(qe,{title:i("settings.openchamber.visual.section.privacy"),children:s.jsx(gt,{checked:Qa,onChange:wi,label:i("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},ey=1,ty=365,dc=30,sy=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],wd=()=>{const t=at.c(105),{t:e}=Ze(),a=fe(ny),n=fe(ay),r=fe(iy),i=fe(ry),l=fe(oy),d=fe(ly),c=fe(cy);let h;t[0]===Symbol.for("react.memo_cache_sentinel")?(h={autoRun:!1},t[0]=h):h=t[0];const{candidates:g,isRunning:f,runCleanup:p,action:u,status:v}=Pu(h),w=g.length;let b;t[1]!==p||t[2]!==e?(b=async()=>{const me=await p({force:!0}).catch(()=>(B.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!me||me.skippedReason&&me.skippedReason!=="no-candidates")){if(me.completedIds.length===0&&me.failedIds.length===0){B.message(me.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}me.completedIds.length>0&&B.success(me.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:me.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:me.completedIds.length})),me.failedIds.length>0&&B.error(me.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:me.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:me.failedIds.length}))}},t[1]=p,t[2]=e,t[3]=b):b=t[3];const k=b;let m;t[4]!==e?(m=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=m):m=t[5];const S=r?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let P;t[6]!==e||t[7]!==S?(P=e(S),t[6]=e,t[7]=S,t[8]=P):P=t[8];let I;t[9]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=I):I=t[10];let j;t[11]!==e?(j=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=j):j=t[12];let D;t[13]!==a||t[14]!==i||t[15]!==I||t[16]!==j?(D=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:I,ariaLabel:j}),t[13]=a,t[14]=i,t[15]=I,t[16]=j,t[17]=D):D=t[17];let x;t[18]!==e?(x=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=x):x=t[19];let A;t[20]!==e?(A=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=A):A=t[21];let R;t[22]!==e?(R=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=R):R=t[23];let C;t[24]!==f||t[25]!==r||t[26]!==c||t[27]!==R||t[28]!==x||t[29]!==A?(C=s.jsx(gt,{settingsItem:"sessions.retention-only-archived",checked:r,onChange:c,disabled:f,label:x,ariaLabel:A,info:R}),t[24]=f,t[25]=r,t[26]=c,t[27]=R,t[28]=x,t[29]=A,t[30]=C):C=t[30];let E;t[31]!==e?(E=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=E):E=t[32];let O;t[33]!==e?(O=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=O):O=t[34];let F;t[35]===Symbol.for("react.memo_cache_sentinel")?(F=Ie(vs,"tabular-nums"),t[35]=F):F=t[35];let N;t[36]!==n||t[37]!==l||t[38]!==O?(N=s.jsx(gs,{value:n,onValueChange:l,min:ey,max:ty,step:1,"aria-label":O,className:F}),t[36]=n,t[37]=l,t[38]=O,t[39]=N):N=t[39];let M;t[40]!==e?(M=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=M):M=t[41];let U;t[42]!==M?(U=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M}),t[42]=M,t[43]=U):U=t[43];let K;t[44]!==l?(K=()=>l(dc),t[44]=l,t[45]=K):K=t[45];const W=n===dc;let te;t[46]!==e?(te=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=te):te=t[47];let Q;t[48]!==e?(Q=e("settings.common.actions.reset"),t[48]=e,t[49]=Q):Q=t[49];let H;t[50]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=H):H=t[50];let _;t[51]!==K||t[52]!==W||t[53]!==te||t[54]!==Q?(_=s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:K,disabled:W,className:ps,"aria-label":te,title:Q,children:H}),t[51]=K,t[52]=W,t[53]=te,t[54]=Q,t[55]=_):_=t[55];let V;t[56]!==E||t[57]!==N||t[58]!==U||t[59]!==_?(V=s.jsxs(Ct,{settingsItem:"sessions.retention-period",label:E,children:[N,U,_]}),t[56]=E,t[57]=N,t[58]=U,t[59]=_,t[60]=V):V=t[60];let X;t[61]!==e?(X=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=X):X=t[62];let $;t[63]!==r||t[64]!==e?($=sy.map(me=>({value:me.value,label:e(me.labelKey),disabled:r&&me.value==="archive"})),t[63]=r,t[64]=e,t[65]=$):$=t[65];let ee;t[66]!==u||t[67]!==d||t[68]!==$?(ee=s.jsx(mn,{value:u,onChange:d,options:$}),t[66]=u,t[67]=d,t[68]=$,t[69]=ee):ee=t[69];let L;t[70]!==X||t[71]!==ee?(L=s.jsx(Ct,{settingsItem:"sessions.retention-action",label:X,children:ee}),t[70]=X,t[71]=ee,t[72]=L):L=t[72];let Y;t[73]!==C||t[74]!==V||t[75]!==L?(Y=s.jsxs(Wa,{className:"space-y-0",children:[C,V,L]}),t[73]=C,t[74]=V,t[75]=L,t[76]=Y):Y=t[76];let oe;t[77]!==e?(oe=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=oe):oe=t[78];let de;t[79]!==f||t[80]!==e?(de=e(f?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=f,t[80]=e,t[81]=de):de=t[81];let ge;t[82]!==k||t[83]!==f||t[84]!==de?(ge=s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:k,disabled:f,className:"!font-normal",children:de}),t[82]=k,t[83]=f,t[84]=de,t[85]=ge):ge=t[85];let ce;t[86]!==oe||t[87]!==ge?(ce=s.jsx(Ct,{label:oe,children:ge}),t[86]=oe,t[87]=ge,t[88]=ce):ce=t[88];let Se;t[89]!==u||t[90]!==w||t[91]!==v||t[92]!==e?(Se=v==="error"?e("sessions.sidebar.group.empty.loadFailed"):v!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):u==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:w}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:w}),t[89]=u,t[90]=w,t[91]=v,t[92]=e,t[93]=Se):Se=t[93];let ie;t[94]!==Se?(ie=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Se}),t[94]=Se,t[95]=ie):ie=t[95];let be;t[96]!==ce||t[97]!==ie?(be=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[ce,ie]}),t[96]=ce,t[97]=ie,t[98]=be):be=t[98];let ae;return t[99]!==m||t[100]!==Y||t[101]!==be||t[102]!==P||t[103]!==D?(ae=s.jsxs(qe,{title:m,info:P,children:[D,Y,be]}),t[99]=m,t[100]=Y,t[101]=be,t[102]=P,t[103]=D,t[104]=ae):ae=t[104],ae};function ny(t){return t.autoDeleteEnabled}function ay(t){return t.autoDeleteAfterDays}function iy(t){return t.sessionRetentionOnlyArchived}function ry(t){return t.setAutoDeleteEnabled}function oy(t){return t.setAutoDeleteAfterDays}function ly(t){return t.setSessionRetentionAction}function cy(t){return t.setSessionRetentionOnlyArchived}const uc=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(yo(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),kd=()=>{const{t}=Ze(),e=fe(D=>D.timeFormatPreference),[a,n]=o.useState(!1),[r,i]=o.useState(!0),[l,d]=o.useState(!1),[c,h]=o.useState(null),[g,f]=o.useState(!1),[p,u]=o.useState([]),[v,w]=o.useState(Au),[b,k]=o.useState(""),m=o.useMemo(()=>Tu(),[]),S=o.useCallback(async()=>{i(!0),k("");try{const D=await Eu();u(D)}catch(D){const x=D instanceof Error?D.message:t("settings.openchamber.passkeys.toast.loadFailed");k(x)}finally{i(!1)}},[t]);o.useEffect(()=>{let D=!1;return(async()=>{try{if(!m.supported){D||(n(!1),i(!1));return}D||n(!0)}catch{D||n(!1)}if(!D){const x=await Ar();if(w(x),!x.enabled){u([]),i(!1);return}await S()}})(),()=>{D=!0,Go()}},[S,m.supported]);const P=o.useCallback(async()=>{if(!v.enabled){const D=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(D),B.message(D);return}if(!a){k(m.reason),B.message(m.reason);return}if(l){Go(),d(!1);return}k(""),d(!0);try{await Du(),w(await Ar()),await S(),B.success(t("settings.openchamber.passkeys.toast.added"))}catch(D){if(Mu(D)){B.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const x=D instanceof Error?D.message:t("settings.openchamber.passkeys.toast.addFailed");k(x),B.error(x)}finally{d(!1)}},[l,S,v.enabled,m.reason,a,t]),I=o.useCallback(async D=>{h(D),k("");try{await Ru(D),w(await Ar()),await S(),B.success(t("settings.openchamber.passkeys.toast.removed"))}catch(x){const A=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.removeFailed");k(A),B.error(A)}finally{h(null)}},[S,t]),j=o.useCallback(async()=>{f(!0),k("");try{await Ou(),window.location.reload()}catch(D){const x=D instanceof Error?D.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(x),B.error(x),f(!1)}},[t]);return s.jsxs(qe,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ct,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(G,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{P()},disabled:r||g,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{j()},disabled:r||l||g,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(g?"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:m.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(D=>s.jsxs(Ct,{label:s.jsx("span",{title:D.label,children:D.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:D.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:uc(D.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:uc(D.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(D.id)},disabled:c===D.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===D.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},D.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},Nd=()=>{const t=at.c(14),{t:e}=Ze(),a=Wo(dy),n=Wo(uy);let r;t[0]!==e?(r=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=r):r=t[1];let i;t[2]!==e?(i=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=i):i=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(h=>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:`${h}://`}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(h),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${h}://`}),children:e("settings.common.actions.delete")})]},h)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let d;t[8]!==l?(d=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=d):d=t[9];let c;return t[10]!==r||t[11]!==i||t[12]!==d?(c=s.jsx(qe,{title:r,description:i,children:d}),t[10]=r,t[11]=i,t[12]=d,t[13]=c):c=t[13],c};function dy(t){return t.trustedSchemes}function uy(t){return t.removeTrustedScheme}const my=()=>{const{t}=Ze(),[e,a]=o.useState(null),n=o.useRef(0);o.useEffect(()=>{let i=!1;return Gs.getConfig(null).then(l=>{!i&&n.current===0&&a(!!l.warming)},l=>console.warn("[session-warming] failed to read config",l)),()=>{i=!0}},[]);const r=o.useCallback(async i=>{const l=e,d=++n.current;a(i),os("saving");try{const c=await St("/api/config/warming",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({enabled:i})});if(!c.ok)throw new Error(`HTTP ${c.status}`);os("saved"),Gs.clearConfigCache()}catch(c){console.warn("[session-warming] failed to save",c),os("error"),d===n.current&&a(l)}},[e]);return s.jsx(gt,{settingsItem:"sessions.warming",checked:e??!1,disabled:e===null,onChange:i=>{r(i)},label:t("settings.openchamber.defaults.field.sessionWarming"),info:t("settings.openchamber.defaults.field.sessionWarmingInfo")})},Gr=t=>{const e=Ln(t);return e||{providerId:"",modelId:""}},Sd=()=>{const{t}=Ze(),e=it(ie=>ie.setProvider),a=it(ie=>ie.setModel),n=it(ie=>ie.setAgent),r=it(ie=>ie.setCurrentVariant),i=it(ie=>ie.setCurrentVariantOverride),l=it(ie=>ie.setSettingsDefaultModel),d=it(ie=>ie.setSettingsDefaultVariant),c=it(ie=>ie.setSettingsDefaultAgent),h=it(ie=>ie.selectionSource==="manual"),g=Fu(ie=>ie.currentSessionId),f=Jo(ie=>ie.getSessionModelSelection),p=Jo(ie=>ie.getSessionAgentSelection),u=it(ie=>ie.agentSelectionSource==="manual"),w=!!(it(ie=>{if(ie.agentSelectionSource!=="manual")return!1;const be=ie.agents.find(ae=>ae.name===ie.currentAgentName);return!!(be?.model?.providerID&&be.model.id)})||h&&g&&f(g)),b=!!(u&&g&&p(g)),k=fe(ie=>ie.showDeletionDialog),m=fe(ie=>ie.setShowDeletionDialog),S=it(ie=>ie.providers),P=it(ie=>ie.modelsMetadata),[I,j]=o.useState(),[D,x]=o.useState(),[A,R]=o.useState(),[C,E]=o.useState(!0),[O,F]=o.useState(),[N,M]=o.useState([]),[U,K]=o.useState(),[W,te]=o.useState(!0),Q=o.useMemo(()=>Gr(I),[I]);o.useEffect(()=>{(async()=>{try{const be=await An();if(be){const ae=be.defaultModel?.trim()||void 0,me=be.defaultVariant?.trim()||void 0,je=be.defaultAgent?.trim()||void 0;ae!==void 0&&j(ae),me!==void 0&&x(me),je!==void 0&&R(je),be.smallModelUseDefault!==void 0&&E(be.smallModelUseDefault);const De=be.smallModelOverride?.trim();De&&F(De);const ue=be.walkthroughModelOverride?.trim();ue&&K(ue)}}catch(be){console.warn("Failed to load defaults settings:",be)}finally{te(!1)}})()},[]);const H=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;j(ae),x(void 0),d(void 0),l(ae),w||(r(void 0),ie&&be&&(S.find(je=>je.id===ie)||qc(ie,be))&&(e(ie),a(be)));try{await ft({defaultModel:ae??"",defaultVariant:""})}catch(me){console.warn("Failed to save default model:",me)}},[w,S,r,a,e,l,d]),_="__default__",V=o.useCallback(ie=>ie===_?t("settings.openchamber.defaults.option.default"):ie.charAt(0).toUpperCase()+ie.slice(1),[t]),X=o.useCallback(async ie=>{const be=ie===_?void 0:ie||void 0;x(be),d(be),w||i(be??null,be);try{await ft({defaultVariant:be??""})}catch(ae){console.warn("Failed to save default variant:",ae)}},[w,i,d]),$=o.useCallback(async ie=>{const be=ie||void 0;R(be),c(be),ie&&!b&&n(ie);try{await ft({defaultAgent:be??""})}catch(ae){console.warn("Failed to save default agent:",ae)}},[b,n,c]),ee=o.useCallback(async ie=>{E(ie);try{await ft({smallModelUseDefault:ie})}catch(be){console.warn("Failed to save small model preference:",be)}},[]),L=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;F(ae);try{await ft({smallModelOverride:ae??""})}catch(me){console.warn("Failed to save small model override:",me)}},[]),Y=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;K(ae);try{await ft({walkthroughModelOverride:ae??""})}catch(me){console.warn("Failed to save walkthrough model override:",me)}},[]),oe=o.useCallback((ie,be)=>P.get(`${ie}/${be}`)?.structured_output!==!1,[P]),de=o.useMemo(()=>Gr(O),[O]),ge=o.useMemo(()=>Gr(U),[U]);o.useEffect(()=>{let ie=!1;return(async()=>{try{const be=await St("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!be.ok)return;const ae=await be.json().catch(()=>null);!ie&&Array.isArray(ae?.authenticatedProviders)&&M(ae.authenticatedProviders.filter(me=>typeof me=="string"))}catch{}})(),()=>{ie=!0}},[]);const ce=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const be=S.find(ae=>ae.id===Q.providerId)?.models.find(ae=>ae.id===Q.modelId);return Lu(be?.variants)},[Q.modelId,Q.providerId,S]),Se=ce.length>0;return W?null:s.jsx(s.Fragment,{children:s.jsx(qe,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,Se?` (${D??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),A&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:A})]})]}),s.jsxs("div",{children:[s.jsx(Ct,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ca,{providerId:Q.providerId,modelId:Q.modelId,onChange:H,className:Ws,offerAuto:!0})}),s.jsx(Ct,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Tt,{value:D??_,onValueChange:X,disabled:!Se,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:V(D??_)})}),s.jsxs(At,{children:[s.jsx(mt,{value:_,children:t("settings.openchamber.defaults.option.default")}),ce.map(ie=>s.jsx(mt,{value:ie,children:V(ie)},ie))]})]})}),s.jsx(Ct,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(fo,{agentName:A||"",onChange:$,filter:ie=>Fc(ie.mode),className:Ws})})]}),s.jsxs(Wa,{className:cs,children:[s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:k,onChange:m,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx(my,{})]}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(qt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:C,onChange:ie=>{ee(ie)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),C?null:s.jsx(Ct,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ca,{providerId:de.providerId,modelId:de.modelId,onChange:L,allowedProviderIds:N,className:Ws})}),s.jsxs(Wa,{className:cs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(qt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ct,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ca,{providerId:ge.providerId,modelId:ge.modelId,onChange:Y,allowedProviderIds:N,isModelAllowed:oe,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Ws})})]})]})]})})})},mc={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"}},py={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"},gy=()=>{const{t}=Ze(),e=o.useMemo(()=>ls(),[]),a=o.useMemo(()=>fs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!a&&!n,i=fe(_=>_.nativeNotificationsEnabled),l=fe(_=>_.setNativeNotificationsEnabled),d=fe(_=>_.notificationMode),c=fe(_=>_.setNotificationMode),h=fe(_=>_.notifyOnSubtasks),g=fe(_=>_.setNotifyOnSubtasks),f=fe(_=>_.notifyOnCompletion),p=fe(_=>_.setNotifyOnCompletion),u=fe(_=>_.notifyOnError),v=fe(_=>_.setNotifyOnError),w=fe(_=>_.notifyOnQuestion),b=fe(_=>_.setNotifyOnQuestion),k=fe(_=>_.notificationTemplates),m=fe(_=>_.setNotificationTemplates),[S,P]=o.useState("default"),[I,j]=o.useState(!1),[D,x]=o.useState(!1),[A,R]=o.useState(!1);o.useEffect(()=>{if(!r){j(!1),x(!1);return}typeof Notification<"u"&&P(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(_),(async()=>{if(!_){x(!1);return}try{const X=await navigator.serviceWorker.getRegistration();if(!X){x(!1);return}const $=await X.pushManager.getSubscription();x(!!$)}catch{x(!1)}})()},[r]);const C=async _=>{if(e){l(_);return}if(!r){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();P(V),V==="granted"?l(!0):B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(V){console.error("Failed to request notification permission:",V),B.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&S==="granted"))},E=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",O=(_,V,X)=>{m($=>({...$,[_]:{...$[_],[V]:X}}))},F=_=>{const V="=".repeat((4-_.length%4)%4),X=(_+V).replace(/-/g,"+").replace(/_/g,"/"),$=atob(X),ee=new Uint8Array($.length);for(let L=0;L<$.length;L+=1)ee[L]=$.charCodeAt(L);return ee},N=async(_,V,X)=>{let $=null;const ee=new Promise((L,Y)=>{$=setTimeout(()=>{Y(new Error(X))},V)});try{return await Promise.race([_,ee])}finally{$&&clearTimeout($)}},M=async _=>{if(_.active)return;const V=_.installing||_.waiting;V&&V.state!=="activated"&&await N(new Promise(X=>{const $=()=>{V.state==="activated"&&(V.removeEventListener("statechange",$),X())};V.addEventListener("statechange",$),$()}),15e3,"Service worker activation timed out")},U=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 V=null;for(const X of _)try{const $=X.opts?navigator.serviceWorker.register("/sw.js",X.opts):navigator.serviceWorker.register("/sw.js");return await N($,1e4,`Service worker registration timed out (${X.label})`)}catch($){V=$}throw V instanceof Error?V:new Error("Service worker registration failed")},K=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const V=await U();try{await V.update()}catch{}return await M(V),V},W=_=>{const V=_,X=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let $="";try{$=JSON.stringify(_)}catch{}return{summary:X.filter(Boolean).join(" | "),json:$,stack:typeof V?.stack=="string"?V.stack:""}},te=async()=>{const _=Va();if(!_?.notifications){B.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"})?B.success(t("settings.notifications.page.toast.testNotificationSent")):B.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(V){console.error("Test notification failed:",V),B.error(t("settings.notifications.page.toast.testNotificationFailed"))}},Q=async()=>{if(!I){B.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=Va();if(!_?.push){B.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}R(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(P(de),de!=="granted"){B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const V=await _.push.getVapidPublicKey();if(!V?.publicKey){B.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const X=await K();await M(X);const $=await X.pushManager.getSubscription();if(!("pushManager"in X)||!X.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const L=($??await N(X.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:F(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Y=L.keys;if(!L.endpoint||!Y?.p256dh||!Y.auth)throw new Error("Push subscription missing keys");if(!(await N(_.push.subscribe({endpoint:L.endpoint,keys:{p256dh:Y.p256dh,auth:Y.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:xm()}),15e3,"Push subscribe request timed out"))?.ok){B.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}x(!0),B.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(V){console.error("[Push] Enable failed:",V);const X=W(V);B.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:X.summary})}finally{R(!1)}},H=async()=>{if(!I){x(!1);return}const _=Va();if(!_?.push){B.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}R(!0);try{const X=await(await K()).pushManager.getSubscription();if(!X){x(!1);return}const $=X.endpoint;await X.unsubscribe(),await _.push.unsubscribe({endpoint:$}),x(!1),B.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{R(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(qe,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:cs,children:[s.jsx(gt,{checked:i&&E,onChange:_=>{C(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:r?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&E&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:d==="always",onChange:_=>c(_?"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(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{te()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1",children:[S==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),S==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&E&&s.jsxs(s.Fragment,{children:[s.jsx(qe,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:cs,children:[s.jsx(gt,{checked:f,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:h,onChange:g,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:u,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:w,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(qe,{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(--syntax-variable)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{last_message}"})]}),children:s.jsx(Rn,{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(Cn,{className:"capitalize",children:t(py[_])}),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(We,{value:k[_].title,onChange:V=>O(_,"title",V.target.value),className:"h-7",placeholder:t(mc[_].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(We,{value:k[_].message,onChange:V=>O(_,"message",V.target.value),className:"h-7",placeholder:t(mc[_].messageKey)})]})]})]},_))})})]}),r&&s.jsx(qe,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:I?D:!1,disabled:!I||A,onChange:_=>{_?Q():H()},label:t("settings.notifications.page.push.enableLabel"),description:I?void 0:t("settings.notifications.page.push.unsupportedHint"),info:I?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:A?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()},Mn="oc-surface-elevated w-full h-7 rounded-lg border border-input bg-surface-elevated px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring focus:border-interactive-border-focus",hy=[{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"}],pc=t=>{const e=at.c(8),{value:a,label:n}=t,r=`${n}: ${a}/5`,i=`${a/5*100}%`;let l;e[0]!==i?(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:i}})}),e[0]=i,e[1]=l):l=e[1];let d;e[2]!==n?(d=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=d):d=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==d?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,d]}),e[4]=r,e[5]=l,e[6]=d,e[7]=c):c=e[7],c},fy=({selectedModelId:t,onSelect:e})=>{const{t:a}=Ze(),n=et.useCallback(p=>a(p),[a]),[r,i]=et.useState(new Map),[l,d]=et.useState(null),c=et.useCallback(async()=>{try{const p=await St("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const u=await p.json();Array.isArray(u?.models)&&i(new Map(u.models.map(v=>[v.id,v])))}catch{}},[]);et.useEffect(()=>{c()},[c]);const h=Array.from(r.values()).some(p=>p.downloading);et.useEffect(()=>{if(!h)return;const p=setInterval(()=>{c()},2e3);return()=>clearInterval(p)},[h,c]);const g=async p=>{d(p);try{await St(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},f=async p=>{d(p);try{await St(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await c()}catch{}finally{d(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:hy.map(p=>{const u=t===p.id,v=r.get(p.id)??null;return s.jsx("div",{className:Ie("rounded-lg border border-[var(--interactive-border)] p-3",u&&"border-border bg-interactive-selection text-interactive-selection-foreground"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(xo,{checked:u,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:Ie("typography-ui-label font-normal",u?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(pc,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(pc,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),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(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===p.id,onClick:()=>{f(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):v?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof v.downloadProgress=="number"?`${v.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===p.id,onClick:()=>{g(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},xy=[{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)"}],uo="kokoro-en-v0_19",by="kokoro-multi-lang-v1_1",vy=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],ai=(t,e)=>`${t}:${e}`,yy=()=>{const[t,e]=et.useState([]),[a,n]=et.useState(null),r=et.useCallback(async()=>{try{const d=await St("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);et.useEffect(()=>{r()},[r]);const i=t.some(d=>d.downloading);et.useEffect(()=>{if(!i)return;const d=setInterval(()=>{r()},2e3);return()=>clearInterval(d)},[i,r]);const l=et.useCallback(async(d,c)=>{n(d);try{const h=c==="POST"?`/api/dictation/models/${d}/download`:`/api/dictation/models/${d}`;await St(h,{method:c}),await r()}catch{}finally{n(null)}},[r]);return{models:t,requestingId:a,request:l,refresh:r}},jy=t=>{const e=xy.map(a=>({modelId:uo,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===uo||!a.installed)){if(a.id===by){for(const n of vy)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},wy=t=>{const e=at.c(14),{models:a,requestingId:n,request:r}=t,{t:i}=Ze();let l,d,c;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==i){c=Symbol.for("react.early_return_sentinel");e:{const g=a.filter(Sy);if(g.length===0){c=null;break e}l="flex flex-col";let f;e[7]!==r||e[8]!==n||e[9]!==i?(f=p=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:p.description??p.id}),p.installed?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{r(p.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})})]}):p.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof p.downloadProgress=="number"?`${p.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(p.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})}),p.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:p.downloadError}):null]},p.id),e[7]=r,e[8]=n,e[9]=i,e[10]=f):f=e[10],d=g.map(f)}e[0]=a,e[1]=r,e[2]=n,e[3]=i,e[4]=l,e[5]=d,e[6]=c}else l=e[4],d=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let h;return e[11]!==l||e[12]!==d?(h=s.jsx("div",{className:l,children:d}),e[11]=l,e[12]=d,e[13]=h):h=e[13],h},ky=[{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"}],Ny=()=>{const{t}=Ze(),{isMobile:e}=Qn(),a=it(q=>q.voiceProvider),n=it(q=>q.setVoiceProvider),r=it(q=>q.speechRate),i=it(q=>q.setSpeechRate),l=it(q=>q.speechPitch),d=it(q=>q.setSpeechPitch),c=it(q=>q.speechVolume),h=it(q=>q.setSpeechVolume),g=it(q=>q.sayVoice),f=it(q=>q.setSayVoice),p=it(q=>q.localTtsVoiceId),u=it(q=>q.localTtsModelId),v=it(q=>q.setLocalTtsModelId),w=yy(),b=et.useMemo(()=>jy(w.models),[w.models]),k=it(q=>q.ttsFollowTextLanguage),m=it(q=>q.setTtsFollowTextLanguage),S=it(q=>q.setLocalTtsVoiceId),{speak:P,stop:I,isPlaying:j,error:D}=Ku(),x=et.useCallback(()=>{if(j){I();return}const q=b.find(Le=>Le.modelId===u&&Le.speakerId===p)?.label??String(p);P(t("settings.voice.page.preview.voiceLine",{voiceName:q}),{model:u,speakerId:p,speed:it.getState().speechRate})},[j,u,p,b,P,I,t]),A=it(q=>q.browserVoice),R=it(q=>q.setBrowserVoice),C=it(q=>q.openaiVoice),E=it(q=>q.setOpenaiVoice),O=it(q=>q.openaiApiKey),F=it(q=>q.setOpenaiApiKey),N=it(q=>q.openaiCompatibleUrl),M=it(q=>q.setOpenaiCompatibleUrl),U=it(q=>q.openaiCompatibleApiKey),K=it(q=>q.setOpenaiCompatibleApiKey),W=it(q=>q.openaiCompatibleVoice),te=it(q=>q.setOpenaiCompatibleVoice),Q=it(q=>q.openaiCompatibleTtsModel),H=it(q=>q.setOpenaiCompatibleTtsModel),_=it(q=>q.showMessageTTSButtons),V=it(q=>q.ttsInputMode),X=it(q=>q.setTtsInputMode),$=it(q=>q.sttProvider),ee=it(q=>q.setSttProvider),L=it(q=>q.sttServerUrl),Y=it(q=>q.setSttServerUrl),oe=it(q=>q.sttApiKey),de=it(q=>q.setSttApiKey),ge=it(q=>q.sttModel),ce=it(q=>q.setSttModel),Se=it(q=>q.sttLocalModel),ie=it(q=>q.setSttLocalModel),be=it(q=>q.sttLanguage),ae=it(q=>q.setSttLanguage),me=it(q=>q.setShowMessageTTSButtons),je=it(q=>q.dictationEnabled),De=it(q=>q.setDictationEnabled),[ue,$e]=et.useState(!1),[Ge,xe]=et.useState([]),[Pe,J]=et.useState(!1),[se,he]=et.useState(null),[ve,Fe]=et.useState(!1),[Ke,Be]=et.useState(!1),[ze,_e]=et.useState(null),[Me,tt]=et.useState(!1),[pt,ct]=et.useState(null),[dt,ht]=et.useState([]),[Ue,st]=et.useState(!1);et.useEffect(()=>((async()=>{const Le=await Tr.waitForVoices();ht(Le)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{ht(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ut=et.useMemo(()=>dt.filter(q=>q.lang).sort((q,Le)=>{const Qe=q.lang.startsWith("en"),lt=Le.lang.startsWith("en");if(Qe&&!lt)return-1;if(!Qe&&lt)return 1;const ot=q.lang.localeCompare(Le.lang);return ot!==0?ot:q.name.localeCompare(Le.name)}),[dt]),ye=et.useCallback(()=>{if(Ue){Tr.cancelSpeech(),st(!1);return}const q=dt.find(ot=>ot.name===A),Le=q?.name??t("settings.voice.page.preview.browserVoiceFallback"),Qe=t("settings.voice.page.preview.voiceLine",{voiceName:Le});st(!0);const lt=new SpeechSynthesisUtterance(Qe);lt.rate=r,lt.pitch=l,lt.volume=c,q&&(lt.voice=q,lt.lang=q.lang),lt.onend=()=>st(!1),lt.onerror=()=>st(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[A,dt,r,l,c,Ue,t]);et.useEffect(()=>()=>{Ue&&Tr.cancelSpeech()},[Ue]),et.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){Fe(O.trim().length>0);return}(async()=>{try{const lt=(await(await St("/api/tts/status")).json()).available,ot=O.trim().length>0;Fe(lt||ot)}catch{Fe(O.trim().length>0)}})()},[O,_,a]),et.useEffect(()=>{if(!_){$e(!1),xe([]);return}St("/api/tts/say/status").then(q=>q.json()).then(q=>{if($e(q.available),q.voices){const Le=q.voices.filter((Qe,lt,ot)=>ot.findIndex(bt=>bt.name===Qe.name)===lt).sort((Qe,lt)=>Qe.name.localeCompare(lt.name));xe(Le)}}).catch(()=>{$e(!1)})},[_]);const re=et.useCallback(async()=>{if(se){Ds(se),he(null),J(!1);return}J(!0);let q=null;try{const Le=await St("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,rate:Math.round(100+(r-.5)*200)})});if(!Le.ok)throw new Error("Preview failed");const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),he(null),J(!1)},q.onerror=()=>{Ds(q),he(null),J(!1)},he(q),await q.play()}catch{Ds(q),he(null),J(!1)}},[g,r,se,t]);et.useEffect(()=>()=>{Ds(se)},[se]);const Te=et.useCallback(async()=>{if(ze){Ds(ze),_e(null),Be(!1);return}Be(!0);let q=null;try{const Le=await St("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:C}),voice:C,speed:r,apiKey:O||void 0})});if(!Le.ok){const ot=await Le.json().catch(()=>({error:"Unknown error"}));throw new Error(ot.error||`HTTP ${Le.status}`)}const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),_e(null),Be(!1)},q.onerror=()=>{Ds(q),_e(null),Be(!1)},_e(q),await q.play()}catch{Ds(q),_e(null),Be(!1)}},[C,r,ze,O,t]);et.useEffect(()=>()=>{Ds(ze)},[ze]);const Ne=et.useCallback(async()=>{if(pt){Ds(pt),ct(null),tt(!1);return}if(!N.trim())return;tt(!0);let q=null;try{const Le=await St("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:W,model:Q||void 0,speed:r,baseURL:N,apiKey:U||void 0})});if(!Le.ok){const ot=await Le.json().catch(()=>({error:"Unknown error"}));throw new Error(ot.error||`HTTP ${Le.status}`)}const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),ct(null),tt(!1)},q.onerror=()=>{Ds(q),ct(null),tt(!1)},ct(q),await q.play()}catch{Ds(q),ct(null),tt(!1)}},[N,W,Q,U,r,pt,t]);et.useEffect(()=>()=>{Ds(pt)},[pt]);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(qe,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(gt,{checked:_,onChange:me,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),_&&s.jsxs(s.Fragment,{children:[s.jsx(ws,{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(mn,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...ue?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ie(Nt,!ve&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Ie(ys,!ve&&"text-[var(--status-error)]/80"),children:t(ve&&!O?"settings.voice.page.field.apiKeyHintUsingConfig":ve?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:O,onChange:q=>F(q.target.value),placeholder:"sk-...",className:Mn}),O&&s.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ie(Nt,!N.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(qt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:N,onChange:q=>M(q.target.value),placeholder:"http://localhost:8880/v1",className:Mn}),N&&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(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:"API Key"}),s.jsx("span",{className:ys,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:U,onChange:q=>K(q.target.value),placeholder:"sk-...",className:Mn}),U&&s.jsx("button",{type:"button",onClick:()=>K(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:Q,onChange:q=>H(q.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:Mn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.voice")}),s.jsx(qt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:Ie("flex items-center gap-2",Ps),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:W,onChange:q=>te(q.target.value),placeholder:"af_sky",className:Mn})}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Ne,title:t("settings.voice.page.actions.preview"),disabled:!N.trim(),children:Me?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(wy,{...w}),(a==="local"||a==="say")&&s.jsx(gt,{checked:k,onChange:m,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ct,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:ai(u,p),onValueChange:q=>{const Le=b.find(Qe=>ai(Qe.modelId,Qe.speakerId)===q);Le&&(v(Le.modelId),S(Le.speakerId))},children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:q=>b.find(Le=>ai(Le.modelId,Le.speakerId)===q)?.label??q})}),s.jsx(At,{children:b.map(q=>s.jsx(mt,{value:ai(q.modelId,q.speakerId),children:q.label},ai(q.modelId,q.speakerId)))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:x,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})}),D?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:D}):null]}),a==="openai"&&ve&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:C,onValueChange:E,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:ky.map(q=>s.jsx(mt,{value:q.value,children:q.label},q.value))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Te,title:t("settings.voice.page.actions.preview"),children:Ke?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:ys,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ue&&Ge.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:g,onValueChange:f,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Ge.map(q=>s.jsx(mt,{value:q.name,children:q.name},q.name))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:re,title:t("settings.voice.page.actions.preview"),children:Pe?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&ut.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:A||"$auto",onValueChange:q=>R(q==="$auto"?"":q),children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"$auto",children:t("settings.voice.page.field.auto")}),ut.map(q=>s.jsxs(mt,{value:q.name,children:[q.name," (",q.lang,")"]},q.name))]})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:ye,title:t("settings.voice.page.actions.preview"),children:Ue?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:q=>i(Number(q.target.value)),className:Ae}),s.jsx(gs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:Ie(vs,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:q=>d(Number(q.target.value)),className:Ae}),s.jsx(gs,{value:l,onValueChange:d,min:.5,max:2,step:.1,className:Ie(vs,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:q=>h(Number(q.target.value)),className:Ae}),e?s.jsx(gs,{value:Math.round(c*100),onValueChange:q=>h(q/100),min:0,max:100,step:10,className:Ie(vs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(ws,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(mn,{value:V,onChange:X,"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(qe,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(gt,{checked:je,onChange:De,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),je&&s.jsxs(s.Fragment,{children:[s.jsx(ws,{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(mn,{value:$,onChange:ee,"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")}]})}),$==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx(fy,{selectedModelId:Se,onSelect:ie})]}),$==="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:Ie(Nt,!L.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(qt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:L,onChange:q=>Y(q.target.value),placeholder:"http://localhost:8001/v1",className:Mn}),L&&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(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:"API Key"}),s.jsx("span",{className:ys,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:oe,onChange:q=>de(q.target.value),placeholder:"sk-...",className:Mn}),oe&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:ge,onChange:q=>ce(q.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:Mn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.language")}),s.jsx(qt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:be,onChange:q=>ae(q.target.value),placeholder:"auto",className:Mn})})]})]})]})]})]})};function Sy(t){return t.id===uo||t.installed||t.downloading}const $i=[{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}],Bi=[{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}],Cy="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Iy="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Wr=[{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"}],Py=[".yml",".yaml",".json"],Ay="settings.openchamber.tunnel.error.invalidConfigExtension",ii=t=>{const e=t.trim().toLowerCase();return Py.some(a=>e.endsWith(a))},Ty=t=>t==="ngrok"?"ngrok":"cloudflared",Cd=()=>{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"},Ey=(t,e=Cd())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",Jr=(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():Ty(a),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Cd(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Ey(a,r);return{provider:a,dependency:n,installCommand:i}},Id=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,gc=t=>{const e=at.c(11),{provider:a}=t;let n;e[0]!==a?(n=Id(a),e[0]=a,e[1]=n):n=e[1];const r=n,d=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=Ie("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let h;e[4]!==c?(h=s.jsx(z,{name:"cloud",className:c}),e[4]=c,e[5]=h):h=e[5];let g;e[6]!==r?(g=s.jsx("span",{children:r}),e[6]=r,e[7]=g):g=e[7];let f;return e[8]!==h||e[9]!==g?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[h,g]}),e[8]=h,e[9]=g,e[10]=f):f=e[10],f},qn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",mo=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,hc=(t,e,a)=>{const n=mo(t,e,a);return t.find(r=>r.value===n)?.label||n},fc=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),r=Math.floor(a%3600/60),i=a%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},Dy=(t,e)=>Dc(t,e,{hour:"2-digit",precision:"second"}),Wi=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()}},My=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const r of t){if(!r||typeof r!="object")continue;const i=r,l=typeof i.id=="string"?i.id.trim():"",d=typeof i.name=="string"?i.name.trim():"",c=Wi(typeof i.hostname=="string"?i.hostname:"");!l||!d||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:d,hostname:c}))}return n},Ry=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Oy=()=>{const{t}=Ze(),e=fe(Z=>Z.timeFormatPreference),a=o.useCallback(Z=>t(Z),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[d,c]=o.useState(null),[h,g]=o.useState(null),[f,p]=o.useState(null),[u,v]=o.useState(null),[w,b]=o.useState(!1),[k,m]=o.useState(!1),[S,P]=o.useState(!1),[I,j]=o.useState("cloudflare"),[D,x]=o.useState(()=>Jr("cloudflare")),[A,R]=o.useState([]),[C,E]=o.useState("quick"),[O,F]=o.useState(null),[N,M]=o.useState([]),[U,K]=o.useState({}),[W,te]=o.useState(""),[Q,H]=o.useState({}),[_,V]=o.useState(new Set),[X,$]=o.useState(!1),[ee,L]=o.useState(""),[Y,oe]=o.useState(""),[de,ge]=o.useState(""),[ce,Se]=o.useState(1800*1e3),[ie,be]=o.useState(480*60*1e3),[ae,me]=o.useState(""),[je,De]=o.useState([]),[ue,$e]=o.useState(()=>Date.now()),[Ge,xe]=o.useState(null),Pe=t(Ay),J=o.useRef(null),se=o.useMemo(()=>O?!ii(O):!1,[O]),he=o.useMemo(()=>N.find(Z=>Z.id===W)||N[0]||null,[N,W]),ve=o.useMemo(()=>je.map(Z=>{const pe=Z.expiresAt<=ue,Oe=Z.status==="active"&&!pe,Ee=Oe?fc(Z.expiresAt-ue):Z.inactiveReason==="expired"||pe?"expired":"inactive",Ye=Ee==="expired"?t("settings.openchamber.tunnel.state.expired"):Z.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ne=qn(Z.mode);return{...Z,isActive:Oe,mode:ne,remainingTextForSession:Ee,inactiveLabel:Ye}}),[ue,je,t]),Fe=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>ue:!1,[ue,i?.bootstrapExpiresAt,i?.connectUrl]),Ke=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:d===C,[d,n,i,C]),Be=o.useMemo(()=>!i||n!=="active"||!d?!1:d!==C,[d,n,i,C]),ze=o.useMemo(()=>{if(typeof Ge=="number"&&Number.isFinite(Ge)&&Ge>0)return Ge;if(typeof window>"u")return null;const pe=hi()||window.location.href;let Oe=0;try{Oe=Number(new URL(pe).port)}catch{Oe=Number(window.location.port)}return Number.isFinite(Oe)&&Oe>0?Oe:null},[Ge]),_e=o.useMemo(()=>A.find(Z=>Z.provider===I)??null,[A,I]),Me=o.useMemo(()=>{const Z=new Set(_e?.modes?.map(pe=>pe.key).filter(pe=>pe==="quick"||pe==="managed-remote"||pe==="managed-local"));return Z.size===0?Wr:Wr.filter(pe=>Z.has(pe.value))},[_e]),tt=o.useMemo(()=>Me.some(Z=>Z.value==="managed-remote"||Z.value==="managed-local"),[Me]),pt=o.useMemo(()=>D.provider===I?D:Jr(I),[D,I]),ct=o.useCallback(async Z=>{await yn(Z)},[]),dt=o.useCallback((Z,pe)=>(x(Jr(pe,Z)),Z.available===!0),[]),ht=o.useCallback(async(Z,pe)=>{try{const Oe=await St("/api/openchamber/tunnel/check",{query:{provider:Z},...pe?{signal:pe}:{}});if(!Oe.ok)return null;const Ee=await Oe.json();if(pe?.aborted)return null;const Ye=dt(Ee,Z);return r(ne=>ne==="checking"||ne==="starting"||ne==="active"||ne==="stopping"?ne:Ye?"idle":"not-available"),Ye}catch{return null}},[dt]),Ue=o.useCallback(async Z=>{try{const[pe,Oe,Ee,Ye]=await Promise.all([St("/api/openchamber/tunnel/check",{signal:Z}),St("/api/openchamber/tunnel/status",{signal:Z}),An(),St("/api/openchamber/tunnel/providers",{signal:Z})]),ne=await pe.json(),we=await Oe.json(),nt=Ee??{},Rt=Ye.ok?await Ye.json():{},Jt=we.ttlConfig?.bootstrapTtlMs??(nt.tunnelBootstrapTtlMs===void 0?1800*1e3:nt.tunnelBootstrapTtlMs),Ce=typeof we.ttlConfig?.sessionTtlMs=="number"?we.ttlConfig.sessionTtlMs:nt.tunnelSessionTtlMs??480*60*1e3,He=qn(we.mode??nt.tunnelMode),yt=nt.tunnelProvider??"cloudflare",It=nt.managedLocalTunnelConfigPath??null,Qt=dt(ne,yt),Xt=My(we?.managedRemoteTunnelPresets),ts=typeof we.managedRemoteTunnelHostname=="string"?we.managedRemoteTunnelHostname:"",es=Xt.length>0?Xt:ts?[{id:`legacy-${Wi(ts)}`,name:ts,hostname:Wi(ts)}]:[],Fs=es[0]?.id||"";if(Se(Jt),be(Ce),j(yt),R(Array.isArray(Rt?.providers)?Rt.providers:[]),E(He),F(It),M(es),te(Fs),De(Array.isArray(we.activeSessions)?we.activeSessions:[]),c(we.activeTunnelMode?qn(we.activeTunnelMode):we.active&&we.mode?qn(we.mode):null),V(new Set(Array.isArray(we.managedRemoteTunnelTokenPresetIds)?we.managedRemoteTunnelTokenPresetIds:[])),xe(typeof we.localPort=="number"?we.localPort:null),we.active&&we.url){l({url:we.url,connectUrl:null,bootstrapExpiresAt:typeof we.bootstrapExpiresAt=="number"?we.bootstrapExpiresAt:null}),r("active");return}r(Qt?"idle":"not-available")}catch{Z.aborted||(r("error"),p(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[dt,t]);o.useEffect(()=>{const Z=new AbortController;return Ue(Z.signal),()=>Z.abort()},[Ue]),o.useEffect(()=>{if(!i?.connectUrl){g(null);return}let Z=!1;return Wc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(pe=>{Z||g(pe)}).catch(()=>{Z||g(null)}),()=>{Z=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){me(t("settings.openchamber.tunnel.state.noExpiry"));return}let Z=null,pe=Date.now();const Oe=()=>{const ne=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;ne<=0?me(t("settings.openchamber.tunnel.state.expired")):me(fc(ne))},Ee=()=>{const ne=Date.now();ne-pe>=1e3&&(Oe(),pe=ne),Z=requestAnimationFrame(Ee)};Oe(),(typeof document>"u"||document.visibilityState==="visible")&&(Z=requestAnimationFrame(Ee));const Ye=()=>{document.visibilityState==="visible"&&Z===null?Z=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&Z!==null&&(cancelAnimationFrame(Z),Z=null)};return document.addEventListener("visibilitychange",Ye),()=>{document.removeEventListener("visibilitychange",Ye),Z!==null&&cancelAnimationFrame(Z)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let Z=null,pe=Date.now();const Oe=()=>{const Ye=Date.now();Ye-pe>=1e3&&($e(Ye),pe=Ye),Z=requestAnimationFrame(Oe)};(typeof document>"u"||document.visibilityState==="visible")&&(Z=requestAnimationFrame(Oe));const Ee=()=>{document.visibilityState==="visible"&&Z===null?Z=requestAnimationFrame(Oe):document.visibilityState!=="visible"&&Z!==null&&(cancelAnimationFrame(Z),Z=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),Z!==null&&cancelAnimationFrame(Z)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Z=!1;const pe=async()=>{try{const Ee=await St("/api/openchamber/tunnel/status");if(!Ee.ok||Z)return;const Ye=await Ee.json();if(Z)return;De(Array.isArray(Ye.activeSessions)?Ye.activeSessions:[]),V(new Set(Array.isArray(Ye.managedRemoteTunnelTokenPresetIds)?Ye.managedRemoteTunnelTokenPresetIds:[])),xe(typeof Ye.localPort=="number"?Ye.localPort:null)}catch{}},Oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||pe()},5e3);return()=>{Z=!0,window.clearInterval(Oe)}},[n]);const st=o.useCallback(async Z=>{P(!0);try{await ft(Z),Object.prototype.hasOwnProperty.call(Z,"tunnelMode")&&Z.tunnelMode&&E(Z.tunnelMode),Object.prototype.hasOwnProperty.call(Z,"tunnelProvider")&&typeof Z.tunnelProvider=="string"&&j(Z.tunnelProvider),Object.prototype.hasOwnProperty.call(Z,"managedLocalTunnelConfigPath")&&F(Z.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Z,"managedRemoteTunnelPresets")&&Z.managedRemoteTunnelPresets&&M(Z.managedRemoteTunnelPresets)}catch{B.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{P(!1)}},[t]),ut=o.useCallback(async(Z,pe)=>{m(!0);try{await ft({tunnelBootstrapTtlMs:Z,tunnelSessionTtlMs:pe})}catch{B.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{m(!1)}},[t]),ye=o.useCallback(async Z=>{const pe=Z.token.trim();if(pe)try{const Oe={...Q,[Z.presetId]:pe};await ft({managedRemoteTunnelPresetTokens:Oe}),V(Ee=>{const Ye=new Set(Ee);return Ye.add(Z.presetId),Ye})}catch{B.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[Q,t]),re=o.useCallback(async Z=>{v(null),p(null);const pe=A.find(Ee=>Ee.provider===Z),Oe=pe?.modes?.some(Ee=>Ee.key===C)?C:qn(pe?.modes?.[0]?.key);await st({tunnelProvider:Z,tunnelMode:Oe}),ht(Z)},[A,ht,st,C]),Te=o.useCallback(async()=>{const Z=await No({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Z.success&&typeof Z.path=="string"&&Z.path.trim().length>0){const pe=Z.path.trim();if(!ii(pe)){B.error(Pe);return}F(pe),await st({managedLocalTunnelConfigPath:pe});return}J.current?.click()},[Pe,st]),Ne=o.useCallback(Z=>{const pe=Z.trim();F(pe.length>0?pe:null)},[]),Ae=o.useCallback(async()=>{if(O&&!ii(O)){B.error(Pe);return}await st({managedLocalTunnelConfigPath:O})},[Pe,O,st]),q=o.useCallback(async()=>{F(null),await st({managedLocalTunnelConfigPath:null})},[st]),Le=o.useCallback(async Z=>{const pe=Z.target.files?.[0];if(!pe)return;const Oe=pe.name.trim();if(Oe.length!==0){if(!ii(Oe)){B.error(Pe);return}F(Oe),await st({managedLocalTunnelConfigPath:Oe}),Z.target.value=""}},[Pe,st]),Qe=o.useCallback(async()=>{if(p(null),v(null),C==="managed-local"&&O&&!ii(O)){p(Pe),B.error(Pe);return}r("starting");try{let Z="",pe="";if(C==="managed-remote"){if(!he){r("idle"),v(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),B.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Z=he.hostname,pe=(Q[he.id]||"").trim(),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const Oe=await St("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:C,...C==="managed-remote"&&he?{managedRemoteTunnelPresetId:he.id,managedRemoteTunnelPresetName:he.name}:{},...C==="managed-remote"&&Z?{managedRemoteTunnelHostname:Z}:{},...C==="managed-remote"&&pe?{managedRemoteTunnelToken:pe}:{},...C==="managed-local"&&O?{configPath:O}:{}})}),Ee=await Oe.json();if(!Oe.ok||!Ee.ok){if(C==="managed-remote"&&typeof Ee.error=="string"&&Ee.error.includes("Managed remote tunnel token is required")){r("idle"),v(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),B.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),p(Ee.error||t("settings.openchamber.tunnel.toast.startFailed")),B.error(Ee.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const Ye=typeof Ee.url=="string"?Ee.url:"";if(!Ye){r("error"),p(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),B.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:Ye,connectUrl:typeof Ee.connectUrl=="string"?Ee.connectUrl:null,bootstrapExpiresAt:typeof Ee.bootstrapExpiresAt=="number"?Ee.bootstrapExpiresAt:null}),c(Ee.activeTunnelMode?qn(Ee.activeTunnelMode):Ee.mode?qn(Ee.mode):C),De(Array.isArray(Ee.activeSessions)?Ee.activeSessions:[]),Array.isArray(Ee.managedRemoteTunnelTokenPresetIds)&&V(new Set(Ee.managedRemoteTunnelTokenPresetIds)),typeof Ee.localPort=="number"&&xe(Ee.localPort),typeof Ee.mode=="string"&&E(qn(Ee.mode)),r("active"),Ee.replacedTunnel){const ne=typeof Ee.revokedBootstrapCount=="number"?Ee.revokedBootstrapCount:0,we=typeof Ee.invalidatedSessionCount=="number"?Ee.invalidatedSessionCount:0;ne===1&&we===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ne===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:we})):we===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ne})):B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ne,invalidatedSessionCount:we}))}else B.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),p(t("settings.openchamber.tunnel.toast.startFailed")),B.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Pe,N,st,he,Q,t,I,C,O]),lt=o.useCallback(async()=>{r("stopping");try{await St("/api/openchamber/tunnel/stop",{method:"POST"});const Z=await St("/api/openchamber/tunnel/status");if(Z.ok){const pe=await Z.json();De(Array.isArray(pe.activeSessions)?pe.activeSessions:[]),V(new Set(Array.isArray(pe.managedRemoteTunnelTokenPresetIds)?pe.managedRemoteTunnelTokenPresetIds:[])),xe(typeof pe.localPort=="number"?pe.localPort:null)}l(null),c(null),g(null),r("idle"),B.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),p(t("settings.openchamber.tunnel.toast.stopFailed")),B.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ot=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),b(!0),B.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{B.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),bt=o.useCallback(async Z=>{const pe=$i.find(Oe=>Oe.value===Z);pe&&(Se(pe.ms),await ut(pe.ms,ie))},[ut,ie]),wt=o.useCallback(async Z=>{const pe=Bi.find(Oe=>Oe.value===Z);!pe||pe.ms===null||(be(pe.ms),await ut(ce,pe.ms))},[ce,ut]),jt=o.useCallback(async Z=>{v(null),p(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await st({tunnelMode:Z,managedRemoteTunnelPresets:N})},[N,st,n]),vt=o.useCallback(async(Z,pe)=>{try{await ft({managedRemoteTunnelPresets:pe})}catch{B.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Xe=o.useCallback(Z=>{const pe=N.find(Oe=>Oe.id===Z);pe&&(te(pe.id),v(null),vt(pe,N))},[N,vt]),kt=o.useCallback(async()=>{const Z=ee.trim(),pe=Wi(Y),Oe=de.trim();if(!Z){B.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!pe){B.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Oe){B.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(ne=>ne.hostname===pe)){B.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ee={id:Ry(),name:Z,hostname:pe},Ye=[...N,Ee];M(Ye),te(Ee.id),K(ne=>({...ne,[Ee.id]:!0})),H(ne=>({...ne,[Ee.id]:Oe})),v(null),$(!1),L(""),oe(""),ge(""),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:Ye,managedRemoteTunnelPresetTokens:{...Q,[Ee.id]:Oe}}),await ye({presetId:Ee.id,presetName:Ee.name,hostname:Ee.hostname,token:Oe}),B.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,Y,ee,de,ye,st,Q,t]),Re=o.useCallback(async Z=>{const pe=N.find(we=>we.id===Z);if(!pe)return;const Oe=N.filter(we=>we.id!==pe.id),Ee=Oe[0]?.id||"",Ye=W===pe.id?Ee:W,ne=Object.fromEntries(Object.entries(Q).filter(([we,nt])=>we!==pe.id&&nt.trim().length>0));M(Oe),te(Ye),K(we=>{const nt={...we};return delete nt[pe.id],nt}),H(we=>{const nt={...we};return delete nt[pe.id],nt}),V(we=>{const nt=new Set(we);return nt.delete(pe.id),nt}),v(null),await st({managedRemoteTunnelPresets:Oe,managedRemoteTunnelPresetTokens:ne}),B.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,st,W,Q,t]),Ve="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(qe,{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:[ve.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(z,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Qo,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ve.map(Z=>{const pe=Z.mode==="quick",Oe=Z.mode==="managed-remote",Ee=pe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Oe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",Ye=Z.isActive?pe?"text-[var(--status-warning)]":Oe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ne=t(pe?"settings.openchamber.tunnel.badge.quick":Oe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(z,{name:"checkbox-blank-circle-fill",className:Ie("size-2.5 shrink-0",Ye)}),s.jsx("span",{className:Ie("typography-micro rounded border px-1.5 py-0.5 uppercase",Ee),children:ne}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Dy(Z.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Z.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Z.remainingTextForSession}):Z.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Z.inactiveLabel})})]},Z.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:Qo,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:pt.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:pt.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:Nt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Tt,{value:I,onValueChange:Z=>{re(Z)},disabled:S||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[16rem]",children:s.jsx(zt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Id(I)})}),s.jsxs(At,{children:[A.length>0?A.map(Z=>s.jsx(mt,{value:Z.provider,children:s.jsx(gc,{provider:Z.provider})},Z.provider)):s.jsx(mt,{value:"cloudflare",children:s.jsx(gc,{provider:"cloudflare"})}),s.jsx(mt,{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:Nt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Me.map(Z=>s.jsxs(nr,{children:[s.jsx(ar,{asChild:!0,children:s.jsx(G,{variant:"chip",size:"xs","aria-pressed":C===Z.value,className:"!font-normal",onClick:()=>{jt(Z.value)},disabled:S||n==="starting"||n==="stopping",children:a(Z.labelKey)})}),s.jsx(bo,{sideOffset:8,className:"max-w-xs",children:a(Z.tooltipKey)})]},Z.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:Ie(Nt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Tt,{value:mo($i,ce,"1800000"),onValueChange:Z=>{bt(Z)},disabled:k||S||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(zt,{className:"truncate",children:hc($i,ce,"1800000")})}),s.jsx(At,{children:$i.map(Z=>s.jsx(mt,{value:Z.value,children:Z.label},Z.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(Nt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Tt,{value:mo(Bi,ie,"28800000"),onValueChange:Z=>{wt(Z)},disabled:k||S||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(zt,{className:"truncate",children:hc(Bi,ie,"28800000")})}),s.jsx(At,{children:Bi.map(Z=>s.jsx(mt,{value:Z.value,children:Z.label},Z.value))})]})]})]}),C==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),tt&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),C==="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 ze=="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:",ze]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Cn,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>$(Z=>!Z),disabled:n==="starting"||n==="stopping"||S,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((Z,pe)=>{const Oe=Q[Z.id]||"",Ee=_.has(Z.id),Ye=U[Z.id]??!1;return s.jsx("div",{className:Ie(pe<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(kn,{open:Ye,onOpenChange:ne=>{K(we=>({...we,[Z.id]:ne})),ne&&Xe(Z.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Nn,{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"||S,children:[Ye?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Z.name})]}),s.jsx(G,{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:Z.name}),onClick:()=>{Re(Z.id)},disabled:n==="starting"||n==="stopping"||S,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Sn,{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:Z.hostname})]}),s.jsx(We,{type:"password",value:Oe,onChange:ne=>{const we=ne.target.value;v(null),H(nt=>({...nt,[Z.id]:we}))},onBlur:ne=>{const we=ne.currentTarget.value.trim();we&&ye({presetId:Z.id,presetName:Z.name,hostname:Z.hostname,token:we})},placeholder:t(Ee?"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(G,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Oe.trim().length===0,onClick:()=>{ye({presetId:Z.id,presetName:Z.name,hostname:Z.hostname,token:Oe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Z.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),X&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(We,{value:ee,onChange:Z=>L(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:S||n==="starting"||n==="stopping"}),s.jsx(We,{value:Y,onChange:Z=>oe(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:S||n==="starting"||n==="stopping"}),s.jsx(We,{type:"password",value:de,onChange:Z=>ge(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:S||n==="starting"||n==="stopping"}),typeof ze=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",ze]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:S||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$(!1),L(""),oe(""),ge("")},disabled:S||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(qt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!he&&u&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:u})]}),C==="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:Nt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:J,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Z=>{Le(Z)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:O||"",onChange:Z=>{Ne(Z.target.value)},onBlur:()=>{Ae()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||S}),s.jsx(G,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Te()},disabled:n==="starting"||n==="stopping"||S,children:s.jsx(z,{name:"folder",className:"size-3.5"})}),O&&s.jsx(G,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{q()},disabled:n==="starting"||n==="stopping"||S,children:s.jsx(z,{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")}),se&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Pe})]})}),!Ke&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[C==="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:()=>{ct(Cy)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),C==="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:()=>{ct(Iy)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(Wr.find(Z=>Z.value===C)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),C==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Nt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Tt,{value:W||(N[0]?.id??""),onValueChange:Z=>{Xe(Z)},disabled:S||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(Pt,{size:$t,children:s.jsx(zt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:he?.name})}),s.jsx(At,{fitContent:!0,children:N.map(Z=>s.jsx(mt,{value:Z.id,children:Z.name},Z.id))})]})]}),Be&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(G,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="starting"||S||C==="managed-remote"&&!he||C==="managed-local"&&se,className:Ie(Ve,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ke&&i&&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:i.url})]}),Fe&&i.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:i.connectUrl}),s.jsxs(G,{size:"sm",variant:"ghost",onClick:ot,className:"shrink-0 gap-1.5",children:[w?s.jsx(z,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(z,{name:"file-copy",className:"size-3.5"}),t(w?"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"),": ",i.bootstrapExpiresAt?ae: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:[h?s.jsx("img",{src:h,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(G,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="stopping"||S||C==="managed-local"&&se,className:Ve,children:[s.jsx(z,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:lt,disabled:n==="stopping"||S,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&f&&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:f}),s.jsx(G,{size:"sm",variant:"ghost",onClick:Qe,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Pd=()=>{const{t}=Ze(),[e,a]=et.useState(""),[n,r]=et.useState(!0),[i,l]=et.useState(!1),d=fe(u=>u.showOpenCodeUpdateNotifications),c=fe(u=>u.setShowOpenCodeUpdateNotifications);et.useEffect(()=>{let u=!1;return(async()=>{try{const v=await An();if(u||!v)return;a(v.opencodeBinary??"")}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const h=et.useCallback(async()=>{if(!(typeof window>"u")&&ls())try{const u=await No();u.success&&u.path&&u.path.trim().length>0&&a(u.path.trim())}catch{}},[]),g=et.useCallback(async()=>{l(!0);try{const u=e.trim(),v=u.length>=2&&(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))?u.slice(1,-1).trim():u;await ft({opencodeBinary:v}),await kc({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(u){if(u?.requiresManualRestart){B.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}B.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{l(!1)}},[t,e]),f=et.useCallback(async()=>{l(!0);try{await Dm(t)}finally{l(!1)}},[t]),p=et.useCallback(u=>{c(u),ft({showOpenCodeUpdateNotifications:u})},[c]);return s.jsx(qe,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ct,{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(We,{value:e,onChange:u=>a(u.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||i,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:n||i||!ls(),className:ps,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(z,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Wa,{className:cs,children:[s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:d,onChange:p,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsxs("div",{className:"flex flex-wrap justify-start gap-2 py-1.5","data-settings-item":"sessions.opencode-restart",children:[s.jsx(G,{type:"button",size:"xs",onClick:g,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")}),s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:n||i,className:"shrink-0 !font-normal",children:t("settings.openchamber.opencodeCli.actions.restart")})]})]})]})})},Qr="builtin",Fy=t=>t.filter(e=>wo(e)&&Lc(e.service,"browser")),Ad=()=>{const t=at.c(99),{t:e}=Ze(),a=fe(Ly),n=fe(Ky),r=fe(_y),i=fe(Uy),l=fe(zy),d=fe($y),c=Hs(By),h=fe(Vy),g=fe(Hy),f=fe(qy),p=fe(Gy),u=fe(Wy);let v;t[0]!==n?(v=ue=>{n(ue),ft({agentControlToolEnabled:ue})},t[0]=n,t[1]=v):v=t[1];const w=v;let b;t[2]!==i?(b=ue=>{i(ue),ft({agentWebToolEnabled:ue})},t[2]=i,t[3]=b):b=t[3];const k=b;let m;t[4]!==u?(m=ue=>{u(ue),ft({agentNotifyToolEnabled:ue})},t[4]=u,t[5]=m):m=t[5];const S=m;let P;t[6]===Symbol.for("react.memo_cache_sentinel")?(P=[],t[6]=P):P=t[6],et.useEffect(Jy,P);let I;t[7]!==c?(I=Fy(c),t[7]=c,t[8]=I):I=t[8];const j=I;let D;t[9]!==l||t[10]!==j?(D=j.some(ue=>ue.id===l)?l:Qr,t[9]=l,t[10]=j,t[11]=D):D=t[11];const x=D;let A;t[12]!==d?(A=ue=>{d(ue),ft({browserProvider:ue})},t[12]=d,t[13]=A):A=t[13];const R=A;let C;t[14]!==f?(C=ue=>{f(ue),ft({agentMemoryToolEnabled:ue}).finally(()=>{ue&&_u.getState().refresh()})},t[14]=f,t[15]=C):C=t[15];const E=C;let O;t[16]!==e?(O=e("settings.openchamber.tools.title"),t[16]=e,t[17]=O):O=t[17];let F;t[18]!==e?(F=e("settings.openchamber.tools.field.agentControlTool"),t[18]=e,t[19]=F):F=t[19];let N;t[20]!==e?(N=e("settings.openchamber.tools.field.agentControlToolAria"),t[20]=e,t[21]=N):N=t[21];let M;t[22]!==e?(M=e("settings.openchamber.tools.field.agentControlToolInfo"),t[22]=e,t[23]=M):M=t[23];let U;t[24]!==a||t[25]!==w||t[26]!==N||t[27]!==M||t[28]!==F?(U=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:w,label:F,ariaLabel:N,info:M}),t[24]=a,t[25]=w,t[26]=N,t[27]=M,t[28]=F,t[29]=U):U=t[29];let K;t[30]!==e?(K=e("settings.openchamber.tools.field.agentWebTool"),t[30]=e,t[31]=K):K=t[31];let W;t[32]!==e?(W=e("settings.openchamber.tools.field.agentWebToolAria"),t[32]=e,t[33]=W):W=t[33];let te;t[34]!==e?(te=e("settings.openchamber.tools.field.agentWebToolInfo"),t[34]=e,t[35]=te):te=t[35];let Q;t[36]!==r||t[37]!==k||t[38]!==K||t[39]!==W||t[40]!==te?(Q=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:k,label:K,ariaLabel:W,info:te}),t[36]=r,t[37]=k,t[38]=K,t[39]=W,t[40]=te,t[41]=Q):Q=t[41];let H;t[42]!==e?(H=e("settings.openchamber.tools.browserProvider.label"),t[42]=e,t[43]=H):H=t[43];let _;t[44]!==e?(_=e("settings.openchamber.tools.browserProvider.info"),t[44]=e,t[45]=_):_=t[45];const V=!r||j.length===0;let X;t[46]!==e?(X=e("settings.openchamber.tools.browserProvider.aria"),t[46]=e,t[47]=X):X=t[47];let $;t[48]!==j||t[49]!==e?($=s.jsx(zt,{children:ue=>ue===Qr?e("settings.openchamber.tools.browserProvider.option.builtin"):j.find($e=>$e.id===ue)?.name??null}),t[48]=j,t[49]=e,t[50]=$):$=t[50];let ee;t[51]!==X||t[52]!==$?(ee=s.jsx(Pt,{size:$t,className:an,"aria-label":X,children:$}),t[51]=X,t[52]=$,t[53]=ee):ee=t[53];let L;t[54]!==e?(L=e("settings.openchamber.tools.browserProvider.option.builtin"),t[54]=e,t[55]=L):L=t[55];let Y;t[56]!==L?(Y=s.jsx(mt,{value:Qr,children:L}),t[56]=L,t[57]=Y):Y=t[57];let oe;t[58]!==j?(oe=j.map(Qy),t[58]=j,t[59]=oe):oe=t[59];let de;t[60]!==Y||t[61]!==oe?(de=s.jsxs(At,{children:[Y,oe]}),t[60]=Y,t[61]=oe,t[62]=de):de=t[62];let ge;t[63]!==R||t[64]!==x||t[65]!==V||t[66]!==ee||t[67]!==de?(ge=s.jsxs(Tt,{value:x,onValueChange:R,disabled:V,children:[ee,de]}),t[63]=R,t[64]=x,t[65]=V,t[66]=ee,t[67]=de,t[68]=ge):ge=t[68];let ce;t[69]!==H||t[70]!==_||t[71]!==ge?(ce=s.jsx(Ct,{settingsItem:"sessions.browser-provider",label:H,info:_,children:ge}),t[69]=H,t[70]=_,t[71]=ge,t[72]=ce):ce=t[72];let Se;t[73]!==e?(Se=e("settings.openchamber.tools.field.agentNotifyTool"),t[73]=e,t[74]=Se):Se=t[74];let ie;t[75]!==e?(ie=e("settings.openchamber.tools.field.agentNotifyToolAria"),t[75]=e,t[76]=ie):ie=t[76];let be;t[77]!==e?(be=e("settings.openchamber.tools.field.agentNotifyToolInfo"),t[77]=e,t[78]=be):be=t[78];let ae;t[79]!==p||t[80]!==S||t[81]!==Se||t[82]!==ie||t[83]!==be?(ae=s.jsx(gt,{settingsItem:"sessions.agent-notify-tool",checked:p,onChange:S,label:Se,ariaLabel:ie,info:be}),t[79]=p,t[80]=S,t[81]=Se,t[82]=ie,t[83]=be,t[84]=ae):ae=t[84];let me;t[85]!==g||t[86]!==h||t[87]!==E||t[88]!==e?(me=g?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:h,onChange:E,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[85]=g,t[86]=h,t[87]=E,t[88]=e,t[89]=me):me=t[89];let je;t[90]!==U||t[91]!==Q||t[92]!==ce||t[93]!==ae||t[94]!==me?(je=s.jsxs("div",{className:cs,children:[U,Q,ce,ae,me]}),t[90]=U,t[91]=Q,t[92]=ce,t[93]=ae,t[94]=me,t[95]=je):je=t[95];let De;return t[96]!==je||t[97]!==O?(De=s.jsx(qe,{title:O,children:je}),t[96]=je,t[97]=O,t[98]=De):De=t[98],De};function Ly(t){return t.agentControlToolEnabled}function Ky(t){return t.setAgentControlToolEnabled}function _y(t){return t.agentWebToolEnabled}function Uy(t){return t.setAgentWebToolEnabled}function zy(t){return t.browserProvider}function $y(t){return t.setBrowserProvider}function By(t){return t.guests}function Vy(t){return t.agentMemoryToolEnabled}function Hy(t){return t.agentMemoryFeatureAvailable}function qy(t){return t.setAgentMemoryToolEnabled}function Gy(t){return t.agentNotifyToolEnabled}function Wy(t){return t.setAgentNotifyToolEnabled}function Jy(){Fn()}function Qy(t){return s.jsx(mt,{value:t.id,children:t.name},t.id)}const Td=()=>{const{t}=Ze(),e=ls()&&fi(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,r]=et.useState(!1),[i,l]=et.useState(!1),[d,c]=et.useState(!1),[h,g]=et.useState(""),[f,p]=et.useState(!1),[u,v]=et.useState(!1),[w,b]=et.useState(null),[k,m]=et.useState(!0),[S,P]=et.useState(!1),[I,j]=et.useState(!1),[D,x]=et.useState(!1),[A,R]=et.useState(!1),[C,E]=et.useState(!1),[O,F]=et.useState(!1),[N,M]=et.useState(!1),[U,K]=et.useState(!0),[W,te]=et.useState(!0),[Q,H]=et.useState(!1),[_,V]=et.useState(!1),[X,$]=et.useState(!1),[ee,L]=et.useState(null),[Y,oe]=et.useState(null);et.useEffect(()=>{if(!e){m(!1);return}let J=!1;return(async()=>{try{const se=await An();if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(J)return;const he=se.desktopLanAccessEnabled===!0;r(he),l(he),c(se.hasDesktopUiPassword===!0),g(""),p(!1),v(se.desktopLanAccessActive===!0),b(se.desktopLanAccessBlockedReason??null);const ve=se.desktopMacMenuBarEnabled!==!1;K(ve),te(ve),L(null)}catch(se){J||L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{J||m(!1)}})(),()=>{J=!0}},[e,t]),et.useEffect(()=>{if(!e){j(!1);return}let J=!1;return(async()=>{const se=await bm();J||(j(se?.supported===!0),x(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e){E(!1);return}let J=!1;return(async()=>{const se=await vm();J||(E(se?.supported===!0),F(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e){H(!1);return}let J=!1;return(async()=>{const se=await ym();J||(H(se?.supported===!0),V(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e||!i){oe(null);return}let J=!1;return(async()=>{const se=await $c();J||oe(se)})(),()=>{J=!0}},[i,e]);const de=h.trim(),ge=de.length>0||f,ce=i!==n||ge||W!==U,Se=et.useMemo(()=>{if(typeof window>"u")return null;const se=hi()||window.location.href;let he=0;try{he=Number(new URL(se).port)}catch{he=Number(window.location.port)}return Number.isFinite(he)&&he>0?he:null},[]),ie=i&&u&&Y&&Se?`http://${Y}:${Se}`:null,be=de.length>0||d&&!f,ae=i&&!be,me=n&&!u&&w==="missing-password",je=k||S||!ce||ae,De=et.useCallback(J=>{g(J),J.trim()&&p(!1)},[]),ue=et.useCallback(()=>{g(""),p(!0),l(!1)},[]),$e=et.useCallback(async()=>{if(!I||A)return;const J=!D;x(J),R(!0),L(null);try{const se=await jm(J);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));x(se.enabled)}catch(se){x(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{R(!1)}},[A,D,I,t]),Ge=et.useCallback(async()=>{if(!C||N)return;const J=!O;F(J),M(!0),L(null);try{const se=await wm(J);if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!se.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));F(se.enabled)}catch(se){F(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{M(!1)}},[N,O,C,t]),xe=et.useCallback(async()=>{if(!Q||X)return;const J=!_;V(J),$(!0),L(null);try{const se=await km(J);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));V(se.enabled)}catch(se){V(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{$(!1)}},[X,_,Q,t]),Pe=et.useCallback(async()=>{if(ce){P(!0),L(null);try{if(!(await ft({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:f?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:W})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):f&&c(!1),g(""),p(!1),K(W),!await Nm())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(J){L(J instanceof Error?J.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),P(!1)}}},[W,i,ce,de,f,t]);return e?s.jsx(qe,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[I||a||C||Q?s.jsxs("div",{className:cs,children:[I?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:D,onChange:J=>{J!==D&&$e()},disabled:A,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(gt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:te,disabled:k||S,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,C?s.jsx(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:O,onChange:J=>{J!==O&&Ge()},disabled:N,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,Q?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:J=>{J!==_&&xe()},disabled:X,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(Ot,{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(We,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:h,onChange:J=>De(J.target.value),placeholder:t(d&&!f?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||S,required:i&&!be,"aria-invalid":ae}),d&&!f?s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:ue,disabled:k||S,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:i,onChange:l,disabled:k||S,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")}),ae||me?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")})}),ee?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:ee}):null,ie?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ce&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ie})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(G,{type:"button",size:"xs",onClick:Pe,disabled:je,className:"shrink-0 !font-normal",children:t(S?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Ed=new Set(["shift","control","alt","meta"]),Fo=3,Yy=3e3;function Lo(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Zy(t){return t.action.customizable}function xc(t){if(Lo(t)>Fo)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?ir(e.join("+")):null}function Xy(t){if(Ed.has(t.key.toLowerCase())||Lo(t,!0)>Fo)return null;const e=$u(Bu(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),ir(a.join("+"))}function e1(t){const e=t.key.toLowerCase();if(!Ed.has(e)||Lo(t,!0)>Fo)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?ir(a.join("+")):null}function bc(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function t1(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:xc(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Xy(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const r=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:r,livePreview:null,settled:r.length===2}}return{...t,livePreview:xc(e)}}const s1=t=>{const e=at.c(117),{action:a,overrides:n,onSave:r,onOpenChange:i}=t,{t:l}=Ze();let d;e[0]!==l?(d=Se=>l(Se.settingsLabelKey),e[0]=l,e[1]=d):d=e[1];const c=d;let h;e[2]!==c?(h=Se=>Se.action.customizable?c(Se.action):ua(Se.action.defaultBinding),e[2]=c,e[3]=h):h=e[3];const g=h;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f={chords:[],livePreview:null,settled:!1},e[4]=f):f=e[4];const[p,u]=o.useState(f),v=o.useRef(null);let w,b;e[5]!==a?(w=()=>{a&&(u({chords:[],livePreview:null,settled:!1}),v.current?.focus())},b=[a],e[5]=a,e[6]=w,e[7]=b):(w=e[6],b=e[7]),o.useEffect(w,b);const k=p.chords.length===1&&!p.settled;let m,S;e[8]!==k?(m=()=>{if(!k)return;const Se=window.setTimeout(()=>u(bc),Yy);return()=>window.clearTimeout(Se)},S=[k],e[8]=k,e[9]=m,e[10]=S):(m=e[9],S=e[10]),o.useEffect(m,S);let P;e[11]!==p.chords?(P=ir(p.chords.join(" ")),e[11]=p.chords,e[12]=P):P=e[12];const I=P;let j;e[13]!==a||e[14]!==I||e[15]!==n?(j=a&&I?Uu(a.id,I,n):[],e[13]=a,e[14]=I,e[15]=n,e[16]=j):j=e[16];const D=j;let x;e[17]!==D?(x=D.find(n1),e[17]=D,e[18]=x):x=e[18];const A=x;let R,C,E,O,F,N,M,U,K,W,te,Q,H,_,V;if(e[19]!==a||e[20]!==c||e[21]!==I||e[22]!==g||e[23]!==D||e[24]!==i||e[25]!==r||e[26]!==A||e[27]!==p||e[28]!==l){const Se=D.filter(Zy);F=Se.find(a1);const ie=Se.find(i1),be=D.find(r1);let ae;e[44]!==i?(ae=()=>i(!1),e[44]=i,e[45]=ae):ae=e[45],E=ae,O=()=>{p.settled||u(bc),!(!a||!I||A||F)&&(r(a.id,I,ie?.action.id),E())};let me;e[46]!==a||e[47]!==p?(me=(Ke,Be)=>{Ke.preventDefault(),Ke.stopPropagation();const ze=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Be==="keyup"&&ze&&p.chords.length===0){const Me=e1(Ke);if(Me){u({chords:[Me],livePreview:null,settled:!0});return}}const _e=t1(p,{altKey:Ke.altKey,code:Ke.nativeEvent.code,ctrlKey:Ke.ctrlKey,isComposing:Ke.nativeEvent.isComposing,key:Ke.key,metaKey:Ke.metaKey,repeat:Ke.repeat,shiftKey:Ke.shiftKey},Be);u(ze&&_e.chords.length>1?p:_e)},e[46]=a,e[47]=p,e[48]=me):me=e[48];const je=me;C=_t,_=a!==null,V=o1,R=Ut,N="max-w-md",M=v,U=!1;let De;e[49]!==a||e[50]!==c||e[51]!==l?(De=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=De):De=e[52];let ue;e[53]!==De?(ue=s.jsx(Vt,{children:De}),e[53]=De,e[54]=ue):ue=e[54];let $e;e[55]!==l?($e=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=$e):$e=e[56];let Ge;e[57]!==$e?(Ge=s.jsx(Ht,{children:$e}),e[57]=$e,e[58]=Ge):Ge=e[58],e[59]!==ue||e[60]!==Ge?(K=s.jsxs(Bt,{children:[ue,Ge]}),e[59]=ue,e[60]=Ge,e[61]=K):K=e[61];let xe,Pe;e[62]!==je?(xe=Ke=>je(Ke,"keydown"),Pe=Ke=>je(Ke,"keyup"),e[62]=je,e[63]=xe,e[64]=Pe):(xe=e[63],Pe=e[64]);let J;e[65]===Symbol.for("react.memo_cache_sentinel")?(J=()=>u(l1),e[65]=J):J=e[65];let se;e[66]!==p.chords?(se=p.chords.map(c1),e[66]=p.chords,e[67]=se):se=e[67];let he;e[68]!==p.livePreview?(he=p.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:ua(p.livePreview)}):null,e[68]=p.livePreview,e[69]=he):he=e[69];let ve;e[70]!==p.chords.length||e[71]!==p.livePreview||e[72]!==l?(ve=p.chords.length===0&&!p.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=p.chords.length,e[71]=p.livePreview,e[72]=l,e[73]=ve):ve=e[73];let Fe;e[74]!==se||e[75]!==he||e[76]!==ve?(Fe=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[se,he,ve]}),e[74]=se,e[75]=he,e[76]=ve,e[77]=Fe):Fe=e[77],e[78]!==xe||e[79]!==Pe||e[80]!==Fe?(W=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:v,onKeyDown:xe,onKeyUp:Pe,onBlur:J,children:Fe}),e[78]=xe,e[79]=Pe,e[80]=Fe,e[81]=W):W=e[81],te=p.settled&&A?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):p.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c(F.action)})}):null,Q=p.settled&&ie&&!A&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(ie.action)})}):null,H=p.settled&&be&&!A&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:g(be)})}):null,e[19]=a,e[20]=c,e[21]=I,e[22]=g,e[23]=D,e[24]=i,e[25]=r,e[26]=A,e[27]=p,e[28]=l,e[29]=R,e[30]=C,e[31]=E,e[32]=O,e[33]=F,e[34]=N,e[35]=M,e[36]=U,e[37]=K,e[38]=W,e[39]=te,e[40]=Q,e[41]=H,e[42]=_,e[43]=V}else R=e[29],C=e[30],E=e[31],O=e[32],F=e[33],N=e[34],M=e[35],U=e[36],K=e[37],W=e[38],te=e[39],Q=e[40],H=e[41],_=e[42],V=e[43];let X;e[82]!==I||e[83]!==p.settled||e[84]!==l?(X=p.settled&&I&&zu(I)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=I,e[83]=p.settled,e[84]=l,e[85]=X):X=e[85];let $;e[86]!==l?($=l("settings.common.actions.cancel"),e[86]=l,e[87]=$):$=e[87];let ee;e[88]!==E||e[89]!==$?(ee=s.jsx(G,{type:"button",variant:"ghost",size:"sm",onClick:E,children:$}),e[88]=E,e[89]=$,e[90]=ee):ee=e[90];const L=!I||p.settled&&(!!A||!!F);let Y;e[91]!==l?(Y=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=Y):Y=e[92];let oe;e[93]!==O||e[94]!==L||e[95]!==Y?(oe=s.jsx(G,{type:"button",size:"sm",disabled:L,onClick:O,children:Y}),e[93]=O,e[94]=L,e[95]=Y,e[96]=oe):oe=e[96];let de;e[97]!==ee||e[98]!==oe?(de=s.jsxs(as,{children:[ee,oe]}),e[97]=ee,e[98]=oe,e[99]=de):de=e[99];let ge;e[100]!==R||e[101]!==N||e[102]!==M||e[103]!==U||e[104]!==K||e[105]!==W||e[106]!==te||e[107]!==Q||e[108]!==H||e[109]!==X||e[110]!==de?(ge=s.jsxs(R,{className:N,initialFocus:M,showCloseButton:U,children:[K,W,te,Q,H,X,de]}),e[100]=R,e[101]=N,e[102]=M,e[103]=U,e[104]=K,e[105]=W,e[106]=te,e[107]=Q,e[108]=H,e[109]=X,e[110]=de,e[111]=ge):ge=e[111];let ce;return e[112]!==C||e[113]!==_||e[114]!==V||e[115]!==ge?(ce=s.jsx(C,{open:_,onOpenChange:V,children:ge}),e[112]=C,e[113]=_,e[114]=V,e[115]=ge,e[116]=ce):ce=e[116],ce};function n1(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function a1(t){return t.kind==="prefix"}function i1(t){return t.kind==="exact"}function r1(t){return t.kind==="contextual-prefix"}function o1(t,e){t||e.cancel()}function l1(t){return{...t,livePreview:null}}function c1(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:ua(t)},`${t}-${e}`)}const d1=["session","models","panels","navigation","application"],u1=()=>{const t=at.c(24),{t:e}=Ze(),a=fe(m1),n=fe(p1),r=fe(g1),i=fe(h1),[l,d]=o.useState(null);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c=Vu(),t[0]=c):c=t[0];const h=c,g=f1;let f;t[1]!==n||t[2]!==a?(f=(I,j,D)=>{const x={...a,[I]:j};D&&(x[D]=Er),n(I,j),D&&n(D,Er),g(x)},t[1]=n,t[2]=a,t[3]=f):f=t[3];const p=f;let u;t[4]!==r||t[5]!==a?(u=I=>{const j={...a};delete j[I],r(I),g(j)},t[4]=r,t[5]=a,t[6]=u):u=t[6];const v=u;let w;t[7]!==a||t[8]!==e?(w=I=>{const j="prefixStyle"in I&&I.prefixStyle,D=j?Hu(I.id,a):zc(I.id,a),x=ua(D,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!j||!D||D===Er)return x;const A=I.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${x}${A}`},t[7]=a,t[8]=e,t[9]=w):w=t[9];const b=w;let k;t[10]!==i||t[11]!==v||t[12]!==b||t[13]!==a||t[14]!==e?(k=d1.map((I,j)=>{const D=h.filter(x=>x.category===I);return D.length===0?null:s.jsx(qe,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${I}`),divider:j!==0,info:j===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),g({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:D.map(x=>s.jsxs(Ct,{label:e(x.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:b(x)}),s.jsx(G,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>d(x),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),x.id in a?s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>v(x.id),children:e("settings.common.actions.reset")}):null]},x.id))})},I)}),t[10]=i,t[11]=v,t[12]=b,t[13]=a,t[14]=e,t[15]=k):k=t[15];let m;t[16]===Symbol.for("react.memo_cache_sentinel")?(m=I=>{I||d(null)},t[16]=m):m=t[16];let S;t[17]!==l||t[18]!==p||t[19]!==a?(S=s.jsx(s1,{action:l,overrides:a,onSave:p,onOpenChange:m}),t[17]=l,t[18]=p,t[19]=a,t[20]=S):S=t[20];let P;return t[21]!==k||t[22]!==S?(P=s.jsxs(s.Fragment,{children:[k,S]}),t[21]=k,t[22]=S,t[23]=P):P=t[23],P};function m1(t){return t.shortcutOverrides}function p1(t){return t.setShortcutOverride}function g1(t){return t.clearShortcutOverride}function h1(t){return t.resetAllShortcutOverrides}function f1(t){ft({shortcutOverrides:t})}const Dd=()=>{const t=at.c(2),[e,a]=o.useState(0);let n,r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>rr(()=>a(I1)),r=[],t[0]=n,t[1]=r):(n=t[0],r=t[1]),o.useEffect(n,r),e},x1=t=>{const e=at.c(83),{section:a}=t,{t:n}=Ze(),{isMobile:r}=Qn(),i=Dd();let l;e[0]!==r?(l=r&&da(),e[0]=r,e[1]=l):l=e[1];const d=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[2]=c):c=e[2];const h=c;let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=ls()&&fi(),e[3]=g):g=e[3];const f=g;if(!a){let H;e[4]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(or,{}),e[4]=H):H=e[4];let _;e[5]!==i?(_=s.jsx(Sd,{},i),e[5]=i,e[6]=_):_=e[6];let V,X,$,ee,L,Y;e[7]===Symbol.for("react.memo_cache_sentinel")?($=f&&s.jsx(Td,{}),ee=!h&&s.jsx(Pd,{}),L=!h&&s.jsx(Ad,{}),Y=s.jsx(wd,{}),V=s.jsx(Nd,{}),X=da()&&!ls()&&!h&&!ko()&&s.jsx(kd,{}),e[7]=V,e[8]=X,e[9]=$,e[10]=ee,e[11]=L,e[12]=Y):(V=e[7],X=e[8],$=e[9],ee=e[10],L=e[11],Y=e[12]);let oe;e[13]!==d?(oe=d&&s.jsx(Jc,{}),e[13]=d,e[14]=oe):oe=e[14];let de;return e[15]!==oe||e[16]!==_?(de=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[H,_,$,ee,L,Y,V,X,oe]}),e[15]=oe,e[16]=_,e[17]=de):de=e[17],de}let p;e[18]!==i||e[19]!==a?(p=()=>{switch(a){case"general":return s.jsx(v1,{});case"visual":return s.jsx(y1,{});case"chat":return s.jsx(j1,{});case"sessions":return s.jsx(w1,{runtimeEndpointEpoch:i});case"shortcuts":return s.jsx(b1,{});case"git":return s.jsx(k1,{});case"notifications":return s.jsx(N1,{});case"voice":return s.jsx(S1,{});case"tunnel":return s.jsx(C1,{});default:return null}},e[18]=i,e[19]=a,e[20]=p):p=e[20];const u=p;let v;e[21]!==n?(v=n("settings.page.general.title"),e[21]=n,e[22]=v):v=e[22];let w;e[23]!==n?(w=n("settings.page.appearance.title"),e[23]=n,e[24]=w):w=e[24];let b;e[25]!==n?(b=n("settings.page.chat.title"),e[25]=n,e[26]=b):b=e[26];let k;e[27]!==n?(k=n("settings.page.sessions.title"),e[27]=n,e[28]=k):k=e[28];let m;e[29]!==n?(m=n("settings.page.shortcuts.title"),e[29]=n,e[30]=m):m=e[30];let S;e[31]!==n?(S=n("settings.page.git.title"),e[31]=n,e[32]=S):S=e[32];let P;e[33]!==n?(P=n("settings.page.git.title"),e[33]=n,e[34]=P):P=e[34];let I;e[35]!==n?(I=n("settings.page.notifications.title"),e[35]=n,e[36]=I):I=e[36];let j;e[37]!==n?(j=n("settings.page.voice.title"),e[37]=n,e[38]=j):j=e[38];let D;e[39]!==n?(D=n("settings.page.tunnel.title"),e[39]=n,e[40]=D):D=e[40];let x;e[41]!==S||e[42]!==P||e[43]!==I||e[44]!==j||e[45]!==D||e[46]!==v||e[47]!==w||e[48]!==b||e[49]!==k||e[50]!==m?(x={general:v,visual:w,chat:b,sessions:k,shortcuts:m,git:S,github:P,notifications:I,voice:j,tunnel:D},e[41]=S,e[42]=P,e[43]=I,e[44]=j,e[45]=D,e[46]=v,e[47]=w,e[48]=b,e[49]=k,e[50]=m,e[51]=x):x=e[51];const A=x[a];let R;e[52]!==n?(R=n("settings.page.general.description"),e[52]=n,e[53]=R):R=e[53];let C;e[54]!==n?(C=n("settings.page.appearance.description"),e[54]=n,e[55]=C):C=e[55];let E;e[56]!==n?(E=n("settings.page.chat.description"),e[56]=n,e[57]=E):E=e[57];let O;e[58]!==n?(O=n("settings.page.sessions.description"),e[58]=n,e[59]=O):O=e[59];let F;e[60]!==n?(F=n("settings.page.shortcuts.description"),e[60]=n,e[61]=F):F=e[61];let N;e[62]!==n?(N=n("settings.page.notifications.description"),e[62]=n,e[63]=N):N=e[63];let M;e[64]!==n?(M=n("settings.page.voice.description"),e[64]=n,e[65]=M):M=e[65];let U;e[66]!==n?(U=n("settings.page.tunnel.description"),e[66]=n,e[67]=U):U=e[67];let K;e[68]!==R||e[69]!==C||e[70]!==E||e[71]!==O||e[72]!==F||e[73]!==N||e[74]!==M||e[75]!==U?(K={general:R,visual:C,chat:E,sessions:O,shortcuts:F,git:void 0,github:void 0,notifications:N,voice:M,tunnel:U},e[68]=R,e[69]=C,e[70]=E,e[71]=O,e[72]=F,e[73]=N,e[74]=M,e[75]=U,e[76]=K):K=e[76];const W=K[a];let te;e[77]!==u?(te=u(),e[77]=u,e[78]=te):te=e[78];let Q;return e[79]!==W||e[80]!==A||e[81]!==te?(Q=s.jsx(ns,{title:A,description:W,showSaveStatus:!0,className:"openchamber-page-body",children:te}),e[79]=W,e[80]=A,e[81]=te,e[82]=Q):Q=e[82],Q},b1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(u1,{}),t[0]=e):e=t[0],e},v1=()=>{const t=at.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),t[0]=e):e=t[0];const a=e;Dd();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=ls()&&fi(),t[1]=n):n=t[1];const r=n;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=da()&&!ls()&&!a&&!ko(),t[2]=i):i=t[2];const l=i;let d,c,h,g,f;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=r&&s.jsx(Td,{}),c=l&&s.jsx(kd,{}),h=s.jsx(Nd,{}),g=!a&&s.jsx(Pd,{}),f=!a&&s.jsx(Ad,{}),t[3]=d,t[4]=c,t[5]=h,t[6]=g,t[7]=f):(d=t[3],c=t[4],h=t[5],g=t[6],f=t[7]);let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=a?[]:["sessionTabs"],t[8]=p):p=t[8];let u;return t[9]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsxs(s.Fragment,{children:[d,c,h,g,f,s.jsx(or,{visibleSettings:["fileEditorKeymap",...p,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=u):u=t[9],u},y1=()=>{const t=at.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(or,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=n):n=t[1],n},j1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(or,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","promptNavigatorEnabled","wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[0]=e):e=t[0],e},w1=t=>{const e=at.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(Sd,{},a),e[0]=a,e[1]=n):n=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(wd,{}),e[2]=r):r=e[2];let i;return e[3]!==n?(i=s.jsxs(s.Fragment,{children:[n,r]}),e[3]=n,e[4]=i):i=e[4],i},k1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(hd,{}),t[0]=e):e=t[0],e},N1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(gy,{}),t[0]=e):e=t[0],e},S1=()=>{const t=at.c(1);if(fs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ny,{}),t[0]=e):e=t[0],e},C1=()=>{const t=at.c(1);if(fs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Oy,{}),t[0]=e):e=t[0],e};function I1(t){return t+1}const P1=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{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.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],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.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{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.animated-activity-indicators",page:"appearance",titleKey:"settings.openchamber.visual.field.animatedActivityIndicators",descriptionKey:"settings.openchamber.visual.field.animatedActivityIndicatorsInfo",keywords:["spinner","animation","session","activity","motion","running","indicator"]},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"],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.warming",page:"sessions",titleKey:"settings.openchamber.defaults.field.sessionWarming",descriptionKey:"settings.openchamber.defaults.field.sessionWarmingInfo",keywords:["warming","warm","cache","prompt cache","keep-alive","idle"]},{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-only-archived",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.onlyArchived",descriptionKey:"settings.openchamber.sessionRetention.field.onlyArchivedDescription",keywords:["archive","archived","only","delete","cleanup","retention"]},{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-restart",page:"general",titleKey:"settings.openchamber.opencodeCli.actions.restart",keywords:["opencode","restart","reload","plugin"],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},{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.browser-provider",page:"general",titleKey:"settings.openchamber.tools.browserProvider.label",descriptionKey:"settings.openchamber.tools.browserProvider.info",keywords:["agent","browser","provider","extension","chrome","server","headless"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-notify-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentNotifyTool",descriptionKey:"settings.openchamber.tools.field.agentNotifyToolInfo",keywords:["agent","tool","notify","notification","alert","ping","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&&fe.getState().agentMemoryFeatureAvailable},{id:"routing.token",page:"routing",titleKey:"settings.routing.token.label",descriptionKey:"settings.routing.token.info",keywords:["jev","typesafe","api key","token","routing","zen","free"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.enabled",page:"routing",titleKey:"settings.routing.auto.enable",descriptionKey:"settings.routing.auto.enableInfo",keywords:["auto","routing","model","jev","automatic"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.fallback-model",page:"routing",titleKey:"settings.routing.auto.fallbackModel",descriptionKey:"settings.routing.auto.fallbackModelInfo",keywords:["fallback","default","model","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.safety-enabled",page:"routing",titleKey:"settings.routing.safety.enable",descriptionKey:"settings.routing.safety.enableInfo",keywords:["safety net","auto-accept","permissions","destructive","hold"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.add-category",page:"routing",titleKey:"settings.routing.categories.title",descriptionKey:"settings.routing.categories.description",keywords:["category","categories","task type","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{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-agent",page:"projects",titleKey:"settings.projects.page.field.projectAgent",keywords:["agent","default","new chat","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:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".openchamber","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{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",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.steps",page:"agents",titleKey:"settings.agents.page.field.steps",descriptionKey:"settings.agents.page.field.stepsTooltip",keywords:["steps","loop","tool calls"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","rules","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.variant",page:"commands",titleKey:"settings.agents.page.field.variant",keywords:["variant","reasoning","thinking"]},{id:"commands.subagent",page:"commands",titleKey:"settings.commands.page.field.subagent",descriptionKey:"settings.commands.page.field.subagentTooltip",keywords:["subagent","background","child session"]},{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","code mode","codemode"]},{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:"web-search.provider",page:"web-search",titleKey:"settings.webSearch.section.provider",descriptionKey:"settings.webSearch.section.providerInfo",keywords:["web search","websearch","internet","default provider","disable","off","random"]},{id:"web-search.keys",page:"web-search",titleKey:"settings.webSearch.section.keys",keywords:["api key","exa","tavily","firecrawl","parallel","tinyfish","credentials"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{id:"integrations.guests",page:"integrations",titleKey:"settings.integrations.guests.title",descriptionKey:"settings.integrations.guests.info",keywords:["guest","extension","oauth","clickup","gitlab","panel","connect"],isAvailable:t=>!t.isVSCode},{id:"extensions.add",page:"extensions",titleKey:"settings.extensions.add.label",descriptionKey:"settings.extensions.add.info",keywords:["folder","path","zip","git","url","install","guest","panel"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.gitIdentity",page:"extensions",titleKey:"settings.extensions.identity.title",descriptionKey:"settings.extensions.add.info",keywords:["ssh","key","identity","git","private","clone","extension"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.updates.check",page:"extensions",titleKey:"settings.extensions.updates.check",keywords:["update","upgrade","version","git","extension","guest","refresh"],isAvailable:t=>!t.isVSCode&&!t.isMobile}];function vc(t){return t.trim().toLocaleLowerCase()}function A1({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=vc(t);if(!i)return[];const l=a?new Set(a):null,d=i.split(/\s+/).filter(Boolean);return P1.flatMap(c=>{if(l&&!l.has(c.page))return[];const h=_a(c.page);if(!h||h.isAvailable&&!h.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const g=n(c.titleKey),f=c.descriptionKey?n(c.descriptionKey):null,p=vc([g,f,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(u=>p.includes(u))?[{...c,title:g,description:f,pageTitle:r(c.page)}]:[]})}const yc=256,jc=280,Md="__openchamberSettingsDetail",T1=["general","appearance","chat","notifications","sessions","routing","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","providers","web-search","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],E1=["general","projects","opencode","content"],D1="__add_provider__";function M1(t,e,a){const n=fs(),r=!t&&da();return{isVSCode:n,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:a}}function wc(t,e){return t.isAvailable?t.isAvailable(e):!0}function po(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ri(t,e){const a=new Set(e);let n=t,r=1;for(;a.has(n);)n=`${t}-${r}`,r+=1;return n}function Yr(t){if(!po(t))return null;const e=t[Md];if(!po(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Gc(a),stage:n}}function R1(){return typeof window>"u"||!po(window.history.state)?{}:window.history.state}const Y1=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:r="nav",registerBackHandler:i})=>{const{t:l}=Ze(),d=Qn(),c=e??d.isMobile,h=fe(J=>J.settingsPage),g=fe(J=>J.isSettingsDialogOpen),f=fe(J=>J.setSettingsPage),p=fe(J=>J.shortcutOverrides.open_settings),u=Gc(h),[v,w]=o.useState(r),b=o.useRef(r==="nav"?u:null);o.useEffect(()=>{!c&&u==="home"&&f("general")},[c,f,u]);const[k,m]=o.useState(""),[S,P]=o.useState(null),[I,j]=o.useState(0),D=o.useRef(null),x=o.useRef(!1),A=o.useRef([]),R=o.useRef(0),C=o.useRef(!1),E=o.useMemo(()=>ls(),[]),O=o.useMemo(()=>ls()&&fi(),[]),F=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),N=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),M=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),U=fe(J=>J.routingFeatureAvailable),K=o.useMemo(()=>M1(E,c,U),[E,c,U]),W=o.useMemo(()=>{const J=n?new Set(n):null;return Mm.filter(se=>se.slug!=="home").filter(se=>!J||J.has(se.slug)).filter(se=>wc(se,K)).filter(se=>!(K.isVSCode&&se.slug==="projects")).filter(se=>!(c&&se.slug==="shortcuts"))},[K,c,n]),te=o.useMemo(()=>{const J=new Map(T1.map((se,he)=>[se,he]));return W.slice().sort((se,he)=>(J.get(se.slug)??999)-(J.get(he.slug)??999))},[W]),Q=rn(J=>J.activeProjectId),H=Js();o.useEffect(()=>{if(!(!g&&!K.isVSCode&&!a)){if(u==="agents"){Wn.getState().loadAgents(H);return}if(u==="commands"){Ga.getState().loadCommands(H);return}if(u==="mcp"){Jn.getState().loadMcpConfigs({directory:H});return}if(u==="plugins"){Wt.getState().loadPlugins();return}(u==="skills.installed"||u==="skills.catalog")&&(nn.getState().loadSkills(H),On.getState().loadCatalog()),u==="snippets"&&Qi.getState().loadSnippets()}},[Q,g,a,K.isVSCode,H,u]);const _=o.useCallback(J=>{if(f(J),b.current=J,!c)return;const se=_a(J);if(!se||se.slug==="home"){w("nav");return}w(se.kind==="split"?"page-sidebar":"page-content")},[c,f]),V=o.useMemo(()=>_a(u),[u]),X=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),$=o.useCallback(J=>{switch(J){case"general":return l("settings.page.general.title");case"projects":return l("settings.page.projects.title");case"remote-instances":return l("settings.page.remoteInstances.title");case"providers":return l("settings.page.providers.title");case"web-search":return l("settings.page.webSearch.title");case"usage":return l("settings.page.usage.title");case"agents":return l("settings.page.agents.title");case"behavior":return l("settings.page.behavior.title");case"commands":return l("settings.page.commands.title");case"mcp":return l("settings.page.mcp.title");case"plugins":return l("settings.page.plugins.title");case"skills.installed":return l("settings.page.skills.title");case"skills.catalog":return l("settings.page.skillsCatalog.title");case"git":return l("settings.page.git.title");case"integrations":return l("settings.page.integrations.title");case"extensions":return l("settings.page.extensions.title");case"appearance":return l("settings.page.appearance.title");case"chat":return l("settings.page.chat.title");case"shortcuts":return l("settings.page.shortcuts.title");case"sessions":return l("settings.page.sessions.title");case"routing":return l("settings.page.routing.title");case"magic-prompts":return l("settings.page.magicPrompts.title");case"snippets":return l("settings.page.snippets.title");case"notifications":return l("settings.page.notifications.title");case"voice":return l("settings.page.voice.title");case"tunnel":return l("settings.page.tunnel.title");case"about":return l("settings.page.about.title");default:return l("settings.view.home.title")}},[l]),ee=o.useMemo(()=>A1({query:k,runtimeCtx:{...K,isDesktopLocalOrigin:O,isMac:F,isWindows:N,isLinux:M},visiblePageSlugs:n,t:l,getPageTitle:$}),[$,O,F,N,M,K,k,l,n]),L=o.useCallback(J=>{if(J.id.startsWith("agents.")){const se=Wn.getState(),he=ri("new-agent",se.agents.map(ve=>ve.name));return se.setAgentDraft({name:he,scope:"user"}),se.setSelectedAgent(he),J.id==="agents.create"?"agents.name":J.id}if(J.id.startsWith("commands.")){const se=Ga.getState(),he=ri("new-command",se.commands.map(ve=>ve.name));return se.setCommandDraft({name:he,scope:"user"}),se.setSelectedCommand(he),J.id==="commands.create"?"commands.name":J.id}if(J.id.startsWith("mcp.")){const se=Jn.getState(),he=ri("new-mcp-server",se.mcpServers.map(ve=>ve.name));return se.setMcpDraft({name:he,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1}),se.setSelectedMcp(he),J.id==="mcp.create"?"mcp.server":J.id}if(J.id.startsWith("snippets.")){const se=Qi.getState(),he=ri("new-snippet",se.snippets.map(ve=>ve.name));return se.setSnippetDraft({name:he,scope:"global"}),se.setSelectedSnippet(he),J.id==="snippets.create"?"snippets.content":J.id}if(J.id.startsWith("skills.")){const se=nn.getState(),he=ri("new-skill",se.skills.map(ve=>ve.name));return se.setSkillDraft({name:he,scope:"user",source:"opencode",description:"",instructions:""}),se.setSelectedSkill(he),J.id==="skills.create"?"skills.basic-information":J.id}return J.id==="providers.connect"&&it.getState().setSelectedProvider(D1),J.id==="plugins.create"?"plugins.spec":J.id},[]),Y=o.useMemo(()=>{const J=[],se=new Map;for(const he of ee){let ve=se.get(he.page);ve||(ve={page:he.page,pageTitle:he.pageTitle,results:[]},se.set(he.page,ve),J.push(ve)),ve.results.push(he)}return J},[ee]);o.useEffect(()=>{j(0),R.current=0,C.current=!1},[k]),o.useEffect(()=>{R.current=I},[I]),o.useEffect(()=>{A.current[I]?.scrollIntoView({block:"nearest"})},[I]),o.useEffect(()=>{I>=ee.length&&j(Math.max(0,ee.length-1)),A.current.length=ee.length},[I,ee.length]);const oe=o.useCallback(J=>{const se=L(J);P(se),_(J.page),c&&w("page-content"),J.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,_,L]),de=o.useCallback(J=>{if(k.trim()){if(J.key==="Escape"){J.preventDefault(),m("");return}if(ee.length!==0){if(J.key==="ArrowDown"){J.preventDefault(),C.current=!0,j(se=>(se+1)%ee.length);return}if(J.key==="ArrowUp"){J.preventDefault(),C.current=!0,j(se=>(se-1+ee.length)%ee.length);return}if(J.key==="Enter"){J.preventDefault();const se=(R.current%ee.length+ee.length)%ee.length,he=ee[se]??ee[0];he&&oe(he)}}}},[oe,k,ee]);o.useEffect(()=>{const J=S;if(!J)return;let se=!1;const he=window.requestAnimationFrame(()=>{if(se)return;const ve=typeof CSS<"u"&&CSS.escape?CSS.escape(J):J.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Fe=D.current?.querySelector(`[data-settings-item="${ve}"]`);Fe&&(P(null),Fe.scrollIntoView({block:"center",behavior:"smooth"}),Fe.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Fe.removeAttribute("data-settings-search-highlight")},1600))});return()=>{se=!0,window.cancelAnimationFrame(he)}},[S,u]);const ge=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:Ac,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),ce=o.useCallback((J,se)=>{switch(J){case"projects":return s.jsx(Df,{onItemSelect:se.onItemSelect});case"agents":return s.jsx(wp,{onItemSelect:se.onItemSelect});case"commands":return s.jsx(pg,{onItemSelect:se.onItemSelect});case"mcp":return s.jsx(wg,{onItemSelect:se.onItemSelect});case"plugins":return s.jsx(vh,{onItemSelect:se.onItemSelect});case"skills.installed":return s.jsx(Xh,{onItemSelect:se.onItemSelect});case"providers":return s.jsx(dx,{onItemSelect:se.onItemSelect});case"usage":return s.jsx(Vx,{onItemSelect:se.onItemSelect});case"magic-prompts":return s.jsx(ob,{onItemSelect:se.onItemSelect});case"snippets":return s.jsx(ub,{onItemSelect:se.onItemSelect});default:return null}},[]),Se=o.useCallback(J=>{const se=_a(J);if(se&&!wc(se,K))return ge();switch(J){case"projects":return s.jsx(Lf,{});case"remote-instances":return s.jsx(ox,{});case"agents":return s.jsx(Gp,{});case"behavior":return s.jsx(eg,{});case"commands":return s.jsx(yg,{});case"mcp":return s.jsx(sh,{});case"plugins":return s.jsx(Uh,{});case"skills.installed":return s.jsx(Al,{view:"installed"});case"skills.catalog":return s.jsx(Al,{view:"catalog"});case"providers":return s.jsx($x,{});case"web-search":return s.jsx(ig,{});case"usage":return s.jsx(ib,{});case"about":return s.jsx(ns,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Jc,{})});case"magic-prompts":return s.jsx(db,{});case"snippets":return s.jsx(hb,{});case"git":return s.jsx(yb,{});case"integrations":return s.jsx(Ub,{});case"routing":return s.jsx(Wb,{});case"extensions":return s.jsx(bv,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const he=X[J]??"visual";return s.jsx(x1,{section:he})}default:return null}},[X,ge,K,l]);o.useEffect(()=>{if(!c||v!=="nav"||u==="home"||b.current===u)return;const J=_a(u);!J||J.slug==="home"||(b.current=u,w(J.kind==="split"?"page-sidebar":"page-content"))},[c,v,u]);const ie=c&&v!=="nav",be=c&&v==="page-content"&&V?.kind==="split",ae=l(be?"settings.view.actions.back":ie?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),me=zc("open_settings",p===void 0?void 0:{open_settings:p}),je=me?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:ua(me)}):l("settings.view.actions.closeSettings"),De=o.useCallback(J=>{if(typeof window>"u"||K.isVSCode)return;const se=Yr(window.history.state);se?.page===J&&se.stage==="page-content"||window.history.pushState({...R1(),[Md]:{page:J,stage:"page-content"}},"",window.location.href)},[K.isVSCode]),ue=o.useCallback(()=>{x.current=!0,w("page-content"),De(u)},[De,u]);o.useEffect(()=>{if(!c||v!=="page-content"||!x.current)return;x.current=!1;const J=window.requestAnimationFrame(()=>{D.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(J)}},[c,v,u]);const $e=o.useCallback(()=>{if(be){if((typeof window<"u"?Yr(window.history.state):null)?.page===u&&!K.isVSCode){window.history.back();return}w("page-sidebar");return}w("nav")},[be,K.isVSCode,u]);o.useEffect(()=>{if(i)return i(()=>!c||v==="nav"?!1:($e(),!0)),()=>i(null)},[$e,c,v,i]),o.useEffect(()=>{if(!c||K.isVSCode)return;const J=se=>{if(_a(u)?.kind!=="split")return;if(Yr(se.state)?.page===u){w("page-content");return}w(ve=>ve==="page-content"?"page-sidebar":ve)};return window.addEventListener("popstate",J),()=>{window.removeEventListener("popstate",J)}},[c,K.isVSCode,u]);const Ge=()=>{const J=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:"oc-surface-elevated flex h-10 items-center gap-1.5 rounded-md border border-border bg-surface-elevated/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-ring sm:h-8",children:[s.jsx(z,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:k,onChange:se=>m(se.target.value),onKeyDown:de,placeholder:l("settings.view.search.placeholder"),"aria-label":l("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),J&&s.jsx("button",{type:"button",onClick:()=>m(""),"aria-label":l("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:J?ee.length>0?(()=>{let se=0;return Y.map(he=>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:he.pageTitle}),he.results.map(ve=>{const Fe=se;se+=1;const Ke=Fe===I,Be=!!ve.description;return s.jsxs("button",{type:"button",ref:ze=>{A.current[Fe]=ze},onMouseMove:()=>{C.current=!1,j(Fe)},onClick:()=>oe(ve),className:Ie("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Be?"min-h-11 py-1.5":"py-2",Ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ve.title}),Be&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ve.description})]},ve.id)})]},he.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const se=new Map;for(const ve of te){const Fe=ve.group,Ke=se.get(Fe);Ke?Ke.push(ve):se.set(Fe,[ve])}return E1.map(ve=>({group:ve,pages:se.get(ve)??[]})).filter(ve=>ve.pages.length>0).map(({group:ve,pages:Fe},Ke)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:Ie("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ke===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${ve}`)}),Fe.map(Be=>{const ze=u===Be.slug&&!(c&&v==="nav"),_e=Rm(Be.slug);return!_e&&Be.slug!=="mcp"?null:s.jsx(nr,{children:s.jsx(ar,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>_(Be.slug),"aria-current":ze?"page":void 0,className:Ie("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",ze?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Be.slug==="mcp"?s.jsx(qu,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(z,{name:_e,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:$(Be.slug)}),Be.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:l("settings.view.badge.beta")})]})]})})},Be.slug)})]},ve))})()})})]})},xe=()=>{if(v==="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(Hn,{children:Ge()})})});if(!V)return s.jsx("div",{className:"flex-1 bg-background"});if(v==="page-sidebar"){if(V.kind!=="split"){const se=Se(u);return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:se})})}return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:ce(u,{onItemSelect:ue})})})}const J=Se(u);return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:J})})},Pe=()=>!V||u==="home"?null:V.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:Ie("border-r",K.isVSCode?"bg-background":"bg-sidebar"),style:{width:jc,minWidth:jc,borderColor:"var(--interactive-border)"},children:s.jsx(Hn,{children:ce(u,{})})}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:Se(u)})})]}):s.jsx(bs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:Se(u)})});return s.jsxs("div",{ref:D,"data-settings-view":"true",className:Ie("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:Ie("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",v!=="nav"&&"border-b","bg-background"),style:v!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ie?s.jsx("button",{type:"button",onClick:$e,"aria-label":ae,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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:v==="nav"?l("settings.view.home.title"):V?$(V.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:je,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ie&&s.jsx("div",{className:Ie("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:$e,"aria-label":l("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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:Ie("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:je,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?xe():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Ie("relative flex h-full min-h-0 flex-col overflow-hidden border-r",E?"bg-sidebar":K.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${yc}px`,minWidth:`${yc}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Hn,{children:Ge()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Pe()})]})})]})};export{Jc as A,Y1 as S};
27
+ `}`},Af=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),dd=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=Um(e[1]);if(Af(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Tf=(t,e)=>{const a=dd(t);return qi(e,a.instructions)},Ef=()=>{const{t}=Ze(),{currentTheme:e}=fa(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:d,setSkillDraft:c,setSelectedSkill:h}=nn($s(ye=>({selectedSkillName:ye.selectedSkillName,getSkillByName:ye.getSkillByName,getSkillDetail:ye.getSkillDetail,createSkill:ye.createSkill,updateSkill:ye.updateSkill,skillDraft:ye.skillDraft,setSkillDraft:ye.setSkillDraft,setSelectedSkill:ye.setSelectedSkill}))),p=Js(),f=nn(ye=>ho(ye,p)),m=a?n(a,p):null,u=!!(d&&d.name===a&&!m),v=!!(a&&!m&&!d),w=m?.path==="<built-in>";o.useEffect(()=>{v&&h(null)},[v,h]);const[b,k]=o.useState(""),[g,I]=o.useState("user"),[C,P]=o.useState("opencode"),[j,T]=o.useState(""),[x,A]=o.useState(""),[M,S]=o.useState(()=>qi("","")),[D,O]=o.useState("edit"),[F,N]=o.useState([]),[R,U]=o.useState([]),[K,W]=o.useState(!1),[te,Q]=o.useState(!1),[H,_]=o.useState(""),[V,X]=o.useState(""),[$,ee]=o.useState(!1),[L,Y]=o.useState(""),[oe,de]=o.useState(""),[ue,ce]=o.useState(null),[Se,ie]=o.useState(!1),[be,ae]=o.useState(""),[pe,je]=o.useState(null),[De,me]=o.useState(!1),$e=ue?oe!==be:L.trim()!=="",Ge=o.useCallback(ye=>{switch(ye){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]),xe=o.useCallback(ye=>{switch(ye){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]),Pe=JSON.stringify([p,a,m?.path,u]),J=o.useRef(null),se=o.useRef({key:Pe,markdown:M});se.current={key:Pe,markdown:M};const he=o.useRef("");o.useEffect(()=>{let ye=!1;const re=(Ne,Ae)=>{if(se.current.key!==Pe)return;const q=qi(Ne,Ae),Le=J.current===Pe&&se.current.markdown!==he.current;J.current=Pe,he.current=q,Le||(T(Ne),A(Ae),S(q))};return(async()=>{if(u&&d){Q(!1);const Ne=d.description||"",Ae=d.instructions||"";k(d.name||""),I(d.scope||"user"),P(d.source==="agents"?"agents":"opencode"),re(Ne,Ae),_(""),X(""),N([]),U(d.pendingFiles||[])}else if(a&&m){Q(J.current!==Pe);try{const Ne=await r(a,p);if(!ye&&se.current.key===Pe&&Ne){const Ae=Ne.sources.md,q=Ae.description||"",Le=Ae.instructions||"";re(q,Le),_(q),X(Le),N(Ae.supportingFiles||[])}}catch(Ne){console.error("Failed to load skill details:",Ne)}finally{ye||Q(!1)}}})(),()=>{ye=!0}},[m,u,a,p,f,d,r,Pe]);const ve=fe(ye=>ye.editorFontSize),Fe=o.useMemo(()=>{const ye=[dl(e,{fontSize:ve})],re=Bo(If);return re&&ye.push(re),ye.push(ml.lineWrapping),ye},[e,ve]),Ke=o.useMemo(()=>{const ye=L.trim()||"supporting-file.md",re=qd(ye),Te=!!re&&re!=="markdown",Ne=[dl(e,Te?{syntaxColors:!1,fontSize:ve}:{fontSize:ve})],Ae=Bo(ye);return Ae&&Ne.push(Ae),Te&&re&&Ne.push(zm({language:re,themeName:e.metadata.id,theme:Bm(e)})),Ne.push(ml.lineWrapping),Ne},[e,L,ve]),Be=o.useCallback(ye=>{T(ye),S(re=>Tf(re,ye))},[]),ze=o.useCallback(ye=>{S(ye);const re=dd(ye);T(re.description??""),A(re.instructions)},[]),_e=ye=>ye?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ye)||ye.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),Me=o.useCallback(async()=>{const ye=a?.trim();return u||w||!ye||j===H&&x===V?Os:j.trim()?await l(ye,{name:ye,description:j.trim(),instructions:x.trim()||void 0,targetPath:m?.path},p)?(se.current.key===Pe&&(he.current=qi(j,x),_(j),X(x)),In):us(t("settings.skills.page.toast.updateSkillFailed")):us(t("settings.skills.page.toast.descriptionRequired"))},[j,x,u,w,H,V,m?.path,a,p,Pe,t,l]),tt=Ja(Me),pt=async()=>{const ye=b.trim().replace(/\s+/g,"-").toLowerCase(),re=_e(ye);if(re){B.error(re);return}if(!j.trim()){B.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f.some(Te=>Te.name===ye)){B.error(t("settings.skills.page.toast.skillExists"));return}W(!0);try{const Te={name:ye,description:j.trim(),instructions:x.trim()||void 0,scope:g,source:C,supportingFiles:R.length>0?R:void 0};await i(Te,p)?(c(null),U([]),h(ye),B.success(t("settings.skills.page.toast.skillCreated"))):B.error(t("settings.skills.page.toast.createSkillFailed"))}catch(Te){console.error("Error creating skill:",Te),B.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{W(!1)}},ct=()=>{c(null),h(null)},dt=()=>{ce(null),Y(""),de(""),ae(""),ee(!0)},ht=async ye=>{if(ce(ye),Y(ye),u){const Te=R.find(Ne=>Ne.path===ye)?.content||"";de(Te),ae(Te),ee(!0);return}if(a){ie(!0),ee(!0);try{const{readSupportingFile:re}=nn.getState(),Te=await re(a,ye,p);de(Te||""),ae(Te||"")}catch{B.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),ae("")}finally{ie(!1)}}},Ue=async()=>{if(!L.trim()){B.error(t("settings.skills.page.toast.fileNameRequired"));return}const ye=L.trim(),re=ue!==null;if(u){if(re)U(Ae=>Ae.map(q=>q.path===ue?{path:ye,content:oe}:q)),B.success(t("settings.skills.page.toast.fileUpdated",{path:ye}));else{if(R.some(Ae=>Ae.path===ye)){B.error(t("settings.skills.page.toast.fileExists"));return}U(Ae=>[...Ae,{path:ye,content:oe}]),B.success(t("settings.skills.page.toast.fileAdded",{path:ye}))}ee(!1),ce(null);return}if(!a){B.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Te}=nn.getState();if(await Te(a,ye,oe,p)){B.success(re?t("settings.skills.page.toast.fileUpdated",{path:ye}):t("settings.skills.page.toast.fileCreated",{path:ye})),ee(!1),ce(null);const Ae=await r(a,p);Ae&&N(Ae.sources.md.supportingFiles||[])}else B.error(t(re?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},st=ye=>{if(u){U(re=>re.filter(Te=>Te.path!==ye)),B.success(t("settings.skills.page.toast.fileRemoved",{path:ye}));return}a&&je(ye)},ut=async()=>{if(!pe||!a)return;me(!0);const{deleteSupportingFile:ye}=nn.getState();if(await ye(a,pe,p)){B.success(t("settings.skills.page.toast.fileDeleted",{path:pe}));const Te=await r(a,p);Te&&N(Te.sources.md.supportingFiles||[]),je(null)}else B.error(t("settings.skills.page.toast.deleteFileFailed"));me(!1)};return!a&&!d||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(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):te?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(ns,{title:u?t("settings.skills.page.title.newSkill"):a,description:m?t("settings.skills.page.subtitle.skillLocation",{location:Ge(ui(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:tt.onBlurCapture,children:[s.jsxs(qe,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[u&&s.jsxs(Ct,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(We,{value:b,onChange:ye=>k(ye.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Tt,{value:ui(g,C),onValueChange:ye=>{const re=cd(ye);I(re.scope),P(re.source==="agents"?"agents":"opencode")},children:[s.jsxs(Pt,{size:$t,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),C==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ge(ui(g,C))})]}),s.jsx(At,{align:"start",children:To.map(ye=>s.jsx(mt,{value:ye.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ye.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ge(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:xe(ye.value)})]})},ye.value))})]})]}),s.jsx(Ot,{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:j,onChange:ye=>Be(ye.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:w})})]}),s.jsx(qe,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx($m,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>O(ye=>ye==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:Ie("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Pf),onKeyDown:ye=>{ye.key==="Enter"&&(ye.metaKey||ye.ctrlKey)&&(ye.preventDefault(),tt.requestSave())},children:D==="preview"?s.jsx(bs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Gd,{content:M,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(ul,{value:M,onChange:ze,readOnly:w,extensions:Fe,className:"h-full",enableSearch:!0})})}),s.jsx(qe,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:dt,disabled:w,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const ye=u?R:F;return ye.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:ye.map(re=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ht(re.path),children:[s.jsx(z,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:re.path}),u&&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")}),!w&&s.jsx(G,{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:Te=>{Te.stopPropagation(),st(re.path)},children:s.jsx(z,{name:"delete-bin",className:"h-3 w-3"})})]},re.path))})})()}),u&&s.jsx(qe,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{onClick:()=>{pt()},disabled:K||!b.trim()||!j.trim(),size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(G,{variant:"ghost",onClick:ct,disabled:K,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(_t,{open:pe!==null,onOpenChange:ye=>{!ye&&!De&&je(null)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.description",{path:pe??""})})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>je(null),disabled:De,children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:ut,disabled:De,children:t("settings.common.actions.delete")})]})]})}),s.jsx(_t,{open:$,onOpenChange:ye=>{if(ye){ee(!0);return}if(ue!==null&&oe!==be){Ue();return}ee(!1),ce(null)},children:s.jsxs(Ut,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Bt,{className:"flex-shrink-0",children:[s.jsx(Vt,{children:t(ue?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ht,{children:t(ue?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Se?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:St,children:t("settings.skills.page.fileDialog.field.filePath")}),!ue&&s.jsx(qt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(We,{value:L,onChange:ye=>Y(ye.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:ue!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${St} 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(ul,{value:oe,onChange:de,extensions:Ke,className:"h-full",enableSearch:!0})})]})]}),s.jsx(as,{className:"mt-4",children:ue?s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Se,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{ee(!1),ce(null)},children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Se||!$e,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},El=t=>{const e=at.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(Cf,{}):s.jsx(Ef,{}),e[0]=n,e[1]=r):r=e[1],r};function Df(){}const Mf=t=>{const e=at.c(38),{onItemSelect:a}=t,{t:n}=Ze(),r=rn(Rf),i=fe(Of),l=fe(Ff),{currentTheme:d}=fa();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[0]=c):c=e[0];const h=c,p=Lf;let f,m;e[1]!==r||e[2]!==i||e[3]!==l?(f=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(T=>T.id===i)||l(r[0].id)},m=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=f,e[5]=m):(f=e[4],m=e[5]),o.useEffect(f,m);let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=Ie("border-b px-3","pt-4 pb-3"),e[6]=u):u=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let w;e[9]!==v?(w=s.jsx("h2",{className:`${Pn} mb-3`,children:v}),e[9]=v,e[10]=w):w=e[10];let b;e[11]!==r.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=n,e[13]=b):b=e[13];let k;e[14]!==b?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=k):k=e[15];let g;e[16]!==n?(g=!h&&s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:p,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(z,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let I;e[18]!==k||e[19]!==g?(I=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,g]}),e[18]=k,e[19]=g,e[20]=I):I=e[20];let C;e[21]!==I||e[22]!==w?(C=s.jsxs("div",{className:u,children:[w,I]}),e[21]=I,e[22]=w,e[23]=C):C=e[23];let P;if(e[24]!==d||e[25]!==a||e[26]!==r||e[27]!==i||e[28]!==l){let T;e[30]!==d||e[31]!==a||e[32]!==i||e[33]!==l?(T=x=>{const A=x.id===i,M=x.icon?Jd[x.icon]:null,S=x.color?Qd[x.color]??null:null,D=M?s.jsx(z,{name:M,className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}):s.jsx(z,{name:"folder",className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}),O=x.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:x.iconBackground?{backgroundColor:x.iconBackground}:void 0,children:s.jsx(Yd,{project:x,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:D})}):D;return s.jsx(Hi,{title:x.label||x.path,icon:O,selected:A,onSelect:()=>{l(x.id),a?.()}},x.id)},e[30]=d,e[31]=a,e[32]=i,e[33]=l,e[34]=T):T=e[34],P=r.map(T),e[24]=d,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=P}else P=e[29];let j;return e[35]!==C||e[36]!==P?(j=s.jsx(ld,{variant:"background",header:C,children:P}),e[35]=C,e[36]=P,e[37]=j):j=e[37],j};function Rf(t){return t.projects}function Of(t){return t.settingsProjectsSelectedId}function Ff(t){return t.setSettingsProjectsSelectedId}function Lf(){Wd.requestDirectoryDialog()}const Kf=()=>{const t=at.c(30),{t:e}=Ze(),a=rn(_f),n=rn(Uf),r=fe(zf),i=fe($f);let l;e:{if(!r){l=null;break e}let b;t[0]!==a||t[1]!==r?(b=a.find(k=>k.id===r)??null,t[0]=a,t[1]=r,t[2]=b):b=t[2],l=b}const d=l;let c,h;t[3]!==a||t[4]!==r||t[5]!==i?(c=()=>{if(a.length===0){i(null);return}r&&a.some(b=>b.id===r)||i(a[0].id)},h=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=c,t[7]=h):(c=t[6],h=t[7]),o.useEffect(c,h);let p;t[8]!==d||t[9]!==n?(p=async b=>{d&&n(d.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultAgent:b.defaultAgent??null,defaultModel:b.defaultModel??null,defaultVariant:b.defaultVariant??null})},t[8]=d,t[9]=n,t[10]=p):p=t[10];const f=p;if(!d){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let k;t[13]!==e?(k=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=k):k=t[14];let g;t[15]!==k?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=g):g=t[16];let I;return t[17]!==b||t[18]!==g?(I=s.jsx(ns,{title:b,showSaveStatus:!0,children:g}),t[17]=b,t[18]=g,t[19]=I):I=t[19],I}let m;t[20]!==d.label||t[21]!==e?(m=d.label??e("settings.projects.page.title.default"),t[20]=d.label,t[21]=e,t[22]=m):m=t[22];const u=m;let v;t[23]!==f||t[24]!==d?(v=s.jsx(Em,{project:d,onIdentitySave:f}),t[23]=f,t[24]=d,t[25]=v):v=t[25];let w;return t[26]!==u||t[27]!==d.path||t[28]!==v?(w=s.jsx(ns,{title:u,description:d.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=u,t[27]=d.path,t[28]=v,t[29]=w):w=t[29],w};function _f(t){return t.projects}function Uf(t){return t.updateProjectMeta}function zf(t){return t.settingsProjectsSelectedId}function $f(t){return t.setSettingsProjectsSelectedId}const Bf=Ts({clientToken:Dt().trim().min(1)}),Vf=Ts({error:Km("Invalid or expired pairing session")}),Hf=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&Vf.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const a=Bf.safeParse(e);return a.success?{kind:"success",token:a.data.clientToken}:{kind:"invalid-response"}};function qf(t){const e=at.c(42),{t:a}=Ze(),[n,r]=et.useState(null),i=et.useRef(null),l=et.useRef(null);let d,c;e[0]!==t?(d=()=>(l.current=t,r(null),()=>{l.current=null;const N=i.current;i.current=null,N?.(null)}),c=[t],e[0]=t,e[1]=d,e[2]=c):(d=e[1],c=e[2]),et.useEffect(d,c);let h;e[3]!==t?(h=(N,R)=>{const U=R===void 0?"settings.common.actions.saveChanges":R;return!t||l.current!==t||i.current?Promise.resolve(null):new Promise(K=>{i.current=K,r({messageKey:N,actionKey:U})})},e[3]=t,e[4]=h):h=e[4];const p=h;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=N=>{const R=i.current;i.current=null,r(null),R?.(N)},e[5]=f):f=e[5];const m=f,u=n!==null;let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=N=>{N||m(!1)},e[6]=v):v=e[6];let w;e[7]!==a?(w=a("settings.remoteInstances.page.title"),e[7]=a,e[8]=w):w=e[8];let b;e[9]!==w?(b=s.jsx(Vt,{children:w}),e[9]=w,e[10]=b):b=e[10];let k;e[11]!==n||e[12]!==a?(k=n?a(n.messageKey):null,e[11]=n,e[12]=a,e[13]=k):k=e[13];let g;e[14]!==k?(g=s.jsx(Ht,{children:k}),e[14]=k,e[15]=g):g=e[15];let I;e[16]!==b||e[17]!==g?(I=s.jsxs(Bt,{children:[b,g]}),e[16]=b,e[17]=g,e[18]=I):I=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=()=>m(!1),e[19]=C):C=e[19];let P;e[20]!==a?(P=a("settings.common.actions.cancel"),e[20]=a,e[21]=P):P=e[21];let j;e[22]!==P?(j=s.jsx(G,{variant:"outline",autoFocus:!0,onClick:C,children:P}),e[22]=P,e[23]=j):j=e[23];let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=()=>m(!0),e[24]=T):T=e[24];let x;e[25]!==n||e[26]!==a?(x=n?a(n.actionKey):null,e[25]=n,e[26]=a,e[27]=x):x=e[27];let A;e[28]!==x?(A=s.jsx(G,{onClick:T,children:x}),e[28]=x,e[29]=A):A=e[29];let M;e[30]!==j||e[31]!==A?(M=s.jsxs(as,{children:[j,A]}),e[30]=j,e[31]=A,e[32]=M):M=e[32];let S;e[33]!==I||e[34]!==M?(S=s.jsxs(Ut,{children:[I,M]}),e[33]=I,e[34]=M,e[35]=S):S=e[35];let D;e[36]!==S||e[37]!==u?(D=s.jsx(_t,{open:u,onOpenChange:v,children:S}),e[36]=S,e[37]=u,e[38]=D):D=e[38];const O=D;let F;return e[39]!==p||e[40]!==O?(F={confirm:p,dialog:O},e[39]=p,e[40]=O,e[41]=F):F=e[41],F}const Gi=()=>Math.floor(2e4+Math.random()*3e4),Gf=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")},Wf=()=>{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"},Dl=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}},Ml=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"}},Jf=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Eo=t=>!!(t&&Jf.has(t)),Rl=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Eo(t)?"connecting":"idle",Ol=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"}},Qf=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},Fl={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Yf=t=>t==="noRuntime"?Fl.noRuntime:t==="noOpencode"?Fl.noOpencode:null,Ll=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Eo(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Zf=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}`,Xf=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Gi(),remoteHost:"127.0.0.1",remotePort:80}),ex=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",tn=t=>{const e=at.c(7),{label:a,hint:n}=t;let r;e[0]!==a?(r=s.jsx("span",{children:a}),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==n?(i=s.jsx(qt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=i):i=e[3];let l;return e[4]!==r||e[5]!==i?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${St}`,children:[r,i]}),e[4]=r,e[5]=i,e[6]=l):l=e[6],l},tx=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"}},Kl=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},sx=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},nx=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],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${n}] [${r}] ${i}`},lo=(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}),ax=t=>t.trim().toLowerCase()==="authorization",zr=t=>{const e={};for(const a of t){const n=a.name.trim(),r=a.value.trim();n&&r&&!ax(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},ix=t=>Object.entries(t||{}).map(([e,a])=>lo(e,a)),ud=()=>{if(typeof window>"u")return null;const e=hi()||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}},_l=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},rx=async()=>{const t=Ka(hi())||window.location.origin;if(!ls()||!fi()||(await An())?.desktopLanAccessActive!==!0)return t;const a=await Vc(),n=ud();return!a||!n?t:`http://${a}:${n}`},_i=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},ox=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.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}},lx=()=>{const{t}=Ze(),e=fe(E=>E.timeFormatPreference),{clientAuth:a}=jo(),n=ls(),r=Is(E=>E.instances),i=Is(E=>E.statusesById),l=Is(E=>E.importCandidates),d=Is(E=>E.isLoading),c=Is(E=>E.isImportsLoading),h=Is(E=>E.isSaving),p=Is(E=>E.error),f=Is(E=>E.load),m=Is(E=>E.loadImports),u=Is(E=>E.refreshStatuses),v=Is(E=>E.upsertInstance),w=Is(E=>E.createFromCommand),b=Is(E=>E.removeInstance),k=Is(E=>E.connect),g=Is(E=>E.disconnect),I=Is(E=>E.retry),C=fe(E=>E.settingsRemoteInstancesSelectedId),P=fe(E=>E.setSettingsRemoteInstancesSelectedId),{confirm:j,dialog:T}=qf(C),x=o.useMemo(()=>C&&r.find(E=>E.id===C)||null,[r,C]),[A,M]=o.useState(null),[S,D]=o.useState(!1),[O,F]=o.useState(!1),[N,R]=o.useState(null),[U,K]=o.useState([]),[W,te]=o.useState(null),[Q,H]=o.useState(""),[_,V]=o.useState(!1),[X,$]=o.useState({}),[ee,L]=o.useState(!1),[Y,oe]=o.useState(!1),[de,ue]=o.useState(()=>Date.now()),[ce,Se]=o.useState([]),[ie,be]=o.useState({}),[ae,pe]=o.useState("local"),[je,De]=o.useState(!1),[me,$e]=o.useState(!1),[Ge,xe]=o.useState(""),[Pe,J]=o.useState(""),[se,he]=o.useState(""),[ve,Fe]=o.useState([]),[Ke,Be]=o.useState(""),[ze,_e]=o.useState(null),[Me,tt]=o.useState(!1),[pt,ct]=o.useState(!1),[dt,ht]=o.useState(!1),[Ue,st]=o.useState(null),[ut,ye]=o.useState(""),[re,Te]=o.useState(""),[Ne,Ae]=o.useState(""),[q,Le]=o.useState([]),[Qe,lt]=o.useState([]),[ot,bt]=o.useState([]),[wt,jt]=o.useState(!1),[vt,Xe]=o.useState(""),[kt,Re]=o.useState(null),[Ve,Z]=o.useState(null),[ge,Oe]=o.useState(null),[Ee,Ye]=o.useState(null),[ne,we]=o.useState(!1),[nt,Rt]=o.useState(!1),[Jt,Ce]=o.useState("configure"),[He,yt]=o.useState(!1),[It,Qt]=o.useState("relay"),[Xt,ts]=o.useState(!0),[es,Fs]=o.useState(null),Qs=o.useMemo(()=>Qe.filter(E=>!!E.revokedAt).length,[Qe]),[pn,Ls]=o.useState(!1),[Ks,on]=o.useState("saved"),[Ys,Zs]=o.useState(""),[_s,Tn]=o.useState(""),[Mt,Gt]=o.useState(""),[Kt,Et]=o.useState(!1);o.useEffect(()=>{f(),m()},[f,m]);const is=o.useCallback(async()=>{De(!0),_e(null);try{const E=await Xo();Se(E.hosts||[]),pe(E.defaultHostId||"local")}catch(E){_e(E instanceof Error?E.message:String(E))}finally{De(!1)}},[]);o.useEffect(()=>{is()},[is]);const ss=o.useCallback(async(E,le=ae)=>{$e(!0),_e(null);try{return await el({hosts:E,defaultHostId:le,initialHostChoiceCompleted:!0}),Se(E),pe(le),!0}catch(Je){return _e(Je instanceof Error?Je.message:String(Je)),!1}finally{$e(!1)}},[ae]),lr=o.useCallback(async()=>{const E=tl(Pe);if(!E){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=E.persistedUrl,rt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ge.trim()||Za(le),url:le,apiUrl:le,...se.trim()?{clientToken:se.trim()}:{},...zr(ve)?{requestHeaders:zr(ve)}:{}};await ss([rt,...ce],ae)&&(xe(""),J(""),he(""),Fe([]),tt(!1),E.redeemUrl&&_i(E.redeemUrl))},[ae,ve,ce,Ge,se,Pe,ss,t]),cr=o.useCallback(async()=>{_e(null);const E=Qu(Ke);if(!E){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const le=await Yu().catch(()=>""),Je=JSON.stringify({pairingId:E.pairingId,secret:E.secret,clientLabel:E.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Wf(),...le?{dedupeKey:`desktop:${le}`}:{}}),rt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Je};let Ft=null;const xs=async Zt=>{const Cs=await Hf(Zt);switch(Cs.kind){case"success":return Cs.token;case"rejected":Ft=t("desktopHostSwitcher.error.pairingRejected");break;case"http-error":Ft??=t("desktopHostSwitcher.error.pairingFailed",{status:Cs.status});break;case"invalid-response":Ft??=t("desktopHostSwitcher.error.pairingInvalidResponse");break}return null},Xs=[...E.candidates].sort((Zt,Cs)=>(Zt.type==="relay"?1:0)-(Cs.type==="relay"?1:0));let ms=null;for(const Zt of Xs){if(Zt.type==="relay"){const Ta=Zu({relayUrl:Zt.relayUrl,serverId:Zt.serverId,hostEncPubJwk:Zt.hostEncPubJwk,...Zt.grant?{grant:Zt.grant}:{}});try{const Ea=await Ta.fetch("/api/client-auth/pairing/redeem",{...rt,signal:AbortSignal.timeout(15e3)}),Da=await xs(Ea);if(Da){ms={kind:"relay",relay:{relayUrl:Zt.relayUrl,serverId:Zt.serverId,hostEncPubJwk:Zt.hostEncPubJwk},token:Da};break}}catch{}finally{Ta.close()}continue}const Cs=Ka(Zt.url);if(Cs)try{const Ta=await fetch(`${Cs}/api/client-auth/pairing/redeem`,{...rt,signal:AbortSignal.timeout(15e3)}),Ea=await xs(Ta);if(Ea){ms={kind:"direct",url:Cs,token:Ea};break}}catch{}}if(!ms){_e(Ft||t("mobile.connect.error.unreachable"));return}const Us=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Dn=E.candidates.find(Zt=>Zt.type==="relay"),fn=ms.kind==="relay"?ms.relay:Dn?{relayUrl:Dn.relayUrl,serverId:Dn.serverId,hostEncPubJwk:Dn.hostEncPubJwk}:void 0,Pa=E.candidates.filter(Zt=>Zt.type!=="relay").map(Zt=>Ka(Zt.url)).find(Zt=>!!Zt),Aa=ms.kind==="direct"?ms.url:Pa,{token:Lt}=ms,Yt=Aa||(fn?Xu(fn.serverId):null);if(!Yt){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const xn={url:Yt,apiUrl:Aa||void 0,clientToken:Lt,...fn?{relay:fn}:{}},dn=ce.find(Zt=>fn?Zt.relay?.serverId===fn.serverId:!Zt.relay&&Ka(Zt.apiUrl||Zt.url)===Yt);if(dn){const Zt=ce.map(Cs=>Cs.id===dn.id?{...Cs,label:E.label||Cs.label,...xn}:Cs);if(!await ss(Zt,ae))return}else if(!await ss([{id:Us(),label:E.label||Za(Yt),...xn},...ce],ae))return;Be(""),_e(null),ct(!1)},[Ke,ae,ce,ss,t]),dr=o.useCallback(async E=>{const le=ce.filter(rt=>rt.id!==E);await ss(le,ae===E?"local":ae)&&Ue===E&&st(null)},[ae,Ue,ce,ss]),ur=o.useCallback(E=>{st(E.id),ye(E.label),Te(E.apiUrl||E.url),Ae(E.clientToken||""),Le(ix(E.requestHeaders)),_e(null)},[]),vi=o.useCallback(async()=>{if(!Ue)return;const E=tl(re);if(!E){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=E.persistedUrl,Je=ce.map(rt=>rt.id===Ue?{...rt,label:ut.trim()||Za(le),url:le,apiUrl:le,clientToken:Ne.trim()||void 0,requestHeaders:zr(q)}:rt);await ss(Je,ae)&&(st(null),E.redeemUrl&&_i(E.redeemUrl))},[ae,q,ut,Ne,re,Ue,ce,ss,t]),mr=o.useCallback(async()=>{const E=_s.trim();if(!E){B.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const le=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await w(le,E,Mt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),P(le),Ls(!1),Tn(""),Gt(""),B.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Je){B.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Je instanceof Error?Je.message:String(Je)})}},[w,P,_s,Mt,t]),yi=o.useCallback(()=>{Zs(""),on(l.length>0?"saved":"manual"),Ls(!0)},[l.length]),pr=o.useCallback(async E=>{await ss(ce,E)},[ce,ss]);o.useEffect(()=>{if(!n||ce.length===0)return;let E=!1;return Promise.all(ce.map(async le=>{const Je=()=>im(le.relay,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(le.relay&&!le.apiUrl)return[le.id,await Je()];const rt=Ka(em(le));if(!rt)return[le.id,le.relay?await Je():{status:"unreachable",latencyMs:0}];const Ft=await tm(rt,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ft.status==="unreachable"&&le.relay){const xs=await Je();if(xs.status==="ok")return[le.id,xs]}return[le.id,Ft]})).then(le=>{E||be(Object.fromEntries(le))}),()=>{E=!0}},[ce,n]);const Bs=o.useCallback(async E=>{if(a){E?.silent||jt(!0),E?.silent||Re(null);try{const[le,Je]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);lt(le),Je&&bt(Je)}catch(le){E?.silent||Re(le instanceof Error?le.message:String(le))}finally{E?.silent||jt(!1)}}},[a]),Qa=o.useRef(!1);o.useEffect(()=>{if(!(!nt||Jt!=="result"||!ge)){if(ot.some(E=>E.id===ge)){Qa.current=!0;return}Qa.current&&(Oe(null),Rt(!1),Qe.some(E=>E.pairingId===ge)&&B.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[nt,Jt,ge,ot,Qe,t]);const ji=o.useCallback(async E=>{if(a)try{await a.cancelPairing(E),bt(le=>le.filter(Je=>Je.id!==E)),await Bs({silent:!0})}catch(le){Re(le instanceof Error?le.message:String(le))}},[a,Bs]);o.useEffect(()=>{if(!a)return;Bs();const E=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Bs({silent:!0})},5e3);return()=>window.clearInterval(E)},[a,Bs]);const wi=o.useCallback(async()=>{if(a?.getPairingTransports)try{const rt=await a.getPairingTransports();return{localUrl:rt.local,lanUrl:rt.lan,relayAvailable:rt.relayAvailable}}catch{}const E=ud(),le=E?`http://127.0.0.1:${E}`:_l(window.location.origin)?window.location.origin:null;let Je=null;try{const rt=Ka(await rx());Je=rt&&!_l(rt)?rt:null}catch{}return{localUrl:le,lanUrl:Je,relayAvailable:!0}},[a]),gr=o.useCallback(async()=>{Re(null),Z(null),Ye(null),we(!1),Oe(null),Ce("configure"),ts(!0),Rt(!0);const E=await wi();Fs(E),Qt(E.relayAvailable?"relay":E.lanUrl?"lan":"local")},[wi]),hr=o.useCallback(async()=>{if(!(!a?.createPairingSession||!es)){Re(null),yt(!0);try{const E=vt.trim()||void 0;let le,Je,rt=!0;It==="local"?(le=es.localUrl??void 0,Je=!1):It==="lan"?(le=es.lanUrl??void 0,Je=Xt):Xt&&es.lanUrl?(le=es.lanUrl,Je=!0):(rt=!1,Je=!0);const{pairing:Ft,server:xs}=await a.createPairingSession({label:E,allowedClientKinds:["mobile","desktop"],serverUrl:le,includeRelay:Je,includeDirect:rt}),Xs=sm({pairingId:Ft.id,secret:Ft.secret,label:xs.label,fingerprint:Ft.fingerprint??void 0,expiresAt:Ft.expiresAt,candidates:xs.candidates}),ms=nm(Xs);Z(ms),Ye(await Qc.toDataURL(ms,{width:1024,margin:2,errorCorrectionLevel:"L"})),we(!1),Qa.current=!1,Oe(Ft.id),Ce("result"),await Bs({silent:!0})}catch(E){Re(E instanceof Error?E.message:String(E))}finally{yt(!1)}}},[a,es,It,Xt,vt,Bs]),ki=o.useCallback(()=>{Ve&&za(Ve).then(E=>{E.ok&&(we(!0),window.setTimeout(()=>we(!1),2e3))})},[Ve]),fr=o.useCallback(async E=>{if(!a)return;const le=E.clientKind==="desktop-local";Re(null);try{if(await a.revokeClient(E.id),le&&ls()){const Je=await Xo();await el({hosts:Je.hosts,defaultHostId:Je.defaultHostId,initialHostChoiceCompleted:Je.initialHostChoiceCompleted,localClientToken:null}),lt(rt=>rt.map(Ft=>Ft.id===E.id?{...Ft,revokedAt:new Date().toISOString()}:Ft)),am({apiBaseUrl:hi(),clientToken:null,runtimeKey:"local"});return}await Bs()}catch(Je){Re(Je instanceof Error?Je.message:String(Je))}},[a,Bs]),xr=o.useCallback(async()=>{if(a){Re(null);try{await a.purgeRevokedClients(),await Bs()}catch(E){Re(E instanceof Error?E.message:String(E))}}},[a,Bs]);o.useEffect(()=>{M(x)},[x]),o.useEffect(()=>{Et(!1)},[C]),o.useEffect(()=>{if(!C)return;const E=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||u()},2e3);return()=>{window.clearInterval(E)}},[u,C]),o.useEffect(()=>{let E=null,le=Date.now();const Je=()=>{const Ft=Date.now();Ft-le>=1e3&&(ue(Ft),le=Ft),E=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(E=requestAnimationFrame(Je));const rt=()=>{document.visibilityState==="visible"&&E===null?E=requestAnimationFrame(Je):document.visibilityState!=="visible"&&E!==null&&(cancelAnimationFrame(E),E=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),E!==null&&cancelAnimationFrame(E)}},[]);const js=C?i[C]:null,ln=js?.phase,ba=ln==="ready",En=ln==="degraded",$n=Eo(ln),cn=ba||($n||En),br=js?Math.max(0,de-js.updatedAtMs):0,va=En&&br>12e3,ya=Rl(ln),Yn=ya==="error"?Qf(js?.detail):null,Ya=Yf(Yn),vr=o.useMemo(()=>!A||!x?!1:JSON.stringify(A)!==JSON.stringify(x),[A,x]),ds=o.useCallback(E=>{M(le=>le&&E(le))},[]),yr=o.useCallback(async()=>{if(!A)return;const E=ox(A);if(!E.sshCommand.trim()){B.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(E.remoteOpenchamber.mode==="external"&&!E.remoteOpenchamber.preferredPort){B.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Et(!0);return}if(E.remoteOpenchamber.mode==="managed"&&E.remoteOpenchamber.bindHost==="0.0.0.0"&&!E.auth.openchamberPassword?.value?.trim()){B.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Et(!0),window.setTimeout(()=>ka.current?.focus(),0);return}if(!(E.localForward.bindHost==="0.0.0.0"&&!await j("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(E.auth.sshPassword?.enabled&&E.auth.sshPassword.value?.trim()&&E.auth.sshPassword.store!=="settings"){const le=await j("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext");if(le===null)return;E.auth.sshPassword.store=le?"settings":"never",le||(E.auth.sshPassword.value=void 0)}if(E.auth.openchamberPassword?.enabled&&E.auth.openchamberPassword.value?.trim()&&E.auth.openchamberPassword.store!=="settings"){const le=await j("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext");if(le===null)return;E.auth.openchamberPassword.store=le?"settings":"never",le||(E.auth.openchamberPassword.value=void 0)}try{await v(E),B.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(le){B.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:le instanceof Error?le.message:String(le)})}}},[j,A,t,v]),ja=o.useCallback(async(E,le)=>{const Je=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await w(Je,`ssh ${le}`,E),P(Je),B.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(rt){return B.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:rt instanceof Error?rt.message:String(rt)}),!1}},[w,P,t]),wa=o.useCallback(()=>{_||(te(null),H(""))},[_]),jr=o.useCallback((E,le)=>{if(Ls(!1),le){te(E),H(ex(E));return}ja(E,E)},[ja]),Ni=o.useMemo(()=>gi(l,Ys,E=>[E.host,E.sshCommand]),[l,Ys]),wr=o.useCallback(E=>{const le=(E||"").trim();if(!le){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}_i(le)},[t]),Bn=o.useCallback(async()=>{const E=W,le=Q.trim();if(E){if(!le){B.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await ja(E,le)&&(te(null),H(""))}finally{V(!1)}}},[ja,Q,W,t]),gn=o.useCallback(async()=>{if(x)try{await k(x.id);return}catch(E){if(!Gf(E)||!await j("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw E;const Je={...x,localForward:{...x.localForward,preferredLocalPort:Gi()}};await v(Je),await k(Je.id),B.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[j,k,x,t,v]),ka=o.useRef(null),Si=o.useRef(null),Na=o.useCallback(async E=>{if(x){if(E==="localPort"){const le={...x,localForward:{...x.localForward,preferredLocalPort:Gi()}};try{await v(le),await k(le.id),B.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Je){B.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Je instanceof Error?Je.message:String(Je)})}return}Et(!0),window.setTimeout(()=>{if(E==="uiPassword"){ka.current?.focus();return}Si.current?.scrollIntoView({block:"center"})},0)}},[k,x,t,v]),Sa=o.useCallback(async E=>(await Zd(E,600)).map(Je=>nx(Je)),[]),kr=o.useCallback(async()=>{if(A){D(!0),F(!0),R(null);try{const E=await Sa(A.id);K(E)}catch(E){K([]),R(E instanceof Error?E.message:String(E))}finally{F(!1)}}},[A,Sa]);o.useEffect(()=>{if(!S||!A)return;let E=!1;const le=async()=>{try{const rt=await Sa(A.id);E||(K(rt),R(null))}catch(rt){E||R(rt instanceof Error?rt.message:String(rt))}};le();const Je=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||le()},1e3);return()=>{E=!0,window.clearInterval(Je)}},[A,S,Sa]);const ke=o.useMemo(()=>U.join(`
28
+ `),[U]),Ss=o.useCallback(()=>{if(!ke.trim()){B.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}za(ke).then(E=>{E.ok&&B.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ke,t]),Ca=o.useCallback(async()=>{if(A)try{await Xd(A.id),K([]),B.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(E){B.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:E instanceof Error?E.message:String(E)})}},[A,t]),Ci=o.useCallback(async()=>{if(!js?.localUrl){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const E=js.localUrl.trim();if(!E){B.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}_i(E)},[js?.localUrl,t]),Ii=o.useCallback(()=>{if(!A)return;if(!cn&&A.remoteOpenchamber.mode==="external"&&!A.remoteOpenchamber.preferredPort){B.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Et(!0);return}if(!cn&&A.remoteOpenchamber.mode==="managed"&&A.remoteOpenchamber.bindHost==="0.0.0.0"&&!A.auth.openchamberPassword?.value?.trim()){B.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Et(!0),window.setTimeout(()=>ka.current?.focus(),0);return}L(!0),(cn?g(A.id):gn()).catch(le=>{const Je=cn?ba?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";B.error(t(Je),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{L(!1)})},[cn,gn,g,A,ba,t]),Pi=o.useCallback(()=>{if(!A||$n)return;oe(!0),(En?g(A.id).then(()=>gn()):I(A.id)).catch(le=>{B.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{oe(!1)})},[gn,g,A,$n,En,I,t]),Ai=t($n?"settings.remoteInstances.page.actions.connecting":En?va?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ti=!ee&&!Y&&(ln==="error"||ln==="idle"||!ln||En&&va)&&!$n,Nr=t(ba?"settings.remoteInstances.sidebar.actions.disconnect":cn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!A)return s.jsxs(ns,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(qe,{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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{gr()},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[Qs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{xr()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,wt&&Qe.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):Qe.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[ot.map(E=>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:E.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),E.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(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ji(E.id)},children:t("settings.common.actions.cancel")})]},`pending-${E.id}`)),Qe.map(E=>{const le=E.clientKind==="desktop-local",Je=E.lastUsedAt?Date.parse(E.lastUsedAt):Number.NaN,rt=!E.revokedAt&&(le||Number.isFinite(Je)&&Date.now()-Je<9e4),Ft=E.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):rt?E.lastTransport==="relay"&&!le?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Je)?t("settings.remoteInstances.clientAuth.lastUsed",{date:eu(Je,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:Ie("h-2 w-2 shrink-0 rounded-full",E.revokedAt?"bg-muted-foreground/20":rt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:E.label}),Dl(E.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:Dl(E.devicePlatform)}):null,le?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:Ie("typography-micro truncate",rt&&!E.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ft})]})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{fr(E)},disabled:!!E.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},E.id)})]})]}),kt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:kt}):null]}):null,n?s.jsxs(qe,{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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{_e(null),ct(!0)},disabled:me,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_e(null),tt(!0)},disabled:me,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:je?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):ce.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):ce.map(E=>{const le=ie[E.id],Je=le?le.status==="ok"?"desktopHostSwitcher.status.connected":le.status==="auth"?"desktopHostSwitcher.status.authRequired":le.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":le.status==="incompatible"?"desktopHostSwitcher.status.incompatible":le.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",rt=le?.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:Ie("h-2 w-2 shrink-0 rounded-full",le?rt?"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:Za(E.label)}),ae===E.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:Ie("typography-micro shrink-0",rt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Je),rt&&typeof le?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(le.latencyMs))}):""]})]}),s.jsx("p",{className:Ie("typography-micro text-muted-foreground truncate",E.apiUrl&&"font-mono"),children:E.relay&&!E.apiUrl?t("mobile.connect.relay.badge"):Za(E.apiUrl||E.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{pr(E.id)},disabled:me||ae===E.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ae===E.id?s.jsx(z,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"star",className:"h-3.5 w-3.5"})}),E.relay&&!E.apiUrl?null:s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ur(E),disabled:me,children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{dr(E.id)},disabled:me,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},E.id)})}),ze&&!pt&&!Me&&!Ue?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ze}):null]}):null,n?s.jsx(_t,{open:Me,onOpenChange:tt,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:E=>{E.preventDefault(),lr()},children:[s.jsx(We,{className:"h-8",value:Ge,onChange:E=>xe(E.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:me}),s.jsx(We,{className:"h-8",value:Pe,onChange:E=>J(E.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:me,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(We,{className:"h-8",value:se,onChange:E=>he(E.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:me}),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(Cn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ve.map(E=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:E.name,onChange:le=>Fe(Je=>Je.map(rt=>rt.id===E.id?{...rt,name:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:me}),s.jsx(We,{className:"h-8 font-mono text-xs",value:E.value,onChange:le=>Fe(Je=>Je.map(rt=>rt.id===E.id?{...rt,value:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:me}),s.jsx("button",{type:"button",onClick:()=>Fe(le=>le.filter(Je=>Je.id!==E.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:me,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},E.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Fe(E=>[...E,lo()]),disabled:me,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>tt(!1),disabled:me,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:me||!Pe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),ze?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null]})]})}):null,n?s.jsx(_t,{open:!!Ue,onOpenChange:E=>{E||st(null)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:E=>{E.preventDefault(),vi()},children:[s.jsx(We,{className:"h-8",value:ut,onChange:E=>ye(E.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:me}),s.jsx(We,{className:"h-8",value:re,onChange:E=>Te(E.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:me,autoFocus:!0}),s.jsx(We,{className:"h-8",value:Ne,onChange:E=>Ae(E.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:me}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.headers.description")})]}),q.map(E=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:E.name,onChange:le=>Le(Je=>Je.map(rt=>rt.id===E.id?{...rt,name:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:me}),s.jsx(We,{className:"h-8 font-mono text-xs",value:E.value,onChange:le=>Le(Je=>Je.map(rt=>rt.id===E.id?{...rt,value:le.target.value}:rt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:me}),s.jsx("button",{type:"button",onClick:()=>Le(le=>le.filter(Je=>Je.id!==E.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:me,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},E.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Le(E=>[...E,lo()]),disabled:me,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>st(null),disabled:me,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:me,children:t("settings.common.actions.saveChanges")})]}),ze?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null]})]})}):null,n?s.jsx(_t,{open:pt,onOpenChange:E=>{dt||ct(E)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":dt,onSubmit:async E=>{if(E.preventDefault(),!(dt||me)){ht(!0);try{await cr()}catch{_e(t("mobile.connect.error.unreachable"))}finally{ht(!1)}}},children:[s.jsx(We,{className:"h-8",value:Ke,onChange:E=>{Be(E.target.value),_e(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:me||dt,"aria-describedby":ze?"direct-import-error":void 0,autoFocus:!0}),ze?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:ze}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ct(!1),disabled:me||dt,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:me||dt||!Ke.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(_t,{open:nt,onOpenChange:Rt,children:s.jsxs(Ut,{className:Jt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t(Jt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Ht,{children:t(Jt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),Jt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:E=>{E.preventDefault(),hr()},children:[s.jsx(We,{className:"h-8",value:vt,onChange:E=>Xe(E.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:!!es?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!es?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!es?.localUrl}].map(E=>{const le=It===E.key;return s.jsxs("div",{className:Ie("flex items-start gap-2 py-0.5",E.available?"cursor-pointer":"opacity-45"),onClick:()=>{E.available&&Qt(E.key)},role:"presentation",children:[s.jsx(xo,{checked:le,disabled:!E.available,onChange:()=>Qt(E.key),ariaLabel:E.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:Ie("typography-ui-label font-normal",le?"text-foreground":"text-foreground/70"),children:E.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:E.hint})]})]},E.key)})}),It==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(eo,{checked:Xt,onChange:ts,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,It==="relay"&&es?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(eo,{checked:Xt,onChange:ts,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]}),kt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:kt}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Rt(!1),disabled:He,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:He||!es,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Ee?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Ee,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,Ve?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:Ve}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:ki,children:[s.jsx(z,{name:ne?"check":"file-copy",className:Ie("h-3.5 w-3.5",ne&&"text-[var(--status-success)]")}),t(ne?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(qe,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:r.length}),headerAction:s.jsxs(G,{type:"button",size:"xs",className:"!font-normal",onClick:yi,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):r.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")}):r.map(E=>{const le=i[E.id],Je=E.nickname?.trim()||E.sshParsed?.destination||E.id,rt=le?.phase,Ft=rt==="ready",xs=Rl(rt),Xs=xs==="error"?le?.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 ${Ll(rt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Je})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Ol(xs)),xs==="connecting"?` · ${t(Ml(rt))}`:"",Ft&&le?.localUrl?` · ${le.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ft?s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>wr(le?.localUrl),children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Ft?g(E.id):k(E.id)).catch(Us=>B.error(t(Ft?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Us instanceof Error?Us.message:String(Us)}))},children:[Ft?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Ft?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>P(E.id),children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(E.id).catch(Us=>B.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Us instanceof Error?Us.message:String(Us)}))},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),Xs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:Xs}):null]},E.id)})}):null,n?s.jsx(_t,{open:pn,onOpenChange:Ls,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Ht,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(mn,{value:Ks,onChange:on,"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")}]}),Ks==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(We,{className:"h-8",value:Ys,onChange:E=>Zs(E.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Ni.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:Ni.map(E=>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:[E.host,E.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:E.sshCommand})]}),s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{jr(E.host,E.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${E.source}:${E.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:E=>{E.preventDefault(),mr()},children:[s.jsx(We,{className:"h-8",value:Mt,onChange:E=>Gt(E.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:h}),s.jsx(We,{className:"h-8",value:_s,onChange:E=>Tn(E.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:h,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ls(!1),disabled:h,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:h||!_s.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(_t,{open:!!W,onOpenChange:E=>{E||wa()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:E=>{E.preventDefault(),Bn()},children:[s.jsx(We,{value:Q,onChange:E=>H(E.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:wa,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const hn=A.remoteOpenchamber.mode==="managed",Vn=hn&&A.remoteOpenchamber.bindHost==="0.0.0.0",Ia=Vn&&!A.auth.openchamberPassword?.value?.trim(),Sr=A.nickname?.trim()||A.sshParsed?.destination||A.id;return s.jsx(_t,{open:!!A,onOpenChange:E=>{E||P(null)},children:s.jsxs(Ut,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Zr} truncate`,children:Sr}),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 ${Ll(ln)}`}),s.jsx("span",{className:"text-foreground",children:t(Ol(ya))}),ya==="connecting"?s.jsx("span",{children:t(Ml(ln))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,va?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(qe,{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(G,{type:"button",variant:cn?"outline":"default",size:"xs",className:"!font-normal",onClick:Ii,disabled:ee||Y,children:[cn?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),Nr]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Pi,disabled:!Ti,children:[s.jsx(z,{name:"refresh",className:`h-3.5 w-3.5 ${$n||En&&!va?"animate-spin":""}`}),Ai]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kr()},children:[s.jsx(z,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(G,{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"))&&b(A.id).then(()=>{P(null),B.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(le=>{B.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:le instanceof Error?le.message:String(le)})})},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ya==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),Ya?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(Ya)}):null,Yn&&!Ya?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Na(Yn)},children:t(Yn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Yn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:js.localUrl})]}):null]}),s.jsxs(qe,{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(We,{className:"h-7 md:max-w-xl",value:A.sshCommand,onChange:E=>ds(le=>({...le,sshCommand:E.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(We,{className:"h-7 md:max-w-sm",value:A.nickname||"",onChange:E=>ds(le=>({...le,nickname:E.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(tn,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Tt,{value:A.remoteOpenchamber.mode,onValueChange:E=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,mode:E==="external"?"external":"managed"}})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(mt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(kn,{open:Kt,onOpenChange:Et,children:[s.jsxs(Nn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:Ec,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(z,{name:Kt?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Sn,{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(hs,{containerClassName:"w-fit",min:5,max:240,step:1,className:Ie(vs,"tabular-nums"),value:A.connectionTimeoutSec,onValueChange:E=>{ds(le=>({...le,connectionTimeoutSec:Number.isFinite(E)?E:le.connectionTimeoutSec}))}})]}),s.jsxs(qe,{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:Si,children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(hs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:A.remoteOpenchamber.preferredPort,onValueChange:E=>{ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,preferredPort:Number.isFinite(E)&&E>0?E:void 0}}))},onClear:()=>{ds(E=>({...E,remoteOpenchamber:{...E.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),hn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Tt,{value:A.remoteOpenchamber.installMethod,onValueChange:E=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,installMethod:E==="npm"||E==="bun"?E:"auto"}})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(mt,{value:"bun",children:"bun"}),s.jsx(mt,{value:"npm",children:"npm"})]})]})]}):null,hn?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(tn,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(Ba,{checked:Vn,onCheckedChange:E=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,bindHost:E?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),Vn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,hn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(Ba,{checked:A.remoteOpenchamber.keepRunning,onCheckedChange:E=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,keepRunning:E}}))})})]}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Tt,{value:A.localForward.bindHost,onValueChange:E=>{E==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ds(le=>({...le,localForward:{...le.localForward,bindHost:E==="localhost"||E==="0.0.0.0"?E:"127.0.0.1"}}))},children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[240px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(mt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(mt,{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(tn,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(hs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:A.localForward.preferredLocalPort,onValueChange:E=>{ds(le=>({...le,localForward:{...le.localForward,preferredLocalPort:Number.isFinite(E)&&E>0?E:void 0}}))},onClear:()=>{ds(E=>({...E,localForward:{...E.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ds(E=>({...E,localForward:{...E.localForward,preferredLocalPort:Gi()}})),children:s.jsx(z,{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:`${A.localForward.bindHost}:${A.localForward.preferredLocalPort||"auto"} → ${A.sshParsed?.destination||A.nickname||"remote"}:${A.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(qe,{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(tn,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(We,{className:"h-7 md:max-w-sm",type:"password",value:A.auth.sshPassword?.value||"",onChange:E=>ds(le=>({...le,auth:{...le.auth,sshPassword:{enabled:E.target.value.trim().length>0,value:E.target.value,store:le.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(tn,{label:t(Vn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(hn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(We,{className:Ie("h-7 md:max-w-sm",Ia&&"border-[var(--status-error)]"),type:"password",ref:ka,"aria-invalid":Ia,value:A.auth.openchamberPassword?.value||"",onChange:E=>ds(le=>({...le,auth:{...le.auth,openchamberPassword:{enabled:E.target.value.trim().length>0,value:E.target.value,store:le.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),Ia?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[A.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,A.portForwards.map((E,le)=>{const Je=Lt=>{ds(Yt=>({...Yt,portForwards:Yt.portForwards.map((xn,dn)=>dn===le?Lt(xn):xn)}))},rt=E.type==="remote"?"Local target":"Local listen",Ft=E.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.",xs=E.type==="remote"?"Remote listen":"Remote target",Xs=E.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",ms=Kl(E.localHost||"localhost",E.localPort),Us=Kl(E.remoteHost||"localhost",E.remotePort),Dn=E.type==="local"&&typeof E.localPort=="number"&&E.localPort>0,fn=Dn?`http://${sx(E.localHost)}:${E.localPort}`:"",Pa=!!X[E.id],Aa=E.type==="local"?t("settings.remoteInstances.page.forwardType.local"):E.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(kn,{open:Pa,onOpenChange:Lt=>{$(Yt=>({...Yt,[E.id]:Lt}))},className:`${le>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(Nn,{className:"flex items-center gap-2 group",children:[s.jsx(z,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Pa?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Zf(E)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Aa})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ba,{checked:E.enabled,onCheckedChange:Lt=>Je(Yt=>({...Yt,enabled:Lt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(G,{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:()=>ds(Lt=>({...Lt,portForwards:Lt.portForwards.filter(Yt=>Yt.id!==E.id)})),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Sn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(tx(E.type))})]})})}),s.jsxs(Tt,{value:E.type,onValueChange:Lt=>Je(Yt=>({...Yt,type:Lt==="dynamic"||Lt==="remote"?Lt:"local"})),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(zt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(mt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(mt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:rt,hint:Ft})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:E.localHost||"127.0.0.1",onChange:Lt=>Je(Yt=>({...Yt,localHost:Lt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(hs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:E.localPort,onValueChange:Lt=>{Je(Yt=>({...Yt,localPort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{Je(Lt=>({...Lt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),E.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:xs,hint:Xs})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:E.remoteHost||"",onChange:Lt=>Je(Yt=>({...Yt,remoteHost:Lt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(hs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(vs,"tabular-nums"),value:E.remotePort,onValueChange:Lt=>{Je(Yt=>({...Yt,remotePort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{Je(Lt=>({...Lt,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:E.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):E.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Dn?s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(fn).then(Lt=>{Lt||B.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},E.id)}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const E=Xf();ds(le=>({...le,portForwards:[...le.portForwards,E]})),$(le=>({...le,[E.id]:!0}))},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{yr()},disabled:!vr||h,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{za(js.localUrl||"").then(E=>{E.ok&&B.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ci()},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,p?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:p}):null]})}),T,s.jsx(_t,{open:S,onOpenChange:D,children:s.jsxs(Ut,{className:"sm:max-w-2xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ht,{children:A?.nickname?.trim()||A?.sshParsed?.destination||A?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ss,disabled:O||!ke.trim(),children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ca()},disabled:O,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):N?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:N}):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:U.length>0?U.join(`
29
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(_t,{open:!!W,onOpenChange:E=>{E||wa()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:E=>{E.preventDefault(),Bn()},children:[s.jsx(We,{value:Q,onChange:E=>H(E.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:wa,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.common.actions.create")})]})]})]})})]})})},cx="__add_provider__",dx=()=>{const t=Gs.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},ux=({onItemSelect:t})=>{const{t:e}=Ze(),a=Js(),n=it(v=>Dc(v,a)),r=it(v=>v.selectedProviderId),i=it(v=>v.setSelectedProvider),l=rn(v=>v.activeProjectId),[d,c]=o.useState({}),h=o.useMemo(()=>a||dx(),[l,a]),p=it(v=>v.loadProviders);o.useEffect(()=>{a&&p({directory:a,source:"settings:providers"})},[p,a]),o.useEffect(()=>{if(n.length===0){c({});return}let v=!1;return(async()=>{const b=n.map(async k=>{try{const g=h?`?directory=${encodeURIComponent(h)}`:"",I=await Nt(`/api/provider/${encodeURIComponent(k.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const C=await I.json().catch(()=>null),P=C?.sources??C?.data?.sources;if(!P||v)return;c(j=>({...j,[k.id]:P}))}catch{}});await Promise.all(b)})(),()=>{v=!0}},[h,n]);const f="bg-background",m=o.useMemo(()=>n.filter(v=>!!d[v.id]?.project?.exists),[n,d]),u=o.useMemo(()=>n.filter(v=>!d[v.id]?.project?.exists),[n,d]);return s.jsxs("div",{className:Ie("flex h-full flex-col",f),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Pn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(xi,{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(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(cx),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"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:[u.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")}),u.map(v=>s.jsx(Ul,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Ie("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(v=>s.jsx(Ul,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]})]})})]})},Ul=t=>{const e=at.c(17),{provider:a,selectedProviderId:n,onSelect:r}=t,i=Array.isArray(a.models)?a.models.length:0,l=a.id===n,d=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==c?(h=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=h):h=e[1];let p;e[2]!==a.id?(p=s.jsx(na,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=p):p=e[3];const f=a.name||a.id;let m;e[4]!==f?(m=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:f}),e[4]=f,e[5]=m):m=e[5];let u;e[6]!==i?(u=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=u):u=e[7];let v;e[8]!==r||e[9]!==p||e[10]!==m||e[11]!==u?(v=s.jsxs("button",{type:"button",onClick:r,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-ring",tabIndex:0,children:[p,m,u]}),e[8]=r,e[9]=p,e[10]=m,e[11]=u,e[12]=v):v=e[12];let w;return e[13]!==a.id||e[14]!==h||e[15]!==v?(w=s.jsx("div",{className:h,children:v},d),e[13]=a.id,e[14]=h,e[15]=v,e[16]=w):w=e[16],w},mx=t=>t,px=(t,e,a)=>t&&!e&&!a,ta=(t,e)=>t.find(a=>a.id===e),li=t=>t==="opencode-go"?"opencode":t,zl=(t,e)=>{const a=ta(t,e)?.connections,n=li(e);if(n===e)return a;const r=ta(t,n)?.connections;if(!(!a&&!r))return[...a??[],...r??[]]},$l=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),gx=t=>(t?.methods??[]).find(e=>e.type==="key"),Bl=t=>t===void 0||gx(t)!==void 0,hx=t=>(t?.connections??[]).filter(e=>e.type==="credential"),Vl=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,fx=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),xx=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Do={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},ea="__custom_provider__",bx=/^[a-z0-9][a-z0-9-_]*$/,md=/^https?:\/\//,vx=/^\{env:([^}]+)\}$/,er=t=>{if(!t)return;if(typeof t.package=="string"&&t.package)return t.package;const e=t.api?.npm;return typeof e=="string"&&e?`aisdk:${e}`:void 0},pd=t=>t.settings&&typeof t.settings=="object"?t.settings:t.options&&typeof t.options=="object"?t.options:{};let yx=0;const tr=()=>`row-${yx++}`,Mo=()=>({row:tr(),id:"",name:"",variants:""});function jx(t,e){switch(t){case"openai-chat":return{settings:{reasoningEffort:e}};case"openai-responses":return{settings:{reasoningEffort:e,reasoningSummary:"auto",include:["reasoning.encrypted_content"]}};case"anthropic-messages":return{settings:{thinking:{type:"adaptive",display:"summarized"},effort:e}}}}function wx(t){const e=t.split(/[,\s]+/).map(a=>a.trim()).filter(Boolean);return e.filter((a,n)=>e.indexOf(a)===n)}function kx(t){return Object.fromEntries((t??[]).map(({id:e,...a})=>[e,a]))}const Ro=()=>({row:tr(),key:"",value:""}),Nx=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Mo()],headers:[Ro()]}),gd={"@opencode/ai/providers/openai-compatible":"openai-chat","@opencode/ai/providers/openai":"openai-responses","@opencode/ai/providers/anthropic":"anthropic-messages"};function Sx(t){const e=t?gd[t]:void 0;if(e)return e;switch(t){case"aisdk:@ai-sdk/openai":case"@ai-sdk/openai":return"openai-responses";case"aisdk:@ai-sdk/anthropic":case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Cx(t){const e=t.trim();if(!e)return{};const n=e.match(vx)?.[1]?.trim();return n?{env:n}:{key:e}}function Ix(t){const e=pd(t),a=typeof e.baseURL=="string"?e.baseURL.trim():"";if(a&&md.test(a))return!0;const n=new Set([...Object.values(Do),...Object.keys(gd)]);return n.has(er(t)??"")?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>!i||typeof i!="object"?!1:n.has(er(i)??""))}function Hl(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&Ix(t):!1}function ql(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function Gl(t){const e=pd(t),a=typeof e.baseURL=="string"?e.baseURL:"",n=t.headers&&typeof t.headers=="object"?t.headers:e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},r=Object.entries(n).filter(h=>typeof h[0]=="string"&&typeof h[1]=="string").map(([h,p])=>({row:tr(),key:h,value:p})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([h,p])=>{const f=p&&typeof p=="object"?p:{};return{id:h,modelID:typeof f.modelID=="string"?f.modelID:h,name:typeof f.name=="string"?f.name:h,package:typeof f.package=="string"?f.package:void 0,variants:hd.safeParse(f.variants).data}}):[],l=i.length>0?i.map(h=>{const p=typeof h?.modelID=="string"&&h.modelID?h.modelID:typeof h?.id=="string"?h.id:"",f=kx(h?.variants);return{row:tr(),id:p,name:typeof h?.name=="string"?h.name:p,variants:Object.keys(f).join(", "),savedVariants:f}}):[Mo()],d=Array.isArray(t.env)?t.env.find(h=>typeof h=="string"&&h.trim().length>0)?.trim():void 0,c=i.map(h=>er(h)).find(h=>!!h);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:Sx(er(t)??c),baseURL:a,apiKey:d?`{env:${d}}`:"",models:l,headers:r.length>0?r:[Ro()]}}const hd=xa(Ts({id:Dt(),settings:Kn(Dt(),so()).optional(),headers:Kn(Dt(),Dt()).optional(),body:Kn(Dt(),so()).optional()})),Px=Ts({name:Dt().optional(),package:Dt().optional(),env:xa(Dt()).optional(),settings:Kn(Dt(),so()).optional(),headers:Kn(Dt(),Dt()).optional(),models:Kn(Dt(),Ts({modelID:Dt().optional(),name:Dt().optional(),package:Dt().optional(),variants:hd.optional()})).optional()});function Ax(t,e){const a=Array.isArray(t.models)?t.models.map(i=>({...i,variants:void 0})):t.models,n=Gl({...t,models:a});if(!e)return{...n,models:n.models.map(i=>({...i,savedVariants:void 0}))};const r=Gl({...e,id:t.id});return{providerID:t.id,name:e.name?.trim()?r.name:n.name,protocol:e.package?r.protocol:n.protocol,baseURL:r.baseURL||n.baseURL,apiKey:r.apiKey,models:e.models&&Object.keys(e.models).length>0?r.models:n.models.map(i=>({...i,savedVariants:void 0})),headers:r.headers}}function Tx(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:r,key:i}=Cx(t.form.apiKey),l=t.disabledProviders??[],d=t.editingProviderID?.trim(),c=e?bx.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),h=a?void 0:t.t("settings.providers.page.custom.error.name.required"),p=n?md.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),m=!!(r||i||d&&t.allowExistingAuth&&d===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),u=l.includes(e),w=c||!!(d&&d===e)?void 0:t.existingProviderIDs.has(e)&&!u?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(M=>{const S=M.id.trim(),D=S?b.has(S)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(S):t.t("settings.providers.page.custom.error.required"),O=M.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:D,name:O}}),g=k.every(M=>!M.id&&!M.name),I=Object.fromEntries(t.form.models.map(M=>{const S=M.id.trim(),D={modelID:S,name:M.name.trim()},O=wx(M.variants);return(O.length>0||M.savedVariants!==void 0)&&(D.variants=O.map(F=>({id:F,...M.savedVariants?.[F]??jx(t.form.protocol,F)}))),[S,D]})),C=new Set,P=t.form.headers.map(M=>{const S=M.key.trim(),D=M.value.trim();if(!S&&!D)return{};const O=S?C.has(S.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void C.add(S.toLowerCase()):t.t("settings.providers.page.custom.error.required"),F=D?void 0:t.t("settings.providers.page.custom.error.required");return{key:O,value:F}}),j=P.every(M=>!M.key&&!M.value),T=Object.fromEntries(t.form.headers.map(M=>({key:M.key.trim(),value:M.value.trim()})).filter(M=>M.key&&M.value).map(M=>[M.key,M.value])),x={providerID:c??w,name:h,baseURL:p,apiKey:m};return!c&&!w&&!h&&!p&&!m&&g&&j?{err:x,models:k,headers:P,result:{providerID:e,name:a,apiKey:i,config:Ex({protocol:t.form.protocol,name:a,env:r,baseURL:n,headers:T,models:I})}}:{err:x,models:k,headers:P}}function Ex(t){const e={package:Do[t.protocol],name:t.name,settings:{baseURL:t.baseURL},models:t.models};return t.env&&(e.env=[t.env]),Object.keys(t.headers).length>0&&(e.headers=t.headers),e}function Dx(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function Mx(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Wl=t=>{const e=at.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:d,authFailureHint:c,onSubmit:h,onCancel:p,onDisconnect:f}=t;let m;e[0]!==n?(m=n===void 0?[]:n,e[0]=n,e[1]=m):m=e[1];const u=m,v=r===void 0?!1:r,w=i===void 0?"create":i,b=d===void 0?!1:d,k=c===void 0?null:c,{t:g}=Ze(),I=w==="edit";let C;e[2]!==l?(C=()=>l??Nx(),e[2]=l,e[3]=C):C=e[3];const[P,j]=o.useState(C);let T;e[4]===Symbol.for("react.memo_cache_sentinel")?(T={},e[4]=T):T=e[4];const[x,A]=o.useState(T);let M;e[5]===Symbol.for("react.memo_cache_sentinel")?(M=[],e[5]=M):M=e[5];const[S,D]=o.useState(M);let O;e[6]===Symbol.for("react.memo_cache_sentinel")?(O=[],e[6]=O):O=e[6];const[F,N]=o.useState(O),R=o.useRef(null);let U,K;e[7]!==l||e[8]!==I?(U=()=>{l&&(I&&R.current===l.providerID||(R.current=I?l.providerID:null,j(l),A({}),D([]),N([])))},K=[l,I],e[7]=l,e[8]=I,e[9]=U,e[10]=K):(U=e[9],K=e[10]),o.useEffect(U,K);let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=(Mt,Gt)=>{j(Kt=>({...Kt,[Mt]:Gt})),A(Kt=>({...Kt,[Mt]:void 0}))},e[11]=W):W=e[11];const te=W;let Q;e[12]===Symbol.for("react.memo_cache_sentinel")?(Q=(Mt,Gt,Kt)=>{j(Et=>({...Et,models:Et.models.map((is,ss)=>ss===Mt?{...is,[Gt]:Kt}:is)})),D(Et=>{const is=[...Et];return is[Mt]={...is[Mt]??{},[Gt]:void 0},is})},e[12]=Q):Q=e[12];const H=Q;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(Mt,Gt,Kt)=>{j(Et=>({...Et,headers:Et.headers.map((is,ss)=>ss===Mt?{...is,[Gt]:Kt}:is)})),N(Et=>{const is=[...Et];return is[Mt]={...is[Mt]??{},[Gt]:void 0},is})},e[13]=_):_=e[13];const V=_;let X;e[14]!==b||e[15]!==v||e[16]!==u||e[17]!==a||e[18]!==P||e[19]!==I||e[20]!==h||e[21]!==g?(X=async Mt=>{if(Mt.preventDefault(),v)return;const Gt=Tx({form:P,t:((Kt,Et)=>g(Kt,Et)),existingProviderIDs:a,disabledProviders:u,editingProviderID:I?P.providerID:void 0,allowExistingAuth:I&&b});A(Gt.err),D(Gt.models),N(Gt.headers),Gt.result&&await h(Gt.result)},e[14]=b,e[15]=v,e[16]=u,e[17]=a,e[18]=P,e[19]=I,e[20]=h,e[21]=g,e[22]=X):X=e[22];const $=X;let ee;e[23]!==I||e[24]!==g?(ee=g(I?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=I,e[24]=g,e[25]=ee):ee=e[25];let L;e[26]!==g?(L=g("settings.providers.page.custom.description"),e[26]=g,e[27]=L):L=e[27];let Y;e[28]!==L?(Y=s.jsx("p",{className:ys,children:L}),e[28]=L,e[29]=Y):Y=e[29];let oe;e[30]!==k?(oe=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=oe):oe=e[31];let de;e[32]!==g?(de=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=de):de=e[33];let ue;e[34]!==g?(ue=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=ue):ue=e[35];const ce=P.providerID;let Se;e[36]===Symbol.for("react.memo_cache_sentinel")?(Se=Mt=>te("providerID",Mt.target.value),e[36]=Se):Se=e[36];let ie;e[37]!==g?(ie=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=ie):ie=e[38];const be=!I,ae=I||v,pe=!!x.providerID;let je;e[39]!==g?(je=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=je):je=e[40];let De;e[41]!==P.providerID||e[42]!==ie||e[43]!==be||e[44]!==ae||e[45]!==pe||e[46]!==je?(De=s.jsx(We,{value:ce,onChange:Se,placeholder:ie,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:be,disabled:ae,"aria-invalid":pe,"aria-label":je}),e[41]=P.providerID,e[42]=ie,e[43]=be,e[44]=ae,e[45]=pe,e[46]=je,e[47]=De):De=e[47];let me;e[48]!==x.providerID?(me=x.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.providerID}):null,e[48]=x.providerID,e[49]=me):me=e[49];let $e;e[50]!==de||e[51]!==ue||e[52]!==De||e[53]!==me?($e=s.jsxs(Ot,{label:de,info:ue,children:[De,me]}),e[50]=de,e[51]=ue,e[52]=De,e[53]=me,e[54]=$e):$e=e[54];let Ge;e[55]!==g?(Ge=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=Ge):Ge=e[56];let xe;e[57]!==g?(xe=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=xe):xe=e[58];const Pe=P.protocol;let J;e[59]===Symbol.for("react.memo_cache_sentinel")?(J=Mt=>{Mt in Do&&j(Gt=>({...Gt,protocol:Mt,models:Gt.models.map(Rx)}))},e[59]=J):J=e[59];let se;e[60]!==g?(se=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=se):se=e[61];let he;e[62]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx(zt,{}),e[62]=he):he=e[62];let ve;e[63]!==se?(ve=s.jsx(Pt,{"aria-label":se,className:"w-full",children:he}),e[63]=se,e[64]=ve):ve=e[64];let Fe;e[65]!==g?(Fe=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=Fe):Fe=e[66];let Ke;e[67]!==Fe?(Ke=s.jsx(mt,{value:"openai-chat",children:Fe}),e[67]=Fe,e[68]=Ke):Ke=e[68];let Be;e[69]!==g?(Be=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=Be):Be=e[70];let ze;e[71]!==Be?(ze=s.jsx(mt,{value:"openai-responses",children:Be}),e[71]=Be,e[72]=ze):ze=e[72];let _e;e[73]!==g?(_e=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=_e):_e=e[74];let Me;e[75]!==_e?(Me=s.jsx(mt,{value:"anthropic-messages",children:_e}),e[75]=_e,e[76]=Me):Me=e[76];let tt;e[77]!==Ke||e[78]!==ze||e[79]!==Me?(tt=s.jsxs(At,{children:[Ke,ze,Me]}),e[77]=Ke,e[78]=ze,e[79]=Me,e[80]=tt):tt=e[80];let pt;e[81]!==v||e[82]!==P.protocol||e[83]!==ve||e[84]!==tt?(pt=s.jsxs(Tt,{value:Pe,onValueChange:J,disabled:v,children:[ve,tt]}),e[81]=v,e[82]=P.protocol,e[83]=ve,e[84]=tt,e[85]=pt):pt=e[85];let ct;e[86]!==Ge||e[87]!==xe||e[88]!==pt?(ct=s.jsx(Ot,{label:Ge,info:xe,children:pt}),e[86]=Ge,e[87]=xe,e[88]=pt,e[89]=ct):ct=e[89];let dt;e[90]!==g?(dt=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=dt):dt=e[91];let ht;e[92]!==g?(ht=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=ht):ht=e[93];const Ue=P.name;let st;e[94]===Symbol.for("react.memo_cache_sentinel")?(st=Mt=>te("name",Mt.target.value),e[94]=st):st=e[94];let ut;e[95]!==g?(ut=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=ut):ut=e[96];const ye=!!x.name;let re;e[97]!==g?(re=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=re):re=e[98];let Te;e[99]!==P.name||e[100]!==ut||e[101]!==ye||e[102]!==re?(Te=s.jsx(We,{value:Ue,onChange:st,placeholder:ut,className:"h-8 rounded-md px-3","aria-invalid":ye,"aria-label":re}),e[99]=P.name,e[100]=ut,e[101]=ye,e[102]=re,e[103]=Te):Te=e[103];let Ne;e[104]!==x.name?(Ne=x.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.name}):null,e[104]=x.name,e[105]=Ne):Ne=e[105];let Ae;e[106]!==dt||e[107]!==ht||e[108]!==Te||e[109]!==Ne?(Ae=s.jsxs(Ot,{label:dt,info:ht,children:[Te,Ne]}),e[106]=dt,e[107]=ht,e[108]=Te,e[109]=Ne,e[110]=Ae):Ae=e[110];let q;e[111]!==g?(q=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=q):q=e[112];let Le;e[113]!==g?(Le=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=Le):Le=e[114];const Qe=P.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=Mt=>te("baseURL",Mt.target.value),e[115]=lt):lt=e[115];let ot;e[116]!==g?(ot=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=ot):ot=e[117];const bt=!!x.baseURL;let wt;e[118]!==g?(wt=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=wt):wt=e[119];let jt;e[120]!==P.baseURL||e[121]!==ot||e[122]!==bt||e[123]!==wt?(jt=s.jsx(We,{value:Qe,onChange:lt,placeholder:ot,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":bt,"aria-label":wt}),e[120]=P.baseURL,e[121]=ot,e[122]=bt,e[123]=wt,e[124]=jt):jt=e[124];let vt;e[125]!==x.baseURL?(vt=x.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.baseURL}):null,e[125]=x.baseURL,e[126]=vt):vt=e[126];let Xe;e[127]!==q||e[128]!==Le||e[129]!==jt||e[130]!==vt?(Xe=s.jsxs(Ot,{label:q,info:Le,children:[jt,vt]}),e[127]=q,e[128]=Le,e[129]=jt,e[130]=vt,e[131]=Xe):Xe=e[131];let kt;e[132]!==g?(kt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=kt):kt=e[133];let Re;e[134]!==b||e[135]!==I||e[136]!==g?(Re=g(I&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=I,e[136]=g,e[137]=Re):Re=e[137];const Ve=P.apiKey;let Z;e[138]===Symbol.for("react.memo_cache_sentinel")?(Z=Mt=>te("apiKey",Mt.target.value),e[138]=Z):Z=e[138];let ge;e[139]!==b||e[140]!==I||e[141]!==g?(ge=g(I&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=I,e[141]=g,e[142]=ge):ge=e[142];const Oe=!!x.apiKey;let Ee;e[143]!==g?(Ee=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=Ee):Ee=e[144];let Ye;e[145]!==P.apiKey||e[146]!==ge||e[147]!==Oe||e[148]!==Ee?(Ye=s.jsx(We,{type:"password",value:Ve,onChange:Z,placeholder:ge,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Oe,"aria-label":Ee}),e[145]=P.apiKey,e[146]=ge,e[147]=Oe,e[148]=Ee,e[149]=Ye):Ye=e[149];let ne;e[150]!==x.apiKey?(ne=x.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.apiKey}):null,e[150]=x.apiKey,e[151]=ne):ne=e[151];let we;e[152]!==kt||e[153]!==Re||e[154]!==Ye||e[155]!==ne?(we=s.jsxs(Ot,{label:kt,info:Re,children:[Ye,ne]}),e[152]=kt,e[153]=Re,e[154]=Ye,e[155]=ne,e[156]=we):we=e[156];let nt;e[157]!==ee||e[158]!==Y||e[159]!==oe||e[160]!==$e||e[161]!==ct||e[162]!==Ae||e[163]!==Xe||e[164]!==we?(nt=s.jsxs(qe,{title:ee,divider:!1,settingsItem:"providers.custom",contentClassName:Rs,children:[Y,oe,$e,ct,Ae,Xe,we]}),e[157]=ee,e[158]=Y,e[159]=oe,e[160]=$e,e[161]=ct,e[162]=Ae,e[163]=Xe,e[164]=we,e[165]=nt):nt=e[165];let Rt;e[166]!==g?(Rt=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=Rt):Rt=e[167];let Jt;if(e[168]!==P.models||e[169]!==S||e[170]!==g){let Mt;e[172]!==P.models.length||e[173]!==S||e[174]!==g?(Mt=(Gt,Kt)=>s.jsx("div",{className:`${Ps} 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:St,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(We,{value:Gt.id,onChange:Et=>H(Kt,"id",Et.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),S[Kt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Kt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:St,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(We,{value:Gt.name,onChange:Et=>H(Kt,"name",Et.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),S[Kt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Kt]?.name}):null]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:St,children:g("settings.providers.page.custom.models.variantsLabel")}),s.jsx(qt,{children:g("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(We,{value:Gt.variants,onChange:Et=>H(Kt,"variants",Et.target.value),placeholder:g("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.variantsLabel")})]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:P.models.length<=1,onClick:()=>{P.models.length<=1||(j(Et=>({...Et,models:Et.models.filter((is,ss)=>ss!==Kt)})),D(Et=>Et.filter((is,ss)=>ss!==Kt)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Gt.row),e[172]=P.models.length,e[173]=S,e[174]=g,e[175]=Mt):Mt=e[175],Jt=P.models.map(Mt),e[168]=P.models,e[169]=S,e[170]=g,e[171]=Jt}else Jt=e[171];let Ce;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>{j(Ox),D(Fx)},e[176]=Ce):Ce=e[176];let He;e[177]!==g?(He=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=He):He=e[178];let yt;e[179]!==He?(yt=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ce,children:He}),e[179]=He,e[180]=yt):yt=e[180];let It;e[181]!==Rt||e[182]!==Jt||e[183]!==yt?(It=s.jsxs(qe,{title:Rt,contentClassName:Rs,children:[Jt,yt]}),e[181]=Rt,e[182]=Jt,e[183]=yt,e[184]=It):It=e[184];let Qt;e[185]!==g?(Qt=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=Qt):Qt=e[186];let Xt;e[187]!==g?(Xt=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=Xt):Xt=e[188];let ts;e[189]!==Xt?(ts=s.jsx("p",{className:ys,children:Xt}),e[189]=Xt,e[190]=ts):ts=e[190];let es;if(e[191]!==P.headers||e[192]!==F||e[193]!==g){let Mt;e[195]!==P.headers.length||e[196]!==F||e[197]!==g?(Mt=(Gt,Kt)=>s.jsx("div",{className:`${Ps} 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:St,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(We,{value:Gt.key,onChange:Et=>V(Kt,"key",Et.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),F[Kt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:F[Kt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:St,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(We,{value:Gt.value,onChange:Et=>V(Kt,"value",Et.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),F[Kt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:F[Kt]?.value}):null]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:P.headers.length<=1,onClick:()=>{P.headers.length<=1||(j(Et=>({...Et,headers:Et.headers.filter((is,ss)=>ss!==Kt)})),N(Et=>Et.filter((is,ss)=>ss!==Kt)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Gt.row),e[195]=P.headers.length,e[196]=F,e[197]=g,e[198]=Mt):Mt=e[198],es=P.headers.map(Mt),e[191]=P.headers,e[192]=F,e[193]=g,e[194]=es}else es=e[194];let Fs;e[199]===Symbol.for("react.memo_cache_sentinel")?(Fs=()=>{j(Lx),N(Kx)},e[199]=Fs):Fs=e[199];let Qs;e[200]!==g?(Qs=g("settings.providers.page.custom.headers.add"),e[200]=g,e[201]=Qs):Qs=e[201];let pn;e[202]!==Qs?(pn=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Fs,children:Qs}),e[202]=Qs,e[203]=pn):pn=e[203];let Ls;e[204]!==Qt||e[205]!==ts||e[206]!==es||e[207]!==pn?(Ls=s.jsxs(qe,{title:Qt,contentClassName:Rs,children:[ts,es,pn]}),e[204]=Qt,e[205]=ts,e[206]=es,e[207]=pn,e[208]=Ls):Ls=e[208];let Ks;e[209]!==v||e[210]!==p||e[211]!==g?(Ks=p?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:p,disabled:v,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=p,e[211]=g,e[212]=Ks):Ks=e[212];let on;e[213]!==v||e[214]!==f||e[215]!==g?(on=f?s.jsx(G,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{f()},disabled:v,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=f,e[215]=g,e[216]=on):on=e[216];let Ys;e[217]!==v||e[218]!==I||e[219]!==g?(Ys=g(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]=g,e[220]=Ys):Ys=e[220];let Zs;e[221]!==v||e[222]!==Ys?(Zs=s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:Ys}),e[221]=v,e[222]=Ys,e[223]=Zs):Zs=e[223];let _s;e[224]!==Ks||e[225]!==on||e[226]!==Zs?(_s=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Ks,on,Zs]}),e[224]=Ks,e[225]=on,e[226]=Zs,e[227]=_s):_s=e[227];let Tn;return e[228]!==$||e[229]!==nt||e[230]!==It||e[231]!==Ls||e[232]!==_s?(Tn=s.jsxs("form",{onSubmit:$,className:"space-y-0",children:[nt,It,Ls,_s]}),e[228]=$,e[229]=nt,e[230]=It,e[231]=Ls,e[232]=_s,e[233]=Tn):Tn=e[233],Tn};function Rx(t){return t.savedVariants?{...t,savedVariants:{}}:t}function Ox(t){return{...t,models:[...t.models,Mo()]}}function Fx(t){return[...t,{}]}function Lx(t){return{...t,headers:[...t.headers,Ro()]}}function Kx(t){return[...t,{}]}const _x=t=>new Intl.NumberFormat(yo(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Jl=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=_x(t);return e.endsWith(".0")?e.slice(0,-2):e},si="__add_provider__",fd=t=>typeof t=="object"&&t!==null,Ux=t=>{if(typeof t=="string")return{id:t};if(!fd(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}},zx=t=>{let e=[];Array.isArray(t)?e=t:fd(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(r=>Ux(r)).filter(r=>!!r),n=new Set;return a.filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))},$x=Dt(),Ql=t=>$x.safeParse(t?.settings?.apiKey).data??null,Bx=()=>{const{t}=Ze(),e=Js(),a=it(re=>Dc(re,e)),n=it(re=>re.selectedProviderId),r=it(re=>re.setSelectedProvider),i=it(re=>re.getModelMetadata),l=fe(re=>re.hiddenModels),d=fe(re=>re.toggleHiddenModel),c=fe(re=>re.hideAllModels),h=fe(re=>re.showAllModels),[p,f]=o.useState(null),[m,u]=o.useState(!1),[v,w]=o.useState({}),[b,k]=o.useState(null),[g,I]=o.useState(""),[C,P]=o.useState([]),[j,T]=o.useState(!1),[x,A]=o.useState(null),[M,S]=o.useState(""),[D,O]=o.useState(""),[F,N]=o.useState(!1),[R,U]=o.useState({}),[K,W]=o.useState({}),[te,Q]=o.useState(0),[H,_]=o.useState(0),[V,X]=o.useState(!1),[$,ee]=o.useState(null),[L,Y]=o.useState(null),[oe,de]=o.useState(null),[ue,ce]=o.useState(null),[Se,ie]=o.useState(null),[be,ae]=o.useState(null),pe=n===si,je=pe&&M===ea,De=!!(L&&n&&L===n&&!pe);o.useEffect(()=>{!n&&a.length>0&&r(a[0].id)},[a,n,r]),o.useEffect(()=>{if(!n)return;let re=!0;return(async()=>{u(!0);try{const{data:Ne}=await Gs.getSdkClient().integration.list();if(!re)return;f(Ne)}catch(Ne){if(!re)return;console.error("Failed to load provider integrations:",Ne),B.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{re&&u(!1)}})(),()=>{re=!1}},[n,H,t]),o.useEffect(()=>{if(!mx(pe))return;let re=!0;return(async()=>{T(!0),A(null);try{const[{data:Ne},Ae]=await Promise.all([Gs.getSdkClient().integration.list(),su(Gs.getDirectory()??null).catch(()=>null)]);if(!re)return;const q=new Set((Ae??[]).map(Le=>Le.id));P(zx(Ne.filter(Le=>!Le.id.startsWith("mcp_")&&!q.has(Le.id)&&Le.connections.length===0)))}catch(Ne){if(!re)return;console.error("Failed to load available providers:",Ne),A(t("settings.providers.page.state.unableToLoadProviderList"))}finally{re&&T(!1)}})(),()=>{re=!1}},[pe,t]);const me=o.useMemo(()=>new Set(a.map(re=>re.id)),[a]),$e=o.useMemo(()=>C.filter(re=>!me.has(re.id)).sort((re,Te)=>{const Ne=(re.name||re.id).toLowerCase(),Ae=(Te.name||Te.id).toLowerCase();return Ne.localeCompare(Ae)}),[C,me]);o.useEffect(()=>{n===si&&M&&M!==ea&&!$e.some(re=>re.id===M)&&S("")},[n,M,$e]),o.useEffect(()=>{if(n===si){X(!0),ee(null),Y(null),de(null),ce(null),ie(null);return}X(!1),ee(null),L&&L!==n&&(Y(null),de(null),ce(null),ie(null))},[n,L]),o.useEffect(()=>{if(!n||n===si)return;const re=R[n];if(!re||p===null)return;const Te=a.find(q=>q.id===n),Ne=Vl({connections:zl(p,n),optionsApiKey:Ql(Te)}),Ae=!!(Te&&Hl(Te,re));xx({hasCredentials:Ne,userDismissed:$===n,isEditableCustomProvider:Ae})&&X(!0)},[n,R,a,p,$]),o.useEffect(()=>{if(!n||n===si)return;let re=!1;return(async()=>{try{const Ne=e?`?directory=${encodeURIComponent(e)}`:"",Ae=await Nt(`/api/provider/${encodeURIComponent(n)}/source${Ne}`,{method:"GET",headers:{Accept:"application/json"}}),q=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(q?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Le=q?.sources??q?.data?.sources;!re&&Le&&(U(Qe=>({...Qe,[n]:Le})),W(Qe=>({...Qe,[n]:Px.safeParse(q?.config??q?.data?.config).data??null})))}catch(Ne){re||console.error("Failed to load provider sources:",Ne)}})(),()=>{re=!0}},[n,te,e,t]);const Ge=o.useCallback(()=>{Q(re=>re+1)},[]),xe=o.useCallback(()=>{_(re=>re+1)},[]),Pe=o.useCallback(re=>{f(Te=>(Te??[]).map(Ne=>Ne.id===re&&Ne.connections.length===0?{...Ne,connections:[{type:"credential",id:`pending:${re}`,label:re,method:"key"}]}:Ne)),ee(null),X(!1),r(re),Ge(),xe()},[xe,Ge,r]),J=a.find(re=>re.id===n),se=n?R[n]:void 0,he=async re=>{const Te=v[re]?.trim()??"";if(!Te){B.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ne=`api:${re}`;k(Ne);try{await Gs.getSdkClient().integration.connect.key({integrationID:re,key:Te}),B.success(t("settings.providers.page.toast.apiKeySaved")),w(Ae=>({...Ae,[re]:""})),Pe(re)}catch(Ae){console.error("Failed to save API key:",Ae),B.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},ve=async re=>{const Te=`custom:${re.providerID}`;k(Te),ae(re.providerID),ie(null);try{const Ne=Dx(re);Ne&&await Gs.getSdkClient().integration.connect.key(Ne);const Ae=Mx(re,{scope:L?ue??ql(R[L]):"user"}),q=await Nt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ae)}),Le=await q.json().catch(()=>null);if(!q.ok)throw Ne&&ie(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(Le?.error||t("settings.providers.page.toast.customProviderSaveFailed"));B.success(t("settings.providers.page.toast.customProviderSaved",{provider:re.name})),S(""),Y(null),de(null),ce(null),ie(null),ae(null),Pe(re.providerID)}catch(Ne){console.error("Failed to save custom provider:",Ne),B.error(Ne instanceof Error&&Ne.message?Ne.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},Fe=re=>{X(!1),Pe(re)},Ke=async re=>{const Te=`disconnect:${re}`;k(Te);try{const Ne=hx(ta(p??[],re)),Ae=Gs.getSdkClient();for(const q of Ne)await Ae.credential.remove({credentialID:q.id});B.success(t("settings.providers.page.toast.providerDisconnected")),ee(null),Ge(),xe()}catch(Ne){console.error("Failed to disconnect provider:",Ne),B.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},Be=async re=>{re&&(await Ke(re),Y(null),de(null),ce(null),ie(null),ae(null),S(""))};if(!pe&&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(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(pe)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(qe,{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")}),j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):x?s.jsx("p",{className:"typography-meta text-muted-foreground",children:x}):s.jsxs(zn,{open:F,onOpenChange:re=>{N(re),re||O("")},children:[s.jsx(Un,{asChild:!0,children:s.jsxs("button",{type:"button",className:Ws,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[M&&M!==ea?s.jsx(na,{providerId:M,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:Ie("truncate typography-ui-label font-normal",M?"text-foreground":"text-muted-foreground"),children:M===ea?t("settings.providers.page.custom.optionLabel"):M?$e.find(re=>re.id===M)?.name||M:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(_n,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:re=>re.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:re=>re.stopPropagation(),children:[s.jsx(z,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:D,onChange:re=>O(re.target.value),onKeyDown:re=>re.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(bs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const re=t("settings.providers.page.custom.optionLabel"),Te=tu([re,"other","custom"],D),Ne=gi($e,D,Ae=>[Ae.name||Ae.id,Ae.id]);return Ne.length===0&&!Te?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:[Ne.map(Ae=>s.jsxs(wn,{onSelect:()=>{S(Ae.id),N(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(na,{providerId:Ae.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ae.name||Ae.id})]}),M===Ae.id&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ae.id)),Te?s.jsxs(wn,{onSelect:()=>{S(ea),N(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(z,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re})]}),M===ea&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ea):null]})})()})]})]})]})}),je?s.jsx(Wl,{mode:"create",existingProviderIDs:me,busy:b?.startsWith("custom:")??!1,authFailureHint:Se,onCancel:()=>{S(""),ie(null),ae(null)},onDisconnect:Se&&be?()=>{Be(be)}:void 0,onSubmit:ve}):M?s.jsx(qe,{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 re=ta(p??[],M),Te=$l(ta(p??[],li(M))),Ne=Bl(re);return s.jsxs(s.Fragment,{children:[Ne?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(qt,{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(We,{type:"password",value:v[M]??"",onChange:Ae=>w(q=>({...q,[M]:Ae.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>he(M),disabled:b===`api:${M}`,children:b===`api:${M}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Te.length>0?s.jsx(ro,{integrationId:li(M),methods:Te,onConnected:()=>Fe(M),className:Ie(Ne&&"border-t border-[var(--surface-subtle)] pt-2")},M):null]})})()})}):null]});if(!J)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ze=Array.isArray(J.models)?J.models:[],_e=ta(p??[],J.id),Me=$l(ta(p??[],li(J.id))),tt=Bl(_e),pt=p!==null,ct=!!se,dt=ct&&Hl(J,se),ht=Vl({connections:zl(p??[],J.id),optionsApiKey:Ql(J)}),Ue=px(pt,ht,dt),st=fx({modelCount:ze.length,integrationsLoaded:pt,hasCredentials:ht,isEditableCustomProvider:dt}),ut=!tt&&Me.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),ye=gi(ze,g,re=>[typeof re?.name=="string"?re.name:"",typeof re?.id=="string"?re.id:""]);return De&&dt&&oe?s.jsx(ns,{title:J.name||J.id,titleLeading:s.jsx(na,{providerId:J.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:J.id}),showSaveStatus:!1,children:s.jsx(Wl,{mode:"edit",existingProviderIDs:me,initialValues:oe,allowExistingAuth:ht||!ct,busy:b?.startsWith("custom:")??!1,authFailureHint:Se,onCancel:()=>{Y(null),de(null),ce(null),ie(null),ae(null)},onDisconnect:()=>{Be(J.id)},onSubmit:ve})}):s.jsxs(ns,{title:J.name||J.id,titleLeading:s.jsx(na,{providerId:J.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:J.id}),showSaveStatus:!1,children:[s.jsx(qe,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[dt?s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ie(null),de(Ax(J,K[J.id]??null)),ce(ql(se)),Y(J.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const re=!V;X(re),ee(re?null:J.id)},children:t(V?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:V?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:[tt?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(qt,{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(We,{type:"password",value:v[J.id]??"",onChange:re=>w(Te=>({...Te,[J.id]:re.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>he(J.id),disabled:b===`api:${J.id}`,children:b===`api:${J.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Me.length>0&&s.jsx(ro,{integrationId:li(J.id),methods:Me,onConnected:()=>Fe(J.id),className:Ie(tt&&"border-t border-[var(--surface-subtle)] pt-2")},J.id)]}):Ue?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(qt,{children:ut})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(qt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(qe,{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:ht||se?.user.exists||se?.project.exists||se?.custom?.exists?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ht?t("settings.providers.page.connectionDetails.source.authCredentials"):null,se?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,se?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,se?.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(G,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>Ke(J.id),disabled:b===`disconnect:${J.id}`,children:b===`disconnect:${J.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),st?s.jsxs(qe,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",ze.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const re=ze.map(Te=>typeof Te?.id=="string"?Te.id:"").filter(Te=>Te.length>0);c(J.id,re)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>h(J.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(z,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(We,{value:g,onChange:re=>I(re.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ye.map(re=>{const Te=typeof re?.id=="string"?re.id:"",Ne=typeof re?.name=="string"?re.name:Te,Ae=Te?i(J.id,Te):void 0,q=l.some(ot=>ot.providerID===J.id&&ot.modelID===Te),Le=Jl(Ae?.limit?.context),Qe=Jl(Ae?.limit?.output),lt=[];return Ae?.tool_call&&lt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ae?.reasoning&&lt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ae?.attachment&&lt.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:Ie("flex items-center gap-3",q&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ne}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Le||Qe)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Le?`${Le} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Le&&Qe?" · ":"",Qe?`${Qe} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),lt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:lt.map(({key:ot,icon:bt,label:wt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:wt,"aria-label":wt,children:s.jsx(z,{name:bt,className:"h-3 w-3"})},ot))}),s.jsx("button",{type:"button",onClick:()=>d(J.id,Te),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(q?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(q?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:q?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},Te)})})]}):null]})},Vx=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)},Hx=t=>{const e=at.c(75),{onItemSelect:a}=t,{t:n}=Ze(),r=rs(qx),i=rs(Gx),l=rs(Wx),d=rs(Jx),c=rs(Qx),h=rs(Yx),p=rs(Zx),f=rs(Xx);let m,u;e[0]!==f?(m=()=>{f()},u=[f],e[0]=f,e[1]=m,e[2]=u):(m=e[1],u=e[2]),o.useEffect(m,u);const v=eb;let w;e[3]!==p?(w=Y=>{Y!=="usage"&&Y!=="remaining"||(p(Y),v({usageDisplayMode:Y}))},e[3]=p,e[4]=w):w=e[4];const b=w;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=Ie("flex h-full flex-col","bg-background"),e[5]=k):k=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let I;e[8]!==g?(I=s.jsx("h2",{className:`${Pn} mb-3`,children:g}),e[8]=g,e[9]=I):I=e[9];let C;e[10]!==n?(C=n("settings.usage.sidebar.total",{count:Ji.length}),e[10]=n,e[11]=C):C=e[11];let P;e[12]!==C?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[12]=C,e[13]=P):P=e[13];let j;e[14]!==d?(j=()=>d(),e[14]=d,e[15]=j):j=e[15];let T;e[16]!==n?(T=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=T):T=e[17];let x;e[18]!==n?(x=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=x):x=e[19];const A=c&&"animate-spin";let M;e[20]!==A?(M=Ie("h-3.5 w-3.5",A),e[20]=A,e[21]=M):M=e[21];let S;e[22]!==M?(S=s.jsx(z,{name:"refresh",className:M}),e[22]=M,e[23]=S):S=e[23];let D;e[24]!==c||e[25]!==T||e[26]!==x||e[27]!==S||e[28]!==j?(D=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:j,"aria-label":T,title:x,disabled:c,children:S})}),e[24]=c,e[25]=T,e[26]=x,e[27]=S,e[28]=j,e[29]=D):D=e[29];let O;e[30]!==D||e[31]!==P?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,D]}),e[30]=D,e[31]=P,e[32]=O):O=e[32];let F;e[33]!==n?(F=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=F):F=e[34];let N;e[35]!==F?(N=s.jsx("span",{className:"typography-micro text-muted-foreground",children:F}),e[35]=F,e[36]=N):N=e[36];let R;e[37]!==n?(R=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=R):R=e[38];let U;e[39]!==R?(U=s.jsx(Pt,{className:"w-fit",children:s.jsx(zt,{placeholder:R})}),e[39]=R,e[40]=U):U=e[40];let K;e[41]!==n?(K=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=K):K=e[42];let W;e[43]!==K?(W=s.jsx(mt,{value:"usage",children:K}),e[43]=K,e[44]=W):W=e[44];let te;e[45]!==n?(te=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=te):te=e[46];let Q;e[47]!==te?(Q=s.jsx(mt,{value:"remaining",children:te}),e[47]=te,e[48]=Q):Q=e[48];let H;e[49]!==W||e[50]!==Q?(H=s.jsxs(At,{children:[W,Q]}),e[49]=W,e[50]=Q,e[51]=H):H=e[51];let _;e[52]!==b||e[53]!==U||e[54]!==H||e[55]!==h?(_=s.jsxs(Tt,{value:h,onValueChange:b,children:[U,H]}),e[52]=b,e[53]=U,e[54]=H,e[55]=h,e[56]=_):_=e[56];let V;e[57]!==N||e[58]!==_?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[N,_]}),e[57]=N,e[58]=_,e[59]=V):V=e[59];let X;e[60]!==O||e[61]!==V||e[62]!==I?(X=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,O,V]}),e[60]=O,e[61]=V,e[62]=I,e[63]=X):X=e[63];let $;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?($=Ji.map(Y=>{const oe=r.find(be=>be.providerId===Y.id),de=Vx(oe?.usage),ue=Mc(de),ce=Y.id===i,Se=oe?.configured,ie=Se?ue==="critical"?{backgroundColor:"var(--status-error)"}:ue==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ce?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(Y.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-ring",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ie}),s.jsx(na,{providerId:Y.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:Y.name}),Se===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},Y.id)}),e[64]=a,e[65]=r,e[66]=i,e[67]=l,e[68]=n,e[69]=$):$=e[69];let ee;e[70]!==$?(ee=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:$}),e[70]=$,e[71]=ee):ee=e[71];let L;return e[72]!==X||e[73]!==ee?(L=s.jsxs("div",{className:k,children:[X,ee]}),e[72]=X,e[73]=ee,e[74]=L):L=e[74],L};function qx(t){return t.results}function Gx(t){return t.selectedProviderId}function Wx(t){return t.setSelectedProvider}function Jx(t){return t.fetchAllQuotas}function Qx(t){return t.isLoading}function Yx(t){return t.displayMode}function Zx(t){return t.setDisplayMode}function Xx(t){return t.loadSettings}async function eb(t){try{await ft(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const tb=t=>{const e=at.c(17),{percent:a,tonePercent:n,className:r}=t;let i;e[0]!==a?(i=nu(a)??0,e[0]=a,e[1]=i):i=e[1];const l=i,d=n??a;let c;e[2]!==d?(c=Mc(d),e[2]=d,e[3]=c):c=e[3];const h=c;let p;e[4]!==h?(p=h==="critical"?{backgroundColor:"var(--status-error)"}:h==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=h,e[5]=p):p=e[5];const f=p;let m;e[6]!==r?(m=Ie("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=m):m=e[7];const u=`${l}%`;let v;e[8]!==f||e[9]!==u?(v={...f,width:u},e[8]=f,e[9]=u,e[10]=v):v=e[10];let w;e[11]!==l||e[12]!==v?(w=s.jsx("div",{className:"h-full transition-all duration-300",style:v,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=v,e[13]=w):w=e[13];let b;return e[14]!==m||e[15]!==w?(b=s.jsx("div",{className:m,children:w}),e[14]=m,e[15]=w,e[16]=b):b=e[16],b},$r=t=>{const e=at.c(37),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:d}=t,c=i===void 0?!1:i,h=l===void 0?!1:l,p=rs(sb),f=fe(nb),m=p==="remaining"?n.remainingPercent:n.usedPercent,u=m!==null,v=p==="remaining"?"remaining":"used";let w;e[0]!==m||e[1]!==n.valueLabel?(w=au(n.valueLabel,m),e[0]=m,e[1]=n.valueLabel,e[2]=w):w=e[2];const b=w,k=n.resetAfterFormatted??n.resetAtFormatted;let g;e[3]!==k||e[4]!==f||e[5]!==n.resetAt?(g=iu(n.resetAt,k,f),e[3]=k,e[4]=f,e[5]=n.resetAt,e[6]=g):g=e[6];const I=g,C=I?`Resets ${I}`:"";let P;e[7]!==a?(P=ru(a),e[7]=a,e[8]=P):P=e[8];const j=P;let T;e[9]!==d||e[10]!==c||e[11]!==h?(T=c&&s.jsx(eo,{checked:h,onChange:U=>d?.(U),ariaLabel:"Show in dropdown"}),e[9]=d,e[10]=c,e[11]=h,e[12]=T):T=e[12];let x;e[13]!==j?(x=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j}),e[13]=j,e[14]=x):x=e[14];let A;e[15]!==r?(A=r&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[15]=r,e[16]=A):A=e[16];let M;e[17]!==x||e[18]!==A?(M=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[x,A]}),e[17]=x,e[18]=A,e[19]=M):M=e[19];let S;e[20]!==M||e[21]!==T?(S=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[T,M]}),e[20]=M,e[21]=T,e[22]=S):S=e[22];const D=b==="-"?"":b;let O;e[23]!==D?(O=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[23]=D,e[24]=O):O=e[24];let F;e[25]!==S||e[26]!==O?(F=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[S,O]}),e[25]=S,e[26]=O,e[27]=F):F=e[27];let N;e[28]!==v||e[29]!==m||e[30]!==u||e[31]!==C||e[32]!==n.usedPercent?(N=u?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(tb,{percent:m,tonePercent:n.usedPercent,className:"h-1.5"}),s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:C}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]})]}):C?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:C}):null,e[28]=v,e[29]=m,e[30]=u,e[31]=C,e[32]=n.usedPercent,e[33]=N):N=e[33];let R;return e[34]!==F||e[35]!==N?(R=s.jsxs("div",{className:"py-3",children:[F,N]}),e[34]=F,e[35]=N,e[36]=R):R=e[36],R};function sb(t){return t.displayMode}function nb(t){return t.timeFormatPreference}const ab=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,ib=({providerId:t,providerName:e})=>{const{t:a}=Ze(),[n,r]=o.useState(null),[i,l]=o.useState({}),[d,c]=o.useState(!1),h=`/api/quota/credentials/${t}`;o.useEffect(()=>{Nt(h).then(async m=>{if(!m.ok)throw new Error;const u=await m.json();r(u),l({})}).catch(()=>r({configured:!1}))},[h]);const p=async(m,u,v)=>{c(!0);try{const w=await Nt(m,{method:u,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error(b?.error);b?.configured!==void 0&&r(b),l({}),B.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(w){B.error(w instanceof Error&&w.message?w.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},f=(m,u,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[u,s.jsx(We,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[m]??"",onChange:w=>l(b=>({...b,[m]:w.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==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:ab})]}),t==="ollama-cloud"&&f("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&f("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("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(G,{size:"xs",disabled:d,onClick:()=>p(h,"PUT",i),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(G,{variant:"outline",size:"xs",disabled:d,onClick:()=>p(`${h}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(G,{variant:"outline",size:"xs",disabled:d,onClick:()=>p(`${h}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(G,{variant:"destructive",size:"xs",disabled:d,onClick:()=>p(h,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Yl=(t,e)=>{if(!t)return"-";try{return Rc(t,e,{fallback:"-"})}catch{return"-"}},rb=()=>{const{t}=Ze(),e=fe(R=>R.timeFormatPreference),a=rs(R=>R.results),n=rs(R=>R.selectedProviderId),r=rs(R=>R.setSelectedProvider),i=rs(R=>R.loadSettings),l=rs(R=>R.fetchAllQuotas),d=rs(R=>R.isLoading),c=rs(R=>R.lastUpdated),h=rs(R=>R.refreshErrors),p=rs(R=>R.dropdownProviderIds),f=rs(R=>R.setDropdownProviderIds),m=rs(R=>R.selectedModels),u=rs(R=>R.toggleModelSelected),v=rs(R=>R.applyDefaultSelections);ou(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const R=a.find(U=>U.configured)?.providerId;r(R??Ji[0]?.id??null)},[a,n,r]);const w=a.find(R=>R.providerId===n)??null,k=Ji.find(R=>R.id===n)?.name??n??t("settings.usage.sidebar.title"),g=w?.usage,I=n?h[n]:void 0,C=I?g?t("header.services.usageRefreshFailedStale",{error:I}):I:w?.configured&&!w.ok?w.error:null,P=n?p.includes(n):!1,j=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",T=o.useCallback(R=>{if(!n)return;const U=R?Array.from(new Set([...p,n])):p.filter(K=>K!==n);f(U),ft({usageDropdownProviders:U})},[p,n,f]),x=o.useMemo(()=>g?.models?Object.entries(g.models).map(([R,U])=>({name:R,windows:U})).filter(R=>Object.keys(R.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&x.length>0&&v(n,x.map(R=>R.name))},[n,x,v]);const A=o.useMemo(()=>!n||x.length===0?new Map:lu(x,R=>R.name,n),[x,n]),M=o.useMemo(()=>{if(!n)return[];const R=du(n);return cu(R)},[n]),[S,D]=o.useState(()=>({})),O=o.useCallback(R=>{D(U=>({...U,[R]:!U[R]}))},[]),F=o.useCallback(R=>{if(!n)return;u(n,R);const U=m[n]??[],W=U.includes(R)?U.filter(Q=>Q!==R):[...U,R],te={...m,[n]:W};ft({usageSelectedModels:te})},[n,m,u]),N=n?m[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(na,{providerId:n,className:"h-5 w-5 shrink-0"}),description:d?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):w?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:w.planLabel,time:Yl(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Yl(c,e)}),showSaveStatus:!0,children:[s.jsx(qe,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:P,onChange:T,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!w&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),C&&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:C})]}),w&&!w.configured&&!j&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(ib,{providerId:n,providerName:k}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(qe,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([R,U])=>s.jsx($r,{title:R,window:U},R))})}),x.length>0&&s.jsxs(qe,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[M.map(R=>{const U=A.get(R.id)??[];if(U.length===0)return null;const K=S[R.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!K,onOpenChange:()=>O(R.id),children:[s.jsxs(Nn,{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:R.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",U.length,")"]})]}),K?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:U.map(W=>{const te=Object.entries(W.windows.windows);if(te.length===0)return null;const[Q,H]=te[0],_=N.includes(W.name);return s.jsx($r,{title:Q,subtitle:Vo(W.name),window:H,showToggle:!0,toggleEnabled:_,onToggle:()=>F(W.name)},W.name)})})})]})},R.id)}),(()=>{const R=A.get(null)??[];if(R.length===0)return null;const U=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!U,onOpenChange:()=>O("other"),children:[s.jsxs(Nn,{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:["(",R.length,")"]})]}),U?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Sn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:R.map(K=>{const W=Object.entries(K.windows.windows);if(W.length===0)return null;const[te,Q]=W[0],H=N.includes(K.name);return s.jsx($r,{title:te,subtitle:Vo(K.name),window:Q,showToggle:!0,toggleEnabled:H,onToggle:()=>F(K.name)},K.name)})})})]})})})()]}),w?.configured&&g&&Object.keys(g.windows??{}).length===0&&x.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")})})},ob="git.commit.generate",co=Lm(t=>({selectedPromptId:ob,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),lb=t=>{const e=at.c(24),{onItemSelect:a}=t,{t:n}=Ze(),r=co(cb),i=co(db);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 d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={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]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=h):h=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=[l,d,c,h,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=p):p=e[4];const f=p;let m;e[5]!==n?(m=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=m):m=e[6];let u;e[7]!==m?(u=s.jsx("h2",{className:Pn,children:m}),e[7]=m,e[8]=u):u=e[8];let v;e[9]!==n?(v=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=v):v=e[10];let w;e[11]!==v?(w=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:v}),e[11]=v,e[12]=w):w=e[12];let b;e[13]!==u||e[14]!==w?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[u,w]}),e[13]=u,e[14]=w,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==r||e[18]!==i||e[19]!==n?(k=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:f.map(I=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(I.groupKey)}),I.items.map(C=>{const P=r===C.id;return s.jsx("button",{type:"button",onClick:()=>{i(C.id),a?.()},className:Ie("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",P?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(C.titleKey)})},C.id)})]},I.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=k):k=e[20];let g;return e[21]!==b||e[22]!==k?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,k]}),e[21]=b,e[22]=k,e[23]=g):g=e[23],g};function cb(t){return t.selectedPromptId}function db(t){return t.setSelectedPromptId}const Zl={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Xl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Br=t=>t.endsWith(".visible"),ub=()=>{const{t}=Ze(),e=o.useCallback(j=>t(j),[t]),a=co(j=>j.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[d,c]=o.useState({}),[h,p]=o.useState({}),[f,m]=o.useState({}),[u,v]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{r(!0);try{const x=await gu();if(!j)return;l(x)}catch(x){console.warn("Failed to load magic prompts:",x),B.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&r(!1)}})(),()=>{j=!1}},[t]);const w=Zl[a]??Zl["git.commit.generate"],b=o.useCallback(j=>Xl(i,j)?i[j]:Pr(j),[i]),k=o.useCallback(j=>d[j]??b(j),[d,b]),g=o.useCallback((j,T)=>{c(x=>x[j]===T?x:{...x,[j]:T})},[]),I=o.useCallback(async j=>{const T=k(j);if(Br(j)&&T.trim().length===0){B.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}p(x=>({...x,[j]:!0}));try{const x=T===Pr(j)?await Ho(j):await uu(j,T);l(x.overrides),B.success(t("settings.magicPrompts.page.toast.saved"))}catch(x){const A=x instanceof Error?x.message:String(x);B.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:A})}finally{p(x=>({...x,[j]:!1}))}},[k,t]),C=o.useCallback(async j=>{m(T=>({...T,[j]:!0}));try{const T=await Ho(j);l(T.overrides),c(x=>({...x,[j]:Pr(j)})),B.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(T){const x=T instanceof Error?T.message:String(T);B.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:x})}finally{m(T=>({...T,[j]:!1}))}},[t]),P=o.useCallback(async()=>{v(!0);try{const j=await mu();l(j.overrides),c({}),B.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const T=j instanceof Error?j.message:String(j);B.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:T})}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(ns,{title:e(w.titleKey),titleAccessory:s.jsx(qt,{contentClassName:"max-w-xs",children:e(w.descriptionKey)}),headerEnd:s.jsx(G,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{P()},disabled:u||Object.keys(i).length===0,children:t(u?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:w.blocks.map((j,T)=>{const x=pu(j.id),A=b(j.id),M=k(j.id),S=Xl(i,j.id),D=M!==A,O=Br(j.id)&&M.trim().length===0,F=h[j.id]===!0,N=f[j.id]===!0;return s.jsxs(qe,{title:e(j.titleKey),info:x.description,description:x.placeholders&&x.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${x.placeholders.map(R=>`{{${R.key}}}`).join(", ")}`:void 0,divider:T>0,settingsItem:Br(j.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:M,onChange:R=>g(j.id,R.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(D?"settings.magicPrompts.page.status.unsavedChanges":S?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"outline",size:"sm",onClick:()=>{C(j.id)},disabled:!S||F||N,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(G,{size:"sm",onClick:()=>{I(j.id)},disabled:!D||F||N||O,children:t(F?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})})},mb=t=>{const e=at.c(89),{onItemSelect:a}=t,{t:n}=Ze(),[r,i]=o.useState(null),[l,d]=o.useState(null),[c,h]=o.useState(null),{selectedSnippetName:p,snippets:f,setSelectedSnippet:m,setSnippetDraft:u,deleteSnippet:v,loadSnippets:w}=Qi($s(pb));let b,k;e[0]!==w?(b=()=>{w()},k=[w],e[0]=w,e[1]=b,e[2]=k):(b=e[1],k=e[2]),o.useEffect(b,k);let g;e[3]!==a||e[4]!==m||e[5]!==u||e[6]!==f?(g=async()=>{const ae=new Set(f.map(gb));let pe="new-snippet",je=1;for(;ae.has(pe);)pe=`new-snippet-${je++}`;u({name:pe,scope:"global"}),m(pe),a?.()},e[3]=a,e[4]=m,e[5]=u,e[6]=f,e[7]=g):g=e[7];const I=g;let C;e[8]!==r||e[9]!==v||e[10]!==n?(C=async()=>{if(!r)return;await v(r.name)?(B.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):B.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=v,e[10]=n,e[11]=C):C=e[11];const P=C;let j;e[12]!==f?(j=[...f].sort(hb),e[12]=f,e[13]=j):j=e[13];const T=j;let x;e[14]===Symbol.for("react.memo_cache_sentinel")?(x=Ie("flex h-full flex-col","bg-background"),e[14]=x):x=e[14];let A;e[15]!==n?(A=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=A):A=e[16];let M;e[17]!==A?(M=s.jsx("h2",{className:`${Pn} mb-3`,children:A}),e[17]=A,e[18]=M):M=e[18];let S;e[19]!==f.length||e[20]!==n?(S=n("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=n,e[21]=S):S=e[21];let D;e[22]!==S?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:S}),e[22]=S,e[23]=D):D=e[23];let O;e[24]!==n?(O=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=O):O=e[25];let F;e[26]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[26]=F):F=e[26];let N;e[27]!==I||e[28]!==O?(N=s.jsx(G,{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:F}),e[27]=I,e[28]=O,e[29]=N):N=e[29];let R;e[30]!==D||e[31]!==N?(R=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,N]}),e[30]=D,e[31]=N,e[32]=R):R=e[32];let U;e[33]!==R||e[34]!==M?(U=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[M,R]}),e[33]=R,e[34]=M,e[35]=U):U=e[35];let K;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==p||e[40]!==m||e[41]!==T||e[42]!==n){let ae;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==p||e[48]!==m||e[49]!==n?(ae=pe=>s.jsxs(ha,{open:c===pe.name,onOpenChange:je=>h(je?pe.name:null),children:[s.jsxs(ga,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",p===pe.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je=>{je.preventDefault(),h(pe.name)}}),children:[s.jsxs("button",{onClick:()=>{m(pe.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-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",pe.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.${pe.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:pe.description||pe.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(zn,{open:l===pe.name,onOpenChange:je=>{je&&h(null),d(je?pe.name:null)},children:[s.jsx(Un,{asChild:!0,children:s.jsx(G,{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:pe.name}),children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(_n,{align:"end",className:"w-fit min-w-20",children:s.jsxs(wn,{onClick:je=>{je.stopPropagation(),i(pe)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(ma,{className:"w-fit min-w-20",children:s.jsxs(pa,{onClick:je=>{je.stopPropagation(),i(pe)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${pe.source}:${pe.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=p,e[48]=m,e[49]=n,e[50]=ae):ae=e[50],K=T.map(ae),e[36]=a,e[37]=l,e[38]=c,e[39]=p,e[40]=m,e[41]=T,e[42]=n,e[43]=K}else K=e[43];let W;e[51]!==K?(W=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:K}),e[51]=K,e[52]=W):W=e[52];const te=r!==null;let Q;e[53]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>{ae||i(null)},e[53]=Q):Q=e[53];let H;e[54]!==n?(H=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=H):H=e[55];let _;e[56]!==H?(_=s.jsx(Vt,{children:H}),e[56]=H,e[57]=_):_=e[57];const V=r?.name??"";let X;e[58]!==n||e[59]!==V?(X=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=X):X=e[60];let $;e[61]!==X?($=s.jsx(Ht,{children:X}),e[61]=X,e[62]=$):$=e[62];let ee;e[63]!==_||e[64]!==$?(ee=s.jsxs(Bt,{children:[_,$]}),e[63]=_,e[64]=$,e[65]=ee):ee=e[65];let L;e[66]===Symbol.for("react.memo_cache_sentinel")?(L=()=>i(null),e[66]=L):L=e[66];let Y;e[67]!==n?(Y=n("settings.common.actions.cancel"),e[67]=n,e[68]=Y):Y=e[68];let oe;e[69]!==Y?(oe=s.jsx(G,{size:"sm",variant:"ghost",onClick:L,children:Y}),e[69]=Y,e[70]=oe):oe=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let ue;e[73]!==P||e[74]!==de?(ue=s.jsx(G,{size:"sm",onClick:P,children:de}),e[73]=P,e[74]=de,e[75]=ue):ue=e[75];let ce;e[76]!==oe||e[77]!==ue?(ce=s.jsxs(as,{children:[oe,ue]}),e[76]=oe,e[77]=ue,e[78]=ce):ce=e[78];let Se;e[79]!==ee||e[80]!==ce?(Se=s.jsxs(Ut,{className:"max-w-md",children:[ee,ce]}),e[79]=ee,e[80]=ce,e[81]=Se):Se=e[81];let ie;e[82]!==te||e[83]!==Se?(ie=s.jsx(_t,{open:te,onOpenChange:Q,children:Se}),e[82]=te,e[83]=Se,e[84]=ie):ie=e[84];let be;return e[85]!==U||e[86]!==W||e[87]!==ie?(be=s.jsxs("div",{className:x,children:[U,W,ie]}),e[85]=U,e[86]=W,e[87]=ie,e[88]=be):be=e[88],be};function pb(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function gb(t){return t.name}function hb(t,e){return t.name.localeCompare(e.name)}const fb=()=>{const{t}=Ze(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=Qi($s(x=>({selectedSnippetName:x.selectedSnippetName,snippets:x.snippets,snippetDraft:x.snippetDraft,setSnippetDraft:x.setSnippetDraft,updateSnippet:x.updateSnippet,createSnippet:x.createSnippet}))),d=o.useMemo(()=>e?a.find(x=>x.name===e||x.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!d),[h,p]=o.useState(""),[f,m]=o.useState("global"),[u,v]=o.useState(""),[w,b]=o.useState(""),[k,g]=o.useState(""),[I,C]=o.useState(!1),P=o.useRef(null);o.useEffect(()=>{if(c&&n){const x={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};p(x.draftName),m(x.draftScope),v(x.description),b(x.aliases),g(x.content),P.current=x}else if(d){const x={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};v(x.description),b(x.aliases),g(x.content),P.current=x}},[d,c,e,n]);const j=o.useMemo(()=>{const x=P.current;return x?c&&h!==x.draftName||c&&f!==x.draftScope?!0:u!==x.description||w!==x.aliases||k!==x.content:!1},[w,k,u,h,f,c]),T=async()=>{const x=c?h.trim().replace(/\s+/g,"-"):e?.trim();if(!x){B.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){B.error(t("settings.snippets.page.toast.contentRequired"));return}const A=w.split(",").map(M=>M.trim()).filter(Boolean);C(!0);try{if(!(c?await l(x,k,{aliases:A,description:u,scope:f}):await i(x,{content:k,aliases:A,description:u}))){B.error(t("settings.snippets.page.toast.saveFailed"));return}B.success(t("settings.snippets.page.toast.saved")),c&&r(null)}finally{C(!1)}};return e?s.jsxs(ns,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:d?d.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(qe,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Ct,{label:"#",children:[s.jsx(We,{value:h,onChange:x=>p(x.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Tt,{value:f,onValueChange:x=>m(x),children:[s.jsx(Pt,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(zt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(mt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(mt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Ot,{label:t("settings.common.field.description"),children:s.jsx(We,{value:u,onChange:x=>v(x.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Ot,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(We,{value:w,onChange:x=>b(x.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(qe,{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(qt,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:k,onChange:x=>g(x.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(G,{onClick:T,disabled:I||!j,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(z,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},xd=()=>{const{t}=Ze(),e=it(f=>f.settingsGitmojiEnabled),a=it(f=>f.setSettingsGitmojiEnabled),n=rm(),r=fe(f=>f.gitChangesViewMode),i=fe(f=>f.setGitChangesViewMode),[l,d]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const m=await An();m&&(m.gitmojiEnabled!==void 0&&a(m.gitmojiEnabled),m.gitChangesViewMode!==void 0&&i(m.gitChangesViewMode))}catch(m){console.warn("Failed to load git settings:",m)}finally{d(!1)}})()},[i,a]);const h=o.useCallback(async f=>{a(f);try{await ft({gitmojiEnabled:f})}catch(m){console.warn("Failed to save gitmoji setting:",m)}},[a]),p=o.useCallback(f=>{f!==r&&(i(f),ft({gitChangesViewMode:f}))},[r,i]);return l?null:s.jsx(qe,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:cs,children:[s.jsx(ws,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(sn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(f=>s.jsx(ks,{selected:r===f.id,onSelect:()=>{p(f.id)},label:f.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:f.label})},f.id))})}),s.jsx(gt,{settingsItem:"git.gitmoji",checked:e,onChange:f=>{h(f)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(gt,{settingsItem:"git.gitignored-files",checked:n,onChange:om,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},ec=[{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)"}],xb=[{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"}],bb=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:r}=Ze(),i=oa($=>$.getProfileById),l=oa($=>$.createProfile),d=oa($=>$.updateProfile),c=oa($=>$.deleteProfile),h=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),p=a==="new"||n!=null,f=a==="global",[m,u]=o.useState(""),[v,w]=o.useState(""),[b,k]=o.useState(""),[g,I]=o.useState("ssh"),[C,P]=o.useState(""),[j,T]=o.useState(!1),[x,A]=o.useState(""),[M,S]=o.useState(""),[D,O]=o.useState("keyword"),[F,N]=o.useState("branch"),[R,U]=o.useState(!1),[K,W]=o.useState(!1),[te,Q]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const $=n.host.split("/"),ee=$.length>=3?$[$.length-1]:n.host;u(ee),w(n.username),k(""),I("token"),P(""),T(!1),A(""),S(n.host),O("string"),N("code")}else if(p)u(""),w(""),k(""),I("ssh"),P(""),T(!1),A(""),S(""),O("keyword"),N("branch");else if(h)u(h.name),w(h.userName),k(h.userEmail),I(h.authType||"ssh"),P(h.sshKey||""),T(h.signCommits===!0),A(h.signingKey||""),S(h.host||""),O(h.color||"keyword"),N(h.icon||"branch");else if(f){const $=i("global");$&&(u($.name),w($.userName),k($.userEmail),I($.authType||"ssh"),P($.sshKey||""),T(!1),A(""),S($.host||""),O($.color||"keyword"),N($.icon||"branch"))}}},[t,a,h,p,n,f,i]);const H=async()=>{if(!v.trim()||!b.trim()){B.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!M.trim()){B.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!x.trim()){B.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}U(!0);try{const $={name:m.trim()||v.trim(),userName:v.trim(),userEmail:b.trim(),authType:g,sshKey:g==="ssh"&&C.trim()||null,signCommits:j,signingKey:x.trim()||null,host:g==="token"&&M.trim()||null,color:D,icon:F};let ee;if(p)ee=await l($);else if(a)ee=await d(a,$);else return;ee?(B.success(r(p?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):B.error(r(p?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch($){console.error("Error saving profile:",$),B.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{U(!1)}},_=async()=>{if(!(!a||p)){Q(!0);try{await c(a)?(B.success(r("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):B.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch($){console.error("Error deleting profile:",$),B.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{Q(!1)}}},V=o.useMemo(()=>ec.find(ee=>ee.key===D)?.cssVar||"var(--syntax-keyword)",[D]),X=n?r("settings.gitIdentities.editor.title.importCredential"):p?r("settings.gitIdentities.editor.title.newIdentity"):f?r("settings.gitIdentities.editor.title.globalIdentity"):h?.name||r("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:X}),s.jsx(Ht,{children:r(f?"settings.gitIdentities.editor.description.globalReadOnly":p?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!f&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${St} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(We,{value:m,onChange:$=>u($.target.value),placeholder:r("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:r("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:ec.map($=>s.jsx("button",{type:"button",onClick:()=>O($.key),className:Ie("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===$.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:$.cssVar},title:$.label},$.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:xb.map($=>{const ee=$.Icon;return s.jsx("button",{type:"button",onClick:()=>N($.key),className:Ie("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",F===$.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:$.label,children:s.jsx(z,{name:ee,className:"w-3.5 h-3.5",style:{color:F===$.key?V:"var(--surface-muted-foreground)"}})},$.key)})})]})]}),!f&&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:St,children:r("settings.gitIdentities.editor.field.userName")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(We,{value:v,onChange:$=>w($.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!f,readOnly:f,disabled:f,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:St,children:r("settings.gitIdentities.editor.field.emailAddress")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(We,{type:"email",value:b,onChange:$=>k($.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!f,readOnly:f,disabled:f,className:"h-8"})]})]}),!f&&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:r("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="ssh",onClick:()=>I("ssh"),children:[s.jsx(z,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>I("token"),children:[s.jsx(z,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:St,children:r("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(We,{value:C,onChange:$=>P($.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(gt,{checked:j,onChange:T,label:r("settings.gitIdentities.editor.field.signCommits"),info:r("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:r("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:St,children:r("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(We,{value:x,onChange:$=>A($.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:St,children:r("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(qt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(We,{value:M,onChange:$=>S($.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(as,{className:"gap-2",children:[!f&&!p&&s.jsxs(G,{variant:"outline",size:"sm",onClick:()=>W(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(z,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),s.jsx(G,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(f?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!f&&s.jsx(G,{size:"sm",onClick:H,disabled:R,children:r(R?"settings.common.actions.saving":p?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(_t,{open:K,onOpenChange:$=>{te||W($)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:r("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ht,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:h?.name||m})})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"ghost",onClick:()=>W(!1),disabled:te,children:r("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:te,children:r("settings.common.actions.delete")})]})]})})]})},vb={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},yb={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},jb=()=>{const t=at.c(112),{t:e}=Ze(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:h,setDefaultGitIdentityId:p,getUnimportedCredentials:f}=oa($s(kb)),[m,u]=o.useState(!1),[v,w]=o.useState(null),[b,k]=o.useState(null),[g,I]=o.useState(null),[C,P]=o.useState(!1);let j,T;t[0]!==h||t[1]!==c||t[2]!==d||t[3]!==l?(j=()=>{l(),d(),c(),h()},T=[l,d,c,h],t[0]=h,t[1]=c,t[2]=d,t[3]=l,t[4]=j,t[5]=T):(j=t[4],T=t[5]),o.useEffect(j,T);let x,A,M,S,D,O,F,N,R,U,K,W,te,Q;if(t[6]!==r||t[7]!==g||t[8]!==i||t[9]!==f||t[10]!==n||t[11]!==a||t[12]!==p||t[13]!==e){const Pe=f();let J;t[28]===Symbol.for("react.memo_cache_sentinel")?(J=(_e,Me)=>{w(_e),k(Me??null),u(!0)},t[28]=J):J=t[28];const se=J;let he;t[29]!==r||t[30]!==p||t[31]!==e?(he=async _e=>{const Me=r===_e?null:_e;if(!await p(Me)){B.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}B.success(e(Me?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=p,t[31]=e,t[32]=he):he=t[32];const ve=he;let Fe;t[33]!==g||t[34]!==i||t[35]!==e?(Fe=async()=>{if(!g)return;P(!0),await i(g.id)?(B.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),I(null)):B.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),P(!1)},t[33]=g,t[34]=i,t[35]=e,t[36]=Fe):Fe=t[36],M=Fe,A=ns,t[37]!==e?(D=e("settings.page.git.title"),t[37]=e,t[38]=D):D=t[38],O=!0,x=qe,t[39]!==e?(W=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=W):W=t[40],te=!1;let Ke,Be;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>se("new"),Be=s.jsx(z,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ke,t[42]=Be):(Ke=t[41],Be=t[42]);let ze;t[43]!==e?(ze=e("settings.common.badge.new"),t[43]=e,t[44]=ze):ze=t[44],t[45]!==ze?(Q=s.jsxs(G,{size:"sm",variant:"outline",onClick:Ke,children:[Be," ",ze]}),t[45]=ze,t[46]=Q):Q=t[46],S="git.identities",F="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",N=n&&s.jsx(tc,{profile:n,isDefault:r==="global",onEdit:()=>se("global"),onToggleDefault:()=>ve("global"),isReadOnly:!0,hasBorder:a.length>0||Pe.length>0}),R=a.map((_e,Me)=>s.jsx(tc,{profile:_e,isDefault:r===_e.id,onEdit:()=>se(_e.id),onToggleDefault:()=>ve(_e.id),onDelete:()=>I(_e),hasBorder:Me<a.length-1||Pe.length>0},_e.id)),U=!n&&a.length===0&&Pe.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),K=Pe.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")})}),Pe.map((_e,Me)=>s.jsx(wb,{credential:_e,onImport:()=>se("new",{host:_e.host,username:_e.username}),hasBorder:Me<Pe.length-1},`${_e.host}-${_e.username}`))]}),t[6]=r,t[7]=g,t[8]=i,t[9]=f,t[10]=n,t[11]=a,t[12]=p,t[13]=e,t[14]=x,t[15]=A,t[16]=M,t[17]=S,t[18]=D,t[19]=O,t[20]=F,t[21]=N,t[22]=R,t[23]=U,t[24]=K,t[25]=W,t[26]=te,t[27]=Q}else x=t[14],A=t[15],M=t[16],S=t[17],D=t[18],O=t[19],F=t[20],N=t[21],R=t[22],U=t[23],K=t[24],W=t[25],te=t[26],Q=t[27];let H;t[47]!==F||t[48]!==N||t[49]!==R||t[50]!==U||t[51]!==K?(H=s.jsxs("div",{className:F,children:[N,R,U,K]}),t[47]=F,t[48]=N,t[49]=R,t[50]=U,t[51]=K,t[52]=H):H=t[52];let _;t[53]!==x||t[54]!==S||t[55]!==H||t[56]!==W||t[57]!==te||t[58]!==Q?(_=s.jsx(x,{title:W,divider:te,headerAction:Q,settingsItem:S,children:H}),t[53]=x,t[54]=S,t[55]=H,t[56]=W,t[57]=te,t[58]=Q,t[59]=_):_=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(xd,{}),t[60]=V):V=t[60];let X;t[61]!==A||t[62]!==D||t[63]!==O||t[64]!==_?(X=s.jsxs(A,{title:D,showSaveStatus:O,children:[_,V]}),t[61]=A,t[62]=D,t[63]=O,t[64]=_,t[65]=X):X=t[65];let $;t[66]!==b||t[67]!==m||t[68]!==v?($=s.jsx(bb,{open:m,onOpenChange:u,profileId:v,importData:b}),t[66]=b,t[67]=m,t[68]=v,t[69]=$):$=t[69];const ee=g!==null;let L;t[70]!==C?(L=Pe=>{C||Pe||I(null)},t[70]=C,t[71]=L):L=t[71];let Y;t[72]!==e?(Y=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=Y):Y=t[73];let oe;t[74]!==Y?(oe=s.jsx(Vt,{children:Y}),t[74]=Y,t[75]=oe):oe=t[75];const de=g?.name??"";let ue;t[76]!==e||t[77]!==de?(ue=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=ue):ue=t[78];let ce;t[79]!==ue?(ce=s.jsx(Ht,{children:ue}),t[79]=ue,t[80]=ce):ce=t[80];let Se;t[81]!==oe||t[82]!==ce?(Se=s.jsxs(Bt,{children:[oe,ce]}),t[81]=oe,t[82]=ce,t[83]=Se):Se=t[83];let ie;t[84]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>I(null),t[84]=ie):ie=t[84];let be;t[85]!==e?(be=e("settings.common.actions.cancel"),t[85]=e,t[86]=be):be=t[86];let ae;t[87]!==C||t[88]!==be?(ae=s.jsx(G,{variant:"ghost",onClick:ie,disabled:C,children:be}),t[87]=C,t[88]=be,t[89]=ae):ae=t[89];let pe;t[90]!==M?(pe=()=>{M()},t[90]=M,t[91]=pe):pe=t[91];let je;t[92]!==e?(je=e("settings.common.actions.delete"),t[92]=e,t[93]=je):je=t[93];let De;t[94]!==C||t[95]!==pe||t[96]!==je?(De=s.jsx(G,{size:"sm",variant:"destructive",onClick:pe,disabled:C,children:je}),t[94]=C,t[95]=pe,t[96]=je,t[97]=De):De=t[97];let me;t[98]!==ae||t[99]!==De?(me=s.jsxs(as,{children:[ae,De]}),t[98]=ae,t[99]=De,t[100]=me):me=t[100];let $e;t[101]!==Se||t[102]!==me?($e=s.jsxs(Ut,{className:"max-w-md",children:[Se,me]}),t[101]=Se,t[102]=me,t[103]=$e):$e=t[103];let Ge;t[104]!==ee||t[105]!==L||t[106]!==$e?(Ge=s.jsx(_t,{open:ee,onOpenChange:L,children:$e}),t[104]=ee,t[105]=L,t[106]=$e,t[107]=Ge):Ge=t[107];let xe;return t[108]!==X||t[109]!==$||t[110]!==Ge?(xe=s.jsxs(s.Fragment,{children:[X,$,Ge]}),t[108]=X,t[109]=$,t[110]=Ge,t[111]=xe):xe=t[111],xe},tc=t=>{const e=at.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:d,hasBorder:c}=t,{t:h}=Ze(),[p,f]=o.useState(!1),m=vb[a.icon||"branch"]||"git-branch",u=yb[a.color||""],v=a.authType||"ssh";let w;e[0]!==r?(w=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),r()))},e[0]=r,e[1]=w):w=e[1];const b=w;let k;e[2]!==n||e[3]!==d||e[4]!==l||e[5]!==i||e[6]!==h?(k=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:V=>{V.stopPropagation(),i()},children:h(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&l&&s.jsxs(_,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[2]=n,e[3]=d,e[4]=l,e[5]=i,e[6]=h,e[7]=k):k=e[7];const g=k,I=c&&"border-b border-[var(--surface-subtle)]";let C;e[8]!==I?(C=Ie("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]=C):C=e[9];let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=_=>{_.preventDefault(),f(!0)},e[10]=P):P=e[10];let j;e[11]!==b||e[12]!==r||e[13]!==C?(j=s.jsx("div",{className:C,onClick:r,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:P}),e[11]=b,e[12]=r,e[13]=C,e[14]=j):j=e[14];let T;e[15]!==u?(T={color:u},e[15]=u,e[16]=T):T=e[16];let x;e[17]!==m||e[18]!==T?(x=s.jsx(z,{name:m,className:"w-4 h-4 shrink-0",style:T}),e[17]=m,e[18]=T,e[19]=x):x=e[19];let A;e[20]!==a.name?(A=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=A):A=e[21];let M;e[22]!==v?(M=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:v}),e[22]=v,e[23]=M):M=e[23];let S;e[24]!==n||e[25]!==h?(S=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:h("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=h,e[26]=S):S=e[26];let D;e[27]!==d||e[28]!==h?(D=d&&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:h("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=h,e[29]=D):D=e[29];let O;e[30]!==M||e[31]!==S||e[32]!==D||e[33]!==A?(O=s.jsxs("div",{className:"flex items-center gap-1.5",children:[A,M,S,D]}),e[30]=M,e[31]=S,e[32]=D,e[33]=A,e[34]=O):O=e[34];const F=v==="token"&&a.host?a.host:a.userEmail;let N;e[35]!==F?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:F}),e[35]=F,e[36]=N):N=e[36];let R;e[37]!==O||e[38]!==N?(R=s.jsxs("div",{className:"min-w-0",children:[O,N]}),e[37]=O,e[38]=N,e[39]=R):R=e[39];let U;e[40]!==R||e[41]!==x?(U=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[x,R]}),e[40]=R,e[41]=x,e[42]=U):U=e[42];let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Un,{asChild:!0,children:s.jsx(G,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Nb,children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=K):K=e[43];let W;e[44]!==g?(W=s.jsxs(zn,{children:[K,s.jsx(_n,{align:"end",className:"w-fit min-w-28",children:g(wn)})]}),e[44]=g,e[45]=W):W=e[45];let te;e[46]!==U||e[47]!==W||e[48]!==j?(te=s.jsxs(ga,{render:j,children:[U,W]}),e[46]=U,e[47]=W,e[48]=j,e[49]=te):te=e[49];let Q;e[50]!==g?(Q=s.jsx(ma,{className:"w-fit min-w-28",children:g(pa)}),e[50]=g,e[51]=Q):Q=e[51];let H;return e[52]!==p||e[53]!==te||e[54]!==Q?(H=s.jsxs(ha,{open:p,onOpenChange:f,children:[te,Q]}),e[52]=p,e[53]=te,e[54]=Q,e[55]=H):H=e[55],H},wb=t=>{const e=at.c(21),{credential:a,onImport:n,hasBorder:r}=t,{t:i}=Ze();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const d=l,c=d.length>=3?d[d.length-1]:a.host,h=a.host.includes("/"),p=r&&"border-b border-[var(--surface-subtle)]";let f;e[2]!==p?(f=Ie("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",p),e[2]=p,e[3]=f):f=e[3];let m;e[4]!==c?(m=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=m):m=e[5];const u=h?a.host:a.username;let v;e[6]!==u?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:u}),e[6]=u,e[7]=v):v=e[7];let w;e[8]!==m||e[9]!==v?(w=s.jsxs("div",{className:"min-w-0",children:[m,v]}),e[8]=m,e[9]=v,e[10]=w):w=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(z,{name:"download",className:"h-3 w-3"}),e[11]=b):b=e[11];let k;e[12]!==i?(k=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=k):k=e[13];let g;e[14]!==n||e[15]!==k?(g=s.jsxs(G,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[b,k]}),e[14]=n,e[15]=k,e[16]=g):g=e[16];let I;return e[17]!==g||e[18]!==f||e[19]!==w?(I=s.jsxs("div",{className:f,children:[w,g]}),e[17]=g,e[18]=f,e[19]=w,e[20]=I):I=e[20],I};function kb(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 Nb(t){return t.stopPropagation()}const bd=({guest:t})=>{const{t:e}=Ze(),a=t.integration,n=Dr(L=>L.byId[t.id]),r=Dr(L=>L.setStatus),i=o.useMemo(()=>Oc(t.id,t.icon,Hc().authenticatedAsset),[t.id,t.icon]),l=Dr(L=>L.refresh),[d,c]=o.useState(!1),[h,p]=o.useState(!1),[f,m]=o.useState(!1),[u,v]=o.useState(""),[w,b]=o.useState(""),[k,g]=o.useState(""),[I,C]=o.useState(""),[P,j]=o.useState({}),[T,x]=o.useState(!1),A=o.useRef(null),[M]=o.useState(jn),S=o.useRef(!0),D=()=>S.current&&jn()===M,O=o.useCallback(()=>{A.current!=null&&(window.clearInterval(A.current),A.current=null),m(!1)},[]);if(o.useEffect(()=>(S.current=!0,l(t.id),()=>{S.current=!1,O()}),[t.id,l,O]),o.useEffect(()=>{n&&j(n.settings)},[n]),!a)return null;const F=a.auth,N=F==="token"&&a.token?.scheme==="basic",R=!!n?.connection.connected,U=n?.connection.account.trim()||"",K=f?e("settings.integrations.guests.status.waiting"):R?U||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),W=f?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":R?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",te=f||d,Q=a.name,H=async()=>{if(!D())return!1;const L=u.trim();if(!L)return n?.hasClient?!0:(B.error(e("settings.integrations.guests.toast.clientRequired")),!1);os("saving");const Y=await Ym(t.id,L,w.trim()||void 0);return D()?Y?(r(t.id,Y),b(""),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.saveFailed",{name:Q})),!1):!1},_=async(L=P)=>{if(!D())return!1;const Y=n?.settings??{};if((a.settings??[]).every(ce=>(L[ce.id]??"").trim()===(Y[ce.id]??"")))return!0;os("saving");const ue=await Vm(t.id,L);return D()?ue?(r(t.id,ue),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.saveFailed",{name:Q})),!1):!1},V=async()=>{if(!D())return!1;const L=k.trim();if(!L)return R?!0:(B.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const Y=I.trim();if(N&&!Y)return B.error(e("settings.integrations.guests.toast.usernameRequired")),!1;os("saving");const oe=await Qm(t.id,L,N?Y:void 0);return D()?oe?(r(t.id,oe),g(""),C(""),os("saved"),!0):(os("error"),B.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},X=async()=>{if(!D())return;O(),p(!0);const L=n?.connection??{connected:!1,account:""};try{if(F==="token"){if(await V()){if((a.settings??[]).length>0&&!await _()||!D())return;B.success(e("settings.integrations.guests.toast.connected",{name:Q}))}return}if(F==="oauth"&&!n?.hasClient&&!await H())return;const Y=await qm(t.id);if(!D())return;if(!Y){B.error(e("settings.integrations.guests.toast.startFailed",{name:Q}));return}m(!0),c(!0),yn(Y);const oe=Date.now()+Gm;A.current=window.setInterval(()=>{(async()=>{if(!D()){O();return}if(Date.now()>oe){O(),B.error(e("settings.integrations.guests.toast.authorizationFailed",{name:Q}));return}const de=await l(t.id);D()&&de&&Wm(L,de.connection)&&(O(),B.success(e("settings.integrations.guests.toast.connected",{name:Q})),ls()&&qc())})()},Jm)}catch(Y){if(!D())return;console.error("Failed to start guest connect:",Y),B.error(e("settings.integrations.guests.toast.startFailed",{name:Q})),O()}finally{D()&&p(!1)}},$=async()=>{if(D()){p(!0);try{O();const L=await Hm(t.id);if(!D())return;if(!L){B.error(e("settings.integrations.guests.toast.disconnectFailed",{name:Q}));return}r(t.id,L),B.success(e("settings.integrations.guests.toast.disconnected",{name:Q}))}catch(L){if(!D())return;console.error("Failed to disconnect guest:",L),B.error(e("settings.integrations.guests.toast.disconnectFailed",{name:Q}))}finally{D()&&p(!1)}}},ee=async()=>{const L=n?.redirectUri??"";!L||!(await za(L)).ok||(x(!0),window.setTimeout(()=>x(!1),1500))};return s.jsx(kn,{open:te,onOpenChange:L=>{if(f){c(!0);return}c(L)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Nn,{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(Fc,{icon:Lc(t.icon),iconSrc:i,className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:Q}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:a.description})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",W),children:K}),s.jsx(z,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",te&&"rotate-180")})]}),s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[F==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Ot,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:u,onChange:L=>v(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}),s.jsx(Ot,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(We,{type:"password",value:w,onChange:L=>b(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})})]}):null,N?s.jsx(Ot,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:I,onChange:L=>C(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,F==="token"?s.jsx(Ot,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(We,{type:"password",value:k,onChange:L=>g(L.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,(a.settings??[]).map(L=>s.jsx(Ot,{label:L.label,controlClassName:"w-full max-w-none",children:s.jsx(We,{value:P[L.id]??"",onChange:Y=>{j(oe=>({...oe,[L.id]:Y.target.value}))},onBlur:()=>{_()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})},L.id)),F==="oauth"?s.jsxs(Ot,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(We,{value:n?.redirectUri??"",readOnly:!0,className:"h-8 min-w-0 flex-1 rounded-md px-3"}),s.jsx(G,{type:"button",size:"sm",variant:"outline",disabled:!n?.redirectUri,onClick:()=>{ee()},children:e(T?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:R?s.jsx(G,{type:"button",size:"sm",variant:"destructive",disabled:h,onClick:()=>{$()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(G,{type:"button",size:"sm",disabled:h||f,onClick:()=>{X()},children:[h?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},Sb=t=>{const e=at.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:r}=Ze(),i=Hs(Cb),l=Hs(Ib);let d;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0],o.useEffect(Pb,d),fs()||Gc())return null;let c,h,p,f,m,u,v,w;if(e[1]!==n||e[2]!==i||e[3]!==l||e[4]!==r){w=Symbol.for("react.early_return_sentinel");e:{const k=i.filter(Ab);if(k.length===0){w=null;break e}c=qe,e[13]!==r?(h=r("settings.integrations.guests.title"),e[13]=r,e[14]=h):h=e[14],e[15]!==r?(p=r("settings.integrations.guests.info"),e[15]=r,e[16]=p):p=e[16],f=n,m="integrations.guests",u="space-y-3";let g;e[17]!==l?(g=I=>s.jsx(bd,{guest:I},`${l}:${I.id}`),e[17]=l,e[18]=g):g=e[18],v=k.map(g)}e[1]=n,e[2]=i,e[3]=l,e[4]=r,e[5]=c,e[6]=h,e[7]=p,e[8]=f,e[9]=m,e[10]=u,e[11]=v,e[12]=w}else c=e[5],h=e[6],p=e[7],f=e[8],m=e[9],u=e[10],v=e[11],w=e[12];if(w!==Symbol.for("react.early_return_sentinel"))return w;let b;return e[19]!==c||e[20]!==h||e[21]!==p||e[22]!==f||e[23]!==m||e[24]!==u||e[25]!==v?(b=s.jsx(c,{title:h,info:p,divider:f,settingsItem:m,contentClassName:u,children:v}),e[19]=c,e[20]=h,e[21]=p,e[22]=f,e[23]=m,e[24]=u,e[25]=v,e[26]=b):b=e[26],b};function Cb(t){return t.guests}function Ib(t){return t.runtimeKey}function Pb(){Fn()}function Ab(t){return t.source!=="bundled"&&t.integration&&wo(t)}const Tb=({embedded:t=!1})=>{const{t:e}=Ze(),{isMobile:a}=Qn(),n=Va()?.github,r=Gn(N=>N.status),i=Gn(N=>N.isLoading),l=Gn(N=>N.hasChecked),d=Gn(N=>N.refreshStatus),c=Gn(N=>N.setStatus),h=o.useCallback(async N=>{await yn(N)},[]),[p,f]=o.useState(!1),[m,u]=o.useState(null),[v,w]=o.useState(null),b=o.useRef(null),k=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),w(null)},[]);o.useEffect(()=>((async()=>{try{l||await d(n)}catch(N){console.warn("Failed to load GitHub auth status:",N)}})(),()=>{k()}),[l,d,n,k]);const g=o.useCallback(async()=>{f(!0);try{const N=n?await n.authStart():await(async()=>{const U=await Nt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),K=await U.json().catch(()=>null);if(!U.ok||!K||!("deviceCode"in K))throw new Error(K?.error||U.statusText);return K})();u(N),w(Math.max(1,N.interval)*1e3);const R=N.verificationUriComplete||N.verificationUri;h(R)}catch(N){console.error("Failed to start GitHub connect:",N),B.error(e("settings.github.page.toast.startConnectFailed"))}finally{f(!1)}},[h,n,e]),I=o.useCallback(async N=>{if(n)return n.authComplete(N);const R=await Nt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:N})}),U=await R.json().catch(()=>null);if(!R.ok||!U)throw new Error(U?.error||R.statusText);return U},[n]);o.useEffect(()=>{if(!(!m?.deviceCode||!v)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const N=await I(m.deviceCode);if(N.connected){B.success(e("settings.github.page.toast.connected")),u(null),k(),await d(n,{force:!0});return}N.status==="slow_down"&&w(R=>R?R+5e3:5e3),(N.status==="expired_token"||N.status==="access_denied")&&(B.error(N.error||e("settings.github.page.toast.authorizationFailed")),u(null),k())}catch(N){console.warn("GitHub polling failed:",N)}})()},v),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[m,v,I,d,n,k,e]);const C=o.useCallback(async N=>{f(!0);try{if(n)await n.authSetGhCliDisabled(N);else{const R=await Nt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:N})}),U=await R.json().catch(()=>null);if(!R.ok)throw new Error(U?.error||R.statusText)}B.success(e(N?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await d(n,{force:!0})}catch(R){console.error("Failed to update gh CLI setting:",R),B.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{f(!1)}},[d,n,e]),P=o.useCallback(async()=>{f(!0);try{if(k(),u(null),n)await n.authDisconnect();else{const N=await Nt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!N.ok)throw new Error(N.statusText)}B.success(e("settings.github.page.toast.disconnected")),await d(n,{force:!0})}catch(N){console.error("Failed to disconnect GitHub:",N),B.error(e("settings.github.page.toast.disconnectFailed"))}finally{f(!1)}},[d,n,k,e]),j=o.useCallback(async N=>{if(N){f(!0);try{const R=n?await n.authActivate(N):await(async()=>{const U=await Nt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:N})}),K=await U.json().catch(()=>null);if(!U.ok||!K)throw new Error(K?.error||U.statusText);return K})();c(R),B.success(e("settings.github.page.toast.accountSwitched"))}catch(R){console.error("Failed to switch GitHub account:",R),B.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{f(!1)}}},[n,c,e]);if(i&&!l)return null;const T=!!r?.connected,x=r?.user,M=(r?.accounts??[]).filter(N=>!N.current),S=r?.ghCli??null,D=S?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),O=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[T?s.jsxs("div",{className:Ie("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Ie("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[x?.avatarUrl?s.jsx("img",{src:x.avatarUrl,alt:x.login?e("settings.github.page.avatarAlt.withLogin",{login:x.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:x?.name?.trim()||x?.login||"GitHub"}),s.jsxs("div",{className:Ie("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:x?.login||e("settings.github.page.label.unknownUser")}),x?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),x?.email&&s.jsx("span",{children:x.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:D})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:r.scope})}),S?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),S?.active?s.jsx(G,{size:"sm",variant:"outline",onClick:()=>C(!0),disabled:p,className:Ie(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(G,{size:"sm",variant:"outline",onClick:P,disabled:p,className:Ie("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(G,{size:"sm",variant:"default",onClick:g,disabled:p,children:e("settings.github.page.actions.connect")})]}),M.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:M.map(N=>{const R=N.user,U=N.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[R?.avatarUrl?s.jsx("img",{src:R.avatarUrl,alt:R.login?e("settings.github.page.avatarAlt.withLogin",{login:R.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R?.name?.trim()||R?.login||"GitHub"}),R?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:R.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:U})]})]})]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>j(N.id),disabled:p,children:e("settings.github.page.actions.switchTo")})]},N.id)})})]})]}),T&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(G,{size:"sm",variant:"outline",onClick:g,disabled:p,className:Ie(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),m&&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(Cn,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:m.userCode}),s.jsx(G,{size:"sm",asChild:!0,children:s.jsx("a",{href:m.verificationUriComplete||m.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(G,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{k(),u(null)},children:e("settings.common.actions.cancel")})]})]})]}),F=S?.available&&!S?.active&&(!S.user||S.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:Ie("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Ie("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[S.user?.avatarUrl?s.jsx("img",{src:S.user.avatarUrl,alt:S.user.login?e("settings.github.page.avatarAlt.withLogin",{login:S.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!S.disabled&&S.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:S.user.name?.trim()||S.user.login||"GitHub"}),!S.disabled&&S.user?.login&&s.jsxs("div",{className:Ie("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:S.user.login}),S.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),S.user.email&&s.jsx("span",{children:S.user.email})]}),s.jsx("div",{className:Ie("typography-meta text-muted-foreground",S.disabled?"opacity-60":void 0),children:S.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>C(!S.disabled),disabled:p,className:Ie(a?"w-full":void 0),children:S.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[O,F?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Cn,{children:e("settings.github.page.ghCli.title")}),F]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:O}),F?s.jsx(qe,{title:e("settings.github.page.ghCli.title"),children:F}):null]})},Eb=()=>{const t=at.c(37),{t:e}=Ze(),a=Gn(Db),n=Gn(Mb),r=Gn(Rb),[i,l]=o.useState(!1),d=a?.connected===!0;let c;t[0]!==d||t[1]!==r||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!r?e("common.loading"):d?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=d,t[1]=r,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const h=c,p=d?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let f;t[6]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=f):f=t[6];let m;t[7]!==e?(m=e("settings.integrations.github.title"),t[7]=e,t[8]=m):m=t[8];let u;t[9]!==m?(u=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:m}),t[9]=m,t[10]=u):u=t[10];let v;t[11]!==e?(v=e("settings.integrations.github.description"),t[11]=e,t[12]=v):v=t[12];let w;t[13]!==v?(w=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:v}),t[13]=v,t[14]=w):w=t[14];let b;t[15]!==u||t[16]!==w?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[u,w]}),t[15]=u,t[16]=w,t[17]=b):b=t[17];let k;t[18]!==p?(k=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",p),t[18]=p,t[19]=k):k=t[19];let g;t[20]!==h||t[21]!==k?(g=s.jsx("span",{"aria-live":"polite",className:k,children:h}),t[20]=h,t[21]=k,t[22]=g):g=t[22];const I=i&&"rotate-180";let C;t[23]!==I?(C=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",I),t[23]=I,t[24]=C):C=t[24];let P;t[25]!==C?(P=s.jsx(z,{name:"arrow-down-s",className:C}),t[25]=C,t[26]=P):P=t[26];let j;t[27]!==P||t[28]!==b||t[29]!==g?(j=s.jsxs(Nn,{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:[f,b,g,P]}),t[27]=P,t[28]=b,t[29]=g,t[30]=j):j=t[30];let T;t[31]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(Tb,{embedded:!0})}),t[31]=T):T=t[31];let x;t[32]!==j?(x=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[j,T]}),t[32]=j,t[33]=x):x=t[33];let A;return t[34]!==i||t[35]!==x?(A=s.jsx(kn,{open:i,onOpenChange:l,children:x}),t[34]=i,t[35]=x,t[36]=A):A=t[36],A};function Db(t){return t.status}function Mb(t){return t.isLoading}function Rb(t){return t.hasChecked}const Ui="__none__",zi="__inherit__";function Ob({linear:t,connected:e,organizationId:a}){const{t:n}=Ze(),r=rn(b=>b.projects),[i,l]=o.useState(null),[d,c]=o.useState(!1),[h,p]=o.useState(!1),f=o.useCallback(async()=>{if(!e){l(null),c(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){l(null),c(!1);return}l(b),c(!1)}catch(b){console.error("Failed to load Linear mapping:",b),c(!0)}},[e,t]);o.useEffect(()=>{f()},[f,a]);const m=o.useCallback(async b=>{const k={};for(const g of b.teams??[])g.projectPath&&(k[g.id]=g.projectPath);p(!0),os("saving");try{const g=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(g.connected===!1){l(null),os("error");return}l(g),c(!1),os("saved")}catch(g){console.error("Failed to save Linear mapping:",g),os("error")}finally{p(!1)}},[t]);if(!e)return null;if(d&&!i)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!i)return null;const u=b=>r.find(g=>g.path===b)?.label?.trim()||b,v=b=>!b||b===Ui?n("settings.integrations.linear.mapping.defaultProject.placeholder"):u(b),w=b=>!b||b===zi?n("settings.integrations.linear.mapping.teams.useDefault"):u(b);return s.jsxs("div",{className:Rs,children:[r.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ct,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Tt,{value:i.defaultProjectPath||Ui,disabled:h||r.length===0,onValueChange:b=>{m({...i,defaultProjectPath:b===Ui?null:b})},children:[s.jsx(Pt,{size:$t,className:an,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(zt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:v})}),s.jsxs(At,{children:[s.jsx(mt,{value:Ui,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),i.defaultProjectPath&&!r.some(b=>b.path===i.defaultProjectPath)?s.jsx(mt,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,r.map(b=>s.jsx(mt,{value:b.path,children:u(b.path)},b.id))]})]})}),s.jsx(ws,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(i.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Rs,children:(i.teams??[]).map(b=>s.jsx(Ct,{label:`${b.key} · ${b.name}`,children:s.jsxs(Tt,{value:b.projectPath||zi,disabled:h||r.length===0,onValueChange:k=>{m({...i,teams:(i.teams??[]).map(g=>g.id===b.id?{...g,projectPath:k===zi?null:k}:g)})},children:[s.jsx(Pt,{size:$t,className:an,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(zt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:w})}),s.jsxs(At,{children:[s.jsx(mt,{value:zi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!r.some(k=>k.path===b.projectPath)?s.jsx(mt,{value:b.projectPath,children:b.projectPath}):null,r.map(k=>s.jsx(mt,{value:k.path,children:u(k.path)},k.id))]})]})},b.id))})})]})}function Fb({linear:t,connected:e}){const{t:a}=Ze(),[n,r]=o.useState(null),[i,l]=o.useState(!1),[d,c]=o.useState(!1);o.useEffect(()=>{if(!e){r(null),l(!1);return}let p=!1;return t.preferencesGet().then(f=>{p||(r(f.sessionComments),l(!1))}).catch(()=>{p||l(!0)}),()=>{p=!0}},[e,t]);const h=o.useCallback(async p=>{const f=n;r(p),c(!0);try{const m=await t.preferencesSet({sessionComments:p});r(m.sessionComments),os("saved")}catch{r(f),os("error")}finally{c(!1)}},[n,t]);return e?i?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Rs,children:s.jsx(Ct,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(Ba,{checked:n===!0,disabled:n===null||d,onCheckedChange:p=>{h(p)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Lb=3*6e4,Kb=1500;function sc(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function _b(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Ub=()=>{const{t}=Ze(),e=Va()?.linear,a=Ma(S=>S.status),n=Ma(S=>S.isLoading),r=Ma(S=>S.hasChecked),i=Ma(S=>S.refreshStatus),l=Ma(S=>S.setStatus),[d,c]=o.useState(!1),[h,p]=o.useState(!1),[f,m]=o.useState(!1),u=o.useRef(null),v=o.useCallback(()=>{u.current!=null&&(window.clearInterval(u.current),u.current=null),p(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{v()}},[r,i,e,v]);const w=o.useCallback(async()=>{if(!e)return;v(),c(!0);const S=sc(Ma.getState().status);try{const D=await e.authStart(ls()?"desktop":"web");p(!0),m(!0),yn(D.authorizationUrl);const O=Date.now()+Lb;u.current=window.setInterval(()=>{(async()=>{if(Date.now()>O){v(),B.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const F=await i(e,{force:!0});_b(S,sc(F))&&(v(),B.success(t("settings.integrations.linear.toast.connected")),qc())})()},Kb)}catch(D){console.error("Failed to start Linear connect:",D),B.error(t("settings.integrations.linear.toast.startConnectFailed")),v()}finally{c(!1)}},[i,e,v,t]),b=o.useCallback(async S=>{if(!(!e||!S)){c(!0);try{const D=await e.authActivate(S);l(D),B.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(D){console.error("Failed to switch Linear workspace:",D),B.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),k=o.useCallback(async()=>{if(e){c(!0);try{v(),await e.authDisconnect(),B.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(S){console.error("Failed to disconnect Linear:",S),B.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[i,e,v,t]);if(!e)return null;const g=!!a?.connected,I=a?.user,C=a?.organization,j=(a?.workspaces??[]).filter(S=>!S.current),T=I?.displayName?.trim()||I?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),x=h?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):g?C?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),A=h?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",M=h||f;return s.jsx(kn,{open:M,onOpenChange:S=>{if(h){m(!0);return}m(S)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Nn,{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(z,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",A),children:x}),s.jsx(z,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",M&&"rotate-180")})]}),s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[g?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[I?.avatarUrl?s.jsx("img",{src:I.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:T}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:T}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[C?.name,I?.email].filter(Boolean).join(" · ")})]})]}):h?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,g?s.jsxs(s.Fragment,{children:[s.jsx(Ob,{linear:e,connected:g,organizationId:C?.id??null}),s.jsx(Fb,{linear:e,connected:g}),j.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:j.map(S=>{const D=S.user,O=S.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:O}),D?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.email}):null]}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(S.id)},disabled:d,children:t("settings.integrations.linear.actions.switchTo")})]},S.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{w()},disabled:d||h,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(G,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},disabled:d,children:t("settings.integrations.linear.actions.disconnect")})]})]}):h?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",disabled:d,onClick:v,children:t("settings.common.actions.cancel")})]}):s.jsxs(G,{type:"button",size:"sm",variant:"default",onClick:()=>{w()},disabled:d||n&&!r,children:[d?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},zb=()=>{const t=at.c(23),{t:e}=Ze();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=fs(),t[0]=a):a=t[0];const n=!a,r=!!Va()?.linear,i=Hs($b),l=Hs(Bb);let d,c,h,p,f,m;if(t[1]!==i||t[2]!==l||t[3]!==e){const w=!fs()&&!Gc()?i.filter(Vb):[];c=n||r||w.length>0,d=ns,t[10]!==e?(h=e("settings.page.integrations.title"),t[10]=e,t[11]=h):h=t[11],t[12]!==e?(p=e("settings.page.integrations.description"),t[12]=e,t[13]=p):p=t[13],f=!0,m=c?s.jsxs(qe,{title:e("settings.integrations.firstParty.title"),info:e("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[n?s.jsx(Eb,{}):null,r?s.jsx(Ub,{}):null,w.map(b=>s.jsx(bd,{guest:b},`${l}:${b.id}`))]}):null,t[1]=i,t[2]=l,t[3]=e,t[4]=d,t[5]=c,t[6]=h,t[7]=p,t[8]=f,t[9]=m}else d=t[4],c=t[5],h=t[6],p=t[7],f=t[8],m=t[9];let u;t[14]!==c?(u=s.jsx(Sb,{divider:c}),t[14]=c,t[15]=u):u=t[15];let v;return t[16]!==d||t[17]!==h||t[18]!==p||t[19]!==f||t[20]!==m||t[21]!==u?(v=s.jsxs(d,{title:h,description:p,showSaveStatus:f,children:[m,u]}),t[16]=d,t[17]=h,t[18]=p,t[19]=f,t[20]=m,t[21]=u,t[22]=v):v=t[22],v};function $b(t){return t.guests}function Bb(t){return t.runtimeKey}function Vb(t){return t.source==="bundled"&&t.integration&&wo(t)}const La="__default__",Hb=500,qb=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),Gb=(t,e)=>{const a=at.c(9),n=it(Qb);let r;e:{if(!t||!e){let c;a[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],a[0]=c):c=a[0],r=c;break e}let i;if(a[1]!==e||a[2]!==t||a[3]!==n){let c;a[5]!==t?(c=p=>p.id===t,a[5]=t,a[6]=c):c=a[6],i=n.find(c)?.models.find(p=>p.id===e),a[1]=e,a[2]=t,a[3]=n,a[4]=i}else i=a[4];const l=i;let d;a[7]!==l?(d=l?.variants?Object.keys(l.variants):[],a[7]=l,a[8]=d):d=a[8],r=d}return r},vd=t=>{const e=at.c(33),{providerID:a,modelID:n,value:r,onChange:i,ariaLabel:l,className:d}=t,{t:c}=Ze(),h=Gb(a,n);let p;e[0]!==c?(p=A=>A===La?c("settings.routing.thinking.default"):A.charAt(0).toUpperCase()+A.slice(1),e[0]=c,e[1]=p):p=e[1];const f=p,m=r??La;let u;e[2]!==i?(u=A=>i(A===La?null:A),e[2]=i,e[3]=u):u=e[3];const v=h.length===0;let w;e[4]!==d?(w=Ie(an,d),e[4]=d,e[5]=w):w=e[5];const b=r??La;let k;e[6]!==f||e[7]!==b?(k=f(b),e[6]=f,e[7]=b,e[8]=k):k=e[8];let g;e[9]!==k?(g=s.jsx(zt,{children:k}),e[9]=k,e[10]=g):g=e[10];let I;e[11]!==l||e[12]!==w||e[13]!==g?(I=s.jsx(Pt,{size:$t,className:w,"aria-label":l,children:g}),e[11]=l,e[12]=w,e[13]=g,e[14]=I):I=e[14];let C;e[15]!==f?(C=f(La),e[15]=f,e[16]=C):C=e[16];let P;e[17]!==C?(P=s.jsx(mt,{value:La,children:C}),e[17]=C,e[18]=P):P=e[18];let j;if(e[19]!==f||e[20]!==h){let A;e[22]!==f?(A=M=>s.jsx(mt,{value:M,children:f(M)},M),e[22]=f,e[23]=A):A=e[23],j=h.map(A),e[19]=f,e[20]=h,e[21]=j}else j=e[21];let T;e[24]!==P||e[25]!==j?(T=s.jsxs(At,{children:[P,j]}),e[24]=P,e[25]=j,e[26]=T):T=e[26];let x;return e[27]!==T||e[28]!==m||e[29]!==u||e[30]!==v||e[31]!==I?(x=s.jsxs(Tt,{value:m,onValueChange:u,disabled:v,children:[I,T]}),e[27]=T,e[28]=m,e[29]=u,e[30]=v,e[31]=I,e[32]=x):x=e[32],x},Wb=t=>{const e=at.c(49),{category:a,expanded:n,onToggle:r,onChange:i,onReset:l,onRemove:d}=t,{t:c}=Ze();let h;e[0]!==a.model||e[1]!==a.variant||e[2]!==c?(h=a.model?`${a.model.modelID}${a.variant?` / ${a.variant}`:""}`:c("settings.routing.model.useFallback"),e[0]=a.model,e[1]=a.variant,e[2]=c,e[3]=h):h=e[3];const p=h;let f;e[4]!==a.agent||e[5]!==p?(f=[p,a.agent].filter(Boolean),e[4]=a.agent,e[5]=p,e[6]=f):f=e[6];const m=f.join(" · "),u=!a.enabled&&"opacity-60";let v;e[7]!==u?(v=Ie("py-1",u),e[7]=u,e[8]=v):v=e[8];const w=n?"arrow-down-s":"arrow-right-s";let b;e[9]!==w?(b=s.jsx(z,{name:w,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[9]=w,e[10]=b):b=e[10];const k=a.name||a.id;let g;e[11]!==k?(g=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:k}),e[11]=k,e[12]=g):g=e[12];let I;e[13]!==m?(I=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m}),e[13]=m,e[14]=I):I=e[14];let C;e[15]!==n||e[16]!==r||e[17]!==b||e[18]!==g||e[19]!==I?(C=s.jsxs("button",{type:"button",onClick:r,"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1.5 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[b,g,I]}),e[15]=n,e[16]=r,e[17]=b,e[18]=g,e[19]=I,e[20]=C):C=e[20];const P=a.enabled;let j;e[21]!==i?(j=D=>i({enabled:D}),e[21]=i,e[22]=j):j=e[22];let T;e[23]!==a.name||e[24]!==c?(T=c("settings.routing.category.enabledAria",{name:a.name}),e[23]=a.name,e[24]=c,e[25]=T):T=e[25];let x;e[26]!==a.enabled||e[27]!==j||e[28]!==T?(x=s.jsx(Ba,{checked:P,onCheckedChange:j,"aria-label":T}),e[26]=a.enabled,e[27]=j,e[28]=T,e[29]=x):x=e[29];let A;e[30]!==C||e[31]!==x?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[C,x]}),e[30]=C,e[31]=x,e[32]=A):A=e[32];let M;e[33]!==a.agent||e[34]!==a.description||e[35]!==a.model?.modelID||e[36]!==a.model?.providerID||e[37]!==a.name||e[38]!==a.variant||e[39]!==n||e[40]!==i||e[41]!==d||e[42]!==l||e[43]!==c?(M=n?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(Rn,{children:[s.jsx(Ot,{label:c("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(We,{value:a.name,onChange:D=>i({name:D.target.value}),"aria-label":c("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(Ot,{label:c("settings.routing.category.agent"),info:c("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(fo,{agentName:a.agent??"",onChange:D=>i({agent:D||null}),filter:Yb,className:Ie(Ws,"w-full")})}),s.jsx(Ot,{label:c("settings.routing.category.model"),info:c("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(ca,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(D,O)=>i({model:{providerID:D,modelID:O},variant:null}),className:Ie(Ws,"w-full"),placeholder:c("settings.routing.model.useFallback")})}),s.jsx(Ot,{label:c("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(vd,{providerID:a.model?.providerID,modelID:a.model?.modelID,value:a.variant,onChange:D=>i({variant:D}),ariaLabel:c("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(Ot,{label:c("settings.routing.category.description"),info:c("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(As,{value:a.description,onChange:D=>i({description:D.target.value}),"aria-label":c("settings.routing.category.description"),rows:5,maxLength:2e3,className:"w-full"})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l?s.jsx(G,{size:"sm",variant:"outline",onClick:l,children:c("settings.routing.category.reset")}):null,s.jsx(G,{size:"sm",variant:"ghost",onClick:d,children:c("settings.routing.category.remove")})]})]}):null,e[33]=a.agent,e[34]=a.description,e[35]=a.model?.modelID,e[36]=a.model?.providerID,e[37]=a.name,e[38]=a.variant,e[39]=n,e[40]=i,e[41]=d,e[42]=l,e[43]=c,e[44]=M):M=e[44];let S;return e[45]!==A||e[46]!==M||e[47]!==v?(S=s.jsxs("div",{className:v,children:[A,M]}),e[45]=A,e[46]=M,e[47]=v,e[48]=S):S=e[48],S},Jb=()=>{const{t}=Ze(),e=en(L=>L.available),a=en(L=>L.autoReady),n=en(L=>L.tokenPresent),r=en(L=>L.jevSource),i=en(L=>L.config),l=en(L=>L.builtins),d=en(L=>L.loaded),c=en(L=>L.loadError),h=en(L=>L.load),p=en(L=>L.saveConfig),f=en(L=>L.setToken),m=en(L=>L.clearToken),[u,v]=o.useState(i),[w,b]=o.useState(""),[k,g]=o.useState(!1),[I,C]=o.useState(null),[P,j]=o.useState(""),[T,x]=o.useState(null),A=o.useRef(null),M=o.useRef(null),S=o.useRef(Promise.resolve()),D=o.useRef(0);o.useEffect(()=>{h()},[h]),o.useEffect(()=>{!A.current&&D.current===0&&v(i)},[i]);const O=o.useCallback(()=>{const L=A.current;if(!L||(A.current=null,L.runtimeKey!==jn()))return S.current;D.current+=1,os("saving");const Y=S.current.then(async()=>{try{if(L.runtimeKey!==jn()){os("saved");return}await p(L.config),os("saved")}catch{os("error")}finally{D.current-=1}});return S.current=Y,Y},[p]);o.useEffect(()=>()=>{M.current&&clearTimeout(M.current),O()},[O]);const F=it(L=>L.settingsDefaultModel),N=it(L=>L.settingsDefaultVariant),R=o.useRef(!1);o.useEffect(()=>{if(R.current||!d||!i||i.fallback)return;const L=Ln(F);!L||Wc(L.providerId,L.modelId)||(R.current=!0,U(Y=>Y.fallback?Y:{...Y,fallback:{model:{providerID:L.providerId,modelID:L.modelId},variant:N??null}}))},[d,i,F,N]);const U=o.useCallback(L=>{v(Y=>{if(!Y)return Y;const oe=L(Y);return A.current={config:oe,runtimeKey:jn()},M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{M.current=null,O()},Hb),oe})},[O]),K=o.useCallback((L,Y)=>{U(oe=>({...oe,categories:oe.categories.map(de=>de.id===L?{...de,...Y}:de)}))},[U]),W=async()=>{const L=w.trim();if(L){g(!0),C(null);try{await f(L),b("")}catch(Y){C(Y instanceof Error?Y.message:String(Y))}finally{g(!1)}}},te=async()=>{g(!0),C(null);try{await m()}catch(L){C(L instanceof Error?L.message:String(L))}finally{g(!1)}},Q=()=>{const L=P.trim();if(!L||!u)return;const Y=qb(L)||`category-${Date.now()}`;let oe=Y,de=2;for(;u.categories.some(ue=>ue.id===oe);)oe=`${Y}-${de++}`;U(ue=>({...ue,categories:[...ue.categories,{id:oe,builtin:!1,enabled:!0,name:L,description:"",model:null,variant:null,agent:null}]})),j(""),x(oe)},H=L=>{const Y=l.find(oe=>oe.id===L);Y&&K(L,{name:Y.name,description:Y.description,model:null,variant:null,agent:null,enabled:!0})},_=L=>{const Y=l.find(oe=>oe.id===L);Y&&U(oe=>({...oe,categories:[...oe.categories,{id:L,builtin:!0,enabled:!0,name:Y.name,description:Y.description,model:null,variant:null,agent:null}]}))},V=L=>{U(Y=>({...Y,categories:Y.categories.filter(oe=>oe.id!==L)}))},X=u?.categories.filter(L=>L.enabled).length??0,$=l.filter(L=>!u?.categories.some(Y=>Y.id===L.id)),ee=u?.enabled?u.fallback?X<2?t("settings.routing.status.tooFewCategories"):t(a?"settings.routing.status.ready":"settings.routing.status.notReady"):t("settings.routing.status.noFallback"):t("settings.routing.status.disabled");return s.jsxs(ns,{title:t("settings.page.routing.title"),description:t("settings.page.routing.description"),showSaveStatus:!0,children:[c?s.jsx("p",{className:Vi,children:t("settings.routing.loadError",{error:c})}):null,!d||!u?null:e?s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:t("settings.routing.access.title"),divider:!1,children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.access.intro")}),s.jsx("p",{className:ys,children:r==="typesafe"?t("settings.routing.access.usingKey"):s.jsxs(s.Fragment,{children:[s.jsx("strong",{className:"font-semibold",children:t("settings.routing.access.usingFree")})," ",t("settings.routing.access.usingFreeDetails")]})}),s.jsx(Ct,{settingsItem:"routing.token",label:t("settings.routing.token.label"),info:t("settings.routing.token.info"),children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(We,{type:"password",autoComplete:"off",value:w,onChange:L=>b(L.target.value),onKeyDown:L=>{L.key==="Enter"&&W()},placeholder:t(n?"settings.routing.token.replacePlaceholder":"settings.routing.token.placeholder"),"aria-label":t("settings.routing.token.label"),className:"h-8 rounded-md px-3 min-w-0 flex-1",disabled:k}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>{W()},disabled:k||w.trim().length===0,children:t("settings.routing.token.save")}),n?s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{te()},disabled:k,children:t("settings.routing.token.remove")}):null]})}),I?s.jsx("p",{className:Vi,children:I}):null]})}),s.jsx(qe,{title:t("settings.routing.auto.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"routing.enabled",checked:u.enabled,onChange:L=>U(Y=>({...Y,enabled:L})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:ys,children:ee}),s.jsx(Ct,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(ca,{providerId:u.fallback?.model.providerID??"",modelId:u.fallback?.model.modelID??"",onChange:(L,Y)=>U(oe=>({...oe,fallback:{model:{providerID:L,modelID:Y},variant:null}})),className:Ws,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(Ct,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(vd,{providerID:u.fallback?.model.providerID,modelID:u.fallback?.model.modelID,value:u.fallback?.variant??null,onChange:L=>U(Y=>Y.fallback?{...Y,fallback:{...Y.fallback,variant:L}}:Y),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(qe,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:u.categories.map(L=>s.jsx(Wb,{category:L,expanded:T===L.id,onToggle:()=>x(Y=>Y===L.id?null:L.id),onChange:Y=>K(L.id,Y),onReset:L.builtin?()=>H(L.id):null,onRemove:()=>V(L.id)},L.id))}),$.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:$.map(L=>s.jsx(G,{size:"sm",variant:"outline",onClick:()=>_(L.id),children:t("settings.routing.category.restore",{name:L.name})},L.id))}):null,s.jsx(Ct,{label:t("settings.routing.categories.addLabel"),settingsItem:"routing.add-category",children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(We,{value:P,onChange:L=>j(L.target.value),onKeyDown:L=>{L.key==="Enter"&&Q()},placeholder:t("settings.routing.categories.addPlaceholder"),"aria-label":t("settings.routing.categories.addLabel"),className:"h-8 rounded-md px-3 min-w-0 flex-1",maxLength:60}),s.jsx(G,{size:"sm",variant:"outline",onClick:Q,disabled:P.trim().length===0,children:t("settings.routing.categories.add")})]})})]})}),s.jsx(qe,{title:t("settings.routing.safety.title"),children:s.jsxs("div",{className:Rs,children:[s.jsx("p",{className:ys,children:t("settings.routing.safety.description")}),s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"routing.safety-enabled",checked:u.safetyNet.enabled,onChange:L=>U(Y=>({...Y,safetyNet:{...Y.safetyNet,enabled:L}})),label:t("settings.routing.safety.enable"),ariaLabel:t("settings.routing.safety.enable"),info:t("settings.routing.safety.enableInfo")})})]})})]}):s.jsx("p",{className:Vi,children:t("settings.routing.unavailable")})]})};function Qb(t){return t.providers}function Yb(t){return Kc(t.mode)}const Zb={prompt:{icon:"chat-1",titleKey:"settings.extensions.capability.prompt",detailKey:"settings.extensions.capability.prompt.detail"},sessions:{icon:"git-branch",titleKey:"settings.extensions.capability.sessions",detailKey:"settings.extensions.capability.sessions.detail"},files:{icon:"file-text",titleKey:"settings.extensions.capability.files",detailKey:"settings.extensions.capability.files.detail"},model:{icon:"sparkling",titleKey:"settings.extensions.capability.model",detailKey:"settings.extensions.capability.model.detail"},conversation:{icon:"chat-history",titleKey:"settings.extensions.capability.conversation",detailKey:"settings.extensions.capability.conversation.detail"},filesystem:{icon:"hard-drive-2",titleKey:"settings.extensions.capability.filesystem",detailKey:"settings.extensions.capability.filesystem.detail"},service:{icon:"terminal",titleKey:"settings.extensions.capability.service",detailKey:"settings.extensions.capability.service.detail"},network:{icon:"plug",titleKey:"settings.extensions.capability.network",detailKey:"settings.extensions.capability.network.detail"}},Xb=t=>{const e=at.c(73),{guest:a,busy:n,onApprove:r,onDecline:i,onDismiss:l}=t,{t:d}=Ze();let c;e[0]!==a?.capabilities.requested?(c=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=c):c=e[1];const h=c;let p;e[2]!==a?.filesystem?(p=a?.filesystem??[],e[2]=a?.filesystem,e[3]=p):p=e[3];const f=p;let m;e[4]!==a?.service?.permissions?.exec?(m=a?.service?.permissions?.exec??[],e[4]=a?.service?.permissions?.exec,e[5]=m):m=e[5];const u=m;let v;e[6]!==a?.service?.permissions?.sockets?(v=a?.service?.permissions?.sockets??[],e[6]=a?.service?.permissions?.sockets,e[7]=v):v=e[7];const w=v,b=a?.service;let k;e[8]!==b?(k=_c(b,"browser"),e[8]=b,e[9]=k):k=e[9];const g=k,I=a?.integration?.apiOrigin??null,C=a!==null;let P;e[10]!==n||e[11]!==l?(P=X=>{!X&&!n&&l()},e[10]=n,e[11]=l,e[12]=P):P=e[12];const j=a?.name??"";let T;e[13]!==d||e[14]!==j?(T=d("settings.extensions.dialog.approveTitle",{name:j}),e[13]=d,e[14]=j,e[15]=T):T=e[15];let x;e[16]!==T?(x=s.jsx(Vt,{children:T}),e[16]=T,e[17]=x):x=e[17];const A=a?.name??"",M=a?.version?`v${a.version}`:"";let S;e[18]!==d||e[19]!==A||e[20]!==M?(S=d("settings.extensions.dialog.approveDescription",{name:A,version:M}),e[18]=d,e[19]=A,e[20]=M,e[21]=S):S=e[21];let D;e[22]!==S?(D=s.jsx(Ht,{children:S}),e[22]=S,e[23]=D):D=e[23];let O;e[24]!==x||e[25]!==D?(O=s.jsxs(Bt,{children:[x,D]}),e[24]=x,e[25]=D,e[26]=O):O=e[26];let F;if(e[27]!==I||e[28]!==f||e[29]!==g||e[30]!==h||e[31]!==u||e[32]!==w||e[33]!==d){let X;e[35]!==I||e[36]!==f||e[37]!==g||e[38]!==u||e[39]!==w||e[40]!==d?(X=$=>{const ee=Zb[$];return s.jsxs("li",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-md bg-[var(--surface-muted)]",children:s.jsx(z,{name:ee.icon,className:"size-4 text-foreground"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:d(ee.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:d(ee.detailKey)}),$==="filesystem"&&f.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:f.map(ev)}):null,$==="network"&&I?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:I})]}):null,$==="service"&&u.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:u.join(", ")})]}):null,$==="service"&&w.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:w.join(", ")})]}):null,$==="service"&&g?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:d("settings.extensions.capability.service.providesBrowser")}):null]})]},$)},e[35]=I,e[36]=f,e[37]=g,e[38]=u,e[39]=w,e[40]=d,e[41]=X):X=e[41],F=h.map(X),e[27]=I,e[28]=f,e[29]=g,e[30]=h,e[31]=u,e[32]=w,e[33]=d,e[34]=F}else F=e[34];let N;e[42]!==F?(N=s.jsx("ul",{className:"space-y-3",children:F}),e[42]=F,e[43]=N):N=e[43];let R;e[44]!==a||e[45]!==i?(R=()=>a&&i(a),e[44]=a,e[45]=i,e[46]=R):R=e[46];let U;e[47]!==d?(U=d("settings.extensions.dialog.decline"),e[47]=d,e[48]=U):U=e[48];let K;e[49]!==n||e[50]!==R||e[51]!==U?(K=s.jsx(G,{size:"sm",variant:"ghost",disabled:n,onClick:R,children:U}),e[49]=n,e[50]=R,e[51]=U,e[52]=K):K=e[52];let W;e[53]!==a||e[54]!==r?(W=()=>a&&r(a),e[53]=a,e[54]=r,e[55]=W):W=e[55];let te;e[56]!==d?(te=d("settings.extensions.dialog.approve"),e[56]=d,e[57]=te):te=e[57];let Q;e[58]!==n||e[59]!==W||e[60]!==te?(Q=s.jsx(G,{size:"sm",disabled:n,onClick:W,children:te}),e[58]=n,e[59]=W,e[60]=te,e[61]=Q):Q=e[61];let H;e[62]!==K||e[63]!==Q?(H=s.jsxs(as,{children:[K,Q]}),e[62]=K,e[63]=Q,e[64]=H):H=e[64];let _;e[65]!==O||e[66]!==N||e[67]!==H?(_=s.jsxs(Ut,{className:"max-w-md",children:[O,N,H]}),e[65]=O,e[66]=N,e[67]=H,e[68]=_):_=e[68];let V;return e[69]!==_||e[70]!==C||e[71]!==P?(V=s.jsx(_t,{open:C,onOpenChange:P,children:_}),e[69]=_,e[70]=C,e[71]=P,e[72]=V):V=e[72],V};function ev(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const tv=t=>{if(t.source!=="git"||!t.origin?.url)return null;const e=t.origin.url.trim(),a=/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?([A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+):([^\s]+)$/.exec(e);try{const n=new URL(a?`ssh://${a[1]}/${a[2]}`:e);if(n.protocol!=="https:"&&n.protocol!=="ssh:")return null;const r=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return r.username="",r.password="",r.search="",r.hash="",r.pathname=r.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),r.pathname==="/"?null:r.href}catch{return null}},sv=Ts({error:Io(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","extract-failed","too-large"]),required:Dt().trim().min(1).max(64).optional(),id:Dt().trim().min(1).max(128).optional()}),nv=t=>{const e=t.trim();if(!e)return{ok:!1,code:"invalid-path"};if(e.slice(0,8).toLowerCase()==="https://")return{ok:!0,request:{url:e}};if(e.slice(0,6).toLowerCase()==="ssh://"||/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?[A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+:[^\s]+$/.test(e))return{ok:!0,request:{url:e}};const a=/^[a-zA-Z]:[\\/]/.test(e);return/^[a-z][a-z0-9+.-]*:/i.test(e)&&!a?{ok:!1,code:"invalid-url"}:e.startsWith("/")||a||e.startsWith("\\\\")?{ok:!0,request:{path:e}}:{ok:!1,code:"invalid-path"}},yd=async t=>{try{const e=sv.safeParse(JSON.parse(await t.text()));return e.success?e.data.error==="host-too-old"&&e.data.required&&e.data.id?{code:"host-too-old",required:e.data.required,id:e.data.id}:e.data.error==="host-too-old"&&e.data.required?{code:"host-too-old",required:e.data.required}:e.data.id?{code:e.data.error,id:e.data.id}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},jd=async(t,e)=>{if(!t.ok)return{ok:!1,...await yd(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:Uc(a);return n?{ok:!0,guest:n,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},av=async(t,e={})=>{const a=nv(t);if(!a.ok)return a;const n={...a.request};e.replace&&(n.replace=!0),"url"in n&&e.gitIdentityId&&(n.gitIdentityId=e.gitIdentityId);try{const r=await Nt("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await jd(r,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},iv=async(t,e={})=>{try{const a=await Nt("/api/guests/upload",{method:"POST",query:{replace:e.replace?"true":void 0,name:t.name||void 0},headers:{"Content-Type":"application/octet-stream",Accept:"application/json"},body:t});return await jd(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},rv=async t=>{try{const e=await Nt(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await yd(e)).code}}catch{return{ok:!1,code:"failed"}}},ov=async(t,e)=>{try{return(await Nt(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},lv=async(t,e)=>{try{return(await Nt(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},Vr=(t,e)=>{const a=`${t.method} ${t.path}`;return t.kind==="network"?`${a}: ${e("settings.extensions.request.noResponse")}`:t.kind==="invalid-response"?`${a}: ${e("settings.extensions.request.invalidResponse",{status:t.status})}`:`${a}: HTTP ${t.status}`},cv=Ts({updates:Kn(Dt().min(1),hu)}),dv=Ts({error:Io(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found"]),required:Dt().trim().min(1).max(64).optional()}),nc=async t=>{try{const e=await Nt("/api/guests/updates/check",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({force:t})});if(!e.ok)return{ok:!1};const a=cv.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},uv=async t=>{try{const e=dv.safeParse(JSON.parse(await t.text()));return e.success?e.data.required?{code:e.data.error,required:e.data.required}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},mv=async t=>{try{const e=await Nt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await uv(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=Uc(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},pv=t=>t==="invalid-path"?"settings.extensions.toast.invalidPath":t==="invalid-url"?"settings.extensions.toast.invalidUrl":t==="not-found"?"settings.extensions.toast.notFound":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="reserved-id"?"settings.extensions.toast.reservedId":t==="id-taken"?"settings.extensions.toast.idTaken":t==="already-installed"?"settings.extensions.toast.alreadyInstalled":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="host-too-old"?"settings.extensions.toast.hostTooOld":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="extract-failed"?"settings.extensions.toast.extractFailed":t==="too-large"?"settings.extensions.toast.zipTooLarge":"settings.extensions.toast.failed",ac=t=>t.name.toLowerCase().endsWith(".zip"),gv=t=>t==="not-git"?"settings.extensions.toast.notGit":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="swap-failed"?"settings.extensions.toast.swapFailed":t==="not-found"?"settings.extensions.toast.notFound":"settings.extensions.toast.updateFailed",hv=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",fv=t=>{const e=(t.service?.socketBindings??[]).map(r=>r.resolved?`${r.id}=${r.resolved}`:`${r.id}?`),a=(t.service?.permissions?.sockets??[]).filter(r=>!(t.service?.socketBindings??[]).some(i=>i.id===r));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},xv=t=>{const e=at.c(27),{guest:a,binding:n,busy:r,onSaved:i}=t,{t:l}=Ze(),[d,c]=o.useState(n.override??n.resolved??""),[h,p]=o.useState(!1),[f,m]=o.useState(!n.resolved);let u;e[0]!==n.override||e[1]!==n.resolved?(u=()=>{c(n.override??n.resolved??""),n.resolved||m(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=u):u=e[2];let v;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(v=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=v):v=e[6],o.useEffect(u,v);let w;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==i||e[11]!==l?(w=async C=>{p(!0);const P=await Zm(a.id,n.id,C);if(p(!1),!P){B.error(l("settings.extensions.toast.socketSaveFailed"));return}B.success(l("settings.extensions.toast.socketSaved",{name:a.name})),m(!1),await i()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=i,e[11]=l,e[12]=w):w=e[12];const b=w;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&m(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const g=k;let I;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==r||e[20]!==g||e[21]!==f||e[22]!==b||e[23]!==h||e[24]!==l||e[25]!==d?(I=s.jsx("div",{className:"space-y-1",children:f?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(We,{value:d,onChange:C=>c(C.target.value),placeholder:l("settings.extensions.service.socket.path",{id:n.id}),"aria-label":l("settings.extensions.service.socket.path.aria",{id:n.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:r||h,autoFocus:!0}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(d.trim()||null)},children:l("settings.extensions.service.socket.save")}),n.override?s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.clear.aria",{id:n.id}),onClick:()=>{b(null)},children:l("settings.extensions.service.socket.clear")}):null,n.resolved?s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:r||h,"aria-label":l("settings.extensions.service.socket.cancel.aria",{id:n.id}),onClick:g,children:l("settings.extensions.service.socket.cancel")}):null]}):s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx("div",{className:"typography-meta min-w-0 flex-1 truncate text-muted-foreground",children:n.resolved?l("settings.extensions.service.socket.resolved",{path:n.resolved}):l("settings.extensions.service.socket.unresolved")}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:r||h,"aria-label":l("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>m(!0),children:s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=n.id,e[17]=n.override,e[18]=n.resolved,e[19]=r,e[20]=g,e[21]=f,e[22]=b,e[23]=h,e[24]=l,e[25]=d,e[26]=I):I=e[26],I},bv=t=>{const e=at.c(143),{guest:a,busy:n,onReview:r,onRemove:i,onSetEnabled:l,onUpdate:d}=t,{t:c}=Ze(),[h,p]=o.useState(!1),f=a.enabled!==!1;let m;e[0]!==a?(m=to(a),e[0]=a,e[1]=m):m=e[1];const u=m;let v,w,b,k,g,I,C,P,j,T,x,A,M,S;if(e[2]!==f||e[3]!==a||e[4]!==u||e[5]!==h||e[6]!==c){const V=fv(a);b=!!(a.source&&a.source!=="bundled");const X=a.source==="bundled";let $;e[21]!==a?($=tv(a),e[21]=a,e[22]=$):$=e[22],k=$,S=a.source==="git"?a.update:void 0;let ee;e[23]!==a.icon||e[24]!==a.id?(ee=Oc(a.id,a.icon,Hc().authenticatedAsset),e[23]=a.icon,e[24]=a.id,e[25]=ee):ee=e[25];const L=ee;let Y;e[26]!==X||e[27]!==a.source||e[28]!==c?(Y=X?null:c(hv(a.source)),e[26]=X,e[27]=a.source,e[28]=c,e[29]=Y):Y=e[29];const oe=a.version?`v${a.version}`:null;let de;e[30]!==a.entry||e[31]!==c?(de=a.entry?null:c("settings.extensions.source.noPanel"),e[30]=a.entry,e[31]=c,e[32]=de):de=e[32];let ue;e[33]!==Y||e[34]!==oe||e[35]!==de?(ue=[Y,oe,de].filter(Boolean),e[33]=Y,e[34]=oe,e[35]=de,e[36]=ue):ue=e[36];const ce=ue.join(" · "),Se=a.path||a.id;let ie;e[37]!==f||e[38]!==u||e[39]!==c?(ie=c(u?"settings.extensions.status.needsApproval":f?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[37]=f,e[38]=u,e[39]=c,e[40]=ie):ie=e[40];const be=ie,ae=u?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":f?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";w=kn,M=h,g=p,x="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let pe;e[41]!==a.icon?(pe=Lc(a.icon),e[41]=a.icon,e[42]=pe):pe=e[42];let je;e[43]!==L||e[44]!==pe?(je=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Fc,{icon:pe,iconSrc:L,className:"size-5 text-foreground"})}),e[43]=L,e[44]=pe,e[45]=je):je=e[45];let De;e[46]!==a.name?(De=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[46]=a.name,e[47]=De):De=e[47];let me;e[48]!==ce?(me=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:ce}),e[48]=ce,e[49]=me):me=e[49];let $e;e[50]!==De||e[51]!==me?($e=s.jsxs("div",{className:"min-w-0 flex-1",children:[De,me]}),e[50]=De,e[51]=me,e[52]=$e):$e=e[52];let Ge;e[53]!==X||e[54]!==c?(Ge=X?s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c("settings.extensions.source.bundled")}):null,e[53]=X,e[54]=c,e[55]=Ge):Ge=e[55];let xe;e[56]!==c||e[57]!==S?(xe=S?s.jsx("span",{className:"max-w-40 shrink-0 truncate rounded-full bg-[var(--status-info)]/15 px-2 py-0.5 text-[10px] font-medium text-[var(--status-info)]",children:c("settings.extensions.update.badge",{version:S.version})}):null,e[56]=c,e[57]=S,e[58]=xe):xe=e[58];let Pe;e[59]!==ae?(Pe=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ae),e[59]=ae,e[60]=Pe):Pe=e[60];let J;e[61]!==be||e[62]!==Pe?(J=s.jsx("span",{"aria-live":"polite",className:Pe,children:be}),e[61]=be,e[62]=Pe,e[63]=J):J=e[63];const se=h&&"rotate-180";let he;e[64]!==se?(he=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",se),e[64]=se,e[65]=he):he=e[65];let ve;e[66]!==he?(ve=s.jsx(z,{name:"arrow-down-s",className:he}),e[66]=he,e[67]=ve):ve=e[67],e[68]!==je||e[69]!==$e||e[70]!==Ge||e[71]!==xe||e[72]!==J||e[73]!==ve?(A=s.jsxs(Nn,{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:[je,$e,Ge,xe,J,ve]}),e[68]=je,e[69]=$e,e[70]=Ge,e[71]=xe,e[72]=J,e[73]=ve,e[74]=A):A=e[74],v=Sn,T="border-t border-[var(--interactive-border)] px-4 py-4",I="space-y-3",e[75]!==Se?(C=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:Se,children:Se}),e[75]=Se,e[76]=C):C=e[76],e[77]!==X||e[78]!==c?(P=X?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[77]=X,e[78]=c,e[79]=P):P=e[79],j=V?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:c("settings.extensions.service.permissions",{list:V})}):null,e[2]=f,e[3]=a,e[4]=u,e[5]=h,e[6]=c,e[7]=v,e[8]=w,e[9]=b,e[10]=k,e[11]=g,e[12]=I,e[13]=C,e[14]=P,e[15]=j,e[16]=T,e[17]=x,e[18]=A,e[19]=M,e[20]=S}else v=e[7],w=e[8],b=e[9],k=e[10],g=e[11],I=e[12],C=e[13],P=e[14],j=e[15],T=e[16],x=e[17],A=e[18],M=e[19],S=e[20];let D;e[80]!==a.service||e[81]!==c?(D=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.service.warning")}):null,e[80]=a.service,e[81]=c,e[82]=D):D=e[82];let O;e[83]!==n||e[84]!==f||e[85]!==a?(O=f?(a.service?.socketBindings??[]).map(V=>s.jsx(xv,{guest:a,binding:V,busy:n,onSaved:Fn},V.id)):null,e[83]=n,e[84]=f,e[85]=a,e[86]=O):O=e[86];let F;e[87]!==n||e[88]!==a||e[89]!==d||e[90]!==c||e[91]!==S?(F=S?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:S.version}),onClick:()=>{d(a)},children:c("settings.extensions.update.action")}):null,e[87]=n,e[88]=a,e[89]=d,e[90]=c,e[91]=S,e[92]=F):F=e[92];let N;e[93]!==n||e[94]!==a||e[95]!==u||e[96]!==r||e[97]!==c?(N=u?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.review.aria",{name:a.name}),onClick:()=>r(a),children:c("settings.extensions.review")}):null,e[93]=n,e[94]=a,e[95]=u,e[96]=r,e[97]=c,e[98]=N):N=e[98];let R;e[99]!==n||e[100]!==f||e[101]!==a.id||e[102]!==a.name||e[103]!==l||e[104]!==c?(R=f?s.jsx(G,{type:"button",size:"sm",variant:"outline",disabled:n,"aria-label":c("settings.extensions.actions.disable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!1)},children:c("settings.extensions.actions.disable")}):s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.actions.enable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!0)},children:c("settings.extensions.actions.enable")}),e[99]=n,e[100]=f,e[101]=a.id,e[102]=a.name,e[103]=l,e[104]=c,e[105]=R):R=e[105];let U;e[106]!==n||e[107]!==b||e[108]!==a.id||e[109]!==a.name||e[110]!==i||e[111]!==c?(U=b?s.jsx(G,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":c("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{i(a.id,a.name)},children:c("settings.extensions.remove")}):null,e[106]=n,e[107]=b,e[108]=a.id,e[109]=a.name,e[110]=i,e[111]=c,e[112]=U):U=e[112];let K;e[113]!==k||e[114]!==c?(K=k?s.jsxs(G,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{yn(k)},children:[s.jsx(z,{name:"external-link",className:"size-4"}),c("settings.extensions.actions.openSource")]}):null,e[113]=k,e[114]=c,e[115]=K):K=e[115];let W;e[116]!==F||e[117]!==N||e[118]!==R||e[119]!==U||e[120]!==K?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[F,N,R,U,K]}),e[116]=F,e[117]=N,e[118]=R,e[119]=U,e[120]=K,e[121]=W):W=e[121];let te;e[122]!==D||e[123]!==O||e[124]!==W||e[125]!==I||e[126]!==C||e[127]!==P||e[128]!==j?(te=s.jsxs("div",{className:I,children:[C,P,j,D,O,W]}),e[122]=D,e[123]=O,e[124]=W,e[125]=I,e[126]=C,e[127]=P,e[128]=j,e[129]=te):te=e[129];let Q;e[130]!==v||e[131]!==te||e[132]!==T?(Q=s.jsx(v,{className:T,children:te}),e[130]=v,e[131]=te,e[132]=T,e[133]=Q):Q=e[133];let H;e[134]!==Q||e[135]!==x||e[136]!==A?(H=s.jsxs("div",{className:x,children:[A,Q]}),e[134]=Q,e[135]=x,e[136]=A,e[137]=H):H=e[137];let _;return e[138]!==w||e[139]!==g||e[140]!==H||e[141]!==M?(_=s.jsx(w,{open:M,onOpenChange:g,children:H}),e[138]=w,e[139]=g,e[140]=H,e[141]=M,e[142]=_):_=e[142],_},vv=()=>{const t=at.c(174),{t:e}=Ze(),a=Hs(yv),n=Hs(jv),r=Hs(wv),i=Hs(kv),[l,d]=o.useState(null),[c,h]=o.useState(!1),[p,f]=o.useState("global"),m=n==="unsupported",[u,v]=o.useState(""),[w,b]=o.useState(!1),[k,g]=o.useState(!1),I=o.useRef(!1),[C,P]=o.useState(null),[j,T]=o.useState(null),[x,A]=o.useState(!1),M=o.useRef(0),S=o.useRef(null);let D;t[0]===Symbol.for("react.memo_cache_sentinel")?(D=lm(),t[0]=D):D=t[0];const O=D;let F;t[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],t[1]=F):F=t[1],o.useEffect(Nv,F);let N,R;t[2]!==i||t[3]!==m?(N=()=>{let Ce=!1;if(d(null),h(!1),f("global"),P(null),T(null),I.current=!1,!m)return Promise.all([fu(),xu()]).then(He=>{const[yt,It]=He;Ce||d({runtimeKey:i,profiles:yt,global:It})}).catch(()=>{Ce||h(!0)}),()=>{Ce=!0}},R=[i,m],t[2]=i,t[3]=m,t[4]=N,t[5]=R):(N=t[4],R=t[5]),o.useEffect(N,R);const U=l?.runtimeKey===i?l:null;let K;t[6]!==e?(K=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=K):K=t[7];const W=U?.global?.userName??"",te=U?.global?.userEmail??"";let Q;t[8]!==K||t[9]!==W||t[10]!==te?(Q={id:"global",name:K,userName:W,userEmail:te,icon:"fingerprint",color:"info"},t[8]=K,t[9]=W,t[10]=te,t[11]=Q):Q=t[11];let H;t[12]!==U?.profiles||t[13]!==Q?(H=[Q,...U?.profiles.filter(Sv)??[]],t[12]=U?.profiles,t[13]=Q,t[14]=H):H=t[14];const _=H;let V;t[15]!==_||t[16]!==p?(V=_.find(Ce=>Ce.id===p)??_[0],t[15]=_,t[16]=p,t[17]=V):V=t[17];const X=V;let $,ee;t[18]!==n?($=()=>{if(n!=="ready"||I.current)return;I.current=!0;const Ce=Hs.getState().runtimeKey;nc(!1).then(He=>{He.ok&&Hs.getState().applyUpdates(He.updates,Ce)})},ee=[n],t[18]=n,t[19]=$,t[20]=ee):($=t[19],ee=t[20]),o.useEffect($,ee);let L;t[21]!==e?(L=async()=>{g(!0);const Ce=Hs.getState().runtimeKey,He=await nc(!0);if(g(!1),!He.ok){B.error(e("settings.extensions.toast.checkFailed"));return}Hs.getState().applyUpdates(He.updates,Ce),Object.keys(He.updates).length===0&&B.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=L):L=t[22];const Y=L;let oe;t[23]!==e?(oe=async Ce=>{b(!0);const He=await mv(Ce.id);if(b(!1),!He.ok){B.error(He.code==="host-too-old"&&He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e(gv(He.code)));return}Mr(Ce.id),B.success(e("settings.extensions.toast.updated",{name:He.guest.name,version:He.guest.version??""})),await Fn(),to(He.guest)&&T(He.guest)},t[23]=e,t[24]=oe):oe=t[24];const de=oe;let ue;if(t[25]!==a||t[26]!==e){const Ce=async(He,yt,It)=>{const Qt=It===void 0?{}:It;if(!He.ok){if(Qt.allowConflictDialog!==!1&&(He.code==="id-taken"||He.code==="already-installed")){const Xt=He.id?a.find(ts=>ts.id===He.id):void 0;return P({source:yt,name:Xt?.name??He.id??(yt.kind==="file"?yt.file.name:yt.input)}),!1}return He.code==="host-too-old"?B.error(He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e("settings.extensions.toast.failed"),{description:He.diagnostic?Vr(He.diagnostic,e):void 0}):B.error(e(pv(He.code)),{description:He.diagnostic?Vr(He.diagnostic,e):void 0}),!1}return v(""),P(null),B.success(He.replaced?e("settings.extensions.toast.reinstalled",{name:He.guest.name}):e("settings.extensions.toast.added",{name:He.guest.name})),await Fn(),to(He.guest)&&T(He.guest),!0};ue=async(He,yt)=>{const It=yt===void 0?{}:yt,Qt=jn();He.kind==="input"&&v(He.input),b(!0);const Xt=He.kind==="file"?await iv(He.file,It):await av(He.input,{...It,gitIdentityId:He.gitIdentityId});b(!1),jn()===Qt&&await Ce(Xt,He,{allowConflictDialog:!It.replace})},t[25]=a,t[26]=e,t[27]=ue}else ue=t[27];const ce=ue;let Se;t[28]!==u||t[29]!==ce||t[30]!==X||t[31]!==e?(Se=async()=>{const Ce=u.trim();if(!Ce){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"input",input:Ce,gitIdentityId:X.id})},t[28]=u,t[29]=ce,t[30]=X,t[31]=e,t[32]=Se):Se=t[32];const ie=Se;let be;t[33]!==ce?(be=async()=>{if(!O)return;const Ce=await cm("");Ce.success&&Ce.path&&await ce({kind:"input",input:Ce.path})},t[33]=ce,t[34]=be):be=t[34];const ae=be;let pe;t[35]!==ce?(pe=async()=>{if(!O){S.current?.click();return}const Ce=await No({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Ce.success&&Ce.path&&await ce({kind:"input",input:Ce.path})},t[35]=ce,t[36]=pe):pe=t[36];const je=pe;let De;t[37]!==ce||t[38]!==e?(De=async Ce=>{const He=Ce.target.files?.[0]??null;if(Ce.target.value="",!!He){if(!ac(He)){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"file",file:He})}},t[37]=ce,t[38]=e,t[39]=De):De=t[39];const me=De;let $e;t[40]!==w?($e=Ce=>{w||(Ce.preventDefault(),M.current=M.current+1,A(!0))},t[40]=w,t[41]=$e):$e=t[41];const Ge=$e;let xe;t[42]!==w?(xe=Ce=>{w||(Ce.preventDefault(),Ce.dataTransfer.dropEffect="copy")},t[42]=w,t[43]=xe):xe=t[43];const Pe=xe;let J;t[44]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{M.current=Math.max(0,M.current-1),M.current===0&&A(!1)},t[44]=J):J=t[44];const se=J;let he;t[45]!==w||t[46]!==ce||t[47]!==e?(he=async Ce=>{if(Ce.preventDefault(),M.current=0,A(!1),w)return;const He=Ce.dataTransfer.items[0],yt=He?.getAsFile()??null,Qt=(He?.webkitGetAsEntry()??null)?.isDirectory===!0,Xt=yt!==null&&!Qt&&ac(yt),ts=yt&&O?dm(yt):null;if(ts&&(Qt||Xt)){await ce({kind:"input",input:ts});return}if(Qt){B.error(e(O?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!yt||!Xt){B.error(e("settings.extensions.toast.invalidPath"));return}await ce({kind:"file",file:yt})},t[45]=w,t[46]=ce,t[47]=e,t[48]=he):he=t[48];const ve=he;let Fe;t[49]!==C||t[50]!==ce?(Fe=async()=>{C&&await ce(C.source,{replace:!0})},t[49]=C,t[50]=ce,t[51]=Fe):Fe=t[51];const Ke=Fe;let Be;t[52]!==e?(Be=async(Ce,He)=>{b(!0);const yt=await rv(Ce);if(b(!1),!yt.ok){B.error(e("settings.extensions.toast.removeFailed"));return}Mr(Ce),B.success(e("settings.extensions.toast.removed",{name:He})),await Fn()},t[52]=e,t[53]=Be):Be=t[53];const ze=Be;let _e;t[54]!==e?(_e=async Ce=>{b(!0);const He=await lv(Ce.id,Ce.capabilities.requested);if(b(!1),!He){B.error(e("settings.extensions.toast.approveFailed"));return}T(null),B.success(e("settings.extensions.toast.approved",{name:Ce.name})),await Fn()},t[54]=e,t[55]=_e):_e=t[55];const Me=_e;let tt;t[56]!==ze?(tt=async Ce=>{T(null),await ze(Ce.id,Ce.name)},t[56]=ze,t[57]=tt):tt=t[57];const pt=tt;let ct;t[58]!==e?(ct=async(Ce,He,yt)=>{b(!0);const It=await ov(Ce,yt);if(b(!1),!It){B.error(e("settings.extensions.toast.enabledFailed"));return}yt||Mr(Ce),B.success(yt?e("settings.extensions.toast.enabled",{name:He}):e("settings.extensions.toast.disabled",{name:He})),await Fn()},t[58]=e,t[59]=ct):ct=t[59];const dt=ct;let ht;t[60]!==e?(ht=e("settings.page.extensions.title"),t[60]=e,t[61]=ht):ht=t[61];let Ue;t[62]!==e?(Ue=e("settings.page.extensions.description"),t[62]=e,t[63]=Ue):Ue=t[63];let st;t[64]!==ie||t[65]!==ae||t[66]!==je||t[67]!==w||t[68]!==x||t[69]!==_||t[70]!==l||t[71]!==c||t[72]!==u||t[73]!==Ge||t[74]!==Pe||t[75]!==ve||t[76]!==me||t[77]!==X||t[78]!==e||t[79]!==m?(st=m?null:s.jsxs(qe,{title:e("settings.extensions.add.action"),info:e("settings.extensions.add.info"),children:[s.jsx(Ot,{label:e("settings.extensions.add.label"),info:e(O?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:Ie("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",x&&"border-primary bg-primary/5"),onDragEnter:Ge,onDragOver:Pe,onDragLeave:se,onDrop:Ce=>{ve(Ce)},children:[x?s.jsx("span",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-md bg-background/80 typography-ui-label text-primary",children:e("settings.extensions.add.drop.active")}):null,s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center",children:[s.jsx(We,{value:u,onChange:Ce=>v(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"&&(Ce.preventDefault(),ie())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:Ie("h-8 min-w-0 flex-1 rounded-md pl-3",O?"pr-14":"pr-8"),disabled:w}),s.jsx("input",{ref:S,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Ce=>{me(Ce)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[O?s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:w,onClick:()=>{ae()},children:s.jsx(z,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseZip"),"aria-label":e("settings.extensions.add.browseZip.aria"),disabled:w,onClick:()=>{je()},children:s.jsx(z,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(Dm,{activeProfile:X,identities:_,onSelect:Ce=>f(Ce.id),isApplying:w||!l&&!c,iconOnly:!0})}),s.jsxs(G,{type:"button",size:"sm",disabled:w,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{ie()},children:[s.jsx(z,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),c?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[64]=ie,t[65]=ae,t[66]=je,t[67]=w,t[68]=x,t[69]=_,t[70]=l,t[71]=c,t[72]=u,t[73]=Ge,t[74]=Pe,t[75]=ve,t[76]=me,t[77]=X,t[78]=e,t[79]=m,t[80]=st):st=t[80];let ut;t[81]!==e?(ut=e("settings.extensions.section.installed"),t[81]=e,t[82]=ut):ut=t[82];let ye;t[83]!==w||t[84]!==Y||t[85]!==k||t[86]!==n||t[87]!==e||t[88]!==m?(ye=m?null:s.jsxs(G,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:w||k||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{Y()},children:[s.jsx(z,{name:"refresh",className:Ie("h-4 w-4",k&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[83]=w,t[84]=Y,t[85]=k,t[86]=n,t[87]=e,t[88]=m,t[89]=ye):ye=t[89];let re;t[90]!==r||t[91]!==n||t[92]!==e?(re=n==="error"||r?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),r?`
30
+ ${Vr(r,e)}`:""]}):null,t[90]=r,t[91]=n,t[92]=e,t[93]=re):re=t[93];let Te;t[94]!==e||t[95]!==m?(Te=m?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[94]=e,t[95]=m,t[96]=Te):Te=t[96];let Ne;t[97]!==a.length||t[98]!==n||t[99]!==e?(Ne=n==="ready"&&a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[97]=a.length,t[98]=n,t[99]=e,t[100]=Ne):Ne=t[100];let Ae;if(t[101]!==w||t[102]!==a||t[103]!==ze||t[104]!==dt||t[105]!==de){let Ce;t[107]!==w||t[108]!==ze||t[109]!==dt||t[110]!==de?(Ce=He=>s.jsx(bv,{guest:He,busy:w,onReview:T,onRemove:ze,onSetEnabled:dt,onUpdate:de},He.id),t[107]=w,t[108]=ze,t[109]=dt,t[110]=de,t[111]=Ce):Ce=t[111],Ae=a.map(Ce),t[101]=w,t[102]=a,t[103]=ze,t[104]=dt,t[105]=de,t[106]=Ae}else Ae=t[106];let q;t[112]!==ut||t[113]!==ye||t[114]!==re||t[115]!==Te||t[116]!==Ne||t[117]!==Ae?(q=s.jsxs(qe,{title:ut,contentClassName:"space-y-3",headerAction:ye,children:[re,Te,Ne,Ae]}),t[112]=ut,t[113]=ye,t[114]=re,t[115]=Te,t[116]=Ne,t[117]=Ae,t[118]=q):q=t[118];let Le;t[119]!==Me?(Le=Ce=>{Me(Ce)},t[119]=Me,t[120]=Le):Le=t[120];let Qe;t[121]!==pt?(Qe=Ce=>{pt(Ce)},t[121]=pt,t[122]=Qe):Qe=t[122];let lt;t[123]===Symbol.for("react.memo_cache_sentinel")?(lt=()=>T(null),t[123]=lt):lt=t[123];let ot;t[124]!==j||t[125]!==w||t[126]!==Le||t[127]!==Qe?(ot=s.jsx(Xb,{guest:j,busy:w,onApprove:Le,onDecline:Qe,onDismiss:lt}),t[124]=j,t[125]=w,t[126]=Le,t[127]=Qe,t[128]=ot):ot=t[128];const bt=C!==null;let wt;t[129]!==w?(wt=Ce=>{!Ce&&!w&&P(null)},t[129]=w,t[130]=wt):wt=t[130];let jt;t[131]!==e?(jt=e("settings.extensions.dialog.reinstallTitle"),t[131]=e,t[132]=jt):jt=t[132];let vt;t[133]!==jt?(vt=s.jsx(Vt,{children:jt}),t[133]=jt,t[134]=vt):vt=t[134];const Xe=C?.name??"";let kt;t[135]!==e||t[136]!==Xe?(kt=e("settings.extensions.dialog.reinstallDescription",{name:Xe}),t[135]=e,t[136]=Xe,t[137]=kt):kt=t[137];let Re;t[138]!==kt?(Re=s.jsx(Ht,{children:kt}),t[138]=kt,t[139]=Re):Re=t[139];let Ve;t[140]!==vt||t[141]!==Re?(Ve=s.jsxs(Bt,{children:[vt,Re]}),t[140]=vt,t[141]=Re,t[142]=Ve):Ve=t[142];let Z;t[143]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>P(null),t[143]=Z):Z=t[143];let ge;t[144]!==e?(ge=e("settings.common.actions.cancel"),t[144]=e,t[145]=ge):ge=t[145];let Oe;t[146]!==w||t[147]!==ge?(Oe=s.jsx(G,{size:"sm",variant:"ghost",disabled:w,onClick:Z,children:ge}),t[146]=w,t[147]=ge,t[148]=Oe):Oe=t[148];let Ee;t[149]!==Ke?(Ee=()=>{Ke()},t[149]=Ke,t[150]=Ee):Ee=t[150];let Ye;t[151]!==e?(Ye=e("settings.extensions.dialog.reinstall"),t[151]=e,t[152]=Ye):Ye=t[152];let ne;t[153]!==w||t[154]!==Ee||t[155]!==Ye?(ne=s.jsx(G,{size:"sm",disabled:w,onClick:Ee,children:Ye}),t[153]=w,t[154]=Ee,t[155]=Ye,t[156]=ne):ne=t[156];let we;t[157]!==Oe||t[158]!==ne?(we=s.jsxs(as,{children:[Oe,ne]}),t[157]=Oe,t[158]=ne,t[159]=we):we=t[159];let nt;t[160]!==Ve||t[161]!==we?(nt=s.jsxs(Ut,{className:"max-w-md",children:[Ve,we]}),t[160]=Ve,t[161]=we,t[162]=nt):nt=t[162];let Rt;t[163]!==bt||t[164]!==wt||t[165]!==nt?(Rt=s.jsx(_t,{open:bt,onOpenChange:wt,children:nt}),t[163]=bt,t[164]=wt,t[165]=nt,t[166]=Rt):Rt=t[166];let Jt;return t[167]!==ht||t[168]!==Ue||t[169]!==st||t[170]!==q||t[171]!==ot||t[172]!==Rt?(Jt=s.jsxs(ns,{title:ht,description:Ue,children:[st,q,ot,Rt]}),t[167]=ht,t[168]=Ue,t[169]=st,t[170]=q,t[171]=ot,t[172]=Rt,t[173]=Jt):Jt=t[173],Jt};function yv(t){return t.guests}function jv(t){return t.status}function wv(t){return t.failure}function kv(t){return t.runtimeKey}function Nv(){Fn()}function Sv(t){return t.id!=="global"}const zs=ia,Cv=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=bu(e),n=(je,De)=>t.colors[je]??De,r=je=>je!=="transparent"&&(Vs(je,"#000000")!==1||Vs(je,"#ffffff")!==1),i=(je,De)=>{const me=n(je,De);return r(me)?me:De},l=n("chat.list.background",n("editor.background",a.colors.surface.background)),d=n("interactive-session.foreground",n("foreground",n("editor.foreground",a.colors.surface.foreground))),h=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([je])=>t.colors[je]),p=h?n(h[0],a.colors.surface.elevated):a.colors.surface.elevated,f=aa(d,p,l),m=h?n(h[1],f):f,u=n("sideBar.background",n("panel.background",a.colors.surface.muted)),v=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),w=n("textBlockQuote.background",u),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),g=n("button.hoverBackground",k),I=t.colors["button.background"]?n("button.foreground",Ms(k,l)):Ms(k,l),C=zs(k,.5),j=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(je=>je&&r(je))||zs(d,e?.25:.2),T=n("toolbar.hoverBackground",n("list.hoverBackground",a.colors.interactive.hover)),x=n("toolbar.activeBackground",T),M=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([je])=>t.colors[je]),S=M.find(([je])=>[l,u,p].every(De=>{const me=Vs(n(je,""),De,l);return me===null||me>1.01}))??M[0],D=S?n(S[0],a.colors.interactive.selection):a.colors.interactive.selection,O=S?n(S[1],d):d,F=n("focusBorder",n("inputOption.activeBorder",k)),N=F,R=n("editorCursor.foreground",a.colors.interactive.cursor),U=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),K=i("editorError.background",zs(U,e?.16:.12)),W=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),te=i("editorWarning.background",zs(W,e?.16:.12)),Q=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),H=zs(Q,e?.16:.12),_=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),V=i("editorInfo.background",zs(_,e?.16:.12)),X=n("editorLineNumber.foreground",v),$=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),ee=n("terminal.ansiBlue",k),L=n("terminal.ansiYellow",a.colors.syntax.base.number),Y=n("terminal.ansiCyan",a.colors.syntax.base.function),oe=n("terminal.ansiMagenta",d),de=n("terminal.ansiYellow",a.colors.syntax.base.type),ue=n("chat.requestBorder",j),ce=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",H)),Se=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",K)),ie=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",Q)),be=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",U)),ae=n("gitDecoration.modifiedResourceForeground",_),pe=n("chat.requestBubbleBackground",n("chat.requestBackground",p));return{...a,metadata:{...a.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:e?"dark":"light",tags:["vscode","auto"]},colors:{...a.colors,primary:{base:k,hover:g,active:g,foreground:I,muted:C},surface:{background:l,foreground:d,muted:u,mutedForeground:v,elevated:p,elevatedForeground:m,overlay:b,subtle:w},interactive:{border:j,borderHover:n("toolbar.hoverOutline",j),borderFocus:F,selection:D,selectionForeground:O,focus:F,focusRing:N,cursor:R,hover:T,active:x},status:{error:U,errorForeground:Ms(U,l),errorBackground:K,errorBorder:zs(U,e?.45:.35),warning:W,warningForeground:Ms(W,l),warningBackground:te,warningBorder:zs(W,e?.45:.35),success:Q,successForeground:Ms(Q,l),successBackground:H,successBorder:zs(Q,e?.45:.35),info:_,infoForeground:Ms(_,l),infoBackground:V,infoBorder:zs(_,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:ie,diffAddedBackground:ce,diffRemoved:be,diffRemovedBackground:Se,diffModified:ae,diffModifiedBackground:zs(ae,e?.16:.12),lineNumber:n("editorLineNumber.foreground",v),lineNumberActive:n("editorLineNumber.activeForeground",d)},base:{background:n("editor.background",l),foreground:n("editor.foreground",d),comment:X,keyword:ee,string:$,number:L,function:Y,variable:oe,type:de,operator:k}},tools:{border:ue,icon:n("icon.foreground",v),title:d,description:zs(v,.8),edit:{added:ie,addedBackground:ce,removed:be,removedBackground:Se,modified:ae,modifiedBackground:zs(ae,e?.16:.12),lineNumber:X}},chat:{background:l,userMessage:d,userMessageBackground:pe,assistantMessage:d,assistantMessageBackground:l,timestamp:v,divider:j,typing:n("chat.thinkingShimmer",v),avatarBackground:n("chat.avatarBackground",l),avatarForeground:n("chat.avatarForeground",d),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",I),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",g),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",C)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",g),inlineCode:n("textPreformat.foreground",$),inlineCodeBackground:n("textPreformat.background",n("editor.background",l)),blockquote:d,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",j),listMarker:zs(k,.6)}}}},Hr=.075;function Iv(t,e,a){const{surface:n,primary:r,status:i,interactive:l}=t.colors,d=n.background,c=t.metadata.variant==="dark",h=Ms(n.muted,d),p=[d,n.muted,n.elevated,Ns(l.selection,n.muted,1,d)].filter(k=>Ms(k,d)===h),f=k=>p.reduce((g,I)=>aa(g,I,d),k),m=k=>[d,n.muted].every(g=>(Vs(k,g,d)??0)>=3),u=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder,e["inputOption.activeBorder"],a.function,a.keyword].filter(k=>k!==void 0),v=f(u.find(m)??r.base);v!==r.base&&(r.base=v,r.foreground=Ms(v,d),r.hover=Ns(n.foreground,v,.08,d),r.active=Ns(n.foreground,v,.16,d),r.muted=ia(v,.5),!e.focusBorder&&!e["inputOption.activeBorder"]&&(l.focus=v,l.focusRing=v,l.borderFocus=v),t.colors.markdown&&(e["textLink.foreground"]||(t.colors.markdown.link=v),e["textLink.activeForeground"]||(t.colors.markdown.linkHover=r.hover),t.colors.markdown.listMarker=ia(v,.6))),p.some(k=>(Vs(l.focusRing,k,d)??0)<1.1)&&(l.focus=r.base,l.focusRing=r.base,l.borderFocus=r.base);const w=(k,g,I)=>p.every(C=>(qo(k,g,C,d)??0)>=I);let b=f(i.info);if(!w(b,r.base,Hr)){const k=C=>w(C,r.base,Hr)&&[i.error,i.warning,i.success].every(P=>w(C,P,.1));let I=[e["notificationsInfoIcon.foreground"],e["editorInfo.foreground"],e["terminal.ansiCyan"],e["terminal.ansiBlue"],e["terminal.ansiMagenta"],e["textLink.foreground"],a.function,a.type].filter(C=>C!==void 0).map(f).find(k);if(!I){const C=Ns(b,d,1,d),j=[C,f(Ns(C,d,.5,d))].flatMap(T=>[.12,.18].flatMap(x=>[0,60,-60,90,-90,120,-120,180].map(A=>f(vu(T,A,x)))));if(I=j.find(k),!I){const T=x=>Math.min(...[i.error,i.warning,i.success].map(A=>qo(x,A,n.muted,d)??0));I=j.filter(x=>w(x,r.base,Hr)).sort((x,A)=>T(A)-T(x))[0]}}I&&(b=I)}if(b!==i.info&&(i.info=b,i.infoForeground=Ms(b,d),i.infoBackground=ia(b,c?.16:.12),i.infoBorder=ia(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((Vs(k,d,d)??1)<1.1){const g=Ns(k,d,1,d);let C=(Vs(g,"#000000")??1)<(Vs(d,"#000000")??1)?"#000000":"#ffffff",P=g;((Vs(C,d,d)??1)<1.1||(Vs(g,d,d)??1)<1.01)&&(P=d,C=n.foreground);let j=0,T=1;for(let A=0;A<16;A++){const M=(j+T)/2,S=Ns(C,P,M,d);(Vs(S,d,d)??1)>=1.1?T=M:j=M}const x=Ns(C,P,T,d);(Vs(n.foreground,x,d)??0)>=4.5&&(t.colors.chat.userMessageBackground=x)}}}const sr=Dt().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),Oo=Ts({foreground:sr.optional()}),wd=Ts({scope:no([Dt(),xa(Dt())]).optional(),settings:Oo}),Pv=Ts({name:Dt().trim().min(1).max(160).optional(),author:Dt().max(160).optional(),description:Dt().max(1024).optional(),type:Io(["light","dark","hc","hc-black","hc-light"]).optional(),include:Dt().optional(),colors:Kn(Dt(),sr.nullable()).default({}),tokenColors:no([xa(wd),Dt()]).optional(),semanticHighlighting:Co().optional(),semanticTokenColors:Kn(Dt(),no([sr,Oo])).optional()});function Av(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(r=>({scope:r.trim(),color:e.settings.foreground}))))}function Tv(t,e){for(const a of e){let n,r=-1;for(const i of t)!i.color||!i.scope||(a===i.scope||a.startsWith(`${i.scope}.`))&&i.scope.length>=r&&(n=i.color,r=i.scope.length);if(n)return n}}function Ev(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const r=sr.safeParse(n);if(r.success)return r.data;const i=Oo.safeParse(n);if(i.success&&i.data.foreground)return i.data.foreground}}function Dv(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function Mv(t,e,a,n){const r=Ms(a,a);if(e.some(c=>Ms(c,a)!==r))return t;let i=t;for(const c of e)i=aa(i,c,a);let l=0,d=1;for(let c=0;c<16;c++){const h=(l+d)/2,p=ia(i,h);e.every(f=>(Vs(p,f,a)??0)>=n)?d=h:l=h}return ia(i,d)}function kd(t,e){if(new TextEncoder().encode(t).byteLength>zc)throw new ra("size");let a;try{a=Pv.parse(JSON.parse(Xm(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ra("invalid")}const n=xa(wd).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ra("include");const r={};for(const[A,M]of Object.entries(a.colors))M!==null&&(r[A]=M);const i={...r},l=r["editor.background"];if(!l)throw new ra("background");const d=a.type?["dark","hc","hc-black"].includes(a.type):Ms(l,"#ffffff")==="#ffffff",c=d?"dark":"light",h=Ns(l,d?"#000000":"#ffffff",1),p=Av(n.data),f=n.data.filter(A=>!A.scope&&A.settings.foreground).at(-1)?.settings.foreground,m=r["editor.foreground"]??f??r.foreground??Ms(h,h),u=r["chat.list.background"]??h,v=r["interactive-session.foreground"]??r.foreground??m;r["editor.background"]=h,r["editor.foreground"]=m,r.foreground??=v,r["sideBar.background"]??=r["panel.background"]??Ns(v,u,.03,u),!r["editorWidget.background"]&&!r["dropdown.background"]&&!r["input.background"]&&(r["editorWidget.background"]=Ns(v,u,.04,u),r["editorWidget.foreground"]=aa(v,r["editorWidget.background"],u)),r.descriptionForeground??=aa(Ns(v,u,.6,u),u),r["widget.border"]??=r["input.border"]??r["panel.border"]??Ns(v,u,.15,u),r["toolbar.hoverBackground"]??=r["list.hoverBackground"]??Ns(v,u,.08,u),r["toolbar.activeBackground"]??=Ns(v,u,.12,u),!r["list.activeSelectionBackground"]&&!r["editor.selectionBackground"]&&(r["list.activeSelectionBackground"]=Ns(v,u,.16,u),r["list.activeSelectionForeground"]=aa(v,r["list.activeSelectionBackground"],u)),r["button.background"]||(r["button.background"]=r["textLink.foreground"]??r.focusBorder??v,r["button.foreground"]=Ms(r["button.background"],u)),r.focusBorder??=r["button.background"],r["editorCursor.foreground"]??=m;const w=a.type?.startsWith("hc")??!1;w&&r.contrastBorder&&(r["widget.border"]=r.contrastBorder);const k=Cv({kind:d&&w?"high-contrast":c,colors:r});if(w)k.colors.interactive.focusRing=r.focusBorder;else{const{surface:A,interactive:M}=k.colors,S=Mv(M.border,[A.background,A.muted,A.elevated],A.background,d?1.15:1.2);M.border=S,r["toolbar.hoverOutline"]||(M.borderHover=S),k.colors.tools&&!r["chat.requestBorder"]&&(k.colors.tools.border=S),k.colors.chat&&(k.colors.chat.divider=S),k.colors.markdown&&!r["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=S)}const g=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},I=(A,M,S)=>Ev(g,A)??Tv(p,M)??S,C={background:h,foreground:m,comment:I(["comment"],["comment","comment.line","comment.block"],aa(Ns(m,h,.6,h),h)),keyword:I(["keyword"],["keyword","storage","keyword.control","storage.type"],m),string:I(["string"],["string","string.quoted","string.template"],m),number:I(["number"],["constant.numeric"],m),function:I(["function"],["entity.name.function","support.function"],m),variable:I(["variable"],["variable.other.readwrite","variable"],m),type:I(["type"],["entity.name.type","support.type","support.class"],m),operator:I(["operator"],["keyword.operator"],m)},P=I(["class"],["entity.name.type.class","entity.name.class"],C.type),j=I(["property"],["variable.other.property","support.type.property-name"],C.variable),T={base:C,tokens:{className:P,interface:I(["interface"],["entity.name.type.interface"],C.type),enum:I(["enum"],["entity.name.type.enum"],P),method:I(["method"],["entity.name.function.method"],C.function),variableProperty:j,parameter:I(["parameter"],["variable.parameter"],C.variable),constant:I(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],C.number),boolean:I([],["constant.language.boolean","constant.language"],C.number),punctuation:I([],["punctuation","punctuation.separator"],C.operator),stringEscape:I([],["constant.character.escape"],C.string),commentDoc:I([],["comment.block.documentation","comment.documentation"],C.comment),keywordImport:I([],["keyword.control.import","keyword.import"],C.keyword),tag:I([],["entity.name.tag"],C.keyword),tagAttribute:I([],["entity.other.attribute-name"],j)},highlights:k.colors.syntax.highlights},x=Dv(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return Iv(k,i,C),yu({metadata:{id:`vscode-import-${c}`,name:x,variant:c,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...k.colors,syntax:T,pr:{open:k.colors.status.success,draft:k.colors.surface.mutedForeground,blocked:k.colors.status.warning,merged:P,closed:k.colors.status.error}}})}const Rv=Ts({namespace:Dt(),name:Dt(),version:Dt(),label:Dt(),icon:Dt().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Ov(t,e){const a=await Nt("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!a.ok)throw new Error("catalog");return Ts({items:xa(Rv).max(24)}).parse(await a.json()).items}async function Fv(t,e){const a=await Nt("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!a.ok)throw new Error("catalog");const{items:n}=Ts({items:xa(Ts({path:Dt(),name:Dt(),text:Dt(),error:Co()})).max(40)}).parse(await a.json());return n.map((r,i)=>{const l=`${i}:${r.path}`;try{if(r.error)throw new Error("invalid");const d=kd(r.text,r.path);return d.metadata.name=r.name,d.metadata.author=t.namespace,{status:"ready",key:l,name:r.name,definition:d,theme:ju(d)}}catch{return{status:"invalid",key:l,name:r.name}}})}function Lv(t){const e=at.c(3),{extension:a}=t,[n,r]=o.useState(!1);let i;return e[0]!==a.icon||e[1]!==n?(i=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>r(!0)}):s.jsx(z,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=i):i=e[2],i}function Kv(t){const e=at.c(93),{pickFile:a,fileBusy:n,onClose:r}=t,{t:i}=Ze(),l=fe(zv),{isMobile:d}=Qn(),c=l||d,{importTheme:h}=fa(),[p,f]=o.useState("");let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={step:"search",status:"idle",results:[]},e[0]=m):m=e[0];const[u,v]=o.useState(m);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=new Set,e[1]=w):w=e[1];const[b,k]=o.useState(w);let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=new Set,e[2]=g):g=e[2];const[I,C]=o.useState(g),[P,j]=o.useState(!1),[T,x]=o.useState(null),A=o.useRef(null);let M,S;e[3]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const $=new AbortController;A.current=$;const ee=rr(()=>$.abort());return()=>{ee(),$.abort()}},S=[],e[3]=M,e[4]=S):(M=e[3],S=e[4]),o.useEffect(M,S);let D,O;e[5]!==p||e[6]!==u.step?(D=()=>{if(u.step!=="search")return;const $=new AbortController,ee=p.trim(),L=setTimeout(async()=>{if(!ee){v({step:"search",status:"idle",results:[]});return}v({step:"search",status:"loading",results:[]});try{const Y=await Ov(ee,$.signal);$.signal.aborted||v({step:"search",status:"ready",results:Y})}catch{$.signal.aborted||v({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(L),$.abort()}},O=[p,u.step],e[5]=p,e[6]=u.step,e[7]=D,e[8]=O):(D=e[7],O=e[8]),o.useEffect(D,O);let F,N;if(e[9]!==n||e[10]!==h||e[11]!==c||e[12]!==a||e[13]!==p||e[14]!==T||e[15]!==I||e[16]!==P||e[17]!==b||e[18]!==u.extension||e[19]!==u.results||e[20]!==u.status||e[21]!==u.step||e[22]!==u.variants||e[23]!==i){const $=async ae=>{const pe=A.current?.signal;if(pe){v({step:"package",status:"loading",extension:ae}),C(new Set),x(null),k(new Set);try{const je=await Fv(ae,pe);pe.aborted||v({step:"variants",extension:ae,variants:je})}catch{pe.aborted||v({step:"package",status:"error",extension:ae})}}};let ee;e[26]!==h||e[27]!==I||e[28]!==P||e[29]!==b||e[30]!==u.step||e[31]!==u.variants||e[32]!==i?(ee=async()=>{if(u.step!=="variants"||P)return;const ae=A.current?.signal;if(!ae)return;j(!0),x(null);let pe=!1;for(const je of u.variants){if(ae.aborted)break;if(!(je.status!=="ready"||!b.has(je.key)||I.has(je.key)))try{if(await h(je.definition,{activate:!1}),ae.aborted)break;C(De=>new Set(De).add(je.key)),k(De=>{const me=new Set(De);return me.delete(je.key),me})}catch{pe=!0}}ae.aborted||(j(!1),x(pe?"partial":null),pe?Ha.error(i("settings.themeImport.partialError")):Ha.success(i("settings.themeImport.complete")))},e[26]=h,e[27]=I,e[28]=P,e[29]=b,e[30]=u.step,e[31]=u.variants,e[32]=i,e[33]=ee):ee=e[33];const L=ee;let Y,oe;e[34]!==I||e[35]!==b||e[36]!==u.step||e[37]!==u.variants?(Y=u.step==="variants"?u.variants.filter(ae=>ae.status==="ready"&&!I.has(ae.key)):[],oe=Y.length>0&&Y.every(ae=>b.has(ae.key)),e[34]=I,e[35]=b,e[36]=u.step,e[37]=u.variants,e[38]=Y,e[39]=oe):(Y=e[38],oe=e[39]);const de=oe;let ue;e[40]!==n||e[41]!==L||e[42]!==P||e[43]!==b||e[44]!==u.step||e[45]!==i?(ue=u.step==="variants"&&s.jsx(G,{disabled:!b.size||P||n,onClick:()=>{L()},children:i(P?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=L,e[42]=P,e[43]=b,e[44]=u.step,e[45]=i,e[46]=ue):ue=e[46];const ce=P||n;let Se;e[47]!==i?(Se=i("settings.themeImport.chooseFile"),e[47]=i,e[48]=Se):Se=e[48];let ie;e[49]!==a||e[50]!==ce||e[51]!==Se?(ie=s.jsx(G,{variant:"outline",className:"self-start",disabled:ce,onClick:a,children:Se}),e[49]=a,e[50]=ce,e[51]=Se,e[52]=ie):ie=e[52];let be;e[53]!==ue||e[54]!==ie?(be=s.jsxs(s.Fragment,{children:[ue,ie]}),e[53]=ue,e[54]=ie,e[55]=be):be=e[55],F=be,N=s.jsx(s.Fragment,{children:u.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(We,{autoFocus:!0,"aria-label":i("settings.themeImport.search"),placeholder:i("settings.themeImport.search"),value:p,maxLength:160,onChange:ae=>f(ae.target.value)}),s.jsxs("div",{className:c?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[u.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:i("common.loading")}),u.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}),u.status==="ready"&&!u.results.length&&s.jsx("p",{className:"text-muted-foreground",children:i("settings.themeImport.empty")}),u.results.map(ae=>s.jsxs(G,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{$(ae)},children:[s.jsx(Lv,{extension:ae}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ae.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ae.namespace})]})]},`${ae.namespace}.${ae.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(G,{variant:"ghost",size:"sm",className:"justify-start",disabled:P||u.step==="package"&&u.status==="loading",onClick:()=>v({step:"search",status:"idle",results:[]}),children:[s.jsx(z,{name:"arrow-left",className:"size-4"}),i("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:u.extension.label}),T==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.partialError")}),u.step==="package"?u.status==="loading"?s.jsx("p",{role:"status",children:i("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[u.variants.length>1&&s.jsx(G,{variant:"ghost",size:"sm",className:"self-start",disabled:P||n||!Y.length,onClick:()=>k(de?new Set:new Set(Y.map(Uv))),children:i(de?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:c?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:u.variants.map(ae=>s.jsxs("div",{className:"flex items-center gap-3",children:[ae.status==="ready"&&s.jsxs("div",{"aria-hidden":"true",className:"flex w-20 shrink-0 items-center gap-2 rounded px-2 py-3",style:{backgroundColor:ae.theme.colors.surface.background,color:ae.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ae.theme.colors.syntax.base.keyword,ae.theme.colors.syntax.base.string,ae.theme.colors.syntax.base.function].map(_v)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[I.has(ae.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(z,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ae.name})]}):s.jsx(gt,{checked:b.has(ae.key),disabled:ae.status!=="ready"||P||n,label:ae.name,onChange:pe=>k(je=>{const De=new Set(je);return pe?De.add(ae.key):De.delete(ae.key),De})}),s.jsx("p",{className:I.has(ae.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ae.status!=="ready"?i("settings.themeImport.error.invalid"):I.has(ae.key)?i("settings.themeImport.installed"):i(ae.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ae.key))})]})]})}),e[9]=n,e[10]=h,e[11]=c,e[12]=a,e[13]=p,e[14]=T,e[15]=I,e[16]=P,e[17]=b,e[18]=u.extension,e[19]=u.results,e[20]=u.status,e[21]=u.step,e[22]=u.variants,e[23]=i,e[24]=F,e[25]=N}else F=e[24],N=e[25];const R=N;if(c){let $;e[56]!==i?($=i("settings.themeImport.catalogTitle"),e[56]=i,e[57]=$):$=e[57];let ee;e[58]!==F?(ee=s.jsx("div",{className:"flex flex-col gap-2",children:F}),e[58]=F,e[59]=ee):ee=e[59];let L;e[60]!==i?(L=i("settings.themeImport.catalogHint"),e[60]=i,e[61]=L):L=e[61];let Y;e[62]!==L?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:L}),e[62]=L,e[63]=Y):Y=e[63];let oe;e[64]!==R||e[65]!==Y?(oe=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[Y,R]}),e[64]=R,e[65]=Y,e[66]=oe):oe=e[66];let de;return e[67]!==r||e[68]!==ee||e[69]!==oe||e[70]!==$?(de=s.jsx($c,{open:!0,title:$,onClose:r,footer:ee,children:oe}),e[67]=r,e[68]=ee,e[69]=oe,e[70]=$,e[71]=de):de=e[71],de}let U;e[72]!==r?(U=$=>{$||r()},e[72]=r,e[73]=U):U=e[73];let K;e[74]===Symbol.for("react.memo_cache_sentinel")?(K={forceRender:!0},e[74]=K):K=e[74];let W;e[75]!==i?(W=i("settings.themeImport.catalogTitle"),e[75]=i,e[76]=W):W=e[76];let te;e[77]!==W?(te=s.jsx(Vt,{children:W}),e[77]=W,e[78]=te):te=e[78];let Q;e[79]!==i?(Q=i("settings.themeImport.catalogHint"),e[79]=i,e[80]=Q):Q=e[80];let H;e[81]!==Q?(H=s.jsx(Ht,{children:Q}),e[81]=Q,e[82]=H):H=e[82];let _;e[83]!==te||e[84]!==H?(_=s.jsxs(Bt,{children:[te,H]}),e[83]=te,e[84]=H,e[85]=_):_=e[85];let V;e[86]!==F||e[87]!==R||e[88]!==_?(V=s.jsxs(Ut,{className:"max-w-lg",backdropProps:K,children:[_,R,F]}),e[86]=F,e[87]=R,e[88]=_,e[89]=V):V=e[89];let X;return e[90]!==V||e[91]!==U?(X=s.jsx(_t,{open:!0,onOpenChange:U,children:V}),e[90]=V,e[91]=U,e[92]=X):X=e[92],X}function _v(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function Uv(t){return t.key}function zv(t){return t.isMobile}function $v(){const{t}=Ze(),{importTheme:e,customThemesLoading:a}=fa(),n=jo(),[r,i]=o.useState(!1),l=o.useCallback(()=>i(!1),[]),d=o.useRef(null),c=o.useRef(0),h=o.useRef(null),[p,f]=o.useState(!1);o.useEffect(()=>rr(()=>{c.current+=1,i(!1)}),[]);const m=async(w,b)=>{f(!0);try{if(w.size>zc)throw new ra("size");const k=await w.text();if(b.key!==jn()||b.generation!==c.current)throw new ra("connection");const g=await e(kd(k,w.name));Ha.success(t("settings.themeImport.success",{name:g.metadata.name})),i(!1)}catch(k){const g=k instanceof ra?k.code:"invalid";Ha.error(t(`settings.themeImport.error.${g}`))}finally{f(!1)}},u=async()=>{if(p)return;const w={key:jn(),generation:c.current};if(h.current=w,!n.themeFiles){d.current?.click();return}f(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const k=b.file;await m({name:k.name,size:k.size,text:async()=>k.text},w)}return}d.current?.click()}catch{Ha.error(t("settings.themeImport.error.invalid"))}finally{f(!1)}},v=async w=>{const b=w.target.files?.[0];w.target.value="",b&&!p&&h.current&&await m(b,h.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(G,{variant:"outline",size:"sm",disabled:p||a,onClick:()=>i(!0),children:[s.jsx(z,{name:p?"loader":"add",className:p?"size-3.5 animate-spin":"size-3.5"}),t(p?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(qt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:d,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:v}),r&&s.jsx(Kv,{pickFile:()=>{u()},fileBusy:p,onClose:l})]})}const ic=(t,e,a)=>{const n=t?.querySelector("[cmdk-list]"),r=t?.querySelector(`[cmdk-item][data-value="${CSS.escape(e)}"]`);if(!n||!r)return;const i=n.getBoundingClientRect(),l=n.offsetHeight>0?i.height/n.offsetHeight:1;if(l<=0)return;const d=r.getBoundingClientRect(),c=(d.top-i.top)/l+n.scrollTop,h=d.height/l;a?.onlyIfHidden&&c>=n.scrollTop&&c+h<=n.scrollTop+n.clientHeight||(n.scrollTop=Math.max(0,c-(n.clientHeight-h)/2))};function rc({options:t,value:e,onValueChange:a,placeholder:n,ariaLabel:r}){const{t:i}=Ze(),{deleteImportedTheme:l,customThemeIds:d}=fa(),{isMobile:c}=Qn(),[h,p]=o.useState(!1),[f,m]=o.useState(""),[u,v]=o.useState(void 0),[w,b]=o.useState(null),k=o.useRef(null),g=o.useRef(null),[I,C]=o.useState(null),[P,j]=o.useState(null),T=o.useCallback(R=>{const U=R instanceof HTMLElement?R:null,K=U?.closest('[data-slot="dialog-content"], [role="dialog"]');C(K instanceof HTMLElement?K:null),j(U?.closest("main")??null)},[]);o.useEffect(()=>{if(h)return wu.suspend()},[h]);const x=o.useRef(e);x.current=e;const A=o.useCallback(R=>{R&&ic(R,x.current)},[]),M=t.find(R=>R.id===e),S=o.useMemo(()=>h?gi(t,f,R=>[R.label]):t,[h,t,f]),D=R=>{a(R),p(!1)},O=async R=>{if(!w){b(R.id);try{await l(R.id),k.current?.focus()}catch{Ha.error(i("settings.themeImport.deleteError"))}finally{b(null)}}},F=R=>{if(!d.includes(R.id))return null;const U=w===R.id;return s.jsx(G,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:U,"aria-label":i("settings.themeImport.delete",{name:R.label}),onPointerDown:K=>K.stopPropagation(),onClick:K=>{K.stopPropagation(),O(R)},children:s.jsx(z,{name:U?"loader":"delete-bin",className:U?"size-4 animate-spin":"size-4"})})},N=s.jsx("div",{role:"status",className:"px-3 py-6 text-center typography-ui-label text-muted-foreground",children:i("settings.openchamber.visual.field.noThemesFound")});return c?s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button","aria-label":r,"aria-haspopup":"dialog",className:Ie(Ws,!M&&"text-muted-foreground"),onClick:()=>{m(""),p(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M?.label??n}),s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx($c,{open:h,title:r,onClose:()=>p(!1),children:s.jsxs("div",{className:"flex flex-col gap-2 px-3 pb-4 pt-1",children:[s.jsx(We,{value:f,onChange:R=>m(R.target.value),placeholder:i("settings.openchamber.visual.field.searchThemes"),"aria-label":i("settings.openchamber.visual.field.searchThemes"),className:"h-9"}),s.jsx("div",{className:"flex flex-col",role:"listbox","aria-label":r,children:S.length===0?N:S.map(R=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{type:"button",role:"option","aria-selected":R.id===e,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]",onClick:()=>D(R.id),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R.label}),R.id===e?s.jsx(z,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),F(R)]},R.id))})]})})]}):s.jsxs(ep,{open:h,onOpenChange:R=>{m(""),v(R?e:void 0),p(R)},onOpenChangeComplete:R=>{if(!R){g.current?.focus();return}k.current?.focus(),ic(k.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs(tp,{ref:g,"aria-label":r,"aria-haspopup":"dialog",className:Ie(Ws,!M&&"text-muted-foreground"),onPointerDownCapture:R=>T(R.currentTarget),onFocusCapture:R=>T(R.currentTarget),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M?.label??n}),s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(sp,{container:I??void 0,children:s.jsx(np,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:P??void 0,className:"z-[120]",children:s.jsx(ap,{role:"dialog","aria-label":r,className:Ie(Au,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(ku,{ref:A,className:"min-h-0 flex-1",shouldFilter:!1,value:u,onValueChange:v,children:[s.jsx(Nu,{ref:k,"aria-label":i("settings.openchamber.visual.field.searchThemes"),placeholder:i("settings.openchamber.visual.field.searchThemes"),value:f,onValueChange:m,onKeyDown:R=>{if(Su(R)){R.stopPropagation();return}Cu(R,U=>{R.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:U,bubbles:!0,cancelable:!0}))})}}),s.jsx(Iu,{label:r,className:"max-h-[20rem] p-1",children:S.length===0?N:S.map(R=>s.jsxs(Pu,{value:R.id,onSelect:D,"aria-current":R.id===e?!0:void 0,className:"max-w-full typography-ui-label",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R.label}),R.id===e?s.jsx(z,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,F(R)]},R.id))})]})})})})]})}const Bv=[{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"}],Vv=[{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"}],Hv=[{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"}],ni="OpenChamber - AI Coding Assistant",oc=[{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"}],lc=[{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"}],qr=t=>t==="portrait"||t==="landscape"?t:"system",qv=[{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"}],Gv=[{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"}],cc=[{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"}],Wv=[{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"}],dc=[{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"}],uc=[{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"}],Jv=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Qv=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],Yv=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],Zv=t=>t==="markdown"?"markdown":"plain",Xv=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],ey=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],or=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=Ze(),l=o.useCallback(y=>i(y),[i]),{isMobile:d}=Qn(),{terminal:c}=jo(),{browserTab:h}=Mm(),p=um(),f=fe(y=>y.showReasoningTraces),m=fe(y=>y.sessionRecapEnabled),u=fe(y=>y.sessionSuggestionEnabled),v=fe(y=>y.setSessionRecapEnabled),w=fe(y=>y.setSessionSuggestionEnabled),b=fe(y=>y.sessionGoalEnabled),k=fe(y=>y.setSessionGoalEnabled),g=fe(y=>y.sessionGoalDefaultBudgetEnabled),I=fe(y=>y.setSessionGoalDefaultBudgetEnabled),C=fe(y=>y.sessionGoalDefaultBudget),P=fe(y=>y.setSessionGoalDefaultBudget),j=fe(y=>y.setShowReasoningTraces),T=fe(y=>y.streamingAutoFollowEnabled),x=fe(y=>y.setStreamingAutoFollowEnabled),A=fe(y=>y.collapsibleThinkingBlocks),M=fe(y=>y.setCollapsibleThinkingBlocks),S=sl(y=>y.animatedActivityIndicators),D=sl(y=>y.setAnimatedActivityIndicators),O=fe(y=>y.mermaidRenderingMode),F=fe(y=>y.setMermaidRenderingMode),N=fe(y=>y.userMessageRenderingMode),R=fe(y=>y.setUserMessageRenderingMode),U=fe(y=>y.collapsibleUserMessages),K=fe(y=>y.setCollapsibleUserMessages),W=fe(y=>y.stickyUserHeader),te=fe(y=>y.promptNavigatorEnabled),Q=fe(y=>y.setStickyUserHeader),H=fe(y=>y.setPromptNavigatorEnabled),_=fe(y=>y.autoSaveEnabled),V=fe(y=>y.setAutoSaveEnabled),X=fe(y=>y.wideChatLayoutEnabled),$=fe(y=>y.setWideChatLayoutEnabled),ee=fe(y=>y.codeBlockLineWrap),L=fe(y=>y.setCodeBlockLineWrap),Y=fe(y=>y.chatRenderMode),oe=fe(y=>y.setChatRenderMode),de=fe(y=>y.activityRenderMode),ue=fe(y=>y.setActivityRenderMode),ce=fe(y=>y.fontSize),Se=fe(y=>y.setFontSize),ie=fe(y=>y.terminalFontSize),be=fe(y=>y.setTerminalFontSize),ae=fe(y=>y.terminalShell),pe=fe(y=>y.setTerminalShell),je=fe(y=>y.terminalLoginShells),De=fe(y=>y.setTerminalLoginShells),me=fe(y=>y.editorFontSize),$e=fe(y=>y.setEditorFontSize),Ge=fe(y=>y.uiFont),xe=fe(y=>y.setUiFont),Pe=fe(y=>y.monoFont),J=fe(y=>y.setMonoFont),se=fe(y=>y.padding),he=fe(y=>y.setPadding),ve=fe(y=>y.inputBarOffset),Fe=fe(y=>y.setInputBarOffset),Ke=fe(y=>y.mobileKeyboardMode),Be=fe(y=>y.setMobileKeyboardMode),ze=fe(y=>y.diffLayoutPreference),_e=fe(y=>y.setDiffLayoutPreference),Me=fe(y=>y.showTerminalQuickKeysOnDesktop),tt=fe(y=>y.sessionTabsEnabled),pt=fe(y=>y.setSessionTabsEnabled),ct=fe(y=>y.setShowTerminalQuickKeysOnDesktop),dt=fe(y=>y.fileEditorKeymap),ht=fe(y=>y.setFileEditorKeymap),Ue=nl(y=>y.followUpBehavior),st=nl(y=>y.setFollowUpBehavior),ut=Di(y=>y.scope),ye=Di(y=>y.entryLimit),re=Di(y=>y.applyScope),Te=Di(y=>y.applyEntryLimit),Ne=fe(y=>y.persistChatDraft),Ae=fe(y=>y.setPersistChatDraft),q=fe(y=>y.inputSpellcheckEnabled),Le=fe(y=>y.setInputSpellcheckEnabled),Qe=fe(y=>y.largeTextPasteBehavior),lt=fe(y=>y.setLargeTextPasteBehavior),ot=fe(y=>y.enterToSend),bt=fe(y=>y.setEnterToSend),wt=fe(y=>y.enterToSendConfigured),jt=fe(y=>y.setEnterToSendConfigured),vt=wt?ot:!d,Xe=fe(y=>y.showToolFileIcons),kt=fe(y=>y.setShowToolFileIcons),Re=fe(y=>y.showTurnChangedFiles),Ve=fe(y=>y.setShowTurnChangedFiles),Z=fe(y=>y.showExpandedBashTools),ge=fe(y=>y.setShowExpandedBashTools),Oe=fe(y=>y.showExpandedEditTools),Ee=fe(y=>y.setShowExpandedEditTools),Ye=fe(y=>y.timeFormatPreference),ne=fe(y=>y.setTimeFormatPreference),we=fe(y=>y.weekStartPreference),nt=fe(y=>y.setWeekStartPreference),Rt=fe(y=>y.showSplitAssistantMessageActions),Jt=fe(y=>y.setShowSplitAssistantMessageActions),Ce=fe(y=>y.allowPromptingSubagentSessions),He=fe(y=>y.setAllowPromptingSubagentSessions),yt=fe(y=>y.draftStartersVisible),It=fe(y=>y.setDraftStartersVisible),Qt=it(y=>y.settingsMessageStreamTransport),Xt=it(y=>y.setSettingsMessageStreamTransport),ts=Qt,es=it(y=>y.settingsDefaultFileViewerPreview),Fs=it(y=>y.setSettingsDefaultFileViewerPreview),Qs=fe(y=>y.isSettingsDialogOpen),{themeMode:pn,setThemeMode:Ls,availableThemes:Ks,customThemesLoading:on,reloadCustomThemes:Ys,lightThemeId:Zs,darkThemeId:_s,setLightThemePreference:Tn,setDarkThemePreference:Mt}=fa(),[Gt,Kt]=o.useState(!1),Et=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),is=fe(y=>y.dockBadgeEnabled),ss=fe(y=>y.setDockBadgeEnabled),lr=fe(y=>y.alwaysShowScrollbars===!0),cr=fe(y=>y.setAlwaysShowScrollbars),dr=mm(),ur=fe(y=>y.desktopWindowControlsPosition),vi=fe(y=>y.setDesktopWindowControlsPosition),mr=fe(y=>y.desktopWindowControlsStyle),yi=fe(y=>y.setDesktopWindowControlsStyle),[pr,Bs]=o.useState(0),Qa=fe(y=>y.reportUsage),ji=fe(y=>y.setReportUsage),wi=o.useCallback(y=>{ji(y),ft({reportUsage:y})},[ji]),gr=o.useCallback(y=>{vi(y),ft({desktopWindowControlsPosition:y})},[vi]),hr=o.useCallback(y=>{yi(y),ft({desktopWindowControlsStyle:y})},[yi]),ki=(Qs||d||fs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!ki)return;let y=null,xt=Date.now();const ps=()=>{const bn=Date.now();bn-xt>=420&&(Bs(Zn=>(Zn+1)%24),xt=bn),y=requestAnimationFrame(ps)};(typeof document>"u"||document.visibilityState==="visible")&&(y=requestAnimationFrame(ps));const Es=()=>{document.visibilityState==="visible"&&y===null?y=requestAnimationFrame(ps):document.visibilityState!=="visible"&&y!==null&&(cancelAnimationFrame(y),y=null)};return document.addEventListener("visibilitychange",Es),()=>{document.removeEventListener("visibilitychange",Es),y!==null&&cancelAnimationFrame(y)}},[ki]);const fr=o.useCallback(y=>{R(y),ft({userMessageRenderingMode:y})},[R]),xr=o.useCallback(y=>{Q(y),ft({stickyUserHeader:y})},[Q]),js=o.useCallback(y=>{H(y),ft({promptNavigatorEnabled:y})},[H]),ln=o.useCallback(y=>{It(y),ft({draftStartersVisible:y})},[It]),ba=o.useCallback(y=>{K(y),ft({collapsibleUserMessages:y})},[K]),En=o.useCallback(y=>{$(y),ft({wideChatLayoutEnabled:y})},[$]),$n=o.useCallback(y=>{Jt(y),ft({showSplitAssistantMessageActions:y})},[Jt]),_o=o.useCallback(y=>{Le(y),ft({inputSpellcheckEnabled:y})},[Le]),cn=o.useCallback(y=>{bt(y),jt(!0),ft({enterToSend:y,enterToSendConfigured:!0})},[bt,jt]),br=o.useCallback(y=>{oe(y),ft({chatRenderMode:y})},[oe]),va=o.useCallback(y=>{Xt(y),ft({messageStreamTransport:y})},[Xt]),ya=o.useCallback(y=>{re(y),ft({inputHistoryScope:y})},[re]),Yn=o.useCallback(y=>{const xt=Math.round(y);pm(xt)&&(Te(xt),ft({inputHistoryLimit:xt}))},[Te]),Ya=o.useCallback(y=>{ue(y),ft({activityRenderMode:y})},[ue]),vr=o.useCallback(y=>{F(y),ft({mermaidRenderingMode:y})},[F]),ds=o.useCallback(y=>{kt(y),ft({showToolFileIcons:y})},[kt]),yr=o.useCallback(y=>{Ve(y),ft({showTurnChangedFiles:y})},[Ve]),ja=o.useCallback(y=>{Fs(y),ft({defaultFileViewerPreview:y}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:y}}))},[Fs]),wa=o.useCallback(y=>{ge(y),ft({showExpandedBashTools:y})},[ge]),jr=o.useCallback(y=>{Ee(y),ft({showExpandedEditTools:y})},[Ee]),Ni=o.useCallback(y=>{ne(y),ft({timeFormatPreference:y})},[ne]),wr=o.useCallback(y=>{nt(y),ft({weekStartPreference:y})},[nt]),Bn=o.useMemo(()=>Ks.filter(y=>y.metadata.variant==="light").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ks]),gn=o.useMemo(()=>Ks.filter(y=>y.metadata.variant==="dark").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ks]),ka=o.useMemo(()=>Bn.find(y=>y.metadata.id===Zs)??Bn[0],[Bn,Zs]),Si=o.useMemo(()=>gn.find(y=>y.metadata.id===_s)??gn[0],[gn,_s]),Na=o.useCallback((y,xt)=>{const ps=xt==="dark"?" Dark":" Light";return y.endsWith(ps)?y.slice(0,-ps.length):y},[]),Sa=o.useMemo(()=>Bn.map(y=>({id:y.metadata.id,label:Na(y.metadata.name,"light")})),[Bn,Na]),kr=o.useMemo(()=>gn.map(y=>({id:y.metadata.id,label:Na(y.metadata.name,"dark")})),[gn,Na]),ke=y=>y==="enterToSend"&&d?!1:t?t.includes(y):!0,Ss=fs(),Ca=ke("theme")&&!Ss,Ci=ke("windowControlsPosition")&&dr,Ii=ke("theme")||ke("timeFormat")||ke("weekStart"),Pi=Ss?Ii:ke("theme")||Ci||ke("pwaInstallName")||ke("pwaOrientation")||ke("timeFormat")||ke("weekStart"),Ai=ke("fontSize")||ke("terminalFontSize")||ke("editorFontSize")||ke("spacing")||ke("scrollbars")&&!Ca||ke("inputBarOffset")&&d,Ti=ke("terminalQuickKeys")&&!d||(ke("terminalShell")||ke("terminalLoginShell"))&&!Ss||ke("fileEditorKeymap")||ke("autoSaveEnabled")||ke("sessionTabs")&&!Ss&&!d,Nr=ke("mermaidRendering")||ke("sessionGoal")&&!Ss||ke("userMessageRendering")||ke("chatRenderMode")||ke("messageTransport")||ke("activityRenderMode")||ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("codeBlockLineWrap")||ke("splitAssistantMessageActions")||ke("subagentReadOnlyBanner")||ke("diffLayout")||ke("dotfiles")||ke("fileViewerPreview")||ke("reasoning")||ke("followUpBehavior")||ke("inputHistoryScope")||ke("inputHistoryLimit")||ke("persistDraft")||ke("largeTextPaste")||ke("showToolFileIcons")||ke("expandedTools")||!d&&ke("inputSpellcheck")||ke("enterToSend"),hn=ke("chatRenderMode")||ke("activityRenderMode"),Vn=ke("messageTransport"),Ia=ke("userMessageRendering")||ke("mermaidRendering")||ke("diffLayout")&&!Ss||ke("followUpBehavior")||ke("inputHistoryScope")||ke("inputHistoryLimit"),Sr=ke("sessionAssist")||ke("sessionGoal")&&!Ss||ke("subagentReadOnlyBanner")||ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("codeBlockLineWrap")||ke("splitAssistantMessageActions")||ke("dotfiles")||ke("fileViewerPreview")||ke("persistDraft")||ke("largeTextPaste")||ke("showToolFileIcons")||ke("showTurnChangedFiles")||!d&&ke("inputSpellcheck")||ke("enterToSend")||ke("reasoning")||ke("expandedTools"),E=Pi||Ai||Ti,le=ke("pwaInstallName")&&da()&&h&&!ls()&&!Ss,Je=ke("pwaOrientation")&&da()&&!ls()&&!Ss,rt=ke("mobileKeyboardMode")&&da()&&!ls()&&!Ss&&gm(),Ft=(ke("terminalShell")||ke("terminalLoginShell"))&&!Ss,[xs,Xs]=o.useState([]),[ms,Us]=o.useState(0);o.useEffect(()=>rr(()=>{Xs([]),Us(y=>y+1)}),[]),o.useEffect(()=>{let y=!1;if(!(!Ft||!c.listShells))return c.listShells().then(xt=>{y||Xs(xt)}).catch(()=>{y||Xs([])}),()=>{y=!0}},[Ft,c,ms]);const Dn=o.useMemo(()=>{const y=xs.filter(xt=>xt.id!=="auto");return ae==="auto"||y.some(xt=>xt.id===ae)?y:[{id:ae,name:ae,supportsLogin:!1},...y]},[xs,ae]),fn=xs.find(y=>y.id===ae)?.supportsLogin===!0,Pa=je.includes(ae),Aa=y=>{De(y?[...je.filter(xt=>xt!==ae),ae]:je.filter(xt=>xt!==ae))},[Lt,Yt]=o.useState(""),[xn,dn]=o.useState("system"),Zt=o.useMemo(()=>{const y=dc.find(xt=>xt.id===Ye);return l(y?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Ye,l]),Cs=o.useMemo(()=>{const y=uc.find(xt=>xt.id===we);return l(y?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[we,l]),Ta=o.useMemo(()=>{const y=oc.find(xt=>xt.id===xn);return y?l(y.labelKey):void 0},[xn,l]),Ea=o.useMemo(()=>{const y=lc.find(xt=>xt.id===Ke);return y?l(y.labelKey):void 0},[Ke,l]),Da=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,Es=y.trim().replace(/\s+/g," ").slice(0,64);if(await ft({pwaAppName:Es}),typeof xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const bn=xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Es);Yt(bn);return}Yt(Es||ni),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Uo=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,ps=qr(y);if(await ft({pwaOrientation:ps}),typeof xt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Es=xt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ps);dn(Es);return}dn(ps),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!le&&!Je&&!rt)return;let y=!1;return(async()=>{try{const ps=await An();if(!ps){y||Yt(ni);return}const bn=(ps.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Zn=qr(ps.pwaOrientation),Ei=ll(ps.mobileKeyboardMode);y||(le&&Yt(bn||ni),Je&&dn(Zn),rt&&Be(Ei))}catch{y||(le&&Yt(ni),Je&&dn("system"),rt&&Be("native"))}})(),()=>{y=!0}},[Be,rt,le,Je]);const Cr=ke("scrollbars")?s.jsx(gt,{checked:lr,onChange:cr,label:i("settings.openchamber.visual.field.alwaysShowScrollbars"),info:i("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Pi&&s.jsxs("div",{className:"space-y-0",children:[Ca&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Rn,{children:[s.jsx("div",{className:Rs,children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.colorMode"),children:Bv.map(y=>s.jsx(ks,{selected:pn===y.value,onSelect:()=>Ls(y.value),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.value))})}),s.jsxs("div",{className:Rs,children:[s.jsx(Ot,{label:i("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(rc,{options:Sa,value:ka?.metadata.id??"",onValueChange:Tn,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Ot,{label:i("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(rc,{options:kr,value:Si?.metadata.id??"",onValueChange:Mt,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectDarkThemeAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:on||Gt,onClick:()=>{const y=Date.now();Kt(!0),Ys().finally(()=>{const xt=Date.now()-y;if(xt<500){window.setTimeout(()=>{Kt(!1)},500-xt);return}Kt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(z,{name:"restart",className:Ie("h-3.5 w-3.5",Gt&&"animate-spin")}),i(Gt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(qt,{children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx($v,{})]})]}),Et&&s.jsx(Wa,{settingsItem:"appearance.dock-badge",children:s.jsx(gt,{checked:is,onChange:ss,label:i("settings.openchamber.visual.field.dockBadge"),info:i("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:i("settings.openchamber.visual.field.dockBadge")})}),Cr&&s.jsx(Wa,{children:Cr})]}),Ci&&s.jsx(qe,{title:i("settings.openchamber.desktopNetwork.field.windowControls"),info:i("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Ca,children:s.jsxs(Rn,{children:[s.jsx(Ot,{label:i("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(mn,{value:ur,options:Xv.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:gr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Ot,{label:i("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(mn,{value:mr,options:ey.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:hr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ii&&s.jsx(qe,{title:i("settings.openchamber.visual.section.localization"),children:s.jsxs(Rn,{children:[s.jsx(Ot,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Tt,{value:e,onValueChange:y=>n(y),children:[s.jsx(Pt,{"aria-label":i("settings.appearance.language.select"),size:$t,className:Ra,children:s.jsx(zt,{children:r(e)})}),s.jsx(At,{children:a.map(y=>s.jsx(mt,{value:y,children:r(y)},y))})]})}),(ke("timeFormat")||ke("weekStart"))&&s.jsxs("div",{className:Rs,children:[ke("timeFormat")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Tt,{value:Ye,onValueChange:y=>Ni(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),size:$t,className:Ra,children:s.jsx(zt,{children:Zt})}),s.jsx(At,{children:dc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})}),ke("weekStart")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Tt,{value:we,onValueChange:y=>wr(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),size:$t,className:Ra,children:s.jsx(zt,{children:Cs})}),s.jsx(At,{children:uc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})})]})]})}),(le||Je||rt)&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.appInstall"),contentClassName:Rs,children:[le&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.installAppName"),info:i("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Ps,children:[s.jsx(We,{value:Lt,onChange:y=>{Yt(y.target.value)},onBlur:()=>{Da(Lt)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),Da(Lt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Yt(ni),Da("")},className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),Je&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.installOrientation"),description:i("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Ps,children:[s.jsxs(Tt,{value:xn,onValueChange:y=>{const xt=qr(y);dn(xt),Uo(xt)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:$t,className:Go,children:s.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ta})}),s.jsx(At,{children:oc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{dn("system"),Uo("system")},disabled:xn==="system",className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),rt&&s.jsxs(Ct,{label:i("settings.openchamber.visual.field.mobileKeyboardMode"),info:i("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Ps,children:[s.jsxs(Tt,{value:Ke,onValueChange:y=>{const xt=ll(y);Be(xt),ft({mobileKeyboardMode:xt})},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:$t,className:Go,children:s.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ea})}),s.jsx(At,{children:lc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Be("native"),ft({mobileKeyboardMode:"native"})},disabled:Ke==="native",className:gs,"aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Ai&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.densityAndType"),contentClassName:Rs,children:[ke("fontSize")&&!d||ke("terminalFontSize")?s.jsxs(Rn,{children:[ke("fontSize")&&!d&&s.jsxs(Ot,{label:i("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Tt,{value:Ge,onValueChange:y=>xe(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),size:$t,className:Ra,children:s.jsx(zt,{children:al.find(y=>y.id===Ge)?.label})}),s.jsx(At,{children:al.map(y=>s.jsx(mt,{value:y.id,children:s.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(il),disabled:Ge===il,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),ke("terminalFontSize")&&s.jsxs(Ot,{label:i("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Tt,{value:Pe,onValueChange:y=>J(y),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),size:$t,className:Ra,children:s.jsx(zt,{children:rl.find(y=>y.id===Pe)?.label})}),s.jsx(At,{children:rl.map(y=>s.jsx(mt,{value:y.id,children:s.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>J(ol),disabled:Pe===ol,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ke("fontSize")&&!d||ke("terminalFontSize")||ke("editorFontSize")?s.jsxs(Rn,{children:[ke("fontSize")&&!d&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:ce,onValueChange:Se,min:50,max:200,step:5,className:vs,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Se(100),disabled:ce===100,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("terminalFontSize")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:ie,onValueChange:be,min:9,max:52,step:1,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(13),disabled:ie===13,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("editorFontSize")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:me,onValueChange:$e,min:9,max:32,step:1,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>$e(13),disabled:me===13,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ke("spacing")||ke("inputBarOffset")&&d?s.jsxs(Rn,{children:[ke("spacing")&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:se,onValueChange:he,min:50,max:200,step:5,className:vs}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(100),disabled:se===100,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ke("inputBarOffset")&&d&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.inputBarOffset"),info:i("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:ve,onValueChange:Fe,min:0,max:100,step:5,className:vs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Fe(0),disabled:ve===0,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!Ca&&Cr]}),ke("animatedActivityIndicators")&&s.jsx(qe,{title:i("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:cs,children:s.jsx(gt,{checked:S,onChange:D,label:i("settings.openchamber.visual.field.animatedActivityIndicators"),ariaLabel:i("settings.openchamber.visual.field.animatedActivityIndicatorsAria"),info:i("settings.openchamber.visual.field.animatedActivityIndicatorsInfo"),settingsItem:"appearance.animated-activity-indicators"})}),Ti&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ke("fileEditorKeymap")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(y=>s.jsx(ks,{selected:dt===y,onSelect:()=>ht(y),label:i(`settings.openchamber.visual.option.fileEditorKeymap.${y}`),ariaLabel:i(`settings.openchamber.visual.option.fileEditorKeymap.${y}`)},y))})}),s.jsxs("div",{className:cs,children:[ke("autoSaveEnabled")&&s.jsx(gt,{checked:_,onChange:V,label:i("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:i("settings.openchamber.visual.field.autoSaveEnabledAria"),info:i("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Ft&&s.jsx(Ot,{label:i("settings.openchamber.visual.field.terminalShell"),info:i("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Tt,{value:ae,onValueChange:y=>{hm(y)&&pe(y)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.terminalShellAria"),size:$t,className:Ra,children:s.jsx(zt,{})}),s.jsxs(At,{children:[s.jsx(mt,{value:"auto",children:i("settings.openchamber.visual.option.terminalShell.auto")}),Dn.map(y=>s.jsx(mt,{value:y.id,children:y.name},y.id))]})]})}),Ft&&fn&&s.jsx(gt,{checked:Pa,onChange:Aa,label:i("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:i("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ke("terminalQuickKeys")&&!d&&s.jsx(gt,{checked:Me,onChange:ct,label:i("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:ua("ctrl"),alt:ua("alt")})})]}),ke("sessionTabs")&&!Ss&&!d&&s.jsx(ws,{title:i("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(gt,{checked:tt,onChange:pt,label:i("settings.openchamber.visual.field.sessionTabs"),ariaLabel:i("settings.openchamber.visual.field.sessionTabsAria"),info:i("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Nr&&s.jsxs(s.Fragment,{children:[hn&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.chatDisplay"),divider:E,contentClassName:"space-y-6",children:[ke("chatRenderMode")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Gv.map(y=>{const xt=Y===y.id,ps=pr%12;return s.jsxs("button",{type:"button",onClick:()=>br(y.id),"aria-pressed":xt,className:Ie("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",xt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:Ie("typography-ui-label",xt?"text-inherit":"text-muted-foreground"),children:l(y.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:y.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Es=>{const bn=Es*3+1,Zn=ps-bn+1,Ei=Zn<=0?0:Zn===1?42:Zn===2?68:92,Fd=Ei>0;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Fd?"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:`${Ei}%`}})]},Es)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Es=>{const bn=ps>=(Es+1)*3;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",bn?"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%"}})]},Es)})})})]},y.id)})})}),ke("activityRenderMode")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),children:Wv.map(y=>s.jsx(ks,{selected:de===y.id,onSelect:()=>Ya(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(y.labelKey)})},y.id))})})]}),Vn&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.messageStreamTransport"),divider:hn||E,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(mn,{value:ts,options:cc.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:va,"aria-label":i("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const y=cc.find(xt=>xt.id===ts);return y?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(y.descriptionKey)}):null})()]}),Ia&&s.jsx(qe,{title:i("settings.openchamber.visual.section.chatMessageOptions"),divider:hn||Vn||E,children:s.jsxs(Rn,{className:"lg:gap-y-6",children:[ke("userMessageRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),children:qv.map(y=>s.jsx(ks,{selected:Zv(N)===y.id,onSelect:()=>fr(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(y.labelKey)})},y.id))})}),ke("mermaidRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),children:Hv.map(y=>s.jsx(ks,{selected:O===y.id,onSelect:()=>vr(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(y.labelKey)})},y.id))})}),ke("diffLayout")&&!Ss&&s.jsx(ws,{title:i("settings.openchamber.visual.section.diffLayout"),children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),children:Vv.map(y=>s.jsx(ks,{selected:ze===y.id,onSelect:()=>_e(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(y.labelKey)})},y.id))})}),ke("followUpBehavior")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),children:Jv.map(y=>s.jsx(ks,{selected:Ue===y.id,onSelect:()=>st(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(y.labelKey)})},y.id))})}),ke("inputHistoryScope")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.inputHistoryScope"),info:i("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.section.inputHistoryScopeAria"),children:Yv.map(y=>s.jsx(ks,{selected:ut===y.id,onSelect:()=>ya(y.id),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.id))})}),ke("inputHistoryLimit")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.inputHistoryLimit"),description:i("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Ps,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:Oa,children:[s.jsx(hs,{value:ye,onValueChange:Yn,min:xm,max:fm,step:1,className:vs,deferExternalValueWhileFocused:!0,"aria-label":i("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Fa,children:i("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),Sr&&s.jsxs(s.Fragment,{children:[ke("expandedTools")&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:hn||Vn||Ia||E,contentClassName:cs,children:[s.jsx(gt,{checked:Z,onChange:wa,label:i("settings.openchamber.visual.field.bash"),ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:Oe,onChange:jr,label:i("settings.openchamber.visual.field.editTools"),ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(qe,{title:i("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:cs,children:[s.jsx(gt,{checked:yt,onChange:ln,label:i("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:i("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ke("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:m,onChange:v,label:i("settings.openchamber.visual.field.sessionRecap"),ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:u,onChange:w,label:i("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ke("subagentReadOnlyBanner")&&s.jsx(gt,{checked:Ce,onChange:He,label:i("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ke("sessionGoal")&&!Ss&&s.jsxs(qe,{title:i("settings.openchamber.visual.goal.sectionTitle"),info:i("settings.openchamber.visual.goal.description"),contentClassName:cs,children:[s.jsx(gt,{checked:b,onChange:k,label:i("settings.openchamber.visual.field.sessionGoal"),ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(gt,{checked:g,onChange:I,disabled:!b,label:i("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),b&&g?s.jsx(hs,{value:C,onValueChange:y=>{typeof y=="number"&&Number.isFinite(y)&&y>0&&P(Math.floor(y))},min:1e3,max:1e8,step:5e4}):null]})]}),ke("reasoning")&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:cs,children:[s.jsx(gt,{checked:f,onChange:j,label:i("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),f&&s.jsx(gt,{checked:A,onChange:M,label:i("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(qe,{title:i("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:cs,children:s.jsx(gt,{checked:T,onChange:x,label:i("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:i("settings.openchamber.visual.field.streamingAutoFollowAria"),info:i("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ke("collapsibleUserMessages")||ke("stickyUserHeader")||ke("promptNavigatorEnabled")||ke("wideChatLayout")||ke("splitAssistantMessageActions")||ke("codeBlockLineWrap"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:cs,children:[ke("collapsibleUserMessages")&&s.jsx(gt,{checked:U,onChange:ba,label:i("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ke("stickyUserHeader")&&s.jsx(gt,{checked:W,onChange:xr,label:i("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ke("promptNavigatorEnabled")&&s.jsx(gt,{checked:te,onChange:js,label:i("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ke("wideChatLayout")&&s.jsx(gt,{checked:X,onChange:En,label:i("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ke("splitAssistantMessageActions")&&s.jsx(gt,{checked:Rt,onChange:$n,label:i("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ke("codeBlockLineWrap")&&s.jsx(gt,{checked:ee,onChange:L,label:i("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ke("showToolFileIcons")||ke("showTurnChangedFiles")||ke("dotfiles")&&!fs()||ke("fileViewerPreview"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:cs,children:[ke("showToolFileIcons")&&s.jsx(gt,{checked:Xe,onChange:ds,label:i("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ke("showTurnChangedFiles")&&s.jsx(gt,{checked:Re,onChange:yr,label:i("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ke("dotfiles")&&!fs()&&s.jsx(gt,{checked:p,onChange:bm,label:i("settings.openchamber.visual.field.showDotfiles"),ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ke("fileViewerPreview")&&s.jsx(gt,{checked:es,onChange:ja,label:i("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ke("persistDraft")||ke("largeTextPaste")||!d&&ke("inputSpellcheck")||ke("enterToSend"))&&s.jsxs(qe,{title:i("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ke("persistDraft")||!d&&ke("inputSpellcheck"))&&s.jsxs("div",{className:cs,children:[ke("persistDraft")&&s.jsx(gt,{checked:Ne,onChange:Ae,label:i("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!d&&ke("inputSpellcheck")&&s.jsx(gt,{checked:q,onChange:_o,label:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ke("largeTextPaste")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.largeTextPaste"),info:i("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(sn,{"aria-label":i("settings.openchamber.visual.field.largeTextPasteAria"),children:Qv.map(y=>s.jsx(ks,{selected:Qe===y.id,onSelect:()=>lt(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(y.labelKey)})},y.id))})}),ke("enterToSend")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.enterToSend"),info:i("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(sn,{"aria-label":i("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(ks,{selected:vt,onSelect:()=>cn(!0),label:i("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(ks,{selected:!vt,onSelect:()=>cn(!1),label:i("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ke("reportUsage")&&s.jsx(qe,{title:i("settings.openchamber.visual.section.privacy"),children:s.jsx(gt,{checked:Qa,onChange:wi,label:i("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},ty=1,sy=365,mc=30,ny=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Nd=()=>{const t=at.c(105),{t:e}=Ze(),a=fe(ay),n=fe(iy),r=fe(ry),i=fe(oy),l=fe(ly),d=fe(cy),c=fe(dy);let h;t[0]===Symbol.for("react.memo_cache_sentinel")?(h={autoRun:!1},t[0]=h):h=t[0];const{candidates:p,isRunning:f,runCleanup:m,action:u,status:v}=Tu(h),w=p.length;let b;t[1]!==m||t[2]!==e?(b=async()=>{const pe=await m({force:!0}).catch(()=>(B.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!pe||pe.skippedReason&&pe.skippedReason!=="no-candidates")){if(pe.completedIds.length===0&&pe.failedIds.length===0){B.message(pe.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}pe.completedIds.length>0&&B.success(pe.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:pe.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:pe.completedIds.length})),pe.failedIds.length>0&&B.error(pe.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:pe.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:pe.failedIds.length}))}},t[1]=m,t[2]=e,t[3]=b):b=t[3];const k=b;let g;t[4]!==e?(g=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=g):g=t[5];const I=r?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let C;t[6]!==e||t[7]!==I?(C=e(I),t[6]=e,t[7]=I,t[8]=C):C=t[8];let P;t[9]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=P):P=t[10];let j;t[11]!==e?(j=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=j):j=t[12];let T;t[13]!==a||t[14]!==i||t[15]!==P||t[16]!==j?(T=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:P,ariaLabel:j}),t[13]=a,t[14]=i,t[15]=P,t[16]=j,t[17]=T):T=t[17];let x;t[18]!==e?(x=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=x):x=t[19];let A;t[20]!==e?(A=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=A):A=t[21];let M;t[22]!==e?(M=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=M):M=t[23];let S;t[24]!==f||t[25]!==r||t[26]!==c||t[27]!==M||t[28]!==x||t[29]!==A?(S=s.jsx(gt,{settingsItem:"sessions.retention-only-archived",checked:r,onChange:c,disabled:f,label:x,ariaLabel:A,info:M}),t[24]=f,t[25]=r,t[26]=c,t[27]=M,t[28]=x,t[29]=A,t[30]=S):S=t[30];let D;t[31]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=D):D=t[32];let O;t[33]!==e?(O=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=O):O=t[34];let F;t[35]===Symbol.for("react.memo_cache_sentinel")?(F=Ie(vs,"tabular-nums"),t[35]=F):F=t[35];let N;t[36]!==n||t[37]!==l||t[38]!==O?(N=s.jsx(hs,{value:n,onValueChange:l,min:ty,max:sy,step:1,"aria-label":O,className:F}),t[36]=n,t[37]=l,t[38]=O,t[39]=N):N=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=R):R=t[41];let U;t[42]!==R?(U=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:R}),t[42]=R,t[43]=U):U=t[43];let K;t[44]!==l?(K=()=>l(mc),t[44]=l,t[45]=K):K=t[45];const W=n===mc;let te;t[46]!==e?(te=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=te):te=t[47];let Q;t[48]!==e?(Q=e("settings.common.actions.reset"),t[48]=e,t[49]=Q):Q=t[49];let H;t[50]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=H):H=t[50];let _;t[51]!==K||t[52]!==W||t[53]!==te||t[54]!==Q?(_=s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:K,disabled:W,className:gs,"aria-label":te,title:Q,children:H}),t[51]=K,t[52]=W,t[53]=te,t[54]=Q,t[55]=_):_=t[55];let V;t[56]!==D||t[57]!==N||t[58]!==U||t[59]!==_?(V=s.jsxs(Ct,{settingsItem:"sessions.retention-period",label:D,children:[N,U,_]}),t[56]=D,t[57]=N,t[58]=U,t[59]=_,t[60]=V):V=t[60];let X;t[61]!==e?(X=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=X):X=t[62];let $;t[63]!==r||t[64]!==e?($=ny.map(pe=>({value:pe.value,label:e(pe.labelKey),disabled:r&&pe.value==="archive"})),t[63]=r,t[64]=e,t[65]=$):$=t[65];let ee;t[66]!==u||t[67]!==d||t[68]!==$?(ee=s.jsx(mn,{value:u,onChange:d,options:$}),t[66]=u,t[67]=d,t[68]=$,t[69]=ee):ee=t[69];let L;t[70]!==X||t[71]!==ee?(L=s.jsx(Ct,{settingsItem:"sessions.retention-action",label:X,children:ee}),t[70]=X,t[71]=ee,t[72]=L):L=t[72];let Y;t[73]!==S||t[74]!==V||t[75]!==L?(Y=s.jsxs(Wa,{className:"space-y-0",children:[S,V,L]}),t[73]=S,t[74]=V,t[75]=L,t[76]=Y):Y=t[76];let oe;t[77]!==e?(oe=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=oe):oe=t[78];let de;t[79]!==f||t[80]!==e?(de=e(f?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=f,t[80]=e,t[81]=de):de=t[81];let ue;t[82]!==k||t[83]!==f||t[84]!==de?(ue=s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:k,disabled:f,className:"!font-normal",children:de}),t[82]=k,t[83]=f,t[84]=de,t[85]=ue):ue=t[85];let ce;t[86]!==oe||t[87]!==ue?(ce=s.jsx(Ct,{label:oe,children:ue}),t[86]=oe,t[87]=ue,t[88]=ce):ce=t[88];let Se;t[89]!==u||t[90]!==w||t[91]!==v||t[92]!==e?(Se=v==="error"?e("sessions.sidebar.group.empty.loadFailed"):v!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):u==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:w}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:w}),t[89]=u,t[90]=w,t[91]=v,t[92]=e,t[93]=Se):Se=t[93];let ie;t[94]!==Se?(ie=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Se}),t[94]=Se,t[95]=ie):ie=t[95];let be;t[96]!==ce||t[97]!==ie?(be=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[ce,ie]}),t[96]=ce,t[97]=ie,t[98]=be):be=t[98];let ae;return t[99]!==g||t[100]!==Y||t[101]!==be||t[102]!==C||t[103]!==T?(ae=s.jsxs(qe,{title:g,info:C,children:[T,Y,be]}),t[99]=g,t[100]=Y,t[101]=be,t[102]=C,t[103]=T,t[104]=ae):ae=t[104],ae};function ay(t){return t.autoDeleteEnabled}function iy(t){return t.autoDeleteAfterDays}function ry(t){return t.sessionRetentionOnlyArchived}function oy(t){return t.setAutoDeleteEnabled}function ly(t){return t.setAutoDeleteAfterDays}function cy(t){return t.setSessionRetentionAction}function dy(t){return t.setSessionRetentionOnlyArchived}const pc=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(yo(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Sd=()=>{const{t}=Ze(),e=fe(T=>T.timeFormatPreference),[a,n]=o.useState(!1),[r,i]=o.useState(!0),[l,d]=o.useState(!1),[c,h]=o.useState(null),[p,f]=o.useState(!1),[m,u]=o.useState([]),[v,w]=o.useState(Eu),[b,k]=o.useState(""),g=o.useMemo(()=>Du(),[]),I=o.useCallback(async()=>{i(!0),k("");try{const T=await Mu();u(T)}catch(T){const x=T instanceof Error?T.message:t("settings.openchamber.passkeys.toast.loadFailed");k(x)}finally{i(!1)}},[t]);o.useEffect(()=>{let T=!1;return(async()=>{try{if(!g.supported){T||(n(!1),i(!1));return}T||n(!0)}catch{T||n(!1)}if(!T){const x=await Ar();if(w(x),!x.enabled){u([]),i(!1);return}await I()}})(),()=>{T=!0,Wo()}},[I,g.supported]);const C=o.useCallback(async()=>{if(!v.enabled){const T=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(T),B.message(T);return}if(!a){k(g.reason),B.message(g.reason);return}if(l){Wo(),d(!1);return}k(""),d(!0);try{await Ru(),w(await Ar()),await I(),B.success(t("settings.openchamber.passkeys.toast.added"))}catch(T){if(Ou(T)){B.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const x=T instanceof Error?T.message:t("settings.openchamber.passkeys.toast.addFailed");k(x),B.error(x)}finally{d(!1)}},[l,I,v.enabled,g.reason,a,t]),P=o.useCallback(async T=>{h(T),k("");try{await Fu(T),w(await Ar()),await I(),B.success(t("settings.openchamber.passkeys.toast.removed"))}catch(x){const A=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.removeFailed");k(A),B.error(A)}finally{h(null)}},[I,t]),j=o.useCallback(async()=>{f(!0),k("");try{await Lu(),window.location.reload()}catch(T){const x=T instanceof Error?T.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(x),B.error(x),f(!1)}},[t]);return s.jsxs(qe,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ct,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(G,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{C()},disabled:r||p,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{j()},disabled:r||l||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"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:g.reason}),r?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(T=>s.jsxs(Ct,{label:s.jsx("span",{title:T.label,children:T.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:T.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:pc(T.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:pc(T.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P(T.id)},disabled:c===T.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===T.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},T.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},Cd=()=>{const t=at.c(14),{t:e}=Ze(),a=Jo(uy),n=Jo(my);let r;t[0]!==e?(r=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=r):r=t[1];let i;t[2]!==e?(i=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=i):i=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(h=>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:`${h}://`}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(h),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${h}://`}),children:e("settings.common.actions.delete")})]},h)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let d;t[8]!==l?(d=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=d):d=t[9];let c;return t[10]!==r||t[11]!==i||t[12]!==d?(c=s.jsx(qe,{title:r,description:i,children:d}),t[10]=r,t[11]=i,t[12]=d,t[13]=c):c=t[13],c};function uy(t){return t.trustedSchemes}function my(t){return t.removeTrustedScheme}const py=()=>{const{t}=Ze(),[e,a]=o.useState(null),n=o.useRef(0);o.useEffect(()=>{let i=!1;return Gs.getConfig(null).then(l=>{!i&&n.current===0&&a(!!l.warming)},l=>console.warn("[session-warming] failed to read config",l)),()=>{i=!0}},[]);const r=o.useCallback(async i=>{const l=e,d=++n.current;a(i),os("saving");try{const c=await Nt("/api/config/warming",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({enabled:i})});if(!c.ok)throw new Error(`HTTP ${c.status}`);os("saved"),Gs.clearConfigCache()}catch(c){console.warn("[session-warming] failed to save",c),os("error"),d===n.current&&a(l)}},[e]);return s.jsx(gt,{settingsItem:"sessions.warming",checked:e??!1,disabled:e===null,onChange:i=>{r(i)},label:t("settings.openchamber.defaults.field.sessionWarming"),info:t("settings.openchamber.defaults.field.sessionWarmingInfo")})},Gr=t=>{const e=Ln(t);return e||{providerId:"",modelId:""}},Id=()=>{const{t}=Ze(),e=it(ie=>ie.setProvider),a=it(ie=>ie.setModel),n=it(ie=>ie.setAgent),r=it(ie=>ie.setCurrentVariant),i=it(ie=>ie.setCurrentVariantOverride),l=it(ie=>ie.setSettingsDefaultModel),d=it(ie=>ie.setSettingsDefaultVariant),c=it(ie=>ie.setSettingsDefaultAgent),h=it(ie=>ie.selectionSource==="manual"),p=Ku(ie=>ie.currentSessionId),f=Qo(ie=>ie.getSessionModelSelection),m=Qo(ie=>ie.getSessionAgentSelection),u=it(ie=>ie.agentSelectionSource==="manual"),w=!!(it(ie=>{if(ie.agentSelectionSource!=="manual")return!1;const be=ie.agents.find(ae=>ae.name===ie.currentAgentName);return!!(be?.model?.providerID&&be.model.id)})||h&&p&&f(p)),b=!!(u&&p&&m(p)),k=fe(ie=>ie.showDeletionDialog),g=fe(ie=>ie.setShowDeletionDialog),I=it(ie=>ie.providers),C=it(ie=>ie.modelsMetadata),[P,j]=o.useState(),[T,x]=o.useState(),[A,M]=o.useState(),[S,D]=o.useState(!0),[O,F]=o.useState(),[N,R]=o.useState([]),[U,K]=o.useState(),[W,te]=o.useState(!0),Q=o.useMemo(()=>Gr(P),[P]);o.useEffect(()=>{(async()=>{try{const be=await An();if(be){const ae=be.defaultModel?.trim()||void 0,pe=be.defaultVariant?.trim()||void 0,je=be.defaultAgent?.trim()||void 0;ae!==void 0&&j(ae),pe!==void 0&&x(pe),je!==void 0&&M(je),be.smallModelUseDefault!==void 0&&D(be.smallModelUseDefault);const De=be.smallModelOverride?.trim();De&&F(De);const me=be.walkthroughModelOverride?.trim();me&&K(me)}}catch(be){console.warn("Failed to load defaults settings:",be)}finally{te(!1)}})()},[]);const H=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;j(ae),x(void 0),d(void 0),l(ae),w||(r(void 0),ie&&be&&(I.find(je=>je.id===ie)||Wc(ie,be))&&(e(ie),a(be)));try{await ft({defaultModel:ae??"",defaultVariant:""})}catch(pe){console.warn("Failed to save default model:",pe)}},[w,I,r,a,e,l,d]),_="__default__",V=o.useCallback(ie=>ie===_?t("settings.openchamber.defaults.option.default"):ie.charAt(0).toUpperCase()+ie.slice(1),[t]),X=o.useCallback(async ie=>{const be=ie===_?void 0:ie||void 0;x(be),d(be),w||i(be??null,be);try{await ft({defaultVariant:be??""})}catch(ae){console.warn("Failed to save default variant:",ae)}},[w,i,d]),$=o.useCallback(async ie=>{const be=ie||void 0;M(be),c(be),ie&&!b&&n(ie);try{await ft({defaultAgent:be??""})}catch(ae){console.warn("Failed to save default agent:",ae)}},[b,n,c]),ee=o.useCallback(async ie=>{D(ie);try{await ft({smallModelUseDefault:ie})}catch(be){console.warn("Failed to save small model preference:",be)}},[]),L=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;F(ae);try{await ft({smallModelOverride:ae??""})}catch(pe){console.warn("Failed to save small model override:",pe)}},[]),Y=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;K(ae);try{await ft({walkthroughModelOverride:ae??""})}catch(pe){console.warn("Failed to save walkthrough model override:",pe)}},[]),oe=o.useCallback((ie,be)=>C.get(`${ie}/${be}`)?.structured_output!==!1,[C]),de=o.useMemo(()=>Gr(O),[O]),ue=o.useMemo(()=>Gr(U),[U]);o.useEffect(()=>{let ie=!1;return(async()=>{try{const be=await Nt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!be.ok)return;const ae=await be.json().catch(()=>null);!ie&&Array.isArray(ae?.authenticatedProviders)&&R(ae.authenticatedProviders.filter(pe=>typeof pe=="string"))}catch{}})(),()=>{ie=!0}},[]);const ce=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const be=I.find(ae=>ae.id===Q.providerId)?.models.find(ae=>ae.id===Q.modelId);return _u(be?.variants)},[Q.modelId,Q.providerId,I]),Se=ce.length>0;return W?null:s.jsx(s.Fragment,{children:s.jsx(qe,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,Se?` (${T??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),A&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:A})]})]}),s.jsxs("div",{children:[s.jsx(Ct,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ca,{providerId:Q.providerId,modelId:Q.modelId,onChange:H,className:Ws,offerAuto:!0})}),s.jsx(Ct,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Tt,{value:T??_,onValueChange:X,disabled:!Se,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:V(T??_)})}),s.jsxs(At,{children:[s.jsx(mt,{value:_,children:t("settings.openchamber.defaults.option.default")}),ce.map(ie=>s.jsx(mt,{value:ie,children:V(ie)},ie))]})]})}),s.jsx(Ct,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(fo,{agentName:A||"",onChange:$,filter:ie=>Kc(ie.mode),className:Ws})})]}),s.jsxs(Wa,{className:cs,children:[s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:k,onChange:g,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx(py,{})]}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(qt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:S,onChange:ie=>{ee(ie)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),S?null:s.jsx(Ct,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ca,{providerId:de.providerId,modelId:de.modelId,onChange:L,allowedProviderIds:N,className:Ws})}),s.jsxs(Wa,{className:cs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(qt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ct,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ca,{providerId:ue.providerId,modelId:ue.modelId,onChange:Y,allowedProviderIds:N,isModelAllowed:oe,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Ws})})]})]})]})})})},gc={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"}},gy={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"},hy=()=>{const{t}=Ze(),e=o.useMemo(()=>ls(),[]),a=o.useMemo(()=>fs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!a&&!n,i=fe(_=>_.nativeNotificationsEnabled),l=fe(_=>_.setNativeNotificationsEnabled),d=fe(_=>_.notificationMode),c=fe(_=>_.setNotificationMode),h=fe(_=>_.notifyOnSubtasks),p=fe(_=>_.setNotifyOnSubtasks),f=fe(_=>_.notifyOnCompletion),m=fe(_=>_.setNotifyOnCompletion),u=fe(_=>_.notifyOnError),v=fe(_=>_.setNotifyOnError),w=fe(_=>_.notifyOnQuestion),b=fe(_=>_.setNotifyOnQuestion),k=fe(_=>_.notificationTemplates),g=fe(_=>_.setNotificationTemplates),[I,C]=o.useState("default"),[P,j]=o.useState(!1),[T,x]=o.useState(!1),[A,M]=o.useState(!1);o.useEffect(()=>{if(!r){j(!1),x(!1);return}typeof Notification<"u"&&C(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(_),(async()=>{if(!_){x(!1);return}try{const X=await navigator.serviceWorker.getRegistration();if(!X){x(!1);return}const $=await X.pushManager.getSubscription();x(!!$)}catch{x(!1)}})()},[r]);const S=async _=>{if(e){l(_);return}if(!r){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();C(V),V==="granted"?l(!0):B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(V){console.error("Failed to request notification permission:",V),B.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&I==="granted"))},D=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",O=(_,V,X)=>{g($=>({...$,[_]:{...$[_],[V]:X}}))},F=_=>{const V="=".repeat((4-_.length%4)%4),X=(_+V).replace(/-/g,"+").replace(/_/g,"/"),$=atob(X),ee=new Uint8Array($.length);for(let L=0;L<$.length;L+=1)ee[L]=$.charCodeAt(L);return ee},N=async(_,V,X)=>{let $=null;const ee=new Promise((L,Y)=>{$=setTimeout(()=>{Y(new Error(X))},V)});try{return await Promise.race([_,ee])}finally{$&&clearTimeout($)}},R=async _=>{if(_.active)return;const V=_.installing||_.waiting;V&&V.state!=="activated"&&await N(new Promise(X=>{const $=()=>{V.state==="activated"&&(V.removeEventListener("statechange",$),X())};V.addEventListener("statechange",$),$()}),15e3,"Service worker activation timed out")},U=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 V=null;for(const X of _)try{const $=X.opts?navigator.serviceWorker.register("/sw.js",X.opts):navigator.serviceWorker.register("/sw.js");return await N($,1e4,`Service worker registration timed out (${X.label})`)}catch($){V=$}throw V instanceof Error?V:new Error("Service worker registration failed")},K=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const V=await U();try{await V.update()}catch{}return await R(V),V},W=_=>{const V=_,X=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let $="";try{$=JSON.stringify(_)}catch{}return{summary:X.filter(Boolean).join(" | "),json:$,stack:typeof V?.stack=="string"?V.stack:""}},te=async()=>{const _=Va();if(!_?.notifications){B.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"})?B.success(t("settings.notifications.page.toast.testNotificationSent")):B.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(V){console.error("Test notification failed:",V),B.error(t("settings.notifications.page.toast.testNotificationFailed"))}},Q=async()=>{if(!P){B.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=Va();if(!_?.push){B.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(C(de),de!=="granted"){B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){B.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const V=await _.push.getVapidPublicKey();if(!V?.publicKey){B.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const X=await K();await R(X);const $=await X.pushManager.getSubscription();if(!("pushManager"in X)||!X.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const L=($??await N(X.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:F(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Y=L.keys;if(!L.endpoint||!Y?.p256dh||!Y.auth)throw new Error("Push subscription missing keys");if(!(await N(_.push.subscribe({endpoint:L.endpoint,keys:{p256dh:Y.p256dh,auth:Y.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:vm()}),15e3,"Push subscribe request timed out"))?.ok){B.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}x(!0),B.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(V){console.error("[Push] Enable failed:",V);const X=W(V);B.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:X.summary})}finally{M(!1)}},H=async()=>{if(!P){x(!1);return}const _=Va();if(!_?.push){B.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{const X=await(await K()).pushManager.getSubscription();if(!X){x(!1);return}const $=X.endpoint;await X.unsubscribe(),await _.push.unsubscribe({endpoint:$}),x(!1),B.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{M(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(qe,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:cs,children:[s.jsx(gt,{checked:i&&D,onChange:_=>{S(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:r?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&D&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:d==="always",onChange:_=>c(_?"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(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{te()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&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"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&D&&s.jsxs(s.Fragment,{children:[s.jsx(qe,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:cs,children:[s.jsx(gt,{checked:f,onChange:m,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:h,onChange:p,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:u,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:w,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(qe,{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(--syntax-variable)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{last_message}"})]}),children:s.jsx(Rn,{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(Cn,{className:"capitalize",children:t(gy[_])}),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(We,{value:k[_].title,onChange:V=>O(_,"title",V.target.value),className:"h-7",placeholder:t(gc[_].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(We,{value:k[_].message,onChange:V=>O(_,"message",V.target.value),className:"h-7",placeholder:t(gc[_].messageKey)})]})]})]},_))})})]}),r&&s.jsx(qe,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:P?T:!1,disabled:!P||A,onChange:_=>{_?Q():H()},label:t("settings.notifications.page.push.enableLabel"),description:P?void 0:t("settings.notifications.page.push.unsupportedHint"),info:P?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:A?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()},Mn="oc-surface-elevated w-full h-7 rounded-lg border border-input bg-surface-elevated px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring focus:border-interactive-border-focus",fy=[{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"}],hc=t=>{const e=at.c(8),{value:a,label:n}=t,r=`${n}: ${a}/5`,i=`${a/5*100}%`;let l;e[0]!==i?(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:i}})}),e[0]=i,e[1]=l):l=e[1];let d;e[2]!==n?(d=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=d):d=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==d?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,d]}),e[4]=r,e[5]=l,e[6]=d,e[7]=c):c=e[7],c},xy=({selectedModelId:t,onSelect:e})=>{const{t:a}=Ze(),n=et.useCallback(m=>a(m),[a]),[r,i]=et.useState(new Map),[l,d]=et.useState(null),c=et.useCallback(async()=>{try{const m=await Nt("/api/dictation/status",{query:{provider:"local"}});if(!m.ok)return;const u=await m.json();Array.isArray(u?.models)&&i(new Map(u.models.map(v=>[v.id,v])))}catch{}},[]);et.useEffect(()=>{c()},[c]);const h=Array.from(r.values()).some(m=>m.downloading);et.useEffect(()=>{if(!h)return;const m=setInterval(()=>{c()},2e3);return()=>clearInterval(m)},[h,c]);const p=async m=>{d(m);try{await Nt(`/api/dictation/models/${encodeURIComponent(m)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},f=async m=>{d(m);try{await Nt(`/api/dictation/models/${encodeURIComponent(m)}`,{method:"DELETE"}),await c()}catch{}finally{d(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:fy.map(m=>{const u=t===m.id,v=r.get(m.id)??null;return s.jsx("div",{className:Ie("rounded-lg border border-[var(--interactive-border)] p-3",u&&"border-border bg-interactive-selection text-interactive-selection-foreground"),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:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),e(m.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(xo,{checked:u,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:Ie("typography-ui-label font-normal",u?"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(hc,{value:m.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(hc,{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(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===m.id,onClick:()=>{f(m.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):v?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof v.downloadProgress=="number"?`${v.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===m.id,onClick:()=>{p(m.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})})})]})},m.id)})})},by=[{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)"}],uo="kokoro-en-v0_19",vy="kokoro-multi-lang-v1_1",yy=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],ai=(t,e)=>`${t}:${e}`,jy=()=>{const[t,e]=et.useState([]),[a,n]=et.useState(null),r=et.useCallback(async()=>{try{const d=await Nt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);et.useEffect(()=>{r()},[r]);const i=t.some(d=>d.downloading);et.useEffect(()=>{if(!i)return;const d=setInterval(()=>{r()},2e3);return()=>clearInterval(d)},[i,r]);const l=et.useCallback(async(d,c)=>{n(d);try{const h=c==="POST"?`/api/dictation/models/${d}/download`:`/api/dictation/models/${d}`;await Nt(h,{method:c}),await r()}catch{}finally{n(null)}},[r]);return{models:t,requestingId:a,request:l,refresh:r}},wy=t=>{const e=by.map(a=>({modelId:uo,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===uo||!a.installed)){if(a.id===vy){for(const n of yy)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},ky=t=>{const e=at.c(14),{models:a,requestingId:n,request:r}=t,{t:i}=Ze();let l,d,c;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==i){c=Symbol.for("react.early_return_sentinel");e:{const p=a.filter(Cy);if(p.length===0){c=null;break e}l="flex flex-col";let f;e[7]!==r||e[8]!==n||e[9]!==i?(f=m=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:m.description??m.id}),m.installed?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{r(m.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})})]}):m.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof m.downloadProgress=="number"?`${m.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(m.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})}),m.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:m.downloadError}):null]},m.id),e[7]=r,e[8]=n,e[9]=i,e[10]=f):f=e[10],d=p.map(f)}e[0]=a,e[1]=r,e[2]=n,e[3]=i,e[4]=l,e[5]=d,e[6]=c}else l=e[4],d=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let h;return e[11]!==l||e[12]!==d?(h=s.jsx("div",{className:l,children:d}),e[11]=l,e[12]=d,e[13]=h):h=e[13],h},Ny=[{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"}],Sy=()=>{const{t}=Ze(),{isMobile:e}=Qn(),a=it(q=>q.voiceProvider),n=it(q=>q.setVoiceProvider),r=it(q=>q.speechRate),i=it(q=>q.setSpeechRate),l=it(q=>q.speechPitch),d=it(q=>q.setSpeechPitch),c=it(q=>q.speechVolume),h=it(q=>q.setSpeechVolume),p=it(q=>q.sayVoice),f=it(q=>q.setSayVoice),m=it(q=>q.localTtsVoiceId),u=it(q=>q.localTtsModelId),v=it(q=>q.setLocalTtsModelId),w=jy(),b=et.useMemo(()=>wy(w.models),[w.models]),k=it(q=>q.ttsFollowTextLanguage),g=it(q=>q.setTtsFollowTextLanguage),I=it(q=>q.setLocalTtsVoiceId),{speak:C,stop:P,isPlaying:j,error:T}=Uu(),x=et.useCallback(()=>{if(j){P();return}const q=b.find(Le=>Le.modelId===u&&Le.speakerId===m)?.label??String(m);C(t("settings.voice.page.preview.voiceLine",{voiceName:q}),{model:u,speakerId:m,speed:it.getState().speechRate})},[j,u,m,b,C,P,t]),A=it(q=>q.browserVoice),M=it(q=>q.setBrowserVoice),S=it(q=>q.openaiVoice),D=it(q=>q.setOpenaiVoice),O=it(q=>q.openaiApiKey),F=it(q=>q.setOpenaiApiKey),N=it(q=>q.openaiCompatibleUrl),R=it(q=>q.setOpenaiCompatibleUrl),U=it(q=>q.openaiCompatibleApiKey),K=it(q=>q.setOpenaiCompatibleApiKey),W=it(q=>q.openaiCompatibleVoice),te=it(q=>q.setOpenaiCompatibleVoice),Q=it(q=>q.openaiCompatibleTtsModel),H=it(q=>q.setOpenaiCompatibleTtsModel),_=it(q=>q.showMessageTTSButtons),V=it(q=>q.ttsInputMode),X=it(q=>q.setTtsInputMode),$=it(q=>q.sttProvider),ee=it(q=>q.setSttProvider),L=it(q=>q.sttServerUrl),Y=it(q=>q.setSttServerUrl),oe=it(q=>q.sttApiKey),de=it(q=>q.setSttApiKey),ue=it(q=>q.sttModel),ce=it(q=>q.setSttModel),Se=it(q=>q.sttLocalModel),ie=it(q=>q.setSttLocalModel),be=it(q=>q.sttLanguage),ae=it(q=>q.setSttLanguage),pe=it(q=>q.setShowMessageTTSButtons),je=it(q=>q.dictationEnabled),De=it(q=>q.setDictationEnabled),[me,$e]=et.useState(!1),[Ge,xe]=et.useState([]),[Pe,J]=et.useState(!1),[se,he]=et.useState(null),[ve,Fe]=et.useState(!1),[Ke,Be]=et.useState(!1),[ze,_e]=et.useState(null),[Me,tt]=et.useState(!1),[pt,ct]=et.useState(null),[dt,ht]=et.useState([]),[Ue,st]=et.useState(!1);et.useEffect(()=>((async()=>{const Le=await Tr.waitForVoices();ht(Le)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{ht(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ut=et.useMemo(()=>dt.filter(q=>q.lang).sort((q,Le)=>{const Qe=q.lang.startsWith("en"),lt=Le.lang.startsWith("en");if(Qe&&!lt)return-1;if(!Qe&&lt)return 1;const ot=q.lang.localeCompare(Le.lang);return ot!==0?ot:q.name.localeCompare(Le.name)}),[dt]),ye=et.useCallback(()=>{if(Ue){Tr.cancelSpeech(),st(!1);return}const q=dt.find(ot=>ot.name===A),Le=q?.name??t("settings.voice.page.preview.browserVoiceFallback"),Qe=t("settings.voice.page.preview.voiceLine",{voiceName:Le});st(!0);const lt=new SpeechSynthesisUtterance(Qe);lt.rate=r,lt.pitch=l,lt.volume=c,q&&(lt.voice=q,lt.lang=q.lang),lt.onend=()=>st(!1),lt.onerror=()=>st(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[A,dt,r,l,c,Ue,t]);et.useEffect(()=>()=>{Ue&&Tr.cancelSpeech()},[Ue]),et.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){Fe(O.trim().length>0);return}(async()=>{try{const lt=(await(await Nt("/api/tts/status")).json()).available,ot=O.trim().length>0;Fe(lt||ot)}catch{Fe(O.trim().length>0)}})()},[O,_,a]),et.useEffect(()=>{if(!_){$e(!1),xe([]);return}Nt("/api/tts/say/status").then(q=>q.json()).then(q=>{if($e(q.available),q.voices){const Le=q.voices.filter((Qe,lt,ot)=>ot.findIndex(bt=>bt.name===Qe.name)===lt).sort((Qe,lt)=>Qe.name.localeCompare(lt.name));xe(Le)}}).catch(()=>{$e(!1)})},[_]);const re=et.useCallback(async()=>{if(se){Ds(se),he(null),J(!1);return}J(!0);let q=null;try{const Le=await Nt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:p}),voice:p,rate:Math.round(100+(r-.5)*200)})});if(!Le.ok)throw new Error("Preview failed");const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),he(null),J(!1)},q.onerror=()=>{Ds(q),he(null),J(!1)},he(q),await q.play()}catch{Ds(q),he(null),J(!1)}},[p,r,se,t]);et.useEffect(()=>()=>{Ds(se)},[se]);const Te=et.useCallback(async()=>{if(ze){Ds(ze),_e(null),Be(!1);return}Be(!0);let q=null;try{const Le=await Nt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:S}),voice:S,speed:r,apiKey:O||void 0})});if(!Le.ok){const ot=await Le.json().catch(()=>({error:"Unknown error"}));throw new Error(ot.error||`HTTP ${Le.status}`)}const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),_e(null),Be(!1)},q.onerror=()=>{Ds(q),_e(null),Be(!1)},_e(q),await q.play()}catch{Ds(q),_e(null),Be(!1)}},[S,r,ze,O,t]);et.useEffect(()=>()=>{Ds(ze)},[ze]);const Ne=et.useCallback(async()=>{if(pt){Ds(pt),ct(null),tt(!1);return}if(!N.trim())return;tt(!0);let q=null;try{const Le=await Nt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:W,model:Q||void 0,speed:r,baseURL:N,apiKey:U||void 0})});if(!Le.ok){const ot=await Le.json().catch(()=>({error:"Unknown error"}));throw new Error(ot.error||`HTTP ${Le.status}`)}const Qe=await Le.blob(),lt=URL.createObjectURL(Qe);q=new Audio(lt),q.onended=()=>{Ds(q),ct(null),tt(!1)},q.onerror=()=>{Ds(q),ct(null),tt(!1)},ct(q),await q.play()}catch{Ds(q),ct(null),tt(!1)}},[N,W,Q,U,r,pt,t]);et.useEffect(()=>()=>{Ds(pt)},[pt]);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(qe,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(gt,{checked:_,onChange:pe,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),_&&s.jsxs(s.Fragment,{children:[s.jsx(ws,{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(mn,{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")},...me?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ie(St,!ve&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Ie(ys,!ve&&"text-[var(--status-error)]/80"),children:t(ve&&!O?"settings.voice.page.field.apiKeyHintUsingConfig":ve?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:O,onChange:q=>F(q.target.value),placeholder:"sk-...",className:Mn}),O&&s.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ie(St,!N.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(qt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:N,onChange:q=>R(q.target.value),placeholder:"http://localhost:8880/v1",className:Mn}),N&&s.jsx("button",{type:"button",onClick:()=>R(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:St,children:"API Key"}),s.jsx("span",{className:ys,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:U,onChange:q=>K(q.target.value),placeholder:"sk-...",className:Mn}),U&&s.jsx("button",{type:"button",onClick:()=>K(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:St,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:Q,onChange:q=>H(q.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:Mn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:St,children:t("settings.voice.page.field.voice")}),s.jsx(qt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:Ie("flex items-center gap-2",Ps),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:W,onChange:q=>te(q.target.value),placeholder:"af_sky",className:Mn})}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Ne,title:t("settings.voice.page.actions.preview"),disabled:!N.trim(),children:Me?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(ky,{...w}),(a==="local"||a==="say")&&s.jsx(gt,{checked:k,onChange:g,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ct,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:ai(u,m),onValueChange:q=>{const Le=b.find(Qe=>ai(Qe.modelId,Qe.speakerId)===q);Le&&(v(Le.modelId),I(Le.speakerId))},children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:q=>b.find(Le=>ai(Le.modelId,Le.speakerId)===q)?.label??q})}),s.jsx(At,{children:b.map(q=>s.jsx(mt,{value:ai(q.modelId,q.speakerId),children:q.label},ai(q.modelId,q.speakerId)))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:x,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})}),T?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:T}):null]}),a==="openai"&&ve&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:S,onValueChange:D,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Ny.map(q=>s.jsx(mt,{value:q.value,children:q.label},q.value))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Te,title:t("settings.voice.page.actions.preview"),children:Ke?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:ys,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&me&&Ge.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:p,onValueChange:f,children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Ge.map(q=>s.jsx(mt,{value:q.name,children:q.name},q.name))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:re,title:t("settings.voice.page.actions.preview"),children:Pe?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&ut.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:A||"$auto",onValueChange:q=>M(q==="$auto"?"":q),children:[s.jsx(Pt,{size:$t,className:an,children:s.jsx(zt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(mt,{value:"$auto",children:t("settings.voice.page.field.auto")}),ut.map(q=>s.jsxs(mt,{value:q.name,children:[q.name," (",q.lang,")"]},q.name))]})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:ye,title:t("settings.voice.page.actions.preview"),children:Ue?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:q=>i(Number(q.target.value)),className:Ae}),s.jsx(hs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:Ie(vs,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:q=>d(Number(q.target.value)),className:Ae}),s.jsx(hs,{value:l,onValueChange:d,min:.5,max:2,step:.1,className:Ie(vs,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:q=>h(Number(q.target.value)),className:Ae}),e?s.jsx(hs,{value:Math.round(c*100),onValueChange:q=>h(q/100),min:0,max:100,step:10,className:Ie(vs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(ws,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(mn,{value:V,onChange:X,"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(qe,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(gt,{checked:je,onChange:De,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),je&&s.jsxs(s.Fragment,{children:[s.jsx(ws,{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(mn,{value:$,onChange:ee,"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")}]})}),$==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:St,children:t("settings.voice.page.field.model")}),s.jsx(xy,{selectedModelId:Se,onSelect:ie})]}),$==="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:Ie(St,!L.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(qt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:L,onChange:q=>Y(q.target.value),placeholder:"http://localhost:8001/v1",className:Mn}),L&&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(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:St,children:"API Key"}),s.jsx("span",{className:ys,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:oe,onChange:q=>de(q.target.value),placeholder:"sk-...",className:Mn}),oe&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:St,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:ue,onChange:q=>ce(q.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:Mn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:St,children:t("settings.voice.page.field.language")}),s.jsx(qt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:be,onChange:q=>ae(q.target.value),placeholder:"auto",className:Mn})})]})]})]})]})]})};function Cy(t){return t.id===uo||t.installed||t.downloading}const $i=[{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}],Bi=[{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}],Iy="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Py="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Wr=[{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"}],Ay=[".yml",".yaml",".json"],Ty="settings.openchamber.tunnel.error.invalidConfigExtension",ii=t=>{const e=t.trim().toLowerCase();return Ay.some(a=>e.endsWith(a))},Ey=t=>t==="ngrok"?"ngrok":"cloudflared",Pd=()=>{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"},Dy=(t,e=Pd())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",Jr=(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():Ey(a),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Pd(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Dy(a,r);return{provider:a,dependency:n,installCommand:i}},Ad=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,fc=t=>{const e=at.c(11),{provider:a}=t;let n;e[0]!==a?(n=Ad(a),e[0]=a,e[1]=n):n=e[1];const r=n,d=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=Ie("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let h;e[4]!==c?(h=s.jsx(z,{name:"cloud",className:c}),e[4]=c,e[5]=h):h=e[5];let p;e[6]!==r?(p=s.jsx("span",{children:r}),e[6]=r,e[7]=p):p=e[7];let f;return e[8]!==h||e[9]!==p?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[h,p]}),e[8]=h,e[9]=p,e[10]=f):f=e[10],f},qn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",mo=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,xc=(t,e,a)=>{const n=mo(t,e,a);return t.find(r=>r.value===n)?.label||n},bc=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),r=Math.floor(a%3600/60),i=a%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},My=(t,e)=>Rc(t,e,{hour:"2-digit",precision:"second"}),Wi=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()}},Ry=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const r of t){if(!r||typeof r!="object")continue;const i=r,l=typeof i.id=="string"?i.id.trim():"",d=typeof i.name=="string"?i.name.trim():"",c=Wi(typeof i.hostname=="string"?i.hostname:"");!l||!d||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:d,hostname:c}))}return n},Oy=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Fy=()=>{const{t}=Ze(),e=fe(Z=>Z.timeFormatPreference),a=o.useCallback(Z=>t(Z),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[d,c]=o.useState(null),[h,p]=o.useState(null),[f,m]=o.useState(null),[u,v]=o.useState(null),[w,b]=o.useState(!1),[k,g]=o.useState(!1),[I,C]=o.useState(!1),[P,j]=o.useState("cloudflare"),[T,x]=o.useState(()=>Jr("cloudflare")),[A,M]=o.useState([]),[S,D]=o.useState("quick"),[O,F]=o.useState(null),[N,R]=o.useState([]),[U,K]=o.useState({}),[W,te]=o.useState(""),[Q,H]=o.useState({}),[_,V]=o.useState(new Set),[X,$]=o.useState(!1),[ee,L]=o.useState(""),[Y,oe]=o.useState(""),[de,ue]=o.useState(""),[ce,Se]=o.useState(1800*1e3),[ie,be]=o.useState(480*60*1e3),[ae,pe]=o.useState(""),[je,De]=o.useState([]),[me,$e]=o.useState(()=>Date.now()),[Ge,xe]=o.useState(null),Pe=t(Ty),J=o.useRef(null),se=o.useMemo(()=>O?!ii(O):!1,[O]),he=o.useMemo(()=>N.find(Z=>Z.id===W)||N[0]||null,[N,W]),ve=o.useMemo(()=>je.map(Z=>{const ge=Z.expiresAt<=me,Oe=Z.status==="active"&&!ge,Ee=Oe?bc(Z.expiresAt-me):Z.inactiveReason==="expired"||ge?"expired":"inactive",Ye=Ee==="expired"?t("settings.openchamber.tunnel.state.expired"):Z.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ne=qn(Z.mode);return{...Z,isActive:Oe,mode:ne,remainingTextForSession:Ee,inactiveLabel:Ye}}),[me,je,t]),Fe=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>me:!1,[me,i?.bootstrapExpiresAt,i?.connectUrl]),Ke=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:d===S,[d,n,i,S]),Be=o.useMemo(()=>!i||n!=="active"||!d?!1:d!==S,[d,n,i,S]),ze=o.useMemo(()=>{if(typeof Ge=="number"&&Number.isFinite(Ge)&&Ge>0)return Ge;if(typeof window>"u")return null;const ge=hi()||window.location.href;let Oe=0;try{Oe=Number(new URL(ge).port)}catch{Oe=Number(window.location.port)}return Number.isFinite(Oe)&&Oe>0?Oe:null},[Ge]),_e=o.useMemo(()=>A.find(Z=>Z.provider===P)??null,[A,P]),Me=o.useMemo(()=>{const Z=new Set(_e?.modes?.map(ge=>ge.key).filter(ge=>ge==="quick"||ge==="managed-remote"||ge==="managed-local"));return Z.size===0?Wr:Wr.filter(ge=>Z.has(ge.value))},[_e]),tt=o.useMemo(()=>Me.some(Z=>Z.value==="managed-remote"||Z.value==="managed-local"),[Me]),pt=o.useMemo(()=>T.provider===P?T:Jr(P),[T,P]),ct=o.useCallback(async Z=>{await yn(Z)},[]),dt=o.useCallback((Z,ge)=>(x(Jr(ge,Z)),Z.available===!0),[]),ht=o.useCallback(async(Z,ge)=>{try{const Oe=await Nt("/api/openchamber/tunnel/check",{query:{provider:Z},...ge?{signal:ge}:{}});if(!Oe.ok)return null;const Ee=await Oe.json();if(ge?.aborted)return null;const Ye=dt(Ee,Z);return r(ne=>ne==="checking"||ne==="starting"||ne==="active"||ne==="stopping"?ne:Ye?"idle":"not-available"),Ye}catch{return null}},[dt]),Ue=o.useCallback(async Z=>{try{const[ge,Oe,Ee,Ye]=await Promise.all([Nt("/api/openchamber/tunnel/check",{signal:Z}),Nt("/api/openchamber/tunnel/status",{signal:Z}),An(),Nt("/api/openchamber/tunnel/providers",{signal:Z})]),ne=await ge.json(),we=await Oe.json(),nt=Ee??{},Rt=Ye.ok?await Ye.json():{},Jt=we.ttlConfig?.bootstrapTtlMs??(nt.tunnelBootstrapTtlMs===void 0?1800*1e3:nt.tunnelBootstrapTtlMs),Ce=typeof we.ttlConfig?.sessionTtlMs=="number"?we.ttlConfig.sessionTtlMs:nt.tunnelSessionTtlMs??480*60*1e3,He=qn(we.mode??nt.tunnelMode),yt=nt.tunnelProvider??"cloudflare",It=nt.managedLocalTunnelConfigPath??null,Qt=dt(ne,yt),Xt=Ry(we?.managedRemoteTunnelPresets),ts=typeof we.managedRemoteTunnelHostname=="string"?we.managedRemoteTunnelHostname:"",es=Xt.length>0?Xt:ts?[{id:`legacy-${Wi(ts)}`,name:ts,hostname:Wi(ts)}]:[],Fs=es[0]?.id||"";if(Se(Jt),be(Ce),j(yt),M(Array.isArray(Rt?.providers)?Rt.providers:[]),D(He),F(It),R(es),te(Fs),De(Array.isArray(we.activeSessions)?we.activeSessions:[]),c(we.activeTunnelMode?qn(we.activeTunnelMode):we.active&&we.mode?qn(we.mode):null),V(new Set(Array.isArray(we.managedRemoteTunnelTokenPresetIds)?we.managedRemoteTunnelTokenPresetIds:[])),xe(typeof we.localPort=="number"?we.localPort:null),we.active&&we.url){l({url:we.url,connectUrl:null,bootstrapExpiresAt:typeof we.bootstrapExpiresAt=="number"?we.bootstrapExpiresAt:null}),r("active");return}r(Qt?"idle":"not-available")}catch{Z.aborted||(r("error"),m(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[dt,t]);o.useEffect(()=>{const Z=new AbortController;return Ue(Z.signal),()=>Z.abort()},[Ue]),o.useEffect(()=>{if(!i?.connectUrl){p(null);return}let Z=!1;return Qc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(ge=>{Z||p(ge)}).catch(()=>{Z||p(null)}),()=>{Z=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){pe(t("settings.openchamber.tunnel.state.noExpiry"));return}let Z=null,ge=Date.now();const Oe=()=>{const ne=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;ne<=0?pe(t("settings.openchamber.tunnel.state.expired")):pe(bc(ne))},Ee=()=>{const ne=Date.now();ne-ge>=1e3&&(Oe(),ge=ne),Z=requestAnimationFrame(Ee)};Oe(),(typeof document>"u"||document.visibilityState==="visible")&&(Z=requestAnimationFrame(Ee));const Ye=()=>{document.visibilityState==="visible"&&Z===null?Z=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&Z!==null&&(cancelAnimationFrame(Z),Z=null)};return document.addEventListener("visibilitychange",Ye),()=>{document.removeEventListener("visibilitychange",Ye),Z!==null&&cancelAnimationFrame(Z)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let Z=null,ge=Date.now();const Oe=()=>{const Ye=Date.now();Ye-ge>=1e3&&($e(Ye),ge=Ye),Z=requestAnimationFrame(Oe)};(typeof document>"u"||document.visibilityState==="visible")&&(Z=requestAnimationFrame(Oe));const Ee=()=>{document.visibilityState==="visible"&&Z===null?Z=requestAnimationFrame(Oe):document.visibilityState!=="visible"&&Z!==null&&(cancelAnimationFrame(Z),Z=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),Z!==null&&cancelAnimationFrame(Z)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Z=!1;const ge=async()=>{try{const Ee=await Nt("/api/openchamber/tunnel/status");if(!Ee.ok||Z)return;const Ye=await Ee.json();if(Z)return;De(Array.isArray(Ye.activeSessions)?Ye.activeSessions:[]),V(new Set(Array.isArray(Ye.managedRemoteTunnelTokenPresetIds)?Ye.managedRemoteTunnelTokenPresetIds:[])),xe(typeof Ye.localPort=="number"?Ye.localPort:null)}catch{}},Oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ge()},5e3);return()=>{Z=!0,window.clearInterval(Oe)}},[n]);const st=o.useCallback(async Z=>{C(!0);try{await ft(Z),Object.prototype.hasOwnProperty.call(Z,"tunnelMode")&&Z.tunnelMode&&D(Z.tunnelMode),Object.prototype.hasOwnProperty.call(Z,"tunnelProvider")&&typeof Z.tunnelProvider=="string"&&j(Z.tunnelProvider),Object.prototype.hasOwnProperty.call(Z,"managedLocalTunnelConfigPath")&&F(Z.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Z,"managedRemoteTunnelPresets")&&Z.managedRemoteTunnelPresets&&R(Z.managedRemoteTunnelPresets)}catch{B.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{C(!1)}},[t]),ut=o.useCallback(async(Z,ge)=>{g(!0);try{await ft({tunnelBootstrapTtlMs:Z,tunnelSessionTtlMs:ge})}catch{B.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),ye=o.useCallback(async Z=>{const ge=Z.token.trim();if(ge)try{const Oe={...Q,[Z.presetId]:ge};await ft({managedRemoteTunnelPresetTokens:Oe}),V(Ee=>{const Ye=new Set(Ee);return Ye.add(Z.presetId),Ye})}catch{B.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[Q,t]),re=o.useCallback(async Z=>{v(null),m(null);const ge=A.find(Ee=>Ee.provider===Z),Oe=ge?.modes?.some(Ee=>Ee.key===S)?S:qn(ge?.modes?.[0]?.key);await st({tunnelProvider:Z,tunnelMode:Oe}),ht(Z)},[A,ht,st,S]),Te=o.useCallback(async()=>{const Z=await No({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Z.success&&typeof Z.path=="string"&&Z.path.trim().length>0){const ge=Z.path.trim();if(!ii(ge)){B.error(Pe);return}F(ge),await st({managedLocalTunnelConfigPath:ge});return}J.current?.click()},[Pe,st]),Ne=o.useCallback(Z=>{const ge=Z.trim();F(ge.length>0?ge:null)},[]),Ae=o.useCallback(async()=>{if(O&&!ii(O)){B.error(Pe);return}await st({managedLocalTunnelConfigPath:O})},[Pe,O,st]),q=o.useCallback(async()=>{F(null),await st({managedLocalTunnelConfigPath:null})},[st]),Le=o.useCallback(async Z=>{const ge=Z.target.files?.[0];if(!ge)return;const Oe=ge.name.trim();if(Oe.length!==0){if(!ii(Oe)){B.error(Pe);return}F(Oe),await st({managedLocalTunnelConfigPath:Oe}),Z.target.value=""}},[Pe,st]),Qe=o.useCallback(async()=>{if(m(null),v(null),S==="managed-local"&&O&&!ii(O)){m(Pe),B.error(Pe);return}r("starting");try{let Z="",ge="";if(S==="managed-remote"){if(!he){r("idle"),v(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),B.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Z=he.hostname,ge=(Q[he.id]||"").trim(),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const Oe=await Nt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:P,mode:S,...S==="managed-remote"&&he?{managedRemoteTunnelPresetId:he.id,managedRemoteTunnelPresetName:he.name}:{},...S==="managed-remote"&&Z?{managedRemoteTunnelHostname:Z}:{},...S==="managed-remote"&&ge?{managedRemoteTunnelToken:ge}:{},...S==="managed-local"&&O?{configPath:O}:{}})}),Ee=await Oe.json();if(!Oe.ok||!Ee.ok){if(S==="managed-remote"&&typeof Ee.error=="string"&&Ee.error.includes("Managed remote tunnel token is required")){r("idle"),v(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),B.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),m(Ee.error||t("settings.openchamber.tunnel.toast.startFailed")),B.error(Ee.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const Ye=typeof Ee.url=="string"?Ee.url:"";if(!Ye){r("error"),m(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),B.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:Ye,connectUrl:typeof Ee.connectUrl=="string"?Ee.connectUrl:null,bootstrapExpiresAt:typeof Ee.bootstrapExpiresAt=="number"?Ee.bootstrapExpiresAt:null}),c(Ee.activeTunnelMode?qn(Ee.activeTunnelMode):Ee.mode?qn(Ee.mode):S),De(Array.isArray(Ee.activeSessions)?Ee.activeSessions:[]),Array.isArray(Ee.managedRemoteTunnelTokenPresetIds)&&V(new Set(Ee.managedRemoteTunnelTokenPresetIds)),typeof Ee.localPort=="number"&&xe(Ee.localPort),typeof Ee.mode=="string"&&D(qn(Ee.mode)),r("active"),Ee.replacedTunnel){const ne=typeof Ee.revokedBootstrapCount=="number"?Ee.revokedBootstrapCount:0,we=typeof Ee.invalidatedSessionCount=="number"?Ee.invalidatedSessionCount:0;ne===1&&we===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ne===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:we})):we===1?B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ne})):B.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ne,invalidatedSessionCount:we}))}else B.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),m(t("settings.openchamber.tunnel.toast.startFailed")),B.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Pe,N,st,he,Q,t,P,S,O]),lt=o.useCallback(async()=>{r("stopping");try{await Nt("/api/openchamber/tunnel/stop",{method:"POST"});const Z=await Nt("/api/openchamber/tunnel/status");if(Z.ok){const ge=await Z.json();De(Array.isArray(ge.activeSessions)?ge.activeSessions:[]),V(new Set(Array.isArray(ge.managedRemoteTunnelTokenPresetIds)?ge.managedRemoteTunnelTokenPresetIds:[])),xe(typeof ge.localPort=="number"?ge.localPort:null)}l(null),c(null),p(null),r("idle"),B.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),m(t("settings.openchamber.tunnel.toast.stopFailed")),B.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ot=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),b(!0),B.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{B.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),bt=o.useCallback(async Z=>{const ge=$i.find(Oe=>Oe.value===Z);ge&&(Se(ge.ms),await ut(ge.ms,ie))},[ut,ie]),wt=o.useCallback(async Z=>{const ge=Bi.find(Oe=>Oe.value===Z);!ge||ge.ms===null||(be(ge.ms),await ut(ce,ge.ms))},[ce,ut]),jt=o.useCallback(async Z=>{v(null),m(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await st({tunnelMode:Z,managedRemoteTunnelPresets:N})},[N,st,n]),vt=o.useCallback(async(Z,ge)=>{try{await ft({managedRemoteTunnelPresets:ge})}catch{B.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Xe=o.useCallback(Z=>{const ge=N.find(Oe=>Oe.id===Z);ge&&(te(ge.id),v(null),vt(ge,N))},[N,vt]),kt=o.useCallback(async()=>{const Z=ee.trim(),ge=Wi(Y),Oe=de.trim();if(!Z){B.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!ge){B.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Oe){B.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(ne=>ne.hostname===ge)){B.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ee={id:Oy(),name:Z,hostname:ge},Ye=[...N,Ee];R(Ye),te(Ee.id),K(ne=>({...ne,[Ee.id]:!0})),H(ne=>({...ne,[Ee.id]:Oe})),v(null),$(!1),L(""),oe(""),ue(""),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:Ye,managedRemoteTunnelPresetTokens:{...Q,[Ee.id]:Oe}}),await ye({presetId:Ee.id,presetName:Ee.name,hostname:Ee.hostname,token:Oe}),B.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,Y,ee,de,ye,st,Q,t]),Re=o.useCallback(async Z=>{const ge=N.find(we=>we.id===Z);if(!ge)return;const Oe=N.filter(we=>we.id!==ge.id),Ee=Oe[0]?.id||"",Ye=W===ge.id?Ee:W,ne=Object.fromEntries(Object.entries(Q).filter(([we,nt])=>we!==ge.id&&nt.trim().length>0));R(Oe),te(Ye),K(we=>{const nt={...we};return delete nt[ge.id],nt}),H(we=>{const nt={...we};return delete nt[ge.id],nt}),V(we=>{const nt=new Set(we);return nt.delete(ge.id),nt}),v(null),await st({managedRemoteTunnelPresets:Oe,managedRemoteTunnelPresetTokens:ne}),B.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,st,W,Q,t]),Ve="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(qe,{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:[ve.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(z,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Yo,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ve.map(Z=>{const ge=Z.mode==="quick",Oe=Z.mode==="managed-remote",Ee=ge?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Oe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",Ye=Z.isActive?ge?"text-[var(--status-warning)]":Oe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ne=t(ge?"settings.openchamber.tunnel.badge.quick":Oe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(z,{name:"checkbox-blank-circle-fill",className:Ie("size-2.5 shrink-0",Ye)}),s.jsx("span",{className:Ie("typography-micro rounded border px-1.5 py-0.5 uppercase",Ee),children:ne}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:My(Z.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Z.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Z.remainingTextForSession}):Z.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Z.inactiveLabel})})]},Z.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:Yo,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:pt.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:pt.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:St,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Tt,{value:P,onValueChange:Z=>{re(Z)},disabled:I||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[16rem]",children:s.jsx(zt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Ad(P)})}),s.jsxs(At,{children:[A.length>0?A.map(Z=>s.jsx(mt,{value:Z.provider,children:s.jsx(fc,{provider:Z.provider})},Z.provider)):s.jsx(mt,{value:"cloudflare",children:s.jsx(fc,{provider:"cloudflare"})}),s.jsx(mt,{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:St,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Me.map(Z=>s.jsxs(nr,{children:[s.jsx(ar,{asChild:!0,children:s.jsx(G,{variant:"chip",size:"xs","aria-pressed":S===Z.value,className:"!font-normal",onClick:()=>{jt(Z.value)},disabled:I||n==="starting"||n==="stopping",children:a(Z.labelKey)})}),s.jsx(bo,{sideOffset:8,className:"max-w-xs",children:a(Z.tooltipKey)})]},Z.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:Ie(St,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Tt,{value:mo($i,ce,"1800000"),onValueChange:Z=>{bt(Z)},disabled:k||I||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(zt,{className:"truncate",children:xc($i,ce,"1800000")})}),s.jsx(At,{children:$i.map(Z=>s.jsx(mt,{value:Z.value,children:Z.label},Z.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(St,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Tt,{value:mo(Bi,ie,"28800000"),onValueChange:Z=>{wt(Z)},disabled:k||I||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(zt,{className:"truncate",children:xc(Bi,ie,"28800000")})}),s.jsx(At,{children:Bi.map(Z=>s.jsx(mt,{value:Z.value,children:Z.label},Z.value))})]})]})]}),S==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),tt&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),S==="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 ze=="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:",ze]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Cn,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>$(Z=>!Z),disabled:n==="starting"||n==="stopping"||I,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((Z,ge)=>{const Oe=Q[Z.id]||"",Ee=_.has(Z.id),Ye=U[Z.id]??!1;return s.jsx("div",{className:Ie(ge<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(kn,{open:Ye,onOpenChange:ne=>{K(we=>({...we,[Z.id]:ne})),ne&&Xe(Z.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Nn,{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:[Ye?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Z.name})]}),s.jsx(G,{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:Z.name}),onClick:()=>{Re(Z.id)},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Sn,{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:Z.hostname})]}),s.jsx(We,{type:"password",value:Oe,onChange:ne=>{const we=ne.target.value;v(null),H(nt=>({...nt,[Z.id]:we}))},onBlur:ne=>{const we=ne.currentTarget.value.trim();we&&ye({presetId:Z.id,presetName:Z.name,hostname:Z.hostname,token:we})},placeholder:t(Ee?"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(G,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Oe.trim().length===0,onClick:()=>{ye({presetId:Z.id,presetName:Z.name,hostname:Z.hostname,token:Oe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Z.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),X&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(We,{value:ee,onChange:Z=>L(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(We,{value:Y,onChange:Z=>oe(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(We,{type:"password",value:de,onChange:Z=>ue(Z.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),typeof ze=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",ze]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:I||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$(!1),L(""),oe(""),ue("")},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(qt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!he&&u&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:u})]}),S==="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:St,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:J,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Z=>{Le(Z)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:O||"",onChange:Z=>{Ne(Z.target.value)},onBlur:()=>{Ae()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||I}),s.jsx(G,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Te()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{name:"folder",className:"size-3.5"})}),O&&s.jsx(G,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{q()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{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")}),se&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Pe})]})}),!Ke&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[S==="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:()=>{ct(Iy)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),S==="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:()=>{ct(Py)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(Wr.find(Z=>Z.value===S)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),S==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:St,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Tt,{value:W||(N[0]?.id??""),onValueChange:Z=>{Xe(Z)},disabled:I||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(Pt,{size:$t,children:s.jsx(zt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:he?.name})}),s.jsx(At,{fitContent:!0,children:N.map(Z=>s.jsx(mt,{value:Z.id,children:Z.name},Z.id))})]})]}),Be&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(G,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="starting"||I||S==="managed-remote"&&!he||S==="managed-local"&&se,className:Ie(Ve,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ke&&i&&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:i.url})]}),Fe&&i.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:i.connectUrl}),s.jsxs(G,{size:"sm",variant:"ghost",onClick:ot,className:"shrink-0 gap-1.5",children:[w?s.jsx(z,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(z,{name:"file-copy",className:"size-3.5"}),t(w?"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"),": ",i.bootstrapExpiresAt?ae: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:[h?s.jsx("img",{src:h,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(G,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="stopping"||I||S==="managed-local"&&se,className:Ve,children:[s.jsx(z,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:lt,disabled:n==="stopping"||I,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&f&&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:f}),s.jsx(G,{size:"sm",variant:"ghost",onClick:Qe,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Td=()=>{const{t}=Ze(),[e,a]=et.useState(""),[n,r]=et.useState(!0),[i,l]=et.useState(!1),d=fe(u=>u.showOpenCodeUpdateNotifications),c=fe(u=>u.setShowOpenCodeUpdateNotifications);et.useEffect(()=>{let u=!1;return(async()=>{try{const v=await An();if(u||!v)return;a(v.opencodeBinary??"")}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const h=et.useCallback(async()=>{if(!(typeof window>"u")&&ls())try{const u=await No();u.success&&u.path&&u.path.trim().length>0&&a(u.path.trim())}catch{}},[]),p=et.useCallback(async()=>{l(!0);try{const u=e.trim(),v=u.length>=2&&(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))?u.slice(1,-1).trim():u;await ft({opencodeBinary:v}),await Sc({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(u){if(u?.requiresManualRestart){B.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}B.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{l(!1)}},[t,e]),f=et.useCallback(async()=>{l(!0);try{await Rm(t)}finally{l(!1)}},[t]),m=et.useCallback(u=>{c(u),ft({showOpenCodeUpdateNotifications:u})},[c]);return s.jsx(qe,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ct,{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(We,{value:e,onChange:u=>a(u.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||i,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:n||i||!ls(),className:gs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(z,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Wa,{className:cs,children:[s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:d,onChange:m,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsxs("div",{className:"flex flex-wrap justify-start gap-2 py-1.5","data-settings-item":"sessions.opencode-restart",children:[s.jsx(G,{type:"button",size:"xs",onClick:p,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")}),s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:n||i,className:"shrink-0 !font-normal",children:t("settings.openchamber.opencodeCli.actions.restart")})]})]})]})})},Fo=!1,Qr="builtin",Ly=t=>t.filter(e=>wo(e)&&_c(e.service,"browser")),Ed=()=>{const t=at.c(99),{t:e}=Ze(),a=fe(Ky),n=fe(_y),r=fe(Uy),i=fe(zy),l=fe($y),d=fe(By),c=Hs(Vy),h=fe(Hy),p=fe(qy),f=fe(Gy),m=fe(Wy),u=fe(Jy);let v;t[0]!==n?(v=me=>{n(me),ft({agentControlToolEnabled:me})},t[0]=n,t[1]=v):v=t[1];const w=v;let b;t[2]!==i?(b=me=>{i(me),ft({agentWebToolEnabled:me})},t[2]=i,t[3]=b):b=t[3];const k=b;let g;t[4]!==u?(g=me=>{u(me),ft({agentNotifyToolEnabled:me})},t[4]=u,t[5]=g):g=t[5];const I=g;let C;t[6]===Symbol.for("react.memo_cache_sentinel")?(C=[],t[6]=C):C=t[6],et.useEffect(Qy,C);let P;t[7]!==c?(P=Ly(c),t[7]=c,t[8]=P):P=t[8];const j=P;let T;t[9]!==l||t[10]!==j?(T=j.some(me=>me.id===l)?l:Qr,t[9]=l,t[10]=j,t[11]=T):T=t[11];const x=T;let A;t[12]!==d?(A=me=>{d(me),ft({browserProvider:me})},t[12]=d,t[13]=A):A=t[13];const M=A;let S;t[14]!==f?(S=me=>{f(me),ft({agentMemoryToolEnabled:me}).finally(()=>{me&&zu.getState().refresh()})},t[14]=f,t[15]=S):S=t[15];const D=S;let O;t[16]!==e?(O=e("settings.openchamber.tools.title"),t[16]=e,t[17]=O):O=t[17];let F;t[18]!==e?(F=e("settings.openchamber.tools.field.agentControlTool"),t[18]=e,t[19]=F):F=t[19];let N;t[20]!==e?(N=e("settings.openchamber.tools.field.agentControlToolAria"),t[20]=e,t[21]=N):N=t[21];let R;t[22]!==e?(R=e("settings.openchamber.tools.field.agentControlToolInfo"),t[22]=e,t[23]=R):R=t[23];let U;t[24]!==a||t[25]!==w||t[26]!==N||t[27]!==R||t[28]!==F?(U=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:w,label:F,ariaLabel:N,info:R}),t[24]=a,t[25]=w,t[26]=N,t[27]=R,t[28]=F,t[29]=U):U=t[29];let K;t[30]!==e?(K=e("settings.openchamber.tools.field.agentWebTool"),t[30]=e,t[31]=K):K=t[31];let W;t[32]!==e?(W=e("settings.openchamber.tools.field.agentWebToolAria"),t[32]=e,t[33]=W):W=t[33];let te;t[34]!==e?(te=e("settings.openchamber.tools.field.agentWebToolInfo"),t[34]=e,t[35]=te):te=t[35];let Q;t[36]!==r||t[37]!==k||t[38]!==K||t[39]!==W||t[40]!==te?(Q=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:k,label:K,ariaLabel:W,info:te}),t[36]=r,t[37]=k,t[38]=K,t[39]=W,t[40]=te,t[41]=Q):Q=t[41];let H;t[42]!==e?(H=e("settings.openchamber.tools.browserProvider.label"),t[42]=e,t[43]=H):H=t[43];let _;t[44]!==e?(_=e("settings.openchamber.tools.browserProvider.info"),t[44]=e,t[45]=_):_=t[45];const V=!r||j.length===0;let X;t[46]!==e?(X=e("settings.openchamber.tools.browserProvider.aria"),t[46]=e,t[47]=X):X=t[47];let $;t[48]!==j||t[49]!==e?($=s.jsx(zt,{children:me=>me===Qr?e("settings.openchamber.tools.browserProvider.option.builtin"):j.find($e=>$e.id===me)?.name??null}),t[48]=j,t[49]=e,t[50]=$):$=t[50];let ee;t[51]!==X||t[52]!==$?(ee=s.jsx(Pt,{size:$t,className:an,"aria-label":X,children:$}),t[51]=X,t[52]=$,t[53]=ee):ee=t[53];let L;t[54]!==e?(L=e("settings.openchamber.tools.browserProvider.option.builtin"),t[54]=e,t[55]=L):L=t[55];let Y;t[56]!==L?(Y=s.jsx(mt,{value:Qr,children:L}),t[56]=L,t[57]=Y):Y=t[57];let oe;t[58]!==j?(oe=j.map(Yy),t[58]=j,t[59]=oe):oe=t[59];let de;t[60]!==Y||t[61]!==oe?(de=s.jsxs(At,{children:[Y,oe]}),t[60]=Y,t[61]=oe,t[62]=de):de=t[62];let ue;t[63]!==M||t[64]!==x||t[65]!==V||t[66]!==ee||t[67]!==de?(ue=s.jsxs(Tt,{value:x,onValueChange:M,disabled:V,children:[ee,de]}),t[63]=M,t[64]=x,t[65]=V,t[66]=ee,t[67]=de,t[68]=ue):ue=t[68];let ce;t[69]!==H||t[70]!==_||t[71]!==ue?(ce=s.jsx(Ct,{settingsItem:"sessions.browser-provider",label:H,info:_,children:ue}),t[69]=H,t[70]=_,t[71]=ue,t[72]=ce):ce=t[72];let Se;t[73]!==e?(Se=e("settings.openchamber.tools.field.agentNotifyTool"),t[73]=e,t[74]=Se):Se=t[74];let ie;t[75]!==e?(ie=e("settings.openchamber.tools.field.agentNotifyToolAria"),t[75]=e,t[76]=ie):ie=t[76];let be;t[77]!==e?(be=e("settings.openchamber.tools.field.agentNotifyToolInfo"),t[77]=e,t[78]=be):be=t[78];let ae;t[79]!==m||t[80]!==I||t[81]!==Se||t[82]!==ie||t[83]!==be?(ae=s.jsx(gt,{settingsItem:"sessions.agent-notify-tool",checked:m,onChange:I,label:Se,ariaLabel:ie,info:be}),t[79]=m,t[80]=I,t[81]=Se,t[82]=ie,t[83]=be,t[84]=ae):ae=t[84];let pe;t[85]!==p||t[86]!==h||t[87]!==D||t[88]!==e?(pe=p?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:h,onChange:D,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[85]=p,t[86]=h,t[87]=D,t[88]=e,t[89]=pe):pe=t[89];let je;t[90]!==U||t[91]!==Q||t[92]!==ce||t[93]!==ae||t[94]!==pe?(je=s.jsxs("div",{className:cs,children:[U,Q,ce,ae,pe]}),t[90]=U,t[91]=Q,t[92]=ce,t[93]=ae,t[94]=pe,t[95]=je):je=t[95];let De;return t[96]!==je||t[97]!==O?(De=s.jsx(qe,{title:O,children:je}),t[96]=je,t[97]=O,t[98]=De):De=t[98],De};function Ky(t){return t.agentControlToolEnabled}function _y(t){return t.setAgentControlToolEnabled}function Uy(t){return t.agentWebToolEnabled}function zy(t){return t.setAgentWebToolEnabled}function $y(t){return t.browserProvider}function By(t){return t.setBrowserProvider}function Vy(t){return t.guests}function Hy(t){return t.agentMemoryToolEnabled}function qy(t){return t.agentMemoryFeatureAvailable}function Gy(t){return t.setAgentMemoryToolEnabled}function Wy(t){return t.agentNotifyToolEnabled}function Jy(t){return t.setAgentNotifyToolEnabled}function Qy(){Fn()}function Yy(t){return s.jsx(mt,{value:t.id,children:t.name},t.id)}const Dd=()=>{const{t}=Ze(),e=ls()&&fi(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,r]=et.useState(!1),[i,l]=et.useState(!1),[d,c]=et.useState(!1),[h,p]=et.useState(""),[f,m]=et.useState(!1),[u,v]=et.useState(!1),[w,b]=et.useState(null),[k,g]=et.useState(!0),[I,C]=et.useState(!1),[P,j]=et.useState(!1),[T,x]=et.useState(!1),[A,M]=et.useState(!1),[S,D]=et.useState(!1),[O,F]=et.useState(!1),[N,R]=et.useState(!1),[U,K]=et.useState(!0),[W,te]=et.useState(!0),[Q,H]=et.useState(!1),[_,V]=et.useState(!1),[X,$]=et.useState(!1),[ee,L]=et.useState(null),[Y,oe]=et.useState(null);et.useEffect(()=>{if(!e){g(!1);return}let J=!1;return(async()=>{try{const se=await An();if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(J)return;const he=se.desktopLanAccessEnabled===!0;r(he),l(he),c(se.hasDesktopUiPassword===!0),p(""),m(!1),v(se.desktopLanAccessActive===!0),b(se.desktopLanAccessBlockedReason??null);const ve=se.desktopMacMenuBarEnabled!==!1;K(ve),te(ve),L(null)}catch(se){J||L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{J||g(!1)}})(),()=>{J=!0}},[e,t]),et.useEffect(()=>{if(!e){j(!1);return}let J=!1;return(async()=>{const se=await ym();J||(j(se?.supported===!0),x(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e){D(!1);return}let J=!1;return(async()=>{const se=await jm();J||(D(se?.supported===!0),F(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e){H(!1);return}let J=!1;return(async()=>{const se=await wm();J||(H(se?.supported===!0),V(se?.enabled===!0))})(),()=>{J=!0}},[e]),et.useEffect(()=>{if(!e||!i){oe(null);return}let J=!1;return(async()=>{const se=await Vc();J||oe(se)})(),()=>{J=!0}},[i,e]);const de=h.trim(),ue=de.length>0||f,ce=i!==n||ue||W!==U,Se=et.useMemo(()=>{if(typeof window>"u")return null;const se=hi()||window.location.href;let he=0;try{he=Number(new URL(se).port)}catch{he=Number(window.location.port)}return Number.isFinite(he)&&he>0?he:null},[]),ie=i&&u&&Y&&Se?`http://${Y}:${Se}`:null,be=de.length>0||d&&!f,ae=i&&!be,pe=n&&!u&&w==="missing-password",je=k||I||!ce||ae,De=et.useCallback(J=>{p(J),J.trim()&&m(!1)},[]),me=et.useCallback(()=>{p(""),m(!0),l(!1)},[]),$e=et.useCallback(async()=>{if(!P||A)return;const J=!T;x(J),M(!0),L(null);try{const se=await km(J);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));x(se.enabled)}catch(se){x(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{M(!1)}},[A,T,P,t]),Ge=et.useCallback(async()=>{if(!S||N)return;const J=!O;F(J),R(!0),L(null);try{const se=await Nm(J);if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!se.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));F(se.enabled)}catch(se){F(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{R(!1)}},[N,O,S,t]),xe=et.useCallback(async()=>{if(!Q||X)return;const J=!_;V(J),$(!0),L(null);try{const se=await Sm(J);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));V(se.enabled)}catch(se){V(!J),L(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{$(!1)}},[X,_,Q,t]),Pe=et.useCallback(async()=>{if(ce){C(!0),L(null);try{if(!(await ft({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:f?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:W})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):f&&c(!1),p(""),m(!1),K(W),!await Cm())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(J){L(J instanceof Error?J.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),C(!1)}}},[W,i,ce,de,f,t]);return e?s.jsx(qe,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[P||a||S||Q?s.jsxs("div",{className:cs,children:[P?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:T,onChange:J=>{J!==T&&$e()},disabled:A,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(gt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:te,disabled:k||I,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,S?s.jsx(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:O,onChange:J=>{J!==O&&Ge()},disabled:N,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,Q?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:J=>{J!==_&&xe()},disabled:X,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(Ot,{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(We,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:h,onChange:J=>De(J.target.value),placeholder:t(d&&!f?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||I,required:i&&!be,"aria-invalid":ae}),d&&!f?s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:me,disabled:k||I,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:cs,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:i,onChange:l,disabled:k||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")}),ae||pe?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),ee?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:ee}):null,ie?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ce&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ie})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(G,{type:"button",size:"xs",onClick:Pe,disabled:je,className:"shrink-0 !font-normal",children:t(I?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Md=new Set(["shift","control","alt","meta"]),Lo=3,Zy=3e3;function Ko(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Xy(t){return t.action.customizable}function vc(t){if(Ko(t)>Lo)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?ir(e.join("+")):null}function e1(t){if(Md.has(t.key.toLowerCase())||Ko(t,!0)>Lo)return null;const e=Vu(Hu(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),ir(a.join("+"))}function t1(t){const e=t.key.toLowerCase();if(!Md.has(e)||Ko(t,!0)>Lo)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?ir(a.join("+")):null}function yc(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function s1(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:vc(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=e1(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const r=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:r,livePreview:null,settled:r.length===2}}return{...t,livePreview:vc(e)}}const n1=t=>{const e=at.c(117),{action:a,overrides:n,onSave:r,onOpenChange:i}=t,{t:l}=Ze();let d;e[0]!==l?(d=Se=>l(Se.settingsLabelKey),e[0]=l,e[1]=d):d=e[1];const c=d;let h;e[2]!==c?(h=Se=>Se.action.customizable?c(Se.action):ua(Se.action.defaultBinding),e[2]=c,e[3]=h):h=e[3];const p=h;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f={chords:[],livePreview:null,settled:!1},e[4]=f):f=e[4];const[m,u]=o.useState(f),v=o.useRef(null);let w,b;e[5]!==a?(w=()=>{a&&(u({chords:[],livePreview:null,settled:!1}),v.current?.focus())},b=[a],e[5]=a,e[6]=w,e[7]=b):(w=e[6],b=e[7]),o.useEffect(w,b);const k=m.chords.length===1&&!m.settled;let g,I;e[8]!==k?(g=()=>{if(!k)return;const Se=window.setTimeout(()=>u(yc),Zy);return()=>window.clearTimeout(Se)},I=[k],e[8]=k,e[9]=g,e[10]=I):(g=e[9],I=e[10]),o.useEffect(g,I);let C;e[11]!==m.chords?(C=ir(m.chords.join(" ")),e[11]=m.chords,e[12]=C):C=e[12];const P=C;let j;e[13]!==a||e[14]!==P||e[15]!==n?(j=a&&P?$u(a.id,P,n):[],e[13]=a,e[14]=P,e[15]=n,e[16]=j):j=e[16];const T=j;let x;e[17]!==T?(x=T.find(a1),e[17]=T,e[18]=x):x=e[18];const A=x;let M,S,D,O,F,N,R,U,K,W,te,Q,H,_,V;if(e[19]!==a||e[20]!==c||e[21]!==P||e[22]!==p||e[23]!==T||e[24]!==i||e[25]!==r||e[26]!==A||e[27]!==m||e[28]!==l){const Se=T.filter(Xy);F=Se.find(i1);const ie=Se.find(r1),be=T.find(o1);let ae;e[44]!==i?(ae=()=>i(!1),e[44]=i,e[45]=ae):ae=e[45],D=ae,O=()=>{m.settled||u(yc),!(!a||!P||A||F)&&(r(a.id,P,ie?.action.id),D())};let pe;e[46]!==a||e[47]!==m?(pe=(Ke,Be)=>{Ke.preventDefault(),Ke.stopPropagation();const ze=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Be==="keyup"&&ze&&m.chords.length===0){const Me=t1(Ke);if(Me){u({chords:[Me],livePreview:null,settled:!0});return}}const _e=s1(m,{altKey:Ke.altKey,code:Ke.nativeEvent.code,ctrlKey:Ke.ctrlKey,isComposing:Ke.nativeEvent.isComposing,key:Ke.key,metaKey:Ke.metaKey,repeat:Ke.repeat,shiftKey:Ke.shiftKey},Be);u(ze&&_e.chords.length>1?m:_e)},e[46]=a,e[47]=m,e[48]=pe):pe=e[48];const je=pe;S=_t,_=a!==null,V=l1,M=Ut,N="max-w-md",R=v,U=!1;let De;e[49]!==a||e[50]!==c||e[51]!==l?(De=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=De):De=e[52];let me;e[53]!==De?(me=s.jsx(Vt,{children:De}),e[53]=De,e[54]=me):me=e[54];let $e;e[55]!==l?($e=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=$e):$e=e[56];let Ge;e[57]!==$e?(Ge=s.jsx(Ht,{children:$e}),e[57]=$e,e[58]=Ge):Ge=e[58],e[59]!==me||e[60]!==Ge?(K=s.jsxs(Bt,{children:[me,Ge]}),e[59]=me,e[60]=Ge,e[61]=K):K=e[61];let xe,Pe;e[62]!==je?(xe=Ke=>je(Ke,"keydown"),Pe=Ke=>je(Ke,"keyup"),e[62]=je,e[63]=xe,e[64]=Pe):(xe=e[63],Pe=e[64]);let J;e[65]===Symbol.for("react.memo_cache_sentinel")?(J=()=>u(c1),e[65]=J):J=e[65];let se;e[66]!==m.chords?(se=m.chords.map(d1),e[66]=m.chords,e[67]=se):se=e[67];let he;e[68]!==m.livePreview?(he=m.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:ua(m.livePreview)}):null,e[68]=m.livePreview,e[69]=he):he=e[69];let ve;e[70]!==m.chords.length||e[71]!==m.livePreview||e[72]!==l?(ve=m.chords.length===0&&!m.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=m.chords.length,e[71]=m.livePreview,e[72]=l,e[73]=ve):ve=e[73];let Fe;e[74]!==se||e[75]!==he||e[76]!==ve?(Fe=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[se,he,ve]}),e[74]=se,e[75]=he,e[76]=ve,e[77]=Fe):Fe=e[77],e[78]!==xe||e[79]!==Pe||e[80]!==Fe?(W=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:v,onKeyDown:xe,onKeyUp:Pe,onBlur:J,children:Fe}),e[78]=xe,e[79]=Pe,e[80]=Fe,e[81]=W):W=e[81],te=m.settled&&A?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):m.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c(F.action)})}):null,Q=m.settled&&ie&&!A&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(ie.action)})}):null,H=m.settled&&be&&!A&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:p(be)})}):null,e[19]=a,e[20]=c,e[21]=P,e[22]=p,e[23]=T,e[24]=i,e[25]=r,e[26]=A,e[27]=m,e[28]=l,e[29]=M,e[30]=S,e[31]=D,e[32]=O,e[33]=F,e[34]=N,e[35]=R,e[36]=U,e[37]=K,e[38]=W,e[39]=te,e[40]=Q,e[41]=H,e[42]=_,e[43]=V}else M=e[29],S=e[30],D=e[31],O=e[32],F=e[33],N=e[34],R=e[35],U=e[36],K=e[37],W=e[38],te=e[39],Q=e[40],H=e[41],_=e[42],V=e[43];let X;e[82]!==P||e[83]!==m.settled||e[84]!==l?(X=m.settled&&P&&Bu(P)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=P,e[83]=m.settled,e[84]=l,e[85]=X):X=e[85];let $;e[86]!==l?($=l("settings.common.actions.cancel"),e[86]=l,e[87]=$):$=e[87];let ee;e[88]!==D||e[89]!==$?(ee=s.jsx(G,{type:"button",variant:"ghost",size:"sm",onClick:D,children:$}),e[88]=D,e[89]=$,e[90]=ee):ee=e[90];const L=!P||m.settled&&(!!A||!!F);let Y;e[91]!==l?(Y=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=Y):Y=e[92];let oe;e[93]!==O||e[94]!==L||e[95]!==Y?(oe=s.jsx(G,{type:"button",size:"sm",disabled:L,onClick:O,children:Y}),e[93]=O,e[94]=L,e[95]=Y,e[96]=oe):oe=e[96];let de;e[97]!==ee||e[98]!==oe?(de=s.jsxs(as,{children:[ee,oe]}),e[97]=ee,e[98]=oe,e[99]=de):de=e[99];let ue;e[100]!==M||e[101]!==N||e[102]!==R||e[103]!==U||e[104]!==K||e[105]!==W||e[106]!==te||e[107]!==Q||e[108]!==H||e[109]!==X||e[110]!==de?(ue=s.jsxs(M,{className:N,initialFocus:R,showCloseButton:U,children:[K,W,te,Q,H,X,de]}),e[100]=M,e[101]=N,e[102]=R,e[103]=U,e[104]=K,e[105]=W,e[106]=te,e[107]=Q,e[108]=H,e[109]=X,e[110]=de,e[111]=ue):ue=e[111];let ce;return e[112]!==S||e[113]!==_||e[114]!==V||e[115]!==ue?(ce=s.jsx(S,{open:_,onOpenChange:V,children:ue}),e[112]=S,e[113]=_,e[114]=V,e[115]=ue,e[116]=ce):ce=e[116],ce};function a1(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function i1(t){return t.kind==="prefix"}function r1(t){return t.kind==="exact"}function o1(t){return t.kind==="contextual-prefix"}function l1(t,e){t||e.cancel()}function c1(t){return{...t,livePreview:null}}function d1(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:ua(t)},`${t}-${e}`)}const u1=["session","models","panels","navigation","application"],m1=()=>{const t=at.c(24),{t:e}=Ze(),a=fe(p1),n=fe(g1),r=fe(h1),i=fe(f1),[l,d]=o.useState(null);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c=qu(),t[0]=c):c=t[0];const h=c,p=x1;let f;t[1]!==n||t[2]!==a?(f=(P,j,T)=>{const x={...a,[P]:j};T&&(x[T]=Er),n(P,j),T&&n(T,Er),p(x)},t[1]=n,t[2]=a,t[3]=f):f=t[3];const m=f;let u;t[4]!==r||t[5]!==a?(u=P=>{const j={...a};delete j[P],r(P),p(j)},t[4]=r,t[5]=a,t[6]=u):u=t[6];const v=u;let w;t[7]!==a||t[8]!==e?(w=P=>{const j="prefixStyle"in P&&P.prefixStyle,T=j?Gu(P.id,a):Bc(P.id,a),x=ua(T,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!j||!T||T===Er)return x;const A=P.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${x}${A}`},t[7]=a,t[8]=e,t[9]=w):w=t[9];const b=w;let k;t[10]!==i||t[11]!==v||t[12]!==b||t[13]!==a||t[14]!==e?(k=u1.map((P,j)=>{const T=h.filter(x=>x.category===P);return T.length===0?null:s.jsx(qe,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${P}`),divider:j!==0,info:j===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),p({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:T.map(x=>s.jsxs(Ct,{label:e(x.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:b(x)}),s.jsx(G,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>d(x),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),x.id in a?s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>v(x.id),children:e("settings.common.actions.reset")}):null]},x.id))})},P)}),t[10]=i,t[11]=v,t[12]=b,t[13]=a,t[14]=e,t[15]=k):k=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=P=>{P||d(null)},t[16]=g):g=t[16];let I;t[17]!==l||t[18]!==m||t[19]!==a?(I=s.jsx(n1,{action:l,overrides:a,onSave:m,onOpenChange:g}),t[17]=l,t[18]=m,t[19]=a,t[20]=I):I=t[20];let C;return t[21]!==k||t[22]!==I?(C=s.jsxs(s.Fragment,{children:[k,I]}),t[21]=k,t[22]=I,t[23]=C):C=t[23],C};function p1(t){return t.shortcutOverrides}function g1(t){return t.setShortcutOverride}function h1(t){return t.clearShortcutOverride}function f1(t){return t.resetAllShortcutOverrides}function x1(t){ft({shortcutOverrides:t})}const Rd=()=>{const t=at.c(2),[e,a]=o.useState(0);let n,r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>rr(()=>a(P1)),r=[],t[0]=n,t[1]=r):(n=t[0],r=t[1]),o.useEffect(n,r),e},b1=t=>{const e=at.c(84),{section:a}=t,{t:n}=Ze(),{isMobile:r}=Qn(),i=Rd();let l;e[0]!==r?(l=r&&da(),e[0]=r,e[1]=l):l=e[1];const d=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[2]=c):c=e[2];const h=c;let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=ls()&&fi(),e[3]=p):p=e[3];const f=p;if(!a){let H;e[4]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(or,{}),e[4]=H):H=e[4];let _;e[5]!==i?(_=s.jsx(Id,{},i),e[5]=i,e[6]=_):_=e[6];let V,X,$,ee,L,Y,oe;e[7]===Symbol.for("react.memo_cache_sentinel")?(ee=f&&s.jsx(Dd,{}),L=!h&&s.jsx(Td,{}),Y=!h&&s.jsx(Ed,{}),oe=!h&&Fo,V=s.jsx(Nd,{}),X=s.jsx(Cd,{}),$=da()&&!ls()&&!h&&!ko()&&s.jsx(Sd,{}),e[7]=V,e[8]=X,e[9]=$,e[10]=ee,e[11]=L,e[12]=Y,e[13]=oe):(V=e[7],X=e[8],$=e[9],ee=e[10],L=e[11],Y=e[12],oe=e[13]);let de;e[14]!==d?(de=d&&s.jsx(Yc,{}),e[14]=d,e[15]=de):de=e[15];let ue;return e[16]!==de||e[17]!==_?(ue=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[H,_,ee,L,Y,oe,V,X,$,de]}),e[16]=de,e[17]=_,e[18]=ue):ue=e[18],ue}let m;e[19]!==i||e[20]!==a?(m=()=>{switch(a){case"general":return s.jsx(y1,{});case"visual":return s.jsx(j1,{});case"chat":return s.jsx(w1,{});case"sessions":return s.jsx(k1,{runtimeEndpointEpoch:i});case"shortcuts":return s.jsx(v1,{});case"git":return s.jsx(N1,{});case"notifications":return s.jsx(S1,{});case"voice":return s.jsx(C1,{});case"tunnel":return s.jsx(I1,{});default:return null}},e[19]=i,e[20]=a,e[21]=m):m=e[21];const u=m;let v;e[22]!==n?(v=n("settings.page.general.title"),e[22]=n,e[23]=v):v=e[23];let w;e[24]!==n?(w=n("settings.page.appearance.title"),e[24]=n,e[25]=w):w=e[25];let b;e[26]!==n?(b=n("settings.page.chat.title"),e[26]=n,e[27]=b):b=e[27];let k;e[28]!==n?(k=n("settings.page.sessions.title"),e[28]=n,e[29]=k):k=e[29];let g;e[30]!==n?(g=n("settings.page.shortcuts.title"),e[30]=n,e[31]=g):g=e[31];let I;e[32]!==n?(I=n("settings.page.git.title"),e[32]=n,e[33]=I):I=e[33];let C;e[34]!==n?(C=n("settings.page.git.title"),e[34]=n,e[35]=C):C=e[35];let P;e[36]!==n?(P=n("settings.page.notifications.title"),e[36]=n,e[37]=P):P=e[37];let j;e[38]!==n?(j=n("settings.page.voice.title"),e[38]=n,e[39]=j):j=e[39];let T;e[40]!==n?(T=n("settings.page.tunnel.title"),e[40]=n,e[41]=T):T=e[41];let x;e[42]!==I||e[43]!==C||e[44]!==P||e[45]!==j||e[46]!==T||e[47]!==v||e[48]!==w||e[49]!==b||e[50]!==k||e[51]!==g?(x={general:v,visual:w,chat:b,sessions:k,shortcuts:g,git:I,github:C,notifications:P,voice:j,tunnel:T},e[42]=I,e[43]=C,e[44]=P,e[45]=j,e[46]=T,e[47]=v,e[48]=w,e[49]=b,e[50]=k,e[51]=g,e[52]=x):x=e[52];const A=x[a];let M;e[53]!==n?(M=n("settings.page.general.description"),e[53]=n,e[54]=M):M=e[54];let S;e[55]!==n?(S=n("settings.page.appearance.description"),e[55]=n,e[56]=S):S=e[56];let D;e[57]!==n?(D=n("settings.page.chat.description"),e[57]=n,e[58]=D):D=e[58];let O;e[59]!==n?(O=n("settings.page.sessions.description"),e[59]=n,e[60]=O):O=e[60];let F;e[61]!==n?(F=n("settings.page.shortcuts.description"),e[61]=n,e[62]=F):F=e[62];let N;e[63]!==n?(N=n("settings.page.notifications.description"),e[63]=n,e[64]=N):N=e[64];let R;e[65]!==n?(R=n("settings.page.voice.description"),e[65]=n,e[66]=R):R=e[66];let U;e[67]!==n?(U=n("settings.page.tunnel.description"),e[67]=n,e[68]=U):U=e[68];let K;e[69]!==M||e[70]!==S||e[71]!==D||e[72]!==O||e[73]!==F||e[74]!==N||e[75]!==R||e[76]!==U?(K={general:M,visual:S,chat:D,sessions:O,shortcuts:F,git:void 0,github:void 0,notifications:N,voice:R,tunnel:U},e[69]=M,e[70]=S,e[71]=D,e[72]=O,e[73]=F,e[74]=N,e[75]=R,e[76]=U,e[77]=K):K=e[77];const W=K[a];let te;e[78]!==u?(te=u(),e[78]=u,e[79]=te):te=e[79];let Q;return e[80]!==W||e[81]!==A||e[82]!==te?(Q=s.jsx(ns,{title:A,description:W,showSaveStatus:!0,className:"openchamber-page-body",children:te}),e[80]=W,e[81]=A,e[82]=te,e[83]=Q):Q=e[83],Q},v1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(m1,{}),t[0]=e):e=t[0],e},y1=()=>{const t=at.c(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),t[0]=e):e=t[0];const a=e;Rd();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=ls()&&fi(),t[1]=n):n=t[1];const r=n;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=da()&&!ls()&&!a&&!ko(),t[2]=i):i=t[2];const l=i;let d,c,h,p,f,m;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=r&&s.jsx(Dd,{}),c=l&&s.jsx(Sd,{}),h=s.jsx(Cd,{}),p=!a&&s.jsx(Td,{}),f=!a&&s.jsx(Ed,{}),m=!a&&Fo,t[3]=d,t[4]=c,t[5]=h,t[6]=p,t[7]=f,t[8]=m):(d=t[3],c=t[4],h=t[5],p=t[6],f=t[7],m=t[8]);let u;t[9]===Symbol.for("react.memo_cache_sentinel")?(u=a?[]:["sessionTabs"],t[9]=u):u=t[9];let v;return t[10]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsxs(s.Fragment,{children:[d,c,h,p,f,m,s.jsx(or,{visibleSettings:["fileEditorKeymap",...u,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[10]=v):v=t[10],v},j1=()=>{const t=at.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(or,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=n):n=t[1],n},w1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(or,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","promptNavigatorEnabled","wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[0]=e):e=t[0],e},k1=t=>{const e=at.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(Id,{},a),e[0]=a,e[1]=n):n=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Nd,{}),e[2]=r):r=e[2];let i;return e[3]!==n?(i=s.jsxs(s.Fragment,{children:[n,r]}),e[3]=n,e[4]=i):i=e[4],i},N1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xd,{}),t[0]=e):e=t[0],e},S1=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(hy,{}),t[0]=e):e=t[0],e},C1=()=>{const t=at.c(1);if(fs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Sy,{}),t[0]=e):e=t[0],e},I1=()=>{const t=at.c(1);if(fs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Fy,{}),t[0]=e):e=t[0],e};function P1(t){return t+1}const A1=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{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.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],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.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{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.animated-activity-indicators",page:"appearance",titleKey:"settings.openchamber.visual.field.animatedActivityIndicators",descriptionKey:"settings.openchamber.visual.field.animatedActivityIndicatorsInfo",keywords:["spinner","animation","session","activity","motion","running","indicator"]},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"],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.warming",page:"sessions",titleKey:"settings.openchamber.defaults.field.sessionWarming",descriptionKey:"settings.openchamber.defaults.field.sessionWarmingInfo",keywords:["warming","warm","cache","prompt cache","keep-alive","idle"]},{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-only-archived",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.onlyArchived",descriptionKey:"settings.openchamber.sessionRetention.field.onlyArchivedDescription",keywords:["archive","archived","only","delete","cleanup","retention"]},{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-restart",page:"general",titleKey:"settings.openchamber.opencodeCli.actions.restart",keywords:["opencode","restart","reload","plugin"],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},{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.browser-provider",page:"general",titleKey:"settings.openchamber.tools.browserProvider.label",descriptionKey:"settings.openchamber.tools.browserProvider.info",keywords:["agent","browser","provider","extension","chrome","server","headless"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-notify-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentNotifyTool",descriptionKey:"settings.openchamber.tools.field.agentNotifyToolInfo",keywords:["agent","tool","notify","notification","alert","ping","openchamber"],isAvailable:t=>!t.isVSCode},{id:"general.isolated-spaces",page:"general",titleKey:"settings.openchamber.spaces.field.enabled",descriptionKey:"settings.openchamber.spaces.field.enabledInfo",keywords:["isolated","space","spaces","container","docker","sandbox","agent"],isAvailable:t=>!t.isVSCode&&Fo},{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&&fe.getState().agentMemoryFeatureAvailable},{id:"routing.token",page:"routing",titleKey:"settings.routing.token.label",descriptionKey:"settings.routing.token.info",keywords:["jev","typesafe","api key","token","routing","zen","free"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.enabled",page:"routing",titleKey:"settings.routing.auto.enable",descriptionKey:"settings.routing.auto.enableInfo",keywords:["auto","routing","model","jev","automatic"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.fallback-model",page:"routing",titleKey:"settings.routing.auto.fallbackModel",descriptionKey:"settings.routing.auto.fallbackModelInfo",keywords:["fallback","default","model","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.safety-enabled",page:"routing",titleKey:"settings.routing.safety.enable",descriptionKey:"settings.routing.safety.enableInfo",keywords:["safety net","auto-accept","permissions","destructive","hold"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"routing.add-category",page:"routing",titleKey:"settings.routing.categories.title",descriptionKey:"settings.routing.categories.description",keywords:["category","categories","task type","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{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-agent",page:"projects",titleKey:"settings.projects.page.field.projectAgent",keywords:["agent","default","new chat","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:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".openchamber","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{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",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.steps",page:"agents",titleKey:"settings.agents.page.field.steps",descriptionKey:"settings.agents.page.field.stepsTooltip",keywords:["steps","loop","tool calls"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","rules","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.variant",page:"commands",titleKey:"settings.agents.page.field.variant",keywords:["variant","reasoning","thinking"]},{id:"commands.subagent",page:"commands",titleKey:"settings.commands.page.field.subagent",descriptionKey:"settings.commands.page.field.subagentTooltip",keywords:["subagent","background","child session"]},{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","code mode","codemode"]},{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:"web-search.provider",page:"web-search",titleKey:"settings.webSearch.section.provider",descriptionKey:"settings.webSearch.section.providerInfo",keywords:["web search","websearch","internet","default provider","disable","off","random"]},{id:"web-search.keys",page:"web-search",titleKey:"settings.webSearch.section.keys",keywords:["api key","exa","tavily","firecrawl","parallel","tinyfish","credentials"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{id:"integrations.guests",page:"integrations",titleKey:"settings.integrations.guests.title",descriptionKey:"settings.integrations.guests.info",keywords:["guest","extension","oauth","clickup","gitlab","panel","connect"],isAvailable:t=>!t.isVSCode},{id:"extensions.add",page:"extensions",titleKey:"settings.extensions.add.label",descriptionKey:"settings.extensions.add.info",keywords:["folder","path","zip","git","url","install","guest","panel"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.gitIdentity",page:"extensions",titleKey:"settings.extensions.identity.title",descriptionKey:"settings.extensions.add.info",keywords:["ssh","key","identity","git","private","clone","extension"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.updates.check",page:"extensions",titleKey:"settings.extensions.updates.check",keywords:["update","upgrade","version","git","extension","guest","refresh"],isAvailable:t=>!t.isVSCode&&!t.isMobile}];function jc(t){return t.trim().toLocaleLowerCase()}function T1({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=jc(t);if(!i)return[];const l=a?new Set(a):null,d=i.split(/\s+/).filter(Boolean);return A1.flatMap(c=>{if(l&&!l.has(c.page))return[];const h=_a(c.page);if(!h||h.isAvailable&&!h.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const p=n(c.titleKey),f=c.descriptionKey?n(c.descriptionKey):null,m=jc([p,f,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(u=>m.includes(u))?[{...c,title:p,description:f,pageTitle:r(c.page)}]:[]})}const wc=256,kc=280,Od="__openchamberSettingsDetail",E1=["general","appearance","chat","notifications","sessions","routing","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","providers","web-search","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],D1=["general","projects","opencode","content"],M1="__add_provider__";function R1(t,e,a){const n=fs(),r=!t&&da();return{isVSCode:n,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:a}}function Nc(t,e){return t.isAvailable?t.isAvailable(e):!0}function po(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ri(t,e){const a=new Set(e);let n=t,r=1;for(;a.has(n);)n=`${t}-${r}`,r+=1;return n}function Yr(t){if(!po(t))return null;const e=t[Od];if(!po(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Jc(a),stage:n}}function O1(){return typeof window>"u"||!po(window.history.state)?{}:window.history.state}const Z1=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:r="nav",registerBackHandler:i})=>{const{t:l}=Ze(),d=Qn(),c=e??d.isMobile,h=fe(J=>J.settingsPage),p=fe(J=>J.isSettingsDialogOpen),f=fe(J=>J.setSettingsPage),m=fe(J=>J.shortcutOverrides.open_settings),u=Jc(h),[v,w]=o.useState(r),b=o.useRef(r==="nav"?u:null);o.useEffect(()=>{!c&&u==="home"&&f("general")},[c,f,u]);const[k,g]=o.useState(""),[I,C]=o.useState(null),[P,j]=o.useState(0),T=o.useRef(null),x=o.useRef(!1),A=o.useRef([]),M=o.useRef(0),S=o.useRef(!1),D=o.useMemo(()=>ls(),[]),O=o.useMemo(()=>ls()&&fi(),[]),F=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),N=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),R=o.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),U=fe(J=>J.routingFeatureAvailable),K=o.useMemo(()=>R1(D,c,U),[D,c,U]),W=o.useMemo(()=>{const J=n?new Set(n):null;return Om.filter(se=>se.slug!=="home").filter(se=>!J||J.has(se.slug)).filter(se=>Nc(se,K)).filter(se=>!(K.isVSCode&&se.slug==="projects")).filter(se=>!(c&&se.slug==="shortcuts"))},[K,c,n]),te=o.useMemo(()=>{const J=new Map(E1.map((se,he)=>[se,he]));return W.slice().sort((se,he)=>(J.get(se.slug)??999)-(J.get(he.slug)??999))},[W]),Q=rn(J=>J.activeProjectId),H=Js();o.useEffect(()=>{if(!(!p&&!K.isVSCode&&!a)){if(u==="agents"){Wn.getState().loadAgents(H);return}if(u==="commands"){Ga.getState().loadCommands(H);return}if(u==="mcp"){Jn.getState().loadMcpConfigs({directory:H});return}if(u==="plugins"){Wt.getState().loadPlugins();return}(u==="skills.installed"||u==="skills.catalog")&&(nn.getState().loadSkills(H),On.getState().loadCatalog()),u==="snippets"&&Qi.getState().loadSnippets()}},[Q,p,a,K.isVSCode,H,u]);const _=o.useCallback(J=>{if(f(J),b.current=J,!c)return;const se=_a(J);if(!se||se.slug==="home"){w("nav");return}w(se.kind==="split"?"page-sidebar":"page-content")},[c,f]),V=o.useMemo(()=>_a(u),[u]),X=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),$=o.useCallback(J=>{switch(J){case"general":return l("settings.page.general.title");case"projects":return l("settings.page.projects.title");case"remote-instances":return l("settings.page.remoteInstances.title");case"providers":return l("settings.page.providers.title");case"web-search":return l("settings.page.webSearch.title");case"usage":return l("settings.page.usage.title");case"agents":return l("settings.page.agents.title");case"behavior":return l("settings.page.behavior.title");case"commands":return l("settings.page.commands.title");case"mcp":return l("settings.page.mcp.title");case"plugins":return l("settings.page.plugins.title");case"skills.installed":return l("settings.page.skills.title");case"skills.catalog":return l("settings.page.skillsCatalog.title");case"git":return l("settings.page.git.title");case"integrations":return l("settings.page.integrations.title");case"extensions":return l("settings.page.extensions.title");case"appearance":return l("settings.page.appearance.title");case"chat":return l("settings.page.chat.title");case"shortcuts":return l("settings.page.shortcuts.title");case"sessions":return l("settings.page.sessions.title");case"routing":return l("settings.page.routing.title");case"magic-prompts":return l("settings.page.magicPrompts.title");case"snippets":return l("settings.page.snippets.title");case"notifications":return l("settings.page.notifications.title");case"voice":return l("settings.page.voice.title");case"tunnel":return l("settings.page.tunnel.title");case"about":return l("settings.page.about.title");default:return l("settings.view.home.title")}},[l]),ee=o.useMemo(()=>T1({query:k,runtimeCtx:{...K,isDesktopLocalOrigin:O,isMac:F,isWindows:N,isLinux:R},visiblePageSlugs:n,t:l,getPageTitle:$}),[$,O,F,N,R,K,k,l,n]),L=o.useCallback(J=>{if(J.id.startsWith("agents.")){const se=Wn.getState(),he=ri("new-agent",se.agents.map(ve=>ve.name));return se.setAgentDraft({name:he,scope:"user"}),se.setSelectedAgent(he),J.id==="agents.create"?"agents.name":J.id}if(J.id.startsWith("commands.")){const se=Ga.getState(),he=ri("new-command",se.commands.map(ve=>ve.name));return se.setCommandDraft({name:he,scope:"user"}),se.setSelectedCommand(he),J.id==="commands.create"?"commands.name":J.id}if(J.id.startsWith("mcp.")){const se=Jn.getState(),he=ri("new-mcp-server",se.mcpServers.map(ve=>ve.name));return se.setMcpDraft({name:he,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1}),se.setSelectedMcp(he),J.id==="mcp.create"?"mcp.server":J.id}if(J.id.startsWith("snippets.")){const se=Qi.getState(),he=ri("new-snippet",se.snippets.map(ve=>ve.name));return se.setSnippetDraft({name:he,scope:"global"}),se.setSelectedSnippet(he),J.id==="snippets.create"?"snippets.content":J.id}if(J.id.startsWith("skills.")){const se=nn.getState(),he=ri("new-skill",se.skills.map(ve=>ve.name));return se.setSkillDraft({name:he,scope:"user",source:"opencode",description:"",instructions:""}),se.setSelectedSkill(he),J.id==="skills.create"?"skills.basic-information":J.id}return J.id==="providers.connect"&&it.getState().setSelectedProvider(M1),J.id==="plugins.create"?"plugins.spec":J.id},[]),Y=o.useMemo(()=>{const J=[],se=new Map;for(const he of ee){let ve=se.get(he.page);ve||(ve={page:he.page,pageTitle:he.pageTitle,results:[]},se.set(he.page,ve),J.push(ve)),ve.results.push(he)}return J},[ee]);o.useEffect(()=>{j(0),M.current=0,S.current=!1},[k]),o.useEffect(()=>{M.current=P},[P]),o.useEffect(()=>{A.current[P]?.scrollIntoView({block:"nearest"})},[P]),o.useEffect(()=>{P>=ee.length&&j(Math.max(0,ee.length-1)),A.current.length=ee.length},[P,ee.length]);const oe=o.useCallback(J=>{const se=L(J);C(se),_(J.page),c&&w("page-content"),J.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,_,L]),de=o.useCallback(J=>{if(k.trim()){if(J.key==="Escape"){J.preventDefault(),g("");return}if(ee.length!==0){if(J.key==="ArrowDown"){J.preventDefault(),S.current=!0,j(se=>(se+1)%ee.length);return}if(J.key==="ArrowUp"){J.preventDefault(),S.current=!0,j(se=>(se-1+ee.length)%ee.length);return}if(J.key==="Enter"){J.preventDefault();const se=(M.current%ee.length+ee.length)%ee.length,he=ee[se]??ee[0];he&&oe(he)}}}},[oe,k,ee]);o.useEffect(()=>{const J=I;if(!J)return;let se=!1;const he=window.requestAnimationFrame(()=>{if(se)return;const ve=typeof CSS<"u"&&CSS.escape?CSS.escape(J):J.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Fe=T.current?.querySelector(`[data-settings-item="${ve}"]`);Fe&&(C(null),Fe.scrollIntoView({block:"center",behavior:"smooth"}),Fe.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Fe.removeAttribute("data-settings-search-highlight")},1600))});return()=>{se=!0,window.cancelAnimationFrame(he)}},[I,u]);const ue=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:Ec,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),ce=o.useCallback((J,se)=>{switch(J){case"projects":return s.jsx(Mf,{onItemSelect:se.onItemSelect});case"agents":return s.jsx(Np,{onItemSelect:se.onItemSelect});case"commands":return s.jsx(gg,{onItemSelect:se.onItemSelect});case"mcp":return s.jsx(kg,{onItemSelect:se.onItemSelect});case"plugins":return s.jsx(yh,{onItemSelect:se.onItemSelect});case"skills.installed":return s.jsx(ef,{onItemSelect:se.onItemSelect});case"providers":return s.jsx(ux,{onItemSelect:se.onItemSelect});case"usage":return s.jsx(Hx,{onItemSelect:se.onItemSelect});case"magic-prompts":return s.jsx(lb,{onItemSelect:se.onItemSelect});case"snippets":return s.jsx(mb,{onItemSelect:se.onItemSelect});default:return null}},[]),Se=o.useCallback(J=>{const se=_a(J);if(se&&!Nc(se,K))return ue();switch(J){case"projects":return s.jsx(Kf,{});case"remote-instances":return s.jsx(lx,{});case"agents":return s.jsx(Jp,{});case"behavior":return s.jsx(tg,{});case"commands":return s.jsx(jg,{});case"mcp":return s.jsx(nh,{});case"plugins":return s.jsx(zh,{});case"skills.installed":return s.jsx(El,{view:"installed"});case"skills.catalog":return s.jsx(El,{view:"catalog"});case"providers":return s.jsx(Bx,{});case"web-search":return s.jsx(rg,{});case"usage":return s.jsx(rb,{});case"about":return s.jsx(ns,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Yc,{})});case"magic-prompts":return s.jsx(ub,{});case"snippets":return s.jsx(fb,{});case"git":return s.jsx(jb,{});case"integrations":return s.jsx(zb,{});case"routing":return s.jsx(Jb,{});case"extensions":return s.jsx(vv,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const he=X[J]??"visual";return s.jsx(b1,{section:he})}default:return null}},[X,ue,K,l]);o.useEffect(()=>{if(!c||v!=="nav"||u==="home"||b.current===u)return;const J=_a(u);!J||J.slug==="home"||(b.current=u,w(J.kind==="split"?"page-sidebar":"page-content"))},[c,v,u]);const ie=c&&v!=="nav",be=c&&v==="page-content"&&V?.kind==="split",ae=l(be?"settings.view.actions.back":ie?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),pe=Bc("open_settings",m===void 0?void 0:{open_settings:m}),je=pe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:ua(pe)}):l("settings.view.actions.closeSettings"),De=o.useCallback(J=>{if(typeof window>"u"||K.isVSCode)return;const se=Yr(window.history.state);se?.page===J&&se.stage==="page-content"||window.history.pushState({...O1(),[Od]:{page:J,stage:"page-content"}},"",window.location.href)},[K.isVSCode]),me=o.useCallback(()=>{x.current=!0,w("page-content"),De(u)},[De,u]);o.useEffect(()=>{if(!c||v!=="page-content"||!x.current)return;x.current=!1;const J=window.requestAnimationFrame(()=>{T.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(J)}},[c,v,u]);const $e=o.useCallback(()=>{if(be){if((typeof window<"u"?Yr(window.history.state):null)?.page===u&&!K.isVSCode){window.history.back();return}w("page-sidebar");return}w("nav")},[be,K.isVSCode,u]);o.useEffect(()=>{if(i)return i(()=>!c||v==="nav"?!1:($e(),!0)),()=>i(null)},[$e,c,v,i]),o.useEffect(()=>{if(!c||K.isVSCode)return;const J=se=>{if(_a(u)?.kind!=="split")return;if(Yr(se.state)?.page===u){w("page-content");return}w(ve=>ve==="page-content"?"page-sidebar":ve)};return window.addEventListener("popstate",J),()=>{window.removeEventListener("popstate",J)}},[c,K.isVSCode,u]);const Ge=()=>{const J=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:"oc-surface-elevated flex h-10 items-center gap-1.5 rounded-md border border-border bg-surface-elevated/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-ring sm:h-8",children:[s.jsx(z,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:k,onChange:se=>g(se.target.value),onKeyDown:de,placeholder:l("settings.view.search.placeholder"),"aria-label":l("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),J&&s.jsx("button",{type:"button",onClick:()=>g(""),"aria-label":l("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:J?ee.length>0?(()=>{let se=0;return Y.map(he=>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:he.pageTitle}),he.results.map(ve=>{const Fe=se;se+=1;const Ke=Fe===P,Be=!!ve.description;return s.jsxs("button",{type:"button",ref:ze=>{A.current[Fe]=ze},onMouseMove:()=>{S.current=!1,j(Fe)},onClick:()=>oe(ve),className:Ie("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Be?"min-h-11 py-1.5":"py-2",Ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ve.title}),Be&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ve.description})]},ve.id)})]},he.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const se=new Map;for(const ve of te){const Fe=ve.group,Ke=se.get(Fe);Ke?Ke.push(ve):se.set(Fe,[ve])}return D1.map(ve=>({group:ve,pages:se.get(ve)??[]})).filter(ve=>ve.pages.length>0).map(({group:ve,pages:Fe},Ke)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:Ie("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ke===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${ve}`)}),Fe.map(Be=>{const ze=u===Be.slug&&!(c&&v==="nav"),_e=Fm(Be.slug);return!_e&&Be.slug!=="mcp"?null:s.jsx(nr,{children:s.jsx(ar,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>_(Be.slug),"aria-current":ze?"page":void 0,className:Ie("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",ze?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Be.slug==="mcp"?s.jsx(Wu,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(z,{name:_e,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:$(Be.slug)}),Be.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:l("settings.view.badge.beta")})]})]})})},Be.slug)})]},ve))})()})})]})},xe=()=>{if(v==="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(Hn,{children:Ge()})})});if(!V)return s.jsx("div",{className:"flex-1 bg-background"});if(v==="page-sidebar"){if(V.kind!=="split"){const se=Se(u);return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:se})})}return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:ce(u,{onItemSelect:me})})})}const J=Se(u);return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:J})})},Pe=()=>!V||u==="home"?null:V.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:Ie("border-r",K.isVSCode?"bg-background":"bg-sidebar"),style:{width:kc,minWidth:kc,borderColor:"var(--interactive-border)"},children:s.jsx(Hn,{children:ce(u,{})})}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:Se(u)})})]}):s.jsx(bs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Hn,{children:Se(u)})});return s.jsxs("div",{ref:T,"data-settings-view":"true",className:Ie("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:Ie("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",v!=="nav"&&"border-b","bg-background"),style:v!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ie?s.jsx("button",{type:"button",onClick:$e,"aria-label":ae,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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:v==="nav"?l("settings.view.home.title"):V?$(V.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:je,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ie&&s.jsx("div",{className:Ie("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:$e,"aria-label":l("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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:Ie("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:je,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?xe():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Ie("relative flex h-full min-h-0 flex-col overflow-hidden border-r",D?"bg-sidebar":K.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${wc}px`,minWidth:`${wc}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Hn,{children:Ge()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Pe()})]})})]})};export{Yc as A,Z1 as S};