@vantran-se/openchamber-web 2.0.4 → 2.0.5

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 (243) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DZF8ntaq.js → CodeMirrorCommentWidgets-DCAQTLMM.js} +1 -1
  2. package/dist/assets/DiffView-uzNpHBlV.js +4 -0
  3. package/dist/assets/FilesView-Bkq0sjNx.js +17 -0
  4. package/dist/assets/{GitView-DwQwqDvu.js → GitView-BmibZC7n.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-CoXM0gh_.js → GuestAttachDialog-D7TJG1rt.js} +1 -1
  6. package/dist/assets/GuestSurfacePane-PAcYaFzP.js +1 -0
  7. package/dist/assets/{JsonTreeView-Cq_27v0y.js → JsonTreeView-BNT2yUVu.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-CsSSRMhn.js → LinearIssuesView-D3Azksju.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-BGY6tuiK.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-DJmhQ37f.js +12 -0
  11. package/dist/assets/{OnboardingScreen-ClatMQAX.js → OnboardingScreen-D_41H2qC.js} +1 -1
  12. package/dist/assets/{PatchDiff-DOwlrIK9.js → PatchDiff-C0RSqa9W.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-CrcGqqD_.js → PierreDiffViewer-BBE7tTY2.js} +3 -3
  14. package/dist/assets/{PlanView-BGLsMgQk.js → PlanView-Bqc-xuDe.js} +4 -4
  15. package/dist/assets/PluginPane-DQ0k41Q-.js +3 -0
  16. package/dist/assets/SettingsView-BAiJU5hJ.js +30 -0
  17. package/dist/assets/{SettingsWindow-B0BAy-f9.js → SettingsWindow-DuC4ecLw.js} +1 -1
  18. package/dist/assets/{SubmoduleDiffSummary-fcdDzCSW.js → SubmoduleDiffSummary-0HgmcMXz.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-B7xaUz2H.js → ToolOutputDialog-DdHkQJEE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-CkWCaUmZ.js → ToolPartDiffPreview-DWdN0r5K.js} +2 -2
  21. package/dist/assets/{VirtualizedFileDiff-DONC4eI2.js → VirtualizedFileDiff-ClDezf2d.js} +1 -1
  22. package/dist/assets/{WalkthroughView-CXDImOXW.js → WalkthroughView-BJicp0RC.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-Br2TLSlb.js → appThemeRegistry-CiuyzfSW.js} +1 -1
  24. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  25. package/dist/assets/commitAndPush-DTKb6IwT.js +1 -0
  26. package/dist/assets/{computeVirtualFileMetrics-_-20umCs.js → computeVirtualFileMetrics-kM_zJNMt.js} +2 -2
  27. package/dist/assets/de-BMnfXm-G.js +10 -0
  28. package/dist/assets/es-DKEvCCL6.js +16 -0
  29. package/dist/assets/fr-D9fgE2xE.js +14 -0
  30. package/dist/assets/index-DUke1nme.css +1 -0
  31. package/dist/assets/{index-OKDYjcMF.js → index-DWB8bR_g.js} +1 -1
  32. package/dist/assets/index-Di6zUe5h.js +41 -0
  33. package/dist/assets/{isDiffPlainText-D77M6q1f.js → isDiffPlainText-DOoIsGqs.js} +1 -1
  34. package/dist/assets/{isFilePlainText-C54B4Mns.js → isFilePlainText-bt5VHvcd.js} +1 -1
  35. package/dist/assets/ja-BEXad-KW.js +16 -0
  36. package/dist/assets/ko-DGrQ0lEe.js +16 -0
  37. package/dist/assets/{main-CGEvLMd2.js → main-BpLQbZC2.js} +2 -2
  38. package/dist/assets/main-CI9DtHJv.js +896 -0
  39. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  40. package/dist/assets/markdownCore-DK2KK5RW.js +7 -0
  41. package/dist/assets/{miniChat-BSxkRQLj.js → miniChat-CIWaR8wG.js} +2 -2
  42. package/dist/assets/{mobile-C5KRTNOB.js → mobile-CnWKEYIP.js} +2 -2
  43. package/dist/assets/patchFileDiff-Cqn0C0az.js +13 -0
  44. package/dist/assets/pl-BlhkmR5b.js +16 -0
  45. package/dist/assets/pt-BR-Bs96Ew9I.js +16 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CnkAQV6o.js → renderElectronMiniChatApp-D9t0-9nV.js} +2 -2
  47. package/dist/assets/renderMobileApp-CW7fVs_s.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-D0PcCb3K.js +27 -0
  49. package/dist/assets/scheduledTasksApi-Dahv3ws0.js +1 -0
  50. package/dist/assets/{shikiHighlight-4O0ZM14D.js → shikiHighlight-l-MbaNS4.js} +1 -1
  51. package/dist/assets/{textMateThemeFromAppTheme-yNq7b0DZ.js → textMateThemeFromAppTheme-C-kGcOpD.js} +1 -1
  52. package/dist/assets/tr-CehUK1M9.js +7 -0
  53. package/dist/assets/uk-Bno5WGNz.js +16 -0
  54. package/dist/assets/{useAppFontEffects-Bzyszv2N.js → useAppFontEffects-DDjuwVqi.js} +160 -156
  55. package/dist/assets/{useInlineCommentController-zOf6ORAq.js → useInlineCommentController-Clg8EO3A.js} +2 -2
  56. package/dist/assets/{useRootScrollLock-DCaZ4BWi.js → useRootScrollLock-nDcRrgJ1.js} +2 -2
  57. package/dist/assets/{vendor-codemirror-language-data-6cEFPNUR.js → vendor-codemirror-language-data-oKF0MAwd.js} +2 -2
  58. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  59. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  60. package/dist/assets/{web-components-BEo4-ISu.js → web-components-Bc1WPd4i.js} +1 -1
  61. package/dist/assets/zh-CN-DnAweIWo.js +16 -0
  62. package/dist/assets/zh-TW-BbBBK25p.js +16 -0
  63. package/dist/index.html +5 -5
  64. package/dist/mini-chat.html +5 -5
  65. package/dist/mobile.html +5 -5
  66. package/package.json +3 -3
  67. package/server/index.js +82 -0
  68. package/server/lib/agent-tool/DOCUMENTATION.md +132 -47
  69. package/server/lib/agent-tool/runtime.js +34 -15
  70. package/server/lib/agent-tool/runtime.test.js +15 -0
  71. package/server/lib/browser-control/DOCUMENTATION.md +14 -2
  72. package/server/lib/event-stream/global-hub.js +23 -1
  73. package/server/lib/event-stream/global-hub.test.js +35 -0
  74. package/server/lib/event-stream/global-ws-bridge.js +3 -1
  75. package/server/lib/event-stream/upstream-reader.js +3 -2
  76. package/server/lib/git/DOCUMENTATION.md +1 -1
  77. package/server/lib/git/service.js +22 -0
  78. package/server/lib/git/service.test.js +8 -0
  79. package/server/lib/guests/DOCUMENTATION.md +4 -3
  80. package/server/lib/guests/catalog.js +19 -1
  81. package/server/lib/guests/catalog.test.js +22 -0
  82. package/server/lib/guests/html-styles.js +5 -3
  83. package/server/lib/guests/html-styles.test.js +3 -1
  84. package/server/lib/guests/routes.js +11 -3
  85. package/server/lib/guests/service.js +5 -0
  86. package/server/lib/guests/surface.js +55 -9
  87. package/server/lib/guests/surface.test.js +56 -6
  88. package/server/lib/notifications/DOCUMENTATION.md +10 -0
  89. package/server/lib/notifications/emit-route.js +118 -0
  90. package/server/lib/notifications/emit-route.test.js +112 -0
  91. package/server/lib/openchamber-control/actions.js +16 -2
  92. package/server/lib/openchamber-control/service.js +23 -0
  93. package/server/lib/openchamber-control/service.test.js +31 -0
  94. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  95. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  96. package/server/lib/openchamber-sessions/routes.js +11 -0
  97. package/server/lib/openchamber-sessions/routes.test.js +18 -0
  98. package/server/lib/opencode/bootstrap-runtime.js +14 -1
  99. package/server/lib/opencode/compatibility.js +6 -3
  100. package/server/lib/opencode/compatibility.test.js +8 -0
  101. package/server/lib/opencode/config-entity-v2.test.js +27 -0
  102. package/server/lib/opencode/config-paths.test.js +12 -0
  103. package/server/lib/opencode/config-v2.d.ts +2 -0
  104. package/server/lib/opencode/config-v2.js +42 -0
  105. package/server/lib/opencode/config-v2.test.js +17 -0
  106. package/server/lib/opencode/core-routes.js +20 -4
  107. package/server/lib/opencode/core-routes.test.js +41 -0
  108. package/server/lib/opencode/env-runtime.js +1 -8
  109. package/server/lib/opencode/feature-routes-runtime.js +2 -1
  110. package/server/lib/opencode/lifecycle.js +30 -2
  111. package/server/lib/opencode/lifecycle.test.js +27 -0
  112. package/server/lib/opencode/managed-config-file.js +18 -6
  113. package/server/lib/opencode/managed-config-file.test.js +23 -7
  114. package/server/lib/opencode/mcp.js +7 -2
  115. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  116. package/server/lib/opencode/npm-registry-config.js +123 -0
  117. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  118. package/server/lib/opencode/npm-registry.js +5 -6
  119. package/server/lib/opencode/npm-registry.test.js +30 -0
  120. package/server/lib/opencode/openchamber-routes.js +29 -11
  121. package/server/lib/opencode/openchamber-routes.test.js +18 -0
  122. package/server/lib/opencode/project-directory-runtime.js +8 -0
  123. package/server/lib/opencode/project-directory-runtime.test.js +13 -0
  124. package/server/lib/opencode/provider-source-route.test.js +59 -0
  125. package/server/lib/opencode/providers.js +3 -0
  126. package/server/lib/opencode/providers.test.js +62 -0
  127. package/server/lib/opencode/proxy.js +38 -2
  128. package/server/lib/opencode/routes-upgrade.test.js +1 -1
  129. package/server/lib/opencode/routes.js +36 -1
  130. package/server/lib/opencode/server-utils-runtime.js +5 -0
  131. package/server/lib/opencode/settings-helpers.js +10 -0
  132. package/server/lib/opencode/settings-helpers.test.js +2 -2
  133. package/server/lib/opencode/settings-registry.json +17 -0
  134. package/server/lib/opencode/settings-runtime.js +1 -0
  135. package/server/lib/opencode/shared.js +49 -4
  136. package/server/lib/opencode/shared.test.js +78 -1
  137. package/server/lib/opencode/shutdown-runtime.js +3 -0
  138. package/server/lib/opencode/skill-routes.js +28 -12
  139. package/server/lib/opencode/skill-routes.test.js +121 -1
  140. package/server/lib/opencode/upgrade-capability.js +0 -14
  141. package/server/lib/opencode/v1-migration-topup.js +21 -15
  142. package/server/lib/opencode/v1-migration-topup.test.js +14 -6
  143. package/server/lib/opencode/v2-install.d.ts +1 -0
  144. package/server/lib/opencode/v2-install.js +8 -7
  145. package/server/lib/opencode/v2-install.test.js +13 -4
  146. package/server/lib/opencode/watcher.js +3 -1
  147. package/server/lib/opencode/websearch-config.js +13 -1
  148. package/server/lib/quota/providers/kimi.js +1 -1
  149. package/server/lib/realtime-proxy.js +5 -1
  150. package/server/lib/realtime-proxy.test.js +29 -0
  151. package/server/lib/relay/tunnel-host.js +4 -1
  152. package/server/lib/relay/tunnel-host.test.js +11 -0
  153. package/server/lib/session-assist/DOCUMENTATION.md +17 -5
  154. package/server/lib/session-assist/runtime.js +19 -2
  155. package/server/lib/session-assist/runtime.test.js +8 -0
  156. package/server/lib/session-goal/DOCUMENTATION.md +11 -0
  157. package/server/lib/small-model/DOCUMENTATION.md +11 -10
  158. package/server/lib/small-model/index.js +27 -32
  159. package/server/lib/small-model/index.test.js +28 -16
  160. package/server/lib/spaces/DOCUMENTATION.md +404 -32
  161. package/server/lib/spaces/code-in-bait.js +145 -6
  162. package/server/lib/spaces/code-in.js +10 -150
  163. package/server/lib/spaces/code-in.test.js +7 -83
  164. package/server/lib/spaces/code-out.js +1819 -0
  165. package/server/lib/spaces/code-out.test.js +3945 -0
  166. package/server/lib/spaces/code-transfer.js +173 -0
  167. package/server/lib/spaces/command-stream.test.js +181 -0
  168. package/server/lib/spaces/dispatcher.js +670 -0
  169. package/server/lib/spaces/dispatcher.test.js +582 -0
  170. package/server/lib/spaces/gatekeeper-channel.js +61 -7
  171. package/server/lib/spaces/gatekeeper-channel.test.js +43 -7
  172. package/server/lib/spaces/gatekeeper-program.cjs +68 -14
  173. package/server/lib/spaces/gatekeeper-program.test.js +118 -3
  174. package/server/lib/spaces/hardening.js +20 -4
  175. package/server/lib/spaces/hardening.test.js +18 -3
  176. package/server/lib/spaces/host-git.js +7 -4
  177. package/server/lib/spaces/host-git.test.js +6 -2
  178. package/server/lib/spaces/host.js +310 -0
  179. package/server/lib/spaces/host.test.js +273 -0
  180. package/server/lib/spaces/journey.js +552 -0
  181. package/server/lib/spaces/journey.test.js +589 -0
  182. package/server/lib/spaces/layout.js +42 -8
  183. package/server/lib/spaces/manager.js +4 -3
  184. package/server/lib/spaces/manager.test.js +6 -0
  185. package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
  186. package/server/lib/spaces/places/contract-suite.js +36 -0
  187. package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
  188. package/server/lib/spaces/places/docker-live-support.js +27 -4
  189. package/server/lib/spaces/places/docker.js +33 -5
  190. package/server/lib/spaces/places/docker.test.js +42 -3
  191. package/server/lib/spaces/places/escape-suite.js +118 -14
  192. package/server/lib/spaces/places/fake-docker.js +3 -1
  193. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  194. package/server/lib/spaces/places/memory-place.js +24 -1
  195. package/server/lib/spaces/places/registry.js +1 -1
  196. package/server/lib/spaces/places/server.docker.live.test.js +69 -33
  197. package/server/lib/spaces/places/sessions.docker.live.test.js +222 -0
  198. package/server/lib/spaces/routes.js +216 -0
  199. package/server/lib/spaces/routes.test.js +213 -0
  200. package/server/lib/spaces/run-command.js +261 -8
  201. package/server/lib/spaces/run-command.test.js +193 -3
  202. package/server/lib/spaces/space-events.js +153 -0
  203. package/server/lib/spaces/space-events.test.js +160 -0
  204. package/server/lib/spaces/space-opencode.js +52 -0
  205. package/server/lib/spaces/space-opencode.test.js +41 -0
  206. package/server/lib/spaces/space-records.js +150 -0
  207. package/server/lib/spaces/space-records.test.js +113 -0
  208. package/server/lib/spaces/space-sessions.js +210 -0
  209. package/server/lib/spaces/space-sessions.test.js +161 -0
  210. package/server/lib/spaces/websocket.js +329 -0
  211. package/server/lib/spaces/websocket.test.js +345 -0
  212. package/server/lib/ui-auth/ui-auth.js +8 -2
  213. package/server/lib/ui-auth/ui-auth.test.js +29 -0
  214. package/server/opencode-proxy.test.js +113 -0
  215. package/dist/assets/DiffView-D2p4Ar0H.js +0 -4
  216. package/dist/assets/FilesView-BeTtbsip.js +0 -17
  217. package/dist/assets/GuestSurfacePane-DIJvkkM-.js +0 -1
  218. package/dist/assets/MarkdownImageGallery-CY0dWTaE.js +0 -1
  219. package/dist/assets/MarkdownRendererImpl-ILdXzLrt.js +0 -12
  220. package/dist/assets/PluginPane-B39JEUL8.js +0 -3
  221. package/dist/assets/SettingsView-13B2_G-A.js +0 -29
  222. package/dist/assets/commitAndPush-CcI4ol7c.js +0 -1
  223. package/dist/assets/de-BtYnUgII.js +0 -10
  224. package/dist/assets/es-crP5qPye.js +0 -16
  225. package/dist/assets/fr-CLSRuALk.js +0 -14
  226. package/dist/assets/index-CLcM8HKx.css +0 -1
  227. package/dist/assets/index-CvLgnuNI.js +0 -41
  228. package/dist/assets/ja-SZ1-ucLV.js +0 -16
  229. package/dist/assets/ko-HthbT_Ve.js +0 -16
  230. package/dist/assets/main-BJklC7Cl.js +0 -896
  231. package/dist/assets/markdownCore-BzQuETm0.js +0 -5
  232. package/dist/assets/patchFileDiff-DGw2KryM.js +0 -13
  233. package/dist/assets/pl-C8eYfjL1.js +0 -16
  234. package/dist/assets/pt-BR-cYOrZdxS.js +0 -16
  235. package/dist/assets/renderMobileApp-CMxjwisj.js +0 -25
  236. package/dist/assets/runtimeEndpointReset-C45jrFq4.js +0 -27
  237. package/dist/assets/scheduledTasksApi-CkK1F9s2.js +0 -1
  238. package/dist/assets/tr-B4IQ5t-T.js +0 -7
  239. package/dist/assets/uk-DCoXG6ve.js +0 -16
  240. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +0 -12
  241. package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
  242. package/dist/assets/zh-CN-BXBoxsFk.js +0 -16
  243. package/dist/assets/zh-TW-C6oelpnL.js +0 -16
@@ -1,29 +0,0 @@
1
- import{R as o,j as s,f as rt,r as tt}from"./vendor-react-BUCujlKS.js";import{f as Xe,B as G,I as B,o as yn,bj as Jn,t as $,O as Ad,gY as Td,eY as Ge,gZ as It,b as an,T as ha,h as Ie,au as Ed,g_ as Cr,g$ as Dd,cl as _t,ck as At,cn as mt,cm as Tt,cj as Et,eO as Gn,h0 as bc,h1 as Md,h2 as Ka,h3 as Pn,c8 as vs,c2 as Kt,c3 as zt,c4 as Ut,c5 as $t,c6 as Bt,c7 as as,X as We,h4 as di,av as Kn,bh as wn,at as zn,as as _n,h5 as Yr,h6 as Bi,ad as Wn,ac as dn,f2 as Ht,h7 as mn,h8 as po,h9 as Ss,l as it,ha as ri,fj as Ln,hb as vc,fg as St,fd as Vt,hc as Rt,co as As,e7 as la,ff as qs,fh as nn,hd as gs,ec as fs,he as ys,cV as gt,hf as yc,hg as Rd,hh as Fd,hi as ui,hj as Od,hk as ks,eX as Ps,hl as tn,gg as Va,gm as sn,hm as za,hn as jc,ho as go,e8 as ho,ah as _a,hp as Zr,g as oi,hq as Ko,cg as kn,cr as Nn,ch as Sn,hr as Cn,hs as Gt,ht as fo,ae as sr,af as nr,ag as xo,hu as bo,hv as ta,hw as wc,hx as Fn,a7 as mi,cw as vo,hy as zo,ay as Ld,cp as Kd,d9 as zd,U as _d,V as Ud,W as $d,_ as yo,hz as Bd,hA as Vd,ce as Hd,cq as Xr,hB as kc,fi as Nc,P as sa,hC as Ms,a6 as qd,hD as Gd,n as rs,eu as Wi,y as Sc,x as Wd,i as Jd,j as Qd,ev as Yd,p as Zd,hE as Xd,hF as eu,hG as _o,ed as Cc,hH as tu,hI as Ir,hJ as Uo,hK as su,hL as nu,hM as au,hN as iu,ga as Ji,hO as ls,hP as ws,dg as Ic,bZ as Pc,dh as Ac,b_ as Vs,hQ as On,hR as jo,aH as qn,aI as Ea,hS as Xs,hT as Rn,du as Tc,hU as Ec,hV as Dc,hW as ru,eW as ou,eV as lu,hX as eo,eF as cu,hY as na,hZ as Ds,h_ as Bs,g3 as aa,h$ as Ns,i0 as du,i1 as $o,i2 as Mc,i3 as ia,i4 as uu,i5 as mu,R as Rc,da as pu,d4 as gu,d5 as hu,cJ as fu,eQ as xu,d6 as bu,d0 as vu,bp as yu,i6 as Ha,fc as Da,i7 as Bo,i8 as Ma,i9 as Ra,b$ as da,ia as ju,ib as wu,ic as ku,id as Nu,ie as Pr,ig as Vo,ih as Su,ii as Cu,ij as Iu,ik as Pu,il as Ho,z as Au,m as qo,dx as Tu,im as Eu,io as Ar,ip as Go,eH as Du,ez as Mu,iq as ar,ir as Ru,is as Fu,it as Ou,iu as Lu,iv as Ku,iw as Tr,cW as zu,c0 as Fc,aB as Vn,aC as _u}from"./useAppFontEffects-Bzyszv2N.js";import{h as Nt,u as ge,O as cs,dw as Uu,dx as Wo,t as ft,aD as An,B as un,a as jn,E as os,P as Jo,cK as Qo,cR as Yo,U as Ja,p as $u,dy as Bu,k as Vu,cJ as Oa,dz as Hu,al as qu,cO as Gu,dA as Wu,dB as Ju,s as Qu,e as pi,cP as Yu,F as gi,dC as Oc,_ as Zu,dD as Xu,a3 as Lc,aC as hs,dE as Kc,b8 as zc,x as Ua,b2 as _c,af as em,ag as tm,aM as wo,dF as sm,y as ir,Z as nm,q as Zo,aR as Xo,bc as Ei,aS as am,dG as im,ab as ca,dH as rm,dI as el,dv as tl,dJ as sl,aP as nl,dK as om,dL as lm,dM as cm,dN as dm,dO as al,b as um,dP as Uc,dQ as mm,dR as pm,dS as gm,dT as hm,dU as fm,dV as xm,aw as bm,i as $c}from"./index-CvLgnuNI.js";import{u as vm,W as il,Y as ua,_ as ma,$ as pa,a0 as ga,l as ko,ao as ra,a3 as ym,y as Is,ap as jm,am as wm,aq as La,ar as Bc,a1 as km,a2 as Nm}from"./runtimeEndpointReset-C45jrFq4.js";import{u as Us,c as Sm}from"./vendor-zustand-BAGL70zf.js";import{o as Gs,s as es,b as No,l as Cm,_ as So,r as to,c as so,a as hi}from"./vendor-zod-Gea9uBlY.js";import{s as Im,p as Pm}from"./vendor-yaml-3778uTud.js";import{c as rl,s as Am,C as ol,P as Tm}from"./shikiHighlight-4O0ZM14D.js";import{getResolvedShikiTheme as Em}from"./appThemeRegistry-Br2TLSlb.js";import{E as ll}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Vc}from"./vendor-qrcode-DTJ12-WC.js";import{u as Er,s as Dm,d as Mm,b as Rm,A as Fm,c as Om,e as Lm,f as Km,h as zm,i as Dr,j as _m}from"./PluginPane-B39JEUL8.js";import{toast as $a}from"./vendor-sonner-DFyL3AvE.js";import{s as Um}from"./vendor-strip-json-comments-5dJlOkP1.js";import{Y as $m,U as Bm,X as Vm,W as Hm,V as qm}from"./vendor-base-ui-CsXYnR5c.js";const cl=()=>{const{t}=Xe(),[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,m=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:h,tunnelUrl:m})}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(B,{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))})},dl="https://github.com/openchamber/openchamber",Gm="https://discord.gg/ZYRSdnwwKA",ul="https://x.com/openchamber_dev",Wm=800,Hc=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=Xe(),[a,n]=o.useState(t),[r,i]=o.useState(!1),[l,d]=o.useState(null),[c,h]=o.useState(null),m=vm(Us(j=>({info:j.info,checking:j.checking,available:j.available,error:j.error,downloading:j.downloading,downloaded:j.downloaded,progress:j.progress,runtimeType:j.runtimeType,checkForUpdates:j.checkForUpdates,downloadUpdate:j.downloadUpdate,restartToUpdate:j.restartToUpdate}))),{isMobile:f}=Jn(),u=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let j=!1;return(async()=>{try{const k=await Nt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const p=await k.json().catch(()=>null),N=typeof p?.openchamberVersion=="string"&&p.openchamberVersion.trim().length>0?p.openchamberVersion.trim():null;j||d(N)}catch{j||d(null)}})(),()=>{j=!0}},[]),o.useEffect(()=>{let j=!1;return(async()=>{try{const k=await Nt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const p=await k.json().catch(()=>null),N=typeof p?.currentVersion=="string"&&p.currentVersion.trim().length>0?p.currentVersion.trim():null;j||h(N)}catch{j||h(null)}})(),()=>{j=!0}},[]);const g=o.useRef(!1);o.useEffect(()=>{if(m.checking)i(!0),g.current=!0;else if(r){const j=setTimeout(()=>{i(!1),g.current&&!m.available&&!m.error&&($.success(e("settings.openchamber.about.toast.latestVersion")),g.current=!1)},Wm);return()=>clearTimeout(j)}},[e,m.checking,r,m.available,m.error]);const v=m.checking||r;return f?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(Ad,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Td}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(cl,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&s.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:v,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[v?s.jsx(B,{name:"loader",className:"size-4 animate-spin"}):s.jsx(B,{name:"refresh",className:"size-4"}),e(v?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!v&&m.available&&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(B,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:dl,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(B,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Gm,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(B,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:ul,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(B,{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(il,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):s.jsxs(Ge,{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:It,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:It,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(B,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&s.jsxs(G,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(B,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:It,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(cl,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:dl,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(B,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:ul,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(B,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(il,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Jm=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,Ws=()=>{const t=rt.c(4),e=ge(Qm),a=an(Ym),n=an(Zm);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=Jm(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function Qm(t){return t.settingsProjectPath}function Ym(t){return t.projects}function Zm(t){return t.activeProjectId}const Xm=t=>[...t].sort((e,a)=>(e.label||e.path).localeCompare(a.label||a.path)),fi=t=>{const e=rt.c(75),{className:a}=t,{t:n}=Xe(),{currentTheme:r}=ha(),i=ge(ep),[l,d]=o.useState(!1),c=an(tp),h=Ws(),m=ge(sp),f=cs();let u;e[0]!==c?(u=Xm(c),e[0]=c,e[1]=u):u=e[1];const g=u;let v;e[2]!==h||e[3]!==g?(v=g.find(F=>F.path===h)??g[0]??null,e[2]=h,e[3]=g,e[4]=v):v=e[4];const j=v;if(f||!j)return null;let b;e[5]!==m||e[6]!==g?(b=F=>{const K=g.find(S=>S.id===F);K&&m(K.path)},e[5]=m,e[6]=g,e[7]=b):b=e[7];const k=b;if(i){let F;e[8]!==a?(F=Ie(a),e[8]=a,e[9]=F):F=e[9];let K;e[10]!==n?(K=n("settings.shared.projectSelector.switchProjectAria"),e[10]=n,e[11]=K):K=e[11];let S;e[12]!==n?(S=n("settings.shared.projectSelector.switchProjectTitle"),e[12]=n,e[13]=S):S=e[13];let M,z;e[14]===Symbol.for("react.memo_cache_sentinel")?(M=()=>d(!0),z=Ie(Ed({size:"touch"}),"w-full min-w-0"),e[14]=M,e[15]=z):(M=e[14],z=e[15]);let _;e[16]!==j||e[17]!==r?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(Cr,{project:j,theme:r})}),e[16]=j,e[17]=r,e[18]=_):_=e[18];let q;e[19]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=q):q=e[19];let X;e[20]!==l||e[21]!==K||e[22]!==S||e[23]!==z||e[24]!==_?(X=s.jsxs("button",{type:"button","aria-label":K,title:S,"aria-haspopup":"dialog","aria-expanded":l,onClick:M,className:z,children:[_,q]}),e[20]=l,e[21]=K,e[22]=S,e[23]=z,e[24]=_,e[25]=X):X=e[25];let J;e[26]!==X||e[27]!==F?(J=s.jsx("div",{className:F,children:X}),e[26]=X,e[27]=F,e[28]=J):J=e[28];let H;e[29]===Symbol.for("react.memo_cache_sentinel")?(H=()=>d(!1),e[29]=H):H=e[29];const L=j.id;let V;e[30]!==n?(V=n("settings.shared.projectSelector.sheetTitle"),e[30]=n,e[31]=V):V=e[31];let Z;e[32]!==n?(Z=n("settings.shared.projectSelector.searchPlaceholder"),e[32]=n,e[33]=Z):Z=e[33];let U;e[34]!==j.id||e[35]!==r||e[36]!==k||e[37]!==l||e[38]!==g||e[39]!==V||e[40]!==Z?(U=s.jsx(Dd,{open:l,onClose:H,projects:g,selectedProjectId:L,onSelectProject:k,theme:r,title:V,searchPlaceholder:Z}),e[34]=j.id,e[35]=r,e[36]=k,e[37]=l,e[38]=g,e[39]=V,e[40]=Z,e[41]=U):U=e[41];let te;return e[42]!==J||e[43]!==U?(te=s.jsxs(s.Fragment,{children:[J,U]}),e[42]=J,e[43]=U,e[44]=te):te=e[44],te}let p;e[45]!==a?(p=Ie(a),e[45]=a,e[46]=p):p=e[46];const N=j.id;let P;e[47]!==k?(P=F=>{F&&k(F)},e[47]=k,e[48]=P):P=e[48];let C;e[49]!==n?(C=n("settings.shared.projectSelector.switchProjectAria"),e[49]=n,e[50]=C):C=e[50];let w;e[51]!==n?(w=n("settings.shared.projectSelector.switchProjectTitle"),e[51]=n,e[52]=w):w=e[52];let D;e[53]!==j||e[54]!==r?(D=s.jsx(_t,{children:s.jsx(Cr,{project:j,theme:r})}),e[53]=j,e[54]=r,e[55]=D):D=e[55];let x;e[56]!==C||e[57]!==w||e[58]!==D?(x=s.jsx(At,{size:"settings",className:"w-full","aria-label":C,title:w,children:D}),e[56]=C,e[57]=w,e[58]=D,e[59]=x):x=e[59];let A;if(e[60]!==r||e[61]!==g){let F;e[63]!==r?(F=K=>s.jsx(mt,{value:K.id,className:"max-w-[24rem] truncate",children:s.jsx(Cr,{project:K,theme:r})},K.id),e[63]=r,e[64]=F):F=e[64],A=g.map(F),e[60]=r,e[61]=g,e[62]=A}else A=e[62];let R;e[65]!==A?(R=s.jsx(Tt,{fitContent:!0,children:A}),e[65]=A,e[66]=R):R=e[66];let I;e[67]!==j.id||e[68]!==x||e[69]!==R||e[70]!==P?(I=s.jsxs(Et,{value:N,onValueChange:P,children:[x,R]}),e[67]=j.id,e[68]=x,e[69]=R,e[70]=P,e[71]=I):I=e[71];let E;return e[72]!==I||e[73]!==p?(E=s.jsx("div",{className:p,children:I}),e[72]=I,e[73]=p,e[74]=E):E=e[74],E};function ep(t){return t.isMobile}function tp(t){return t.projects}function sp(t){return t.setSettingsProjectPath}function np(t,e){return`opencode:sidebar-group:${t}:${e}`}const no=t=>{const e=rt.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=np(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const h=c,m=o.useId();let f;e[3]!==d||e[4]!==h?(f=()=>{try{const I=localStorage.getItem(h);if(I!==null)return I==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=f):f=e[5];const[u,g]=tt.useState(f);let v,j;e[6]!==u||e[7]!==h?(v=()=>{try{localStorage.setItem(h,String(u))}catch{}},j=[h,u],e[6]=u,e[7]=h,e[8]=v,e[9]=j):(v=e[8],j=e[9]),tt.useEffect(v,j);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>g(ap),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 p=!u&&"-rotate-90";let N;e[12]!==p?(N=Ie("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",p),e[12]=p,e[13]=N):N=e[13];let P;e[14]!==N?(P=s.jsx(B,{name:"arrow-down-s",className:N}),e[14]=N,e[15]=P):P=e[15];let C;e[16]!==a?(C=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=C):C=e[17];let w;e[18]!==n?(w=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=w):w=e[19];let D;e[20]!==m||e[21]!==u||e[22]!==P||e[23]!==C||e[24]!==w?(D=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":u,"aria-controls":m,className:k,children:[P,C,w]}),e[20]=m,e[21]=u,e[22]=P,e[23]=C,e[24]=w,e[25]=D):D=e[25];const x=!u;let A;e[26]!==l||e[27]!==m||e[28]!==x?(A=s.jsx("div",{id:m,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]=m,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 ap(t){return!t}const ip=({onItemSelect:t})=>{const{t:e}=Xe(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,d]=o.useState(null),[c,h]=o.useState(null),[m,f]=o.useState(!1),[u,g]=o.useState(null),{selectedAgentName:v,setSelectedAgent:j,setAgentDraft:b,createAgent:k,deleteAgent:p,loadAgents:N,fetchAgentEntity:P}=Gn(Us(H=>({selectedAgentName:H.selectedAgentName,setSelectedAgent:H.setSelectedAgent,setAgentDraft:H.setAgentDraft,createAgent:H.createAgent,deleteAgent:H.deleteAgent,loadAgents:H.loadAgents,fetchAgentEntity:H.fetchAgentEntity}))),C=Ws(),w=Gn(H=>bc(H,C));o.useEffect(()=>{N(C)},[N,C]);const D="bg-background",x=()=>{const H="new-agent";let L=H,V=1;for(;w.some(Z=>Z.name===L);)L=`${H}-${V}`,V++;b({name:L,scope:"user"}),j(L),t?.()},A=async H=>{if(Ka(H)){$.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(H),h("delete")},R=async H=>{Ka(H)&&(d(H),h("reset"))},I=()=>{d(null),h(null)},E=async()=>{if(!(!l||!c)){f(!0);try{(await p(l.name,l.scope,C)).ok?(c==="delete"?$.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):$.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),I()):c==="delete"?$.error(e("settings.agents.sidebar.toast.deleteFailed")):$.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(H){const L=H instanceof Error?H.message:"",V=/built-in|not deletable|not found/i.test(L);c==="delete"?$.error(e(V?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):$.error(e("settings.agents.sidebar.toast.resetFailed"))}f(!1)}},F=async H=>{const L=H.name;let V=1,Z=`${L}-copy`;for(;w.some(Q=>Q.name===Z);)V++,Z=`${L}-copy-${V}`;const U=H,te=await P(H.name,C);if(!te){$.error(e("settings.agents.sidebar.toast.renameFailed"));return}const O=te.config.request?.body;b({name:Z,scope:te.scope??U.scope??"user",description:te.config.description??void 0,model:te.config.model??null,system:te.config.system??void 0,steps:te.config.steps??void 0,temperature:O?.temperature,top_p:O?.top_p,mode:te.config.mode??U.mode,permissions:te.config.permissions??void 0}),j(Z),t?.()},K=H=>{i(H.name),n(H)},S=async()=>{if(!a)return;const H=r.trim().replace(/\s+/g,"-");if(!H){$.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(H===a.name){n(null);return}if(w.some(U=>U.name===H)){$.error(e("settings.agents.sidebar.toast.agentExists"));return}const L=a,V=await P(a.name,C);if(!V){$.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await k({...V.config,name:H,scope:V.scope??L.scope},C)).ok?(await p(a.name,L.scope,C)).ok?($.success(e("settings.agents.sidebar.toast.agentRenamed",{name:H})),j(H)):$.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):$.error(e("settings.agents.sidebar.toast.renameFailed")),n(null)},M=H=>{switch(H){case"primary":return s.jsx(B,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(B,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(B,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},z=w.filter(H=>!Md(H)),_=z.filter(Ka),q=z.filter(H=>!Ka(H)),{groupedCustomAgents:X,ungroupedCustomAgents:J}=tt.useMemo(()=>{const H={},L=[];for(const Z of q){const U=Z;U.group?(H[U.group]||(H[U.group]=[]),H[U.group].push(Z)):L.push(Z)}return{groupedCustomAgents:Object.keys(H).sort((Z,U)=>Z.localeCompare(U)).map(Z=>({name:Z,agents:H[Z]})),ungroupedCustomAgents:L}},[q]);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(fi,{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:z.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(B,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:z.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{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:[_.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")}),_.map(H=>s.jsx(Mr,{agent:H,isSelected:v===H.name,onSelect:()=>{j(H.name),t?.()},onReset:()=>R(H),onDuplicate:()=>{F(H)},getAgentModeIcon:M,isMenuOpen:u===H.name,onMenuOpenChange:L=>g(L?H.name:null)},H.name))]}),q.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")}),X.map(({name:H,agents:L})=>s.jsx(no,{label:H,count:L.length,storageKey:"agents",children:L.map(V=>s.jsx(Mr,{agent:V,isSelected:v===V.name,onSelect:()=>{j(V.name),t?.()},onRename:()=>K(V),onDelete:()=>A(V),onDuplicate:()=>{F(V)},getAgentModeIcon:M,isMenuOpen:u===V.name,onMenuOpenChange:Z=>g(Z?V.name:null)},V.name))},H)),J.map(H=>s.jsx(Mr,{agent:H,isSelected:v===H.name,onSelect:()=>{j(H.name),t?.()},onRename:()=>K(H),onDelete:()=>A(H),onDuplicate:()=>{F(H)},getAgentModeIcon:M,isMenuOpen:u===H.name,onMenuOpenChange:L=>g(L?H.name:null)},H.name))]})]})}),s.jsx(Kt,{open:l!==null&&c!==null,onOpenChange:H=>{!H&&!m&&I()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Bt,{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:I,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:E,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:H=>!H&&n(null),children:s.jsxs(zt,{children:[s.jsxs(Ut,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Bt,{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"&&S()}}),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:S,children:e("settings.common.actions.rename")})]})]})})]})},Mr=t=>{const e=rt.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:m,onMenuOpenChange:f}=t,{t:u}=Xe(),g=a;let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=di(),e[0]=v):v=e[0];const j=v,[b,k]=o.useState(!1);let p;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==u?(p=H=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(H,{onClick:L=>{L.stopPropagation(),d()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),s.jsxs(H,{onClick:L=>{L.stopPropagation(),c()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),l&&s.jsxs(H,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(B,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&s.jsxs(H,{onClick:L=>{L.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=u,e[6]=p):p=e[6];const N=p,P=n?"bg-interactive-selection":"hover:bg-interactive-hover";let C;e[7]!==P?(C=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]=C):C=e[8];let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=j?void 0:H=>{H.preventDefault(),k(!0)},e[9]=w):w=e[9];let D;e[10]!==C?(D=s.jsx("div",{className:C,onContextMenu:w}),e[10]=C,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]!==g.scope||e[19]!==u?(R=(g.scope||Ka(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:Ka(a)?u("settings.agents.sidebar.badge.system"):g.scope}),e[17]=a,e[18]=g.scope,e[19]=u,e[20]=R):R=e[20];let I;e[21]!==x||e[22]!==A||e[23]!==R?(I=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]=I):I=e[24];let E;e[25]!==a.description?(E=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=E):E=e[26];let F;e[27]!==r||e[28]!==I||e[29]!==E?(F=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:[I,E]}),e[27]=r,e[28]=I,e[29]=E,e[30]=F):F=e[30];let K;e[31]!==f?(K=H=>{H&&k(!1),f(H)},e[31]=f,e[32]=K):K=e[32];let S;e[33]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=S):S=e[33];let M;e[34]!==N?(M=s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:N(wn)}),e[34]=N,e[35]=M):M=e[35];let z;e[36]!==m||e[37]!==K||e[38]!==M?(z=s.jsxs(_n,{open:m,onOpenChange:K,children:[S,M]}),e[36]=m,e[37]=K,e[38]=M,e[39]=z):z=e[39];let _;e[40]!==F||e[41]!==z?(_=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[F,z]}),e[40]=F,e[41]=z,e[42]=_):_=e[42];let q;e[43]!==_||e[44]!==D?(q=s.jsx(pa,{render:D,children:_}),e[43]=_,e[44]=D,e[45]=q):q=e[45];let X;e[46]!==N?(X=s.jsx(ua,{className:"w-fit min-w-20",children:N(ma)}),e[46]=N,e[47]=X):X=e[47];let J;return e[48]!==b||e[49]!==q||e[50]!==X?(J=s.jsxs(ga,{open:b,onOpenChange:k,children:[q,X]}),e[48]=b,e[49]=q,e[50]=X,e[51]=J):J=e[51],J},ns=t=>{const e=rt.c(22),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:d,description:c,headerEnd:h,showSaveStatus:m,onBlurCapture:f}=t,u=m===void 0?!1:m,g=i!=null||c!=null||h!=null||u,v=typeof i=="string"||typeof i=="number",j=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 p;e[4]!==c||e[5]!==g||e[6]!==j||e[7]!==h||e[8]!==v||e[9]!==u||e[10]!==i||e[11]!==d||e[12]!==l?(p=g&&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?j?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(Yr,"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:Yr,children:i}):i:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Bi,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[h,u&&s.jsx(op,{})]})]}),e[4]=c,e[5]=g,e[6]=j,e[7]=h,e[8]=v,e[9]=u,e[10]=i,e[11]=d,e[12]=l,e[13]=p):p=e[13];let N;e[14]!==a||e[15]!==f||e[16]!==k||e[17]!==p?(N=s.jsxs("div",{className:k,onBlurCapture:f,children:[p,a]}),e[14]=a,e[15]=f,e[16]=k,e[17]=p,e[18]=N):N=e[18];let P;return e[19]!==b||e[20]!==N?(P=s.jsx(vs,{outerClassName:b,className:"w-full @container",children:N}),e[19]=b,e[20]=N,e[21]=P):P=e[21],P},rp=500,op=()=>{const t=rt.c(13),{t:e}=Xe(),a=o.useSyncExternalStore(Uu,Wo,Wo),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const m=setTimeout(()=>r(!0),rp);return()=>clearTimeout(m)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let m;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"size-3.5"}),t[3]=m):m=t[3];let f;t[4]!==e?(f=e("settings.common.status.saveFailed"),t[4]=e,t[5]=f):f=t[5];let u;return t[6]!==f?(u=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[m,s.jsx("span",{children:f})]}),t[6]=f,t[7]=u):u=t[7],u}if(a!=="saving"||!n)return null;let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(B,{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},Rs={ok:!0,changed:!1},In={ok:!0,changed:!0},xs=t=>({ok:!1,reason:t}),lp=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,qa=t=>{const{t:e}=Xe(),[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(u=>u+1)},[]),m=o.useCallback(u=>{lp(u.target)&&h()},[h]),f=o.useCallback(async()=>{l.current=!0;try{for(;;){d.current=!1;let u;try{u=await r.current()}catch(g){u={ok:!1,reason:g instanceof Error?g.message:String(g)}}if(!c.current)return;if(!d.current){u.ok||$.error(i.current("settings.common.status.saveFailedReason",{reason:u.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:m}},cp=["allow","ask","deny"],dp=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],up=["openchamber","openchamber_web","openchamber_memory"],mp=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),qc=t=>mp.has(t),pp=[{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"}],ml=()=>({global:null,keys:{},source:[]}),Zn=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}))}]))}),gp=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},hp=t=>t.action!=="*"||t.resource==="*",oa=(t,e)=>`${t}\0${e}`,fp=t=>{const e=new Map;t.global!==null&&e.set(oa("*","*"),t.global);for(const[a,n]of Object.entries(t.keys)){n.effect!==null&&e.set(oa(a,"*"),n.effect);for(const r of n.patterns){const i=r.pattern.trim();i.length!==0&&e.set(oa(a,i),r.effect)}}return e},ao=t=>{const e=fp(t),a=new Set,n=[];for(const i of t.source){if(qc(i.action))continue;if(!hp(i)){n.push({...i});continue}const l=oa(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=oa("*","*");t.global!==null&&!a.has(r)&&n.unshift({action:"*",resource:"*",effect:t.global});for(const[i,l]of Object.entries(t.keys)){const d=oa(i,"*");if(l.effect!==null&&!a.has(d)){const c=n.findIndex(m=>m.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 m=oa(i,h),f=e.get(m);f===void 0||a.has(m)||(a.add(m),n.push({action:i,resource:h,effect:f}))}}return n},xp=(t,e)=>JSON.stringify(ao(t))===JSON.stringify(ao(e)),bp=(t,e)=>{const a=[...pp,...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},vp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),yp=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),jp={effect:null,patterns:[]},wp=t=>{const e=rt.c(163),{agent:a,registerSave:n,requestSave:r}=t,{t:i}=Xe(),l=Gn(kp),d=Gn(Np);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];const[h,m]=o.useState(c),[f,u]=o.useState(ml),[g,v]=o.useState(ml),[j,b]=o.useState(!0),[k,p]=o.useState(!1);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N={},e[1]=N):N=e[1];const[P,C]=o.useState(N),[w,D]=o.useState(""),[x,A]=o.useState(0),R=a.name,I=Ws(),E=Wn(Sp);let F;e[2]!==I?(F=Fe=>po(Fe,I),e[2]=I,e[3]=F):F=e[3];const K=Wn(F);let S;e[4]!==I?(S=Fe=>Fe.getStatusForDirectory(I),e[4]=I,e[5]=S):S=e[5];const M=dn(S);let z,_;e[6]!==E||e[7]!==I?(z=()=>{E({directory:I})},_=[E,I],e[6]=E,e[7]=I,e[8]=z,e[9]=_):(z=e[8],_=e[9]),o.useEffect(z,_);let q;e[10]!==R||e[11]!==d||e[12]!==I?(q=()=>{let Fe=!1;return b(!0),p(!1),(async()=>{const $e=await d(R,I);if(Fe)return;if(!$e){p(!0),b(!1);return}const W=gp($e.agent);m($e.global),u(Zn(W)),v(W),C({}),b(!1)})(),()=>{Fe=!0}},e[10]=R,e[11]=d,e[12]=I,e[13]=q):q=e[13];let X;e[14]!==R||e[15]!==d||e[16]!==x||e[17]!==I?(X=[R,d,x,I],e[14]=R,e[15]=d,e[16]=x,e[17]=I,e[18]=X):X=e[18],o.useEffect(q,X);let J;e[19]!==R||e[20]!==f||e[21]!==g||e[22]!==I||e[23]!==i||e[24]!==l?(J=async()=>xp(g,f)?Rs:(await l(R,{permissions:ao(g)},I)).ok?(u(Zn(g)),In):xs(i("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=R,e[20]=f,e[21]=g,e[22]=I,e[23]=i,e[24]=l,e[25]=J):J=e[25];const H=J;let L,V;e[26]!==n||e[27]!==H?(L=()=>(n(H),()=>n(null)),V=[n,H],e[26]=n,e[27]=H,e[28]=L,e[29]=V):(L=e[28],V=e[29]),o.useEffect(L,V);let Z;e[30]!==K?(Z=K.map(Cp),e[30]=K,e[31]=Z):Z=e[31];const U=Z;let te;if(e[32]!==U||e[33]!==g.keys){te=[...dp,...up];const Fe=new Set(U.map(Ip));let $e;e[35]!==g.keys?($e=Object.keys(g.keys),e[35]=g.keys,e[36]=$e):$e=e[36];for(const W of $e)!te.includes(W)&&!Fe.has(W)&&te.push(W);e[32]=U,e[33]=g.keys,e[34]=te}else te=e[34];const O=te;let Q;e[37]!==M||e[38]!==i?(Q=Fe=>{switch(M?.[Fe]?.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]=Q):Q=e[39];const ce=Q;let de;e[40]!==h||e[41]!==g.global?(de=Fe=>bp(Fe,{global:h,agentGlobal:g.global}),e[40]=h,e[41]=g.global,e[42]=de):de=e[42];const pe=de;let re;e[43]!==r?(re=Fe=>{v($e=>({...$e,global:Fe})),r()},e[43]=r,e[44]=re):re=e[44];const Ce=re;let ie;e[45]!==r?(ie=(Fe,$e)=>{v(W=>{const Ve=Zn(W),et=Ve.keys[Fe]??{effect:null,patterns:[]};return et.effect=$e,et.effect===null&&et.patterns.length===0?delete Ve.keys[Fe]:Ve.keys[Fe]=et,Ve}),r()},e[45]=r,e[46]=ie):ie=e[46];const be=ie;let ae;e[47]!==r?(ae=(Fe,$e,W,Ve,et)=>{v(dt=>{const ct=Zn(dt),jt=ct.keys[Fe]??{effect:null,patterns:[]};return jt.patterns[$e]={pattern:W,effect:Ve},ct.keys[Fe]=jt,ct}),et&&r()},e[47]=r,e[48]=ae):ae=e[48];const fe=ae;let xe;e[49]===Symbol.for("react.memo_cache_sentinel")?(xe=Fe=>{v($e=>{const W=Zn($e),Ve=W.keys[Fe]??{effect:null,patterns:[]};return Ve.patterns.push({pattern:"",effect:"allow"}),W.keys[Fe]=Ve,W}),C($e=>({...$e,[Fe]:!0}))},e[49]=xe):xe=e[49];const Oe=xe;let Ne;e[50]!==r?(Ne=(Fe,$e)=>{v(W=>{const Ve=Zn(W),et=Ve.keys[Fe];return et?(et.patterns.splice($e,1),et.effect===null&&et.patterns.length===0&&delete Ve.keys[Fe],Ve):W}),r()},e[50]=r,e[51]=Ne):Ne=e[51];const he=Ne;let Te;e[52]!==w||e[53]!==r?(Te=()=>{const Fe=w.trim();!Fe||Fe==="*"||(v($e=>{if($e.keys[Fe])return $e;const W=Zn($e);return W.keys[Fe]={effect:"ask",patterns:[]},W}),D(""),r())},e[52]=w,e[53]=r,e[54]=Te):Te=e[54];const we=Te;let De;e[55]!==i?(De=Fe=>i(Fe==="allow"?"settings.agents.page.permissionsEditor.action.allow":Fe==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=i,e[56]=De):De=e[56];const ve=De;let ee,ne,ye,Ae,ze,Qe,Be,_e,Me;if(e[57]!==ve||e[58]!==pe||e[59]!==P||e[60]!==j||e[61]!==k||e[62]!==U||e[63]!==ce||e[64]!==g.global||e[65]!==g.keys||e[66]!==he||e[67]!==Ce||e[68]!==be||e[69]!==fe||e[70]!==i||e[71]!==O){Me=Symbol.for("react.early_return_sentinel");e:{const Fe=i("settings.agents.page.permissionsEditor.action.inherit"),$e=i("settings.agents.page.permissionsEditor.action.default");let W;e[81]!==ve?(W=He=>[...He?[{value:"inherit",label:He}]:[],...cp.map(Y=>({value:Y,label:ve(Y)}))],e[81]=ve,e[82]=W):W=e[82];const Ve=W,et=(He,Y,me,Ke)=>{const Ee=Ke===void 0?Fe:Ke;return s.jsx(mn,{value:He??"inherit",options:Ve(Ee),onChange:Ye=>Y(Ye==="inherit"?null:Ye),"aria-label":me})};if(j){let He;e[83]!==i?(He=i("settings.agents.page.section.toolPermissions"),e[83]=i,e[84]=He):He=e[84];let Y;e[85]!==i?(Y=i("common.loading"),e[85]=i,e[86]=Y):Y=e[86];let me;e[87]!==Y?(me=s.jsx("p",{className:Ss,children:Y}),e[87]=Y,e[88]=me):me=e[88];let Ke;e[89]!==He||e[90]!==me?(Ke=s.jsx(Ge,{title:He,children:me}),e[89]=He,e[90]=me,e[91]=Ke):Ke=e[91],Me=Ke;break e}if(k){let He;e[92]!==i?(He=i("settings.agents.page.section.toolPermissions"),e[92]=i,e[93]=He):He=e[93];let Y;e[94]!==i?(Y=i("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=i,e[95]=Y):Y=e[95];let me;e[96]!==Y?(me=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Y}),e[96]=Y,e[97]=me):me=e[97];let Ke;e[98]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>A(Pp),e[98]=Ke):Ke=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:Ke,children:Ee}),e[101]=Ee,e[102]=Ye):Ye=e[102];let se;e[103]!==me||e[104]!==Ye?(se=s.jsxs("div",{className:"flex items-center gap-3",children:[me,Ye]}),e[103]=me,e[104]=Ye,e[105]=se):se=e[105];let ke;e[106]!==He||e[107]!==se?(ke=s.jsx(Ge,{title:He,children:se}),e[106]=He,e[107]=se,e[108]=ke):ke=e[108],Me=ke;break e}const dt=(He,Y,me)=>{const Ke=g.keys[He]??jp,Ee=yp.has(He)||Ke.patterns.length>0,Ye=P[He]===!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?()=>C(se=>({...se,[He]:!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(B,{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:It,children:Y}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:He}),me&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:me}),Ke.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:ve(pe(He))})}),Ke.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(Ke.patterns.length)})})]}),et(Ke.effect,se=>be(He,se),i("settings.agents.page.permissionsEditor.keyAria",{key:He}))]}),Ye&&Ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[Ke.patterns.map((se,ke)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(We,{value:se.pattern,onChange:at=>fe(He,ke,at.target.value,se.effect,!1),placeholder:i("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:He}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(mn,{value:se.effect,options:Ve(),onChange:at=>fe(He,ke,se.pattern,at,!0),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:He})}),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:()=>he(He,ke),"aria-label":i("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]},ke)),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Oe(He),children:[s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),i("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},He)};ee=Ge,e[109]!==i?(ne=i("settings.agents.page.section.toolPermissions"),e[109]=i,e[110]=ne):ne=e[110],ye="agents.permissions",e[111]!==i?(Ae=i("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=i,e[112]=Ae):Ae=e[112],ze="space-y-4";let ct;e[113]!==i?(ct=i("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=i,e[114]=ct):ct=e[114];let jt;e[115]!==ct?(jt=s.jsx("span",{className:It,children:ct}),e[115]=ct,e[116]=jt):jt=e[116];let kt;e[117]!==i?(kt=i("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=i,e[118]=kt):kt=e[118];let yt;e[119]!==kt?(yt=s.jsx(Ht,{children:kt}),e[119]=kt,e[120]=yt):yt=e[120];let bt;e[121]!==ve||e[122]!==pe||e[123]!==g.global||e[124]!==i?(bt=g.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:ve(pe("*"))})}),e[121]=ve,e[122]=pe,e[123]=g.global,e[124]=i,e[125]=bt):bt=e[125];let Ze;e[126]!==jt||e[127]!==yt||e[128]!==bt?(Ze=s.jsxs("div",{className:"flex items-center gap-1.5",children:[jt,yt,bt]}),e[126]=jt,e[127]=yt,e[128]=bt,e[129]=Ze):Ze=e[129];const wt=g.global;let Le;e[130]!==i?(Le=i("settings.agents.page.permissionsEditor.defaultAria"),e[130]=i,e[131]=Le):Le=e[131],Qe=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[Ze,et(wt,Ce,Le,$e)]}),Be=s.jsx("div",{children:O.map(He=>dt(He,vp(He),null))}),_e=U.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:It,children:i("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(Ht,{children:i("settings.agents.page.permissionsEditor.mcpInfo")})]}),U.map(He=>dt(He.key,He.server,ce(He.server)))]})}e[57]=ve,e[58]=pe,e[59]=P,e[60]=j,e[61]=k,e[62]=U,e[63]=ce,e[64]=g.global,e[65]=g.keys,e[66]=he,e[67]=Ce,e[68]=be,e[69]=fe,e[70]=i,e[71]=O,e[72]=ee,e[73]=ne,e[74]=ye,e[75]=Ae,e[76]=ze,e[77]=Qe,e[78]=Be,e[79]=_e,e[80]=Me}else ee=e[72],ne=e[73],ye=e[74],Ae=e[75],ze=e[76],Qe=e[77],Be=e[78],_e=e[79],Me=e[80];if(Me!==Symbol.for("react.early_return_sentinel"))return Me;let nt;e[132]===Symbol.for("react.memo_cache_sentinel")?(nt=Fe=>D(Fe.target.value),e[132]=nt):nt=e[132];let pt;e[133]!==we?(pt=Fe=>{Fe.key==="Enter"&&(Fe.preventDefault(),we())},e[133]=we,e[134]=pt):pt=e[134];let lt;e[135]!==i?(lt=i("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=i,e[136]=lt):lt=e[136];let ut;e[137]!==w||e[138]!==pt||e[139]!==lt?(ut=s.jsx(We,{value:w,onChange:nt,onKeyDown:pt,placeholder:lt,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=w,e[138]=pt,e[139]=lt,e[140]=ut):ut=e[140];let ht;e[141]!==w?(ht=w.trim(),e[141]=w,e[142]=ht):ht=e[142];const Ue=!ht;let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=st):st=e[143];let ue;e[144]!==i?(ue=i("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=i,e[145]=ue):ue=e[145];let oe;e[146]!==we||e[147]!==Ue||e[148]!==ue?(oe=s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:we,disabled:Ue,children:[st,ue]}),e[146]=we,e[147]=Ue,e[148]=ue,e[149]=oe):oe=e[149];let Pe;e[150]!==ut||e[151]!==oe?(Pe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[ut,oe]}),e[150]=ut,e[151]=oe,e[152]=Pe):Pe=e[152];let Re;return e[153]!==ee||e[154]!==ne||e[155]!==ye||e[156]!==Ae||e[157]!==ze||e[158]!==Qe||e[159]!==Be||e[160]!==_e||e[161]!==Pe?(Re=s.jsxs(ee,{title:ne,settingsItem:ye,info:Ae,contentClassName:ze,children:[Qe,Be,_e,Pe]}),e[153]=ee,e[154]=ne,e[155]=ye,e[156]=Ae,e[157]=ze,e[158]=Qe,e[159]=Be,e[160]=_e,e[161]=Pe,e[162]=Re):Re=e[162],Re};function kp(t){return t.updateAgent}function Np(t){return t.fetchAgentPermissions}function Sp(t){return t.loadMcpConfigs}function Cp(t){return{key:`${t.name}_*`,server:t.name}}function Ip(t){return t.key}function Pp(t){return t+1}const Co=t=>{const e=rt.c(11),{legacy:a,path:n,className:r}=t,{t:i}=Xe();if(!a)return null;let l;e[0]!==r?(l=Ie("mb-4 flex items-start gap-1.5",Ss,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(B,{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 m;e[5]!==h?(m=s.jsx("span",{children:h}),e[5]=h,e[6]=m):m=e[6];let f;return e[7]!==l||e[8]!==d||e[9]!==m?(f=s.jsxs("p",{className:l,title:d,children:[c,m]}),e[7]=l,e[8]=d,e[9]=m,e[10]=f):f=e[10],f},Ap=(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)??[]:[]},Tp=()=>{const{t}=Xe(),e=it(he=>he.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,fetchAgentEntity:l,agentDraft:d,setAgentDraft:c,setSelectedAgent:h}=Gn(Us(he=>({selectedAgentName:he.selectedAgentName,getAgentByName:he.getAgentByName,createAgent:he.createAgent,updateAgent:he.updateAgent,fetchAgentEntity:he.fetchAgentEntity,agentDraft:he.agentDraft,setAgentDraft:he.setAgentDraft,setSelectedAgent:he.setSelectedAgent}))),m=Ws(),f=Gn(he=>bc(he,m)),u=a?n(a,m):null,g=!!(d&&d.name===a&&!u),[v,j]=o.useState(""),[b,k]=o.useState("user"),[p,N]=o.useState(""),[P,C]=o.useState("subagent"),[w,D]=o.useState(""),[x,A]=o.useState(""),[R,I]=o.useState(void 0),[E,F]=o.useState(void 0),[K,S]=o.useState(void 0),[M,z]=o.useState(""),[_,q]=o.useState(!1),[X,J]=o.useState(null),H=o.useRef({}),L=o.useRef(null),V=o.useCallback(he=>{L.current=he},[]),Z=o.useRef(null),U=JSON.stringify([a,m,g]),te=o.useRef(U);te.current=U;const O=o.useRef(null),Q={description:p,mode:P,model:w,variant:x,steps:R,temperature:E,topP:K,system:M},ce=o.useRef(Q);ce.current=Q;const de=o.useMemo(()=>Ap(e,w),[w,e]),pe=de.length>0,re=x||"__default",Ce=pe,ie=o.useMemo(()=>x&&!de.includes(x)?[x,...de]:de,[x,de]);o.useEffect(()=>{if(!g||!d)return;O.current=null;const he=ri(d.model),Te=d.name||"",we=d.scope||"user",De=d.description||"",ve=d.mode||"subagent",ee=he?`${he.providerID}/${he.modelID}`:"",ne=he?.variant||"",ye=d.steps??void 0,Ae=d.temperature??void 0,ze=d.top_p??void 0,Qe=d.system||"";H.current={},J(null),j(Te),k(we),N(De),C(ve),D(ee),A(ne),I(ye),F(Ae),S(ze),z(Qe),Z.current={draftName:Te,draftScope:we,description:De,mode:ve,model:ee,variant:ne,steps:ye,temperature:Ae,topP:ze,system:Qe}},[d,g]),o.useEffect(()=>{if(g||!a)return;let he=!1;return(async()=>{const Te=await l(a,m);if(he||te.current!==U||!Te)return;const we=Te.config;H.current=we;const De=ri(we.model),ve=we.request?.body,ee={draftName:"",draftScope:"user",description:we.description||"",mode:we.mode||u?.mode||"subagent",model:De?`${De.providerID}/${De.modelID}`:"",variant:De?.variant||"",steps:we.steps??void 0,temperature:ve?.temperature,topP:ve?.top_p,system:we.system||""},ne=Z.current,ye=ce.current,Ae=ne!==null&&(ye.description!==ne.description||ye.mode!==ne.mode||ye.model!==ne.model||ye.variant!==ne.variant||ye.steps!==ne.steps||ye.temperature!==ne.temperature||ye.topP!==ne.topP||ye.system!==ne.system);J({legacy:Te.legacy===!0,path:Te.path}),!(O.current===U&&Ae)&&(O.current=U,N(ee.description),C(ee.mode),D(ee.model),A(ee.variant),I(ee.steps),F(ee.temperature),S(ee.topP),z(ee.system),Z.current=ee)})(),()=>{he=!0}},[l,g,u,a,m,U]);const be=o.useCallback(he=>{const Te=Ln(w.trim()),we=Te?vc({providerID:Te.providerId,modelID:Te.modelId,variant:x.trim()||void 0}):null,De=H.current.request,ve={...De?.body};E===void 0?delete ve.temperature:ve.temperature=E,K===void 0?delete ve.top_p:ve.top_p=K;const ee=De?.headers,ne={};ee&&Object.keys(ee).length>0&&(ne.headers=ee),Object.keys(ve).length>0&&(ne.body=ve);const ye=p.trim(),Ae=M.trim(),ze={name:he,mode:P,model:we,steps:R??null,system:Ae||(g?void 0:null),request:Object.keys(ne).length>0?ne:null};return ye&&(ze.description=ye),g&&b&&(ze.scope=b),g&&d?.permissions?.length&&(ze.permissions=d.permissions),ze},[d,p,b,g,P,w,R,M,E,K,x]),ae=o.useCallback(async()=>{const he=Z.current,Te=a?.trim();if(g||!he||!Te)return Rs;const we=L.current?await L.current():Rs;if(p===he.description&&P===he.mode&&w===he.model&&x===he.variant&&R===he.steps&&E===he.temperature&&K===he.topP&&M===he.system||!we.ok)return we;const ve=be(Te);return(await i(Te,ve,m)).ok?(te.current!==U||(H.current={...H.current,model:ve.model,system:ve.system??void 0,steps:ve.steps,request:ve.request??void 0},Z.current={...he,description:p,mode:P,model:w,variant:x,steps:R,temperature:E,topP:K,system:M}),In):xs(t("settings.agents.page.toast.updateFailed"))},[be,p,g,P,w,a,U,m,R,M,t,E,K,i,x]),fe=qa(ae),{requestSave:xe}=fe,Oe=async()=>{const he=v.trim().replace(/\s+/g,"-");if(!he){$.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(f.some(Te=>Te.name===he)){$.error(t("settings.agents.sidebar.toast.agentExists"));return}q(!0);try{(await r(be(he),m)).ok?(c(null),$.success(t("settings.agents.page.toast.created"))):$.error(t("settings.agents.page.toast.createFailed"))}catch(Te){console.error("Error creating agent:",Te);const we=Te instanceof Error&&Te.message?Te.message:t("settings.agents.page.toast.saveUnexpectedError");$.error(we)}finally{q(!1)}},Ne=()=>{c(null),h(null)};return a?s.jsxs(ns,{title:g?t("settings.agents.page.title.new"):a,description:t(g?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:fe.onBlurCapture,children:[!g&&X&&s.jsx(Co,{legacy:X.legacy,path:X.path}),s.jsxs(Ge,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[g&&s.jsxs(St,{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:v,onChange:he=>j(he.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Et,{value:b,onValueChange:he=>k(he),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Tt,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{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(B,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Rt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:p,onChange:he=>N(he.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Rt,{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:P,onChange:he=>{C(he),xe()},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(Ge,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(St,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(la,{providerId:Ln(w)?.providerId??"",modelId:Ln(w)?.modelId??"",onChange:(he,Te)=>{D(he&&Te?`${he}/${Te}`:""),A(""),xe()},className:qs})}),s.jsx(St,{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:Ce?s.jsxs(Et,{value:re,onValueChange:he=>{A(he==="__default"?"":he),xe()},children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:he=>he==="__default"?t("chat.modelControls.default"):he})}),s.jsxs(Tt,{children:[s.jsx(mt,{value:"__default",children:t("chat.modelControls.default")}),ie.map(he=>s.jsx(mt,{value:he,children:he},he))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(We,{value:x,onChange:he=>A(he.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!w&&!x,className:"h-8 w-40 rounded-md px-3"}),x&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{A(""),xe()},className:gs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(St,{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(fs,{value:E,fallbackValue:.7,onValueChange:F,onClear:()=>{F(void 0),xe()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:ys}),E!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{F(void 0),xe()},className:gs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(St,{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(fs,{value:K,fallbackValue:.9,onValueChange:S,onClear:()=>{S(void 0),xe()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:ys}),K!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{S(void 0),xe()},className:gs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(St,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(fs,{value:R,fallbackValue:20,onValueChange:I,onClear:()=>{I(void 0),xe()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:ys}),R!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{I(void 0),xe()},className:gs,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ge,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:M,onChange:he=>z(he.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent"})}),!g&&u&&s.jsx(wp,{agent:u,registerSave:V,requestSave:xe}),g&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(G,{onClick:()=>{Oe()},disabled:_||!v.trim(),size:"xs",className:"!font-normal",children:t(_?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:Ne,disabled:_,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(B,{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 Ep(t,e){return t.kind==="file"?t.content:e??""}const Dp=Gs({content:es(),exists:No(),path:es().min(1).optional()}),Mp=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Rp=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,Di={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Fp=(t,e)=>t==="custom"?e:Fd(t),Op=t=>t==="custom"?"custom":yc(t)?t:"concise",pl={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"},Lp=()=>{const{t}=Xe(),[e,a]=o.useState(""),[n,r]=o.useState("AGENTS.md"),[i,l]=o.useState(Di.responseStyleEnabled),[d,c]=o.useState(Di.responseStylePreset),[h,m]=o.useState(Di.responseStyleCustomInstructions),[f,u]=o.useState(!0),g=o.useRef(null);o.useEffect(()=>{const p=new AbortController;return(async()=>{try{const[P,C]=await Promise.all([An(),Nt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:p.signal})]);let w=Di,D;P&&(w={...w,responseStyleEnabled:P.responseStyleEnabled===!0,responseStylePreset:Op(P.responseStylePreset),responseStyleCustomInstructions:P.responseStyleCustomInstructions??""},P.globalBehaviorPrompt!==void 0&&(D=P.globalBehaviorPrompt));let x={kind:"missing"};if(C.ok){const A=Dp.parse(await C.json());if(p.signal.aborted)return;r(A.path??"AGENTS.md"),A.exists&&(x={kind:"file",content:A.content})}w={...w,prompt:Ep(x,D)},a(w.prompt),l(w.responseStyleEnabled),c(w.responseStylePreset),m(w.responseStyleCustomInstructions),g.current=w}catch(P){P.name!=="AbortError"&&console.warn("Failed to load behavior settings:",P)}finally{u(!1)}})(),()=>p.abort()},[]);const v=o.useCallback(async()=>{const p=g.current;if(!p||f)return Rs;const N=e!==p.prompt,P=i!==p.responseStyleEnabled||d!==p.responseStylePreset||h!==p.responseStyleCustomInstructions;if(!N&&!P)return Rs;const C=N?Rp(e):p.prompt;if(N){const D=await Nt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:C})});if(!D.ok)return xs(await Mp(D,t("settings.behavior.page.toast.saveFailed")));a(x=>x===e?C:x)}return(await ft({...N?{globalBehaviorPrompt:C}:{},responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h})).ok?(g.current={prompt:C,responseStyleEnabled:i,responseStylePreset:d,responseStyleCustomInstructions:h},In):xs(t("settings.behavior.page.toast.saveFailed"))},[f,e,h,i,d,t]),j=qa(v),{requestSave:b}=j,k=Fp(d,h);return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:j.onBlurCapture,children:[s.jsx(Ge,{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:p=>a(p.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(Ge,{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:p=>{l(p),b()},disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(St,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Et,{value:d,onValueChange:p=>{c(p),b()},disabled:f||!i,children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{children:p=>p==="custom"?t("settings.behavior.page.responseStyle.option.custom"):yc(p)?t(pl[p]):null})}),s.jsxs(Tt,{children:[Rd.map(p=>s.jsx(mt,{value:p,children:t(pl[p])},p)),s.jsx(mt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:k,onChange:p=>m(p.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"})]})]})},Kp=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),zp=t=>{const e=rt.c(73),{snapshot:a}=t,{t:n}=Xe(),r=ui(Bp),i=a.selection,l=a.projectOverride!==null;let d;e[0]!==l||e[1]!==i||e[2]!==r||e[3]!==n?(d=K=>{l||Kp(K,i)||r(K).then(S=>{S||$.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(K=>K.id===i.id)?i.id:null;let m;e[5]!==n?(m=n("settings.webSearch.section.provider"),e[5]=n,e[6]=m):m=e[6];let f;e[7]!==n?(f=n("settings.webSearch.section.providerInfo"),e[7]=n,e[8]=f):f=e[8];let u;e[9]!==n?(u=n("settings.webSearch.section.provider"),e[9]=n,e[10]=u):u=e[10];const g=i.kind==="default";let v;e[11]!==c?(v=()=>c({kind:"default"}),e[11]=c,e[12]=v):v=e[12];let j;e[13]!==n?(j=n("settings.webSearch.option.default"),e[13]=n,e[14]=j):j=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]!==g||e[19]!==v||e[20]!==j||e[21]!==b?(k=s.jsx(ks,{selected:g,onSelect:v,disabled:l,label:j,description:b}),e[17]=l,e[18]=g,e[19]=v,e[20]=j,e[21]=b,e[22]=k):k=e[22];let p;e[23]!==c||e[24]!==l||e[25]!==i.kind||e[26]!==a.providers.length||e[27]!==n?(p=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]=p):p=e[28];let N;if(e[29]!==c||e[30]!==l||e[31]!==i.id||e[32]!==i.kind||e[33]!==a.providers){let K;e[35]!==c||e[36]!==l||e[37]!==i.id||e[38]!==i.kind?(K=S=>s.jsx(ks,{selected:i.kind==="provider"&&i.id===S.id,onSelect:()=>c({kind:"provider",id:S.id}),disabled:l,label:S.name},S.id),e[35]=c,e[36]=l,e[37]=i.id,e[38]=i.kind,e[39]=K):K=e[39],N=a.providers.map(K),e[29]=c,e[30]=l,e[31]=i.id,e[32]=i.kind,e[33]=a.providers,e[34]=N}else N=e[34];let P;e[40]!==h||e[41]!==n?(P=h?s.jsx(ks,{selected:!0,onSelect:Vp,label:h,description:n("settings.webSearch.option.missing")}):null,e[40]=h,e[41]=n,e[42]=P):P=e[42];const C=i.kind==="off";let w;e[43]!==c?(w=()=>c({kind:"off"}),e[43]=c,e[44]=w):w=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]!==C||e[49]!==w||e[50]!==D?(x=s.jsx(ks,{selected:C,onSelect:w,disabled:l,label:D}),e[47]=l,e[48]=C,e[49]=w,e[50]=D,e[51]=x):x=e[51];let A;e[52]!==p||e[53]!==N||e[54]!==P||e[55]!==x||e[56]!==u||e[57]!==k?(A=s.jsxs(tn,{"aria-label":u,children:[k,p,N,P,x]}),e[52]=p,e[53]=N,e[54]=P,e[55]=x,e[56]=u,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:`${Ss} 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 I;e[62]!==a.providers.length||e[63]!==n?(I=a.providers.length===0?s.jsx("p",{className:`${Ss} mt-2`,children:n("settings.webSearch.state.noProviders")}):null,e[62]=a.providers.length,e[63]=n,e[64]=I):I=e[64];let E;e[65]!==A||e[66]!==R||e[67]!==I?(E=s.jsxs("div",{children:[A,R,I]}),e[65]=A,e[66]=R,e[67]=I,e[68]=E):E=e[68];let F;return e[69]!==m||e[70]!==E||e[71]!==f?(F=s.jsx(Ge,{title:m,info:f,divider:!1,settingsItem:"web-search.provider",children:E}),e[69]=m,e[70]=E,e[71]=f,e[72]=F):F=e[72],F},_p=t=>{const e=rt.c(26),{provider:a,access:n}=t,{t:r}=Xe(),i=ui(Hp),l=ui(qp),[d,c]=o.useState(""),[h,m]=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 u=f;let g;e[3]!==d||e[4]!==a.id||e[5]!==a.name||e[6]!==i||e[7]!==r?(g=async()=>{const P=d.trim();if(!P)return;m(!0);const C=await i(a.id,P);m(!1),C?(c(""),$.success(r("settings.webSearch.toast.keySaved",{provider:a.name}))):$.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]=g):g=e[8];const v=g;let j;e[9]!==a.id||e[10]!==l||e[11]!==r?(j=async()=>{m(!0);const P=await l(a.id);m(!1),P||$.error(r("settings.webSearch.toast.keyRemoveFailed"))},e[9]=a.id,e[10]=l,e[11]=r,e[12]=j):j=e[12];const b=j,k=n.key;let p;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?(p=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]=p):p=e[21];let N;return e[22]!==u||e[23]!==a.name||e[24]!==p?(N=s.jsx(St,{label:a.name,info:u,children:p}),e[22]=u,e[23]=a.name,e[24]=p,e[25]=N):N=e[25],N},Up=t=>{const e=rt.c(23),{snapshot:a}=t,{t:n}=Xe(),r=a.access;let i,l,d,c,h,m,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(j=>{const b=r[j.id];return b&&b.key.kind!=="unsupported"?[{provider:j,access:b}]:[]}):[];if(r&&v.length===0){f=null;break e}i=Ge,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],m="web-search.keys",l="space-y-4",d=r===null?s.jsx("p",{className:Ss,children:n("settings.webSearch.state.keysUnavailable")}):v.map(Gp)}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]=m,e[9]=f}else i=e[3],l=e[4],d=e[5],c=e[6],h=e[7],m=e[8],f=e[9];if(f!==Symbol.for("react.early_return_sentinel"))return f;let u;e[14]!==l||e[15]!==d?(u=s.jsx("div",{className:l,children:d}),e[14]=l,e[15]=d,e[16]=u):u=e[16];let g;return e[17]!==i||e[18]!==c||e[19]!==h||e[20]!==m||e[21]!==u?(g=s.jsx(i,{title:c,info:h,settingsItem:m,children:u}),e[17]=i,e[18]=c,e[19]=h,e[20]=m,e[21]=u,e[22]=g):g=e[22],g},$p=()=>{const t=rt.c(17),{t:e}=Xe(),a=ui(Wp),n=ui(Jp);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=Od(),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 m;t[6]!==e?(m=e("settings.page.webSearch.description"),t[6]=e,t[7]=m):m=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(zp,{snapshot:c}),s.jsx(Up,{snapshot:c})]}):a.kind==="failed"?s.jsx(Ge,{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(Ge,{divider:!1,children:s.jsx("p",{className:Ss,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 u;return t[13]!==h||t[14]!==m||t[15]!==f?(u=s.jsx(ns,{title:h,description:m,showSaveStatus:!0,children:f}),t[13]=h,t[14]=m,t[15]=f,t[16]=u):u=t[16],u};function Bp(t){return t.setSelection}function Vp(){}function Hp(t){return t.saveKey}function qp(t){return t.removeKey}function Gp(t){const{provider:e,access:a}=t;return s.jsx(_p,{provider:e,access:a},e.id)}function Wp(t){return t.state}function Jp(t){return t.load}const Qp=t=>{const e=rt.c(176),{onItemSelect:a}=t,{t:n}=Xe(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[m,f]=o.useState(null),[u,g]=o.useState(!1),[v,j]=o.useState(null),{selectedCommandName:b,setSelectedCommand:k,setCommandDraft:p,createCommand:N,deleteCommand:P,loadCommands:C}=Va(Us(Yp)),w=Ws();let D;e[0]!==w?(D=Ze=>jc(Ze,w),e[0]=w,e[1]=D):D=e[1];const x=Va(D);let A;e[2]!==w?(A=Ze=>go(Ze,w),e[2]=w,e[3]=A):A=e[3];const R=sn(A),I=sn(Zp);let E,F;e[4]!==C||e[5]!==I||e[6]!==w?(E=()=>{C(w),I(w)},F=[C,I,w],e[4]=C,e[5]=I,e[6]=w,e[7]=E,e[8]=F):(E=e[7],F=e[8]),o.useEffect(E,F);let K;e[9]!==R?(K=new Set(R.map(Xp)),e[9]=R,e[10]=K):K=e[10];const S=K;let M;if(e[11]!==x||e[12]!==S){let Ze;e[14]!==S?(Ze=wt=>!S.has(wt.name),e[14]=S,e[15]=Ze):Ze=e[15],M=x.filter(Ze),e[11]=x,e[12]=S,e[13]=M}else M=e[13];const z=M;let _,q;e[16]!==b||e[17]!==k||e[18]!==S?(_=()=>{b&&S.has(b)&&k(null)},q=[b,k,S],e[16]=b,e[17]=k,e[18]=S,e[19]=_,e[20]=q):(_=e[19],q=e[20]),o.useEffect(_,q);let X;e[21]!==x||e[22]!==a||e[23]!==p||e[24]!==k?(X=()=>{let Ze="new-command",wt=1;for(;x.some(Le=>Le.name===Ze);)Ze=`new-command-${wt}`,wt++;p({name:Ze,scope:"user"}),k(Ze),a?.()},e[21]=x,e[22]=a,e[23]=p,e[24]=k,e[25]=X):X=e[25];const J=X;let H;e[26]!==n?(H=async Ze=>{if(za(Ze)){$.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(Ze),f("delete")},e[26]=n,e[27]=H):H=e[27];const L=H;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Ze=>{za(Ze)&&(h(Ze),f("reset"))},e[28]=V):V=e[28];const Z=V;let U;e[29]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{h(null),f(null)},e[29]=U):U=e[29];const te=U;let O;e[30]!==c||e[31]!==m||e[32]!==P||e[33]!==w||e[34]!==n?(O=async()=>{if(!c||!m)return;g(!0),await P(c.name,w)?(m==="delete"?$.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):$.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),te()):m==="delete"?$.error(n("settings.commands.sidebar.toast.deleteFailed")):$.error(n("settings.commands.sidebar.toast.resetFailed")),g(!1)},e[30]=c,e[31]=m,e[32]=P,e[33]=w,e[34]=n,e[35]=O):O=e[35];const Q=O;let ce;e[36]!==x||e[37]!==p||e[38]!==k?(ce=Ze=>{const wt=Ze.name;let Le=1,He=`${wt}-copy`;for(;x.some(Y=>Y.name===He);)Le++,He=`${wt}-copy-${Le}`;p({name:He,scope:Ze.scope||"user",description:Ze.description,template:Ze.template,agent:Ze.agent,model:Ze.model,subagent:Ze.subagent}),k(He)},e[36]=x,e[37]=p,e[38]=k,e[39]=ce):ce=e[39];const de=ce;let pe;e[40]===Symbol.for("react.memo_cache_sentinel")?(pe=Ze=>{d(Ze.name),i(Ze)},e[40]=pe):pe=e[40];const re=pe;let Ce;e[41]!==x||e[42]!==N||e[43]!==P||e[44]!==r||e[45]!==l||e[46]!==k||e[47]!==w||e[48]!==n?(Ce=async()=>{if(!r)return;const Ze=l.trim().replace(/\s+/g,"-");if(!Ze){$.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ze===r.name){i(null);return}if(x.some(Le=>Le.name===Ze)){$.error(n("settings.commands.sidebar.toast.commandExists"));return}await N({name:Ze,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},w)?await P(r.name,w)?($.success(`Command renamed to "${Ze}"`),k(Ze)):$.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):$.error(n("settings.commands.sidebar.toast.renameFailed")),i(null)},e[41]=x,e[42]=N,e[43]=P,e[44]=r,e[45]=l,e[46]=k,e[47]=w,e[48]=n,e[49]=Ce):Ce=e[49];const ie=Ce;let be,ae,fe,xe,Oe,Ne;if(e[50]!==z||e[51]!==J||e[52]!==L||e[53]!==de||e[54]!==a||e[55]!==v||e[56]!==b||e[57]!==k||e[58]!==n){const Ze=z.filter(za),wt=z.filter(eg);e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=Ie("flex h-full flex-col","bg-background"),e[65]=Oe):Oe=e[65];let Le;e[66]!==n?(Le=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Le):Le=e[67];let He;e[68]!==Le?(He=s.jsx("h2",{className:`${Pn} mb-3`,children:Le}),e[68]=Le,e[69]=He):He=e[69];let Y;e[70]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(fi,{className:"mb-3"}),e[70]=Y):Y=e[70];let me;e[71]!==z.length||e[72]!==n?(me=n("settings.commands.sidebar.total",{count:z.length}),e[71]=z.length,e[72]=n,e[73]=me):me=e[73];let Ke;e[74]!==me?(Ke=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[74]=me,e[75]=Ke):Ke=e[75];let Ee;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ee=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ee):Ee=e[76];let Ye;e[77]!==J?(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:J,children:Ee}),e[77]=J,e[78]=Ye):Ye=e[78];let se;e[79]!==Ke||e[80]!==Ye?(se=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ke,Ye]}),e[79]=Ke,e[80]=Ye,e[81]=se):se=e[81],e[82]!==He||e[83]!==se?(Ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[He,Y,se]}),e[82]=He,e[83]=se,e[84]=Ne):Ne=e[84],be=vs,ae="flex-1 min-h-0",fe="space-y-1 px-3 py-2",xe=z.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Ze.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...Ze].sort(tg).map(ke=>s.jsx(gl,{command:ke,isSelected:b===ke.name,onSelect:()=>{k(ke.name),a?.()},onReset:()=>Z(ke),onDuplicate:()=>de(ke),isMenuOpen:v===ke.name,onMenuOpenChange:at=>j(at?ke.name:null)},ke.name))]}),wt.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...wt].sort(sg).map(ke=>s.jsx(gl,{command:ke,isSelected:b===ke.name,onSelect:()=>{k(ke.name),a?.()},onRename:()=>re(ke),onDelete:()=>L(ke),onDuplicate:()=>de(ke),isMenuOpen:v===ke.name,onMenuOpenChange:at=>j(at?ke.name:null)},ke.name))]})]}),e[50]=z,e[51]=J,e[52]=L,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]=fe,e[62]=xe,e[63]=Oe,e[64]=Ne}else be=e[59],ae=e[60],fe=e[61],xe=e[62],Oe=e[63],Ne=e[64];let he;e[85]!==be||e[86]!==ae||e[87]!==fe||e[88]!==xe?(he=s.jsx(be,{outerClassName:ae,className:fe,children:xe}),e[85]=be,e[86]=ae,e[87]=fe,e[88]=xe,e[89]=he):he=e[89];const Te=c!==null&&m!==null;let we;e[90]!==u?(we=Ze=>{!Ze&&!u&&te()},e[90]=u,e[91]=we):we=e[91];let De;e[92]!==m||e[93]!==n?(De=n(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=m,e[93]=n,e[94]=De):De=e[94];let ve;e[95]!==De?(ve=s.jsx($t,{children:De}),e[95]=De,e[96]=ve):ve=e[96];let ee;e[97]!==c?.name||e[98]!==m||e[99]!==n?(ee=m==="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]=m,e[99]=n,e[100]=ee):ee=e[100];let ne;e[101]!==ee?(ne=s.jsx(Bt,{children:ee}),e[101]=ee,e[102]=ne):ne=e[102];let ye;e[103]!==ve||e[104]!==ne?(ye=s.jsxs(Ut,{children:[ve,ne]}),e[103]=ve,e[104]=ne,e[105]=ye):ye=e[105];let Ae;e[106]!==n?(Ae=n("settings.common.actions.cancel"),e[106]=n,e[107]=Ae):Ae=e[107];let ze;e[108]!==u||e[109]!==Ae?(ze=s.jsx(G,{size:"sm",variant:"ghost",onClick:te,disabled:u,children:Ae}),e[108]=u,e[109]=Ae,e[110]=ze):ze=e[110];let Qe;e[111]!==m||e[112]!==n?(Qe=n(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=m,e[112]=n,e[113]=Qe):Qe=e[113];let Be;e[114]!==Q||e[115]!==u||e[116]!==Qe?(Be=s.jsx(G,{size:"sm",onClick:Q,disabled:u,children:Qe}),e[114]=Q,e[115]=u,e[116]=Qe,e[117]=Be):Be=e[117];let _e;e[118]!==ze||e[119]!==Be?(_e=s.jsxs(as,{children:[ze,Be]}),e[118]=ze,e[119]=Be,e[120]=_e):_e=e[120];let Me;e[121]!==ye||e[122]!==_e?(Me=s.jsxs(zt,{className:"max-w-md",children:[ye,_e]}),e[121]=ye,e[122]=_e,e[123]=Me):Me=e[123];let nt;e[124]!==Te||e[125]!==we||e[126]!==Me?(nt=s.jsx(Kt,{open:Te,onOpenChange:we,children:Me}),e[124]=Te,e[125]=we,e[126]=Me,e[127]=nt):nt=e[127];const pt=r!==null;let lt;e[128]===Symbol.for("react.memo_cache_sentinel")?(lt=Ze=>!Ze&&i(null),e[128]=lt):lt=e[128];let ut;e[129]!==n?(ut=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=ut):ut=e[130];let ht;e[131]!==ut?(ht=s.jsx($t,{children:ut}),e[131]=ut,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 ue;e[136]!==st?(ue=s.jsx(Bt,{children:st}),e[136]=st,e[137]=ue):ue=e[137];let oe;e[138]!==ht||e[139]!==ue?(oe=s.jsxs(Ut,{children:[ht,ue]}),e[138]=ht,e[139]=ue,e[140]=oe):oe=e[140];let Pe;e[141]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ze=>d(Ze.target.value),e[141]=Pe):Pe=e[141];let Re;e[142]!==n?(Re=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=Re):Re=e[143];let Fe;e[144]!==ie?(Fe=Ze=>{Ze.key==="Enter"&&ie()},e[144]=ie,e[145]=Fe):Fe=e[145];let $e;e[146]!==l||e[147]!==Re||e[148]!==Fe?($e=s.jsx(We,{value:l,onChange:Pe,placeholder:Re,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Fe}),e[146]=l,e[147]=Re,e[148]=Fe,e[149]=$e):$e=e[149];let W;e[150]===Symbol.for("react.memo_cache_sentinel")?(W=()=>i(null),e[150]=W):W=e[150];let Ve;e[151]!==n?(Ve=n("settings.common.actions.cancel"),e[151]=n,e[152]=Ve):Ve=e[152];let et;e[153]!==Ve?(et=s.jsx(G,{size:"sm",variant:"ghost",onClick:W,children:Ve}),e[153]=Ve,e[154]=et):et=e[154];let dt;e[155]!==n?(dt=n("settings.common.actions.rename"),e[155]=n,e[156]=dt):dt=e[156];let ct;e[157]!==ie||e[158]!==dt?(ct=s.jsx(G,{size:"sm",onClick:ie,children:dt}),e[157]=ie,e[158]=dt,e[159]=ct):ct=e[159];let jt;e[160]!==et||e[161]!==ct?(jt=s.jsxs(as,{children:[et,ct]}),e[160]=et,e[161]=ct,e[162]=jt):jt=e[162];let kt;e[163]!==oe||e[164]!==$e||e[165]!==jt?(kt=s.jsxs(zt,{children:[oe,$e,jt]}),e[163]=oe,e[164]=$e,e[165]=jt,e[166]=kt):kt=e[166];let yt;e[167]!==pt||e[168]!==kt?(yt=s.jsx(Kt,{open:pt,onOpenChange:lt,children:kt}),e[167]=pt,e[168]=kt,e[169]=yt):yt=e[169];let bt;return e[170]!==Oe||e[171]!==Ne||e[172]!==he||e[173]!==nt||e[174]!==yt?(bt=s.jsxs("div",{className:Oe,children:[Ne,he,nt,yt]}),e[170]=Oe,e[171]=Ne,e[172]=he,e[173]=nt,e[174]=yt,e[175]=bt):bt=e[175],bt},gl=t=>{const e=rt.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,isMenuOpen:h,onMenuOpenChange:m}=t,{t:f}=Xe();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=di(),e[0]=u):u=e[0];const g=u,[v,j]=o.useState(!1);let b;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==f?(b=q=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(q,{onClick:X=>{X.stopPropagation(),d()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(q,{onClick:X=>{X.stopPropagation(),c()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),l&&s.jsxs(q,{onClick:X=>{X.stopPropagation(),l()},children:[s.jsx(B,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),i&&s.jsxs(q,{onClick:X=>{X.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{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,p=n?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==p?(N=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]=N):N=e[8];let P;e[9]===Symbol.for("react.memo_cache_sentinel")?(P=g?void 0:q=>{q.preventDefault(),j(!0)},e[9]=P):P=e[9];let C;e[10]!==N?(C=s.jsx("div",{className:N,onContextMenu:P}),e[10]=N,e[11]=C):C=e[11];let w;e[12]!==a.name?(w=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=w):w=e[13];let D;e[14]!==a||e[15]!==f?(D=(a.scope||za(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:za(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]!==w||e[18]!==D?(x=s.jsxs("div",{className:"flex items-center gap-2",children:[w,D]}),e[17]=w,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 I;e[26]!==m?(I=q=>{q&&j(!1),m(q)},e[26]=m,e[27]=I):I=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=E):E=e[28];let F;e[29]!==k?(F=s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:k(wn)}),e[29]=k,e[30]=F):F=e[30];let K;e[31]!==h||e[32]!==I||e[33]!==F?(K=s.jsxs(_n,{open:h,onOpenChange:I,children:[E,F]}),e[31]=h,e[32]=I,e[33]=F,e[34]=K):K=e[34];let S;e[35]!==R||e[36]!==K?(S=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,K]}),e[35]=R,e[36]=K,e[37]=S):S=e[37];let M;e[38]!==S||e[39]!==C?(M=s.jsx(pa,{render:C,children:S}),e[38]=S,e[39]=C,e[40]=M):M=e[40];let z;e[41]!==k?(z=s.jsx(ua,{className:"w-fit min-w-20",children:k(ma)}),e[41]=k,e[42]=z):z=e[42];let _;return e[43]!==v||e[44]!==M||e[45]!==z?(_=s.jsxs(ga,{open:v,onOpenChange:j,children:[M,z]}),e[43]=v,e[44]=M,e[45]=z,e[46]=_):_=e[46],_};function Yp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Zp(t){return t.loadSkills}function Xp(t){return t.name}function eg(t){return!za(t)}function tg(t,e){return t.name.localeCompare(e.name)}function sg(t,e){return t.name.localeCompare(e.name)}const ng=()=>{const{t}=Xe(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l,setSelectedCommand:d}=Va(Us(V=>({selectedCommandName:V.selectedCommandName,getCommandByName:V.getCommandByName,createCommand:V.createCommand,updateCommand:V.updateCommand,commandDraft:V.commandDraft,setCommandDraft:V.setCommandDraft,setSelectedCommand:V.setSelectedCommand}))),c=Ws(),h=Va(V=>jc(V,c)),m=e?a(e,c):null,f=!!(i&&i.name===e&&!m),[u,g]=o.useState(""),[v,j]=o.useState("user"),[b,k]=o.useState(""),[p,N]=o.useState(""),[P,C]=o.useState(""),[w,D]=o.useState(""),[x,A]=o.useState(!1),[R,I]=o.useState(""),[E,F]=o.useState(!1),K=o.useRef(null),S=JSON.stringify([c,e]),M=o.useRef(null),z=o.useRef(null);o.useEffect(()=>{const V=M.current===S;if(M.current=S,f&&i){const Z=i.name||"",U=i.scope||"user",te=i.description||"",O=i.agent||"",Q=ri(i.model),ce=Q?`${Q.providerID}/${Q.modelID}`:"",de=Q?.variant||"",pe=i.subagent===!0,re=i.template||"";g(Z),j(U),k(te),N(O),C(ce),D(de),A(pe),I(re),K.current={draftName:Z,draftScope:U,description:te,agent:O,model:ce,variant:de,subagent:pe,template:re}}else if(m){const Z=m.description||"",U=m.agent||"",te=ri(m.model),O=te?`${te.providerID}/${te.modelID}`:"",Q=te?.variant||"",ce=m.subagent===!0,de=m.template||"",pe=z.current,re=[K.current,pe?.identity===S?pe.form:null];if(V&&re.some(Ce=>Ce&&Ce.description===Z&&Ce.agent===U&&Ce.model===O&&Ce.variant===Q&&Ce.subagent===ce&&Ce.template===de))return;k(Z),N(U),C(O),D(Q),A(ce),I(de),K.current={draftName:"",draftScope:"user",description:Z,agent:U,model:O,variant:Q,subagent:ce,template:de}}},[m,f,e,h,i,S]);const _=o.useCallback(V=>{const Z=p.trim(),U=Ln(P.trim()),te=U?vc({providerID:U.providerId,modelID:U.modelId,variant:w.trim()||void 0}):null;return{name:V,description:b.trim()||void 0,agent:Z===""?null:Z,model:te,subagent:x,template:R.trim(),scope:f?v:void 0}},[p,b,v,f,P,x,R,w]),q=o.useCallback(async()=>{const V=K.current,Z=e?.trim();if(f||!V||!Z||b.trim()===V.description.trim()&&p.trim()===V.agent.trim()&&P.trim()===V.model.trim()&&w.trim()===V.variant.trim()&&x===V.subagent&&R.trim()===V.template.trim())return Rs;if(!R.trim())return xs(t("settings.commands.page.toast.templateRequired"));const te=_(Z),O=ri(te.model),Q={identity:S,form:{...V,description:te.description||"",agent:te.agent||"",model:O?`${O.providerID}/${O.modelID}`:"",variant:O?.variant||"",subagent:te.subagent===!0,template:te.template||""}};z.current=Q;try{return await r(Z,te,c)?(M.current===S&&(K.current=Q.form),In):xs(t("settings.commands.page.toast.updateFailed"))}finally{z.current===Q&&(z.current=null)}},[p,_,b,S,f,P,e,c,x,t,R,r,w]),X=qa(q),{requestSave:J}=X,H=async()=>{const V=u.trim().replace(/\s+/g,"-");if(!V){$.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!R.trim()){$.error(t("settings.commands.page.toast.templateRequired"));return}if(h.some(Z=>Z.name===V)){$.error(t("settings.commands.sidebar.toast.commandExists"));return}F(!0);try{await n(_(V),c)?(l(null),$.success(t("settings.commands.page.toast.created"))):$.error(t("settings.commands.page.toast.createFailed"))}catch(Z){console.error("Error creating command:",Z),$.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{F(!1)}},L=()=>{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:X.onBlurCapture,children:[!f&&m&&s.jsx(Co,{legacy:m.legacy===!0,path:m.path}),s.jsxs(Ge,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[f&&s.jsxs(St,{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:u,onChange:V=>g(V.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Et,{value:v,onValueChange:V=>j(V),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Tt,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{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(B,{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(Ge,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(St,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(ho,{agentName:p,onChange:V=>{N(V),J()},className:qs})}),s.jsx(St,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(la,{providerId:Ln(P)?.providerId??"",modelId:Ln(P)?.modelId??"",onChange:(V,Z)=>{C(V&&Z?`${V}/${Z}`:""),J()},className:qs})}),s.jsx(St,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(We,{value:w,onChange:V=>D(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!P&&!w,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(St,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(_a,{checked:x,onCheckedChange:V=>{A(V),J()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(Ge,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:R,onChange:V=>I(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||!u.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:L,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(B,{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")})]})})},Qi={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},ag=t=>t===!1?{...Qi,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)}:Qi,hl=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":return"warning";default:return"idle"}},fl=t=>{const e=rt.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},ig=t=>{const e=rt.c(124),{onItemSelect:a}=t,{t:n}=Xe(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:d,deleteMcp:c}=Wn(Us(rg)),h=Ws();let m;e[0]!==h?(m=Ue=>po(Ue,h),e[0]=h,e[1]=m):m=e[1];const f=Wn(m);let u;e[2]!==h?(u=Ue=>Ue.getStatusForDirectory(h),e[2]=h,e[3]=u):u=e[3];const g=dn(u),v=dn(og),j=dn(lg),[b,k]=o.useState(null),[p,N]=o.useState(!1),[P,C]=o.useState(null),[w,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 I=R;let E;e[6]!==f?(E=f.filter(dg),e[6]=f,e[7]=E):E=e[7];const F=E;let K,S;e[8]!==d||e[9]!==h?(K=()=>{d({directory:h})},S=[d,h],e[8]=d,e[9]=h,e[10]=K,e[11]=S):(K=e[10],S=e[11]),o.useEffect(K,S);let M;e[12]!==j||e[13]!==x||e[14]!==v||e[15]!==h?(M=()=>{if(x)return;A(!0);const Ue=new Promise(ug);Promise.all([v({directory:h,silent:!0}),Ue]).then(()=>{const st=j(h);st&&$.error(st)}).finally(()=>{A(!1)})},e[12]=j,e[13]=x,e[14]=v,e[15]=h,e[16]=M):M=e[16];const z=M;let _;e[17]!==f||e[18]!==a||e[19]!==l||e[20]!==i?(_=()=>{let Ue="new-mcp-server",st=1;for(;f.some(oe=>oe.name===Ue);)Ue=`new-mcp-server-${st}`,st++;const ue={name:Ue,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...Qi,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:!0,disabled:!1};l(ue),i(Ue),a?.()},e[17]=f,e[18]=a,e[19]=l,e[20]=i,e[21]=_):_=e[21];const q=_;let X;e[22]!==c||e[23]!==b||e[24]!==h||e[25]!==n?(X=async()=>{if(!b)return;N(!0);const Ue=await c(b.name,h);Ue.ok?Ue.reloadFailed?$.warning(Ue.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:Ue.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):$.success(Ue.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):$.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),N(!1)},e[22]=c,e[23]=b,e[24]=h,e[25]=n,e[26]=X):X=e[26];const J=X;let H;e[27]!==n?(H=(Ue,st)=>s.jsxs(st,{onClick:ue=>{ue.stopPropagation(),k(Ue)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{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 L=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 Z;e[30]!==n?(Z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=Z):Z=e[31];let U;e[32]!==Z?(U=s.jsx("h2",{className:Pn,children:Z}),e[32]=Z,e[33]=U):U=e[33];let te;e[34]!==n?(te=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=te):te=e[35];let O;e[36]!==n?(O=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=O):O=e[37];const Q=x&&"animate-spin";let ce;e[38]!==Q?(ce=Ie("h-4 w-4",Q),e[38]=Q,e[39]=ce):ce=e[39];let de;e[40]!==ce?(de=s.jsx(B,{name:"refresh",className:ce}),e[40]=ce,e[41]=de):de=e[41];let pe;e[42]!==z||e[43]!==x||e[44]!==te||e[45]!==O||e[46]!==de?(pe=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:z,"aria-label":te,title:O,children:de}),e[42]=z,e[43]=x,e[44]=te,e[45]=O,e[46]=de,e[47]=pe):pe=e[47];let re;e[48]!==U||e[49]!==pe?(re=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[U,pe]}),e[48]=U,e[49]=pe,e[50]=re):re=e[50];let Ce;e[51]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(fi,{className:"mb-3"}),e[51]=Ce):Ce=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 fe;e[59]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[59]=fe):fe=e[59];let xe;e[60]!==q||e[61]!==ae?(xe=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:q,title:ae,children:fe}),e[60]=q,e[61]=ae,e[62]=xe):xe=e[62];let Oe;e[63]!==be||e[64]!==xe?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,xe]}),e[63]=be,e[64]=xe,e[65]=Oe):Oe=e[65];let Ne;e[66]!==re||e[67]!==Oe?(Ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[re,Ce,Oe]}),e[66]=re,e[67]=Oe,e[68]=Ne):Ne=e[68];let he;e[69]!==f.length||e[70]!==g||e[71]!==a||e[72]!==P||e[73]!==I||e[74]!==L||e[75]!==w||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==F?(he=s.jsx(vs,{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(B,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[I.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),I.map(Ue=>{const st=g[Ue.name],ue=hl(st?.status.status),oe=r===Ue.name,Pe=di();return s.jsxs(ga,{open:w===Ue.name,onOpenChange:Re=>D(Re?Ue.name:null),children:[s.jsxs(pa,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Pe?void 0:Re=>{Re.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(fl,{tone:ue,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(B,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(B,{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(_n,{open:P===Ue.name,onOpenChange:Re=>{Re&&D(null),C(Re?Ue.name:null)},children:[s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:L(Ue,wn)})]})]}),s.jsx(ua,{className:"w-fit min-w-20",children:L(Ue,ma)})]},Ue.name)})]}),F.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")}),F.map(Ue=>{const st=g[Ue.name],ue=hl(st?.status.status),oe=r===Ue.name,Pe=di();return s.jsxs(ga,{open:w===Ue.name,onOpenChange:Re=>D(Re?Ue.name:null),children:[s.jsxs(pa,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Pe?void 0:Re=>{Re.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(fl,{tone:ue,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(B,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(B,{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(_n,{open:P===Ue.name,onOpenChange:Re=>{Re&&D(null),C(Re?Ue.name:null)},children:[s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:L(Ue,wn)})]})]}),s.jsx(ua,{className:"w-fit min-w-20",children:L(Ue,ma)})]},Ue.name)})]})]})}),e[69]=f.length,e[70]=g,e[71]=a,e[72]=P,e[73]=I,e[74]=L,e[75]=w,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=F,e[81]=he):he=e[81];const Te=b!==null;let we;e[82]!==p?(we=Ue=>{!Ue&&!p&&k(null)},e[82]=p,e[83]=we):we=e[83];let De;e[84]!==n?(De=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=De):De=e[85];let ve;e[86]!==De?(ve=s.jsx($t,{children:De}),e[86]=De,e[87]=ve):ve=e[87];const ee=b?.name||"";let ne;e[88]!==n||e[89]!==ee?(ne=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:ee}),e[88]=n,e[89]=ee,e[90]=ne):ne=e[90];let ye;e[91]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ye):ye=e[91];let Ae;e[92]!==ne?(Ae=s.jsxs(Bt,{children:[ne," ",ye,"."]}),e[92]=ne,e[93]=Ae):Ae=e[93];let ze;e[94]!==ve||e[95]!==Ae?(ze=s.jsxs(Ut,{children:[ve,Ae]}),e[94]=ve,e[95]=Ae,e[96]=ze):ze=e[96];let Qe;e[97]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>k(null),e[97]=Qe):Qe=e[97];let Be;e[98]!==n?(Be=n("settings.common.actions.cancel"),e[98]=n,e[99]=Be):Be=e[99];let _e;e[100]!==p||e[101]!==Be?(_e=s.jsx(G,{size:"sm",variant:"ghost",onClick:Qe,disabled:p,children:Be}),e[100]=p,e[101]=Be,e[102]=_e):_e=e[102];let Me;e[103]!==p||e[104]!==n?(Me=n(p?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=p,e[104]=n,e[105]=Me):Me=e[105];let nt;e[106]!==J||e[107]!==p||e[108]!==Me?(nt=s.jsx(G,{size:"sm",onClick:J,disabled:p,children:Me}),e[106]=J,e[107]=p,e[108]=Me,e[109]=nt):nt=e[109];let pt;e[110]!==_e||e[111]!==nt?(pt=s.jsxs(as,{children:[_e,nt]}),e[110]=_e,e[111]=nt,e[112]=pt):pt=e[112];let lt;e[113]!==ze||e[114]!==pt?(lt=s.jsxs(zt,{className:"max-w-md",children:[ze,pt]}),e[113]=ze,e[114]=pt,e[115]=lt):lt=e[115];let ut;e[116]!==Te||e[117]!==we||e[118]!==lt?(ut=s.jsx(Kt,{open:Te,onOpenChange:we,children:lt}),e[116]=Te,e[117]=we,e[118]=lt,e[119]=ut):ut=e[119];let ht;return e[120]!==Ne||e[121]!==he||e[122]!==ut?(ht=s.jsxs("div",{className:V,children:[Ne,he,ut]}),e[120]=Ne,e[121]=he,e[122]=ut,e[123]=ht):ht=e[123],ht};function rg(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function og(t){return t.refresh}function lg(t){return t.getErrorForDirectory}function cg(t){return t.scope==="project"}function dg(t){return t.scope!=="project"}function ug(t){return setTimeout(t,500)}function Hs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Qa(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 Mi(t,e,a){const n=pg(a),r=typeof a.url=="string"?a.url.trim():"",i=xl(a,"env","environment"),l=xl(a,"headers"),d=Hs(a.oauth)?a.oauth:null,c=Ya(d,"client_id","clientId"),h=Ya(d,"client_secret","clientSecret"),m=Ya(d,"scope"),f=Ya(d,"redirect_uri","redirectUri"),u=mg(d,"callback_port","callbackPort"),g=Ya(d,"auth_server_metadata_url","authServerMetadataUrl"),v=a.oauth===!1||a.oauth===null||a.oauth===void 0?!1:!!d&&!!(c||h||m||f||u||g),j=gg(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:v,oauthClientId:c,oauthClientSecret:h,oauthScope:m,oauthRedirectUri:f,oauthCallbackPort:u,oauthAuthServerMetadataUrl:g,timeoutStartup:j.startup,timeoutCatalog:j.catalog,timeoutExecution:j.execution,codemode:a.codemode!==!1,disabled:hg(a),protocol:Zr.find(b=>b===a.protocol)??"legacy"}}function Ya(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 mg(t,...e){if(!t)return"";for(const a of e){const n=ai(t[a]);if(n)return n}return""}function ai(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 pg(t){const e=t.command,a=t.args;if(Qa(e)&&Qa(a))return[...e,...a];if(Qa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Qa(a)?[...n,...a]:n}return Qa(a)?a:[]}function xl(t,...e){for(const a of e){const n=t[a];if(!Hs(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 gg(t){return Hs(t.timeout)?{startup:ai(t.timeout.startup),catalog:ai(t.timeout.catalog),execution:ai(t.timeout.execution)}:{startup:"",catalog:"",execution:ai(t.timeout)}}function hg(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function fg(t){const e=t.mcpServers;if(Hs(e)){const n=Object.keys(e);if(n.length===1){const r=n[0],i=e[r];if(Hs(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"&&Hs(r)});if(a.length===1){const n=a[0],r=t[n];if(Gc(r))return{name:n,entry:r}}return null}function Gc(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function xg(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(!Hs(a))return vn("Expected a JSON object, not an array or primitive");const n=a,r=n.mcpServers;if(Hs(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],m=r[h];return Hs(m)?Mi(h,Ri(m),m):vn("Server entry is not a valid object",a)}const i=n.mcp,l=Hs(i)&&Hs(i.servers)?i.servers:i;if(Hs(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],m=l[h];return Hs(m)?Mi(h,Ri(m),m):vn("Server entry in mcp is not a valid object",a)}const d=fg(n);if(d)return Mi(d.name,Ri(d.entry),d.entry);if(Gc(n)){const c=Ri(n),h=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Mi(h,c,n)}return vn("No recognizable MCP server configuration found in JSON",a)}function Ri(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 bg(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 vg=(t,e)=>!!e&&t!=="claude-code",yg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,jg=t=>yg.exec(t)?.[0]??void 0,xi=t=>t.type!=="external",Fi=t=>t.title??t.key,wg=(t,e)=>{if(e===void 0)return!1;const a=String(e),n=String(t.value);return t.op==="eq"?a===n:a!==n},kg=(t,e)=>xi(t)?(t.when??[]).every(a=>wg(a,e[a.key])):!0,Io=(t,e)=>{const a={},n=[];for(const r of t){if(!kg(r,a))continue;n.push(r);const i=e[r.key];xi(r)&&i!==void 0&&(a[r.key]=i)}return n},Ng=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},Wc=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,Sg=(t,e)=>Io(t,e).find(a=>xi(a)&&a.required===!0&&Wc(e[a.key]))??null,Cg=(t,e)=>{const a={};for(const n of Io(t,e)){if(!xi(n))continue;const r=e[n.key];Wc(r)||r===void 0||(a[n.key]=typeof r=="string"?r.trim():r)}return a},bl=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),vl=t=>typeof t=="string"&&t.length>0?t:void 0,Ig=(t,e,a)=>{const n=bl(t)?t:{},r=bl(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 vl(r.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return vl(n.message)??e(a)}},Rr={phase:"idle"},Pg=1500,io=({integrationId:t,methods:e,onConnected:a,directory:n,className:r})=>{const{t:i}=Xe(),l=o.useCallback(()=>n?un.getScopedSdkClient(n):un.getSdkClient(),[n]),[d,c]=o.useState(Rr),[h,m]=o.useState({}),[f,u]=o.useState(""),g=o.useRef(null),v=o.useCallback(E=>{g.current=null,l().integration.oauth.cancel({integrationID:t,attemptID:E}).catch(()=>{})},[t,l]);o.useEffect(()=>()=>{const E=g.current;E&&v(E)},[v]);const j=d.phase==="idle"?null:d.methodID,b=d.phase==="connecting"||d.phase==="waiting"||d.phase==="awaitingCode"&&d.submitting,k=async(E,F,K)=>{const S=await oi(E);if(S.ok){$.success(i(F));return}console.error("Failed to copy OAuth value:",S.error),$.error(i(K))},p=async()=>{g.current=null,c(Rr),$.success(i("settings.providers.page.toast.oauthCompleted")),await a()},N=(E,F,K)=>{g.current=null,console.error("OAuth flow failed:",F),c({phase:"failed",methodID:E,message:Ig(F,i,K)})},P=async(E,F)=>{const K=l();for(;g.current===F;){if(await new Promise(S=>setTimeout(S,Pg)),g.current!==F)return;try{const{data:S}=await K.integration.oauth.status({integrationID:t,attemptID:F});if(g.current!==F)return;if(S.status==="complete"){await p();return}if(S.status==="failed"){c({phase:"failed",methodID:E,message:S.message}),g.current=null;return}}catch(S){if(g.current!==F)return;N(E,S,"settings.providers.page.toast.oauthCompleteFailed");return}}},C=async(E,F)=>{c({phase:"connecting",methodID:E.id});let K;try{const{data:S}=await l().integration.oauth.connect({integrationID:t,methodID:E.id,...Object.keys(F).length>0?{answer:F}:{}});K={attemptID:S.attemptID,mode:S.mode,url:S.url,instructions:S.instructions}}catch(S){N(E.id,S,"settings.providers.page.toast.oauthStartFailed");return}if(g.current=K.attemptID,vg(t,K.url)&&yn(K.url),K.mode==="code"){u(""),c({phase:"awaitingCode",methodID:E.id,attempt:K,submitting:!1});return}c({phase:"waiting",methodID:E.id,attempt:K}),await P(E.id,K.attemptID)},w=E=>{const F=(E.form??[]).filter(xi);if(F.length===0){C(E,{});return}m(Ng(F)),c({phase:"prompting",methodID:E.id,fields:F,error:null})},D=E=>{if(d.phase!=="prompting")return;const F=Sg(d.fields,h);if(F){c({...d,error:i("settings.providers.page.auth.oauth.promptRequired",{field:Fi(F)})});return}C(E,Cg(d.fields,h))},x=async()=>{if(d.phase!=="awaitingCode")return;const E=f.trim();if(!E)return;const{methodID:F,attempt:K}=d;c({...d,submitting:!0});try{await l().integration.oauth.complete({integrationID:t,attemptID:K.attemptID,code:E}),await p()}catch(S){N(F,S,"settings.providers.page.toast.oauthCompleteFailed")}},A=()=>{(d.phase==="waiting"||d.phase==="awaitingCode")&&v(d.attempt.attemptID),c(Rr)},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 F=h[E.key],K=typeof F=="string"?F:"",S=z=>m(_=>({..._,[E.key]:z})),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(Et,{value:K,onValueChange:S,children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{children:z=>M.find(_=>_.value===z)?.label??null})}),s.jsx(Tt,{children:M.map(z=>s.jsx(mt,{value:z.value,children:z.description?`${z.label} · ${z.description}`:z.label},z.value))})]}):E.type==="boolean"?s.jsx("input",{type:"checkbox",checked:F===!0,onChange:z=>S(z.target.checked),"aria-label":Fi(E)}):s.jsx(We,{value:K,onChange:z=>S(z.target.value),placeholder:E.type==="string"?E.placeholder:void 0,className:"max-w-[24rem] text-xs"})]},E.key)},I=E=>{const F=jg(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}),F&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:F,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(F,"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 F=j===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:()=>w(E),disabled:b,children:i("settings.providers.page.actions.connect")})]}),F&&d.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Io(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")})]})]}),F&&d.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(B,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),F&&d.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[I(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(B,{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")})]}),F&&d.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[I(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:K=>u(K.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")})]})]}),F&&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:()=>w(E),children:i("settings.providers.page.actions.tryAgain")})]})]},E.id)})})},Ag=(t,e)=>t.find(a=>a.id.startsWith("mcp_")&&a.metadata?.source==="mcp"&&a.name===e),Tg=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Eg=({serverName:t,directory:e,onConnected:a})=>{const[n,r]=o.useState(null);o.useEffect(()=>{let l=!1;r(null);const d=e?un.getScopedSdkClient(e):un.getSdkClient();return(async()=>{try{const{data:h}=await d.integration.list();l||r(Ag(h,t)??null)}catch(h){console.error("Failed to load MCP integrations:",h)}})(),()=>{l=!0}},[e,t]);const i=Tg(n??void 0);return!n||i.length===0?null:s.jsx(io,{integrationId:n.id,methods:i,directory:e,onConnected:a},n.id)},Fr=t=>t===void 0?"":String(t),Or=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`},Lr={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},Dg=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Za=t=>t?.status.status,Kr=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function Jc(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 Mg=t=>{const e=rt.c(27),{value:a,onChange:n,preview:r,onDetectUrl:i}=t;let l;e[0]!==a?(l=()=>a.join(`
4
- `),e[0]=a,e[1]=l):l=e[1];const[d,c]=o.useState(l),h=o.useRef(a);let m,f;e[2]!==a?(m=()=>{JSON.stringify(h.current)!==JSON.stringify(a)&&(h.current=a,c(a.join(`
5
- `)))},f=[a],e[2]=a,e[3]=m,e[4]=f):(m=e[3],f=e[4]),o.useEffect(m,f);let u;e[5]!==n||e[6]!==i?(u=w=>{const D=w.split(`
6
- `).filter(_g);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]=u):u=e[7];const g=u;let v;e[8]!==n?(v=w=>{const x=w.clipboardData.getData("text").trim();if(!x||x.includes(`
7
- `)||!/\s/.test(x))return;const A=w.currentTarget;if(A.selectionStart!==0||A.selectionEnd!==A.value.length)return;w.preventDefault();const R=Jc(x);c(R.join(`
8
- `)),n(R)},e[8]=n,e[9]=v):v=e[9];const j=v;let b;e[10]!==g?(b=w=>{c(w.target.value),g(w.target.value)},e[10]=g,e[11]=b):b=e[11];let k;e[12]!==g||e[13]!==d?(k=()=>{const w=d.split(`
9
- `).map(Ug).join(`
10
- `);c(w),g(w)},e[12]=g,e[13]=d,e[14]=k):k=e[14];const p=Math.max(4,a.length+1);let N;e[15]!==j||e[16]!==b||e[17]!==k||e[18]!==p||e[19]!==d?(N=s.jsx(As,{onPaste:j,value:d,onChange:b,onBlur:k,placeholder:`npx
11
- -y
12
- @modelcontextprotocol/server-postgres
13
- postgresql://user:pass@host/db`,rows:p,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=j,e[16]=b,e[17]=k,e[18]=p,e[19]=d,e[20]=N):N=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($g)})})]}),e[21]=r,e[22]=a,e[23]=P):P=e[23];let C;return e[24]!==P||e[25]!==N?(C=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[N,P]}),e[24]=P,e[25]=N,e[26]=C):C=e[26],C},Rg=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),yl=({value:t,onChange:e,onCommit:a,keyTransform:n=Rg,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:m,keyLabel:f,valueLabel:u,valuePlaceholder:g,hideValueTitle:v,showValueTitle:j,addVariable:b,plainTextWarning:k,removeVariableAria:p})=>{const[N,P]=o.useState(new Set),C=()=>e([...t,{key:"",value:""}]),w=I=>{e(t.filter((E,F)=>F!==I)),a?.(),P(E=>{const F=new Set(E);return F.delete(I),F})},D=(I,E,F)=>{const K=[...t];K[I]={...K[I],[E]:F},e(K)},x=I=>{P(E=>{const F=new Set(E);return F.has(I)?F.delete(I):F.add(I),F})},A=async()=>{try{const I=await navigator.clipboard.readText(),E=[];for(const K of I.split(`
14
- `)){const S=K.trim();if(!S||S.startsWith("#"))continue;const M=S.indexOf("=");if(M===-1)continue;const z=S.slice(0,M).trim();let _=S.slice(M+1).trim();(_.startsWith('"')&&_.endsWith('"')||_.startsWith("'")&&_.endsWith("'"))&&(_=_.slice(1,-1)),z&&E.push({key:z,value:_})}if(E.length===0){$.error(c);return}const F=[...t];for(const K of E){const S=F.findIndex(M=>M.key===K.key);S!==-1?F[S]=K:F.push(K)}e(F),a?.(),$.success(h(E.length))}catch{$.error(m)}},R=t.some(I=>I.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:u})]}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:d,children:[s.jsx(B,{name:"clipboard",className:"h-3 w-3"}),l]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((I,E)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:I.key,onChange:F=>D(E,"key",n(F.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:N.has(E)?"text":"password",value:I.value,onChange:F=>D(E,"value",F.target.value),placeholder:g,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:N.has(E)?v:j,children:N.has(E)?s.jsx(B,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(B,{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:()=>w(E),"aria-label":p,children:s.jsx(B,{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:C,type:"button",children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),b]}),R&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:k})]})},jl=t=>{const e=rt.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 u={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 g=Ie("typography-micro font-medium rounded-full px-2 py-0.5",u.text,u.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:g,children:["● ",v]});break e}d=Ie("typography-micro font-medium",u.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 m;return e[11]!==d||e[12]!==h?(m=s.jsxs("span",{className:d,children:["● ",h]}),e[11]=d,e[12]=h,e[13]=m):m=e[13],m},Fg=(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")}},Og=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)]"}},Lg=t=>t==="failed"||t==="needs_auth",Kg=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},zg=()=>{const{t}=Xe(),e=o.useCallback((se,ke)=>t(se,ke),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:r,setSelectedMcp:i,getMcpByName:l,createMcp:d,updateMcp:c,deleteMcp:h}=Wn(Us(se=>({selectedMcpName:se.selectedMcpName,mcpDraft:se.mcpDraft,setMcpDraft:se.setMcpDraft,setSelectedMcp:se.setSelectedMcp,getMcpByName:se.getMcpByName,createMcp:se.createMcp,updateMcp:se.updateMcp,deleteMcp:se.deleteMcp}))),m=Ws(),f=dn(se=>se.getStatusForDirectory(m)),u=dn(se=>se.getDiagnosticForDirectory(m)),g=dn(se=>se.refresh),v=dn(se=>se.connect),j=dn(se=>se.disconnect),b=dn(se=>se.testConnection),k=Wn(se=>po(se,m)),p=a?l(a,m):null,N=!!(n&&n.name===a&&!p),[P,C]=o.useState(""),[w,D]=o.useState("user"),[x,A]=o.useState("local"),[R,I]=o.useState([]),[E,F]=o.useState(""),[K,S]=o.useState([]),[M,z]=o.useState([]),[_,q]=o.useState(""),[X,J]=o.useState(""),[H,L]=o.useState(""),[V,Z]=o.useState(!0),[U,te]=o.useState("legacy"),[O,Q]=o.useState(""),[ce,de]=o.useState(Qi),[pe,re]=o.useState(!0),[Ce,ie]=o.useState(!1),[be,ae]=o.useState(!1),[fe,xe]=o.useState(!1),[Oe,Ne]=o.useState(!1),[he,Te]=o.useState(!1),[we,De]=o.useState(!1),[ve,ee]=o.useState(!1),[ne,ye]=o.useState(""),[Ae,ze]=o.useState(null),Qe=o.useMemo(()=>Kg(a,m),[m,a]),Be=o.useRef(Qe),_e=o.useRef(null),Me=JSON.stringify([a,m,N]),nt=o.useRef(Me);nt.current=Me;const pt=o.useRef(null),lt={mcpType:x,command:R,url:E,envEntries:K,headerEntries:M,timeoutStartup:_,timeoutCatalog:X,timeoutExecution:H,codemode:V,protocol:U,oauthAuthServerMetadataUrl:x==="remote"?O:"",enabled:pe},ut=o.useRef(lt);ut.current=lt;const ht=o.useCallback(()=>{ye(""),ze(null),ee(!0)},[]),Ue=o.useCallback(async()=>{try{const se=await navigator.clipboard.readText();ye(se),ze(null)}catch{$.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),st=o.useCallback(()=>{const se=xg(ne,{fallbackName:P});if(!se.ok){ze(se.error);return}const at=bg(se,{name:P,scope:w,type:x,command:R,url:E,environment:K,headers:M,timeoutStartup:_,timeoutCatalog:X,timeoutExecution:H,codemode:V,disabled:!pe,protocol:U,oauthAuthServerMetadataUrl:O},{isNewServer:N});C(at.name),A(at.type),I(at.command??[]),F(at.url??""),S(at.environment??[]),z(at.headers??[]),q(at.timeoutStartup??""),J(at.timeoutCatalog??""),L(at.timeoutExecution??""),Z(at.codemode??!0),re(at.disabled!==!0),te(at.protocol??"legacy"),Q(at.oauthAuthServerMetadataUrl??""),ee(!1),ye(""),ze(null),$.success(t("settings.mcp.page.toast.configImported"))},[ne,P,w,x,R,E,K,M,U,O,_,X,H,V,pe,N,t]);o.useEffect(()=>{if(N&&n){pt.current=null,C(n.name),D(n.scope||"user"),A(n.type),I(n.command),F(n.url),S(n.environment),z(n.headers),q(n.timeoutStartup),J(n.timeoutCatalog),L(n.timeoutExecution),Z(n.codemode),te(n.protocol),Q(n.oauthAuthServerMetadataUrl),de({oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,oauthCallbackPort:n.oauthCallbackPort}),re(!n.disabled),De(!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(p){D(p.scope==="project"?"project":"user");const se=Ko(p.environment),ke=p.type==="remote"?p:null,at=Ko(ke?.headers),Mt=p.type,Wt=Mt==="local"?p.command??[]:[],Se=ke?.url??"",qe=Fr(p.timeout?.startup),vt=Fr(p.timeout?.catalog),Ct=Fr(p.timeout?.execution),Jt=p.codemode!==!1,Zt=p.protocol??"legacy",ts=ag(ke?.oauth),Xt=ke&&ke.oauth?ke.oauth.auth_server_metadata_url??"":"",Fs=p.disabled!==!0;de(ts);const Js=_e.current!==null&&JSON.stringify(_e.current)!==JSON.stringify(ut.current);if(pt.current===Me&&Js)return;pt.current=Me,A(Mt),I(Wt),F(Se),S(se),z(at),q(qe),J(vt),L(Ct),Z(Jt),te(Zt),Q(Xt),re(Fs),De(!1),_e.current={mcpType:Mt,command:Wt,url:Se,envEntries:se,headerEntries:at,timeoutStartup:qe,timeoutCatalog:vt,timeoutExecution:Ct,codemode:Jt,protocol:Zt,oauthAuthServerMetadataUrl:Xt,enabled:Fs}}},[p,a,m,N,n,Me]);const ue=o.useMemo(()=>{const se=O.trim();return!se||Dg(se)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[O,t]),oe=o.useMemo(()=>{const se=[];x==="remote"&&M.length>0&&se.push(`${M.length} ${t("settings.mcp.page.advanced.headers")}`);const ke=x==="local"?Or(_):null;ke&&se.push(t("settings.mcp.page.advanced.summary.startup",{value:ke}));const at=Or(X);at&&se.push(t("settings.mcp.page.advanced.summary.catalog",{value:at}));const Mt=Or(H);return Mt&&se.push(t("settings.mcp.page.advanced.summary.execution",{value:Mt})),V&&se.push(t("settings.mcp.page.advanced.codemode")),U!=="legacy"&&se.push(t(Lr[U])),se.join(" · ")},[V,M.length,x,U,t,X,H,_]),Pe=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(B,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(B,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Re=o.useCallback(se=>{A("remote"),F(se),I([])},[]),Fe=o.useCallback(se=>{F(se);const ke=se.trim();ke&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ke)&&/\s/.test(ke)&&(A("local"),I(Jc(ke)),F(""))},[]),$e=se=>({name:se,scope:w,type:x,command:R,url:E,environment:K,headers:M,...ce,oauthAuthServerMetadataUrl:x==="remote"?O:"",protocol:U,timeoutStartup:_,timeoutCatalog:X,timeoutExecution:H,codemode:V,disabled:!pe}),Ve=qa(async()=>{const se=_e.current;if(N||!se||!a||JSON.stringify(se)===JSON.stringify({mcpType:x,command:R,url:E,envEntries:K,headerEntries:M,timeoutStartup:_,timeoutCatalog:X,timeoutExecution:H,codemode:V,protocol:U,oauthAuthServerMetadataUrl:x==="remote"?O:"",enabled:pe}))return Rs;if(x==="local"&&R.filter(Boolean).length===0)return xs(t("settings.mcp.page.toast.localCommandRequired"));if(x==="remote"&&!E.trim())return xs(t("settings.mcp.page.toast.remoteUrlRequired"));if(x==="remote"&&ue)return xs(ue);const ke=await c(a,$e(a),m);return ke.ok?nt.current!==Me?In:(_e.current={mcpType:x,command:R,url:E,envEntries:K,headerEntries:M,timeoutStartup:_,timeoutCatalog:X,timeoutExecution:H,codemode:V,protocol:U,oauthAuthServerMetadataUrl:x==="remote"?O:"",enabled:pe},await g({directory:m,silent:!0}),ke.reloadFailed?xs(ke.warning||ke.message||t("settings.mcp.page.toast.savedReloadFailed")):In):xs(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:et}=Ve,dt=async()=>{const se=P.trim();if(!se){$.error(t("settings.mcp.page.toast.nameRequired"));return}if(k.some(ke=>ke.name===se)){$.error(t("settings.mcp.page.toast.serverNameExists"));return}if(x==="local"&&R.filter(Boolean).length===0){$.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(x==="remote"&&!E.trim()){$.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(x==="remote"&&ue){$.error(ue);return}ie(!0);try{const ke=await d($e(se),m);ke.ok?(r(null),i(se),await g({directory:m,silent:!0}),ke.reloadFailed?$.warning(ke.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:ke.warning||t("settings.mcp.page.toast.retryRefreshHint")}):$.success(ke.message||t("settings.mcp.page.toast.serverCreatedReloading"))):$.error(t("settings.mcp.page.toast.saveFailed"))}catch(ke){$.error(ke instanceof Error?ke.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ie(!1)}},ct=()=>{r(null),i(null)},jt=async()=>{if(!a)return;xe(!0);const se=await h(a,m);se.ok?(se.reloadFailed?$.warning(se.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:se.warning||t("settings.mcp.page.toast.refreshListIfStale")}):$.success(se.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),ae(!1)):$.error(t("settings.mcp.page.toast.deleteFailed")),xe(!1)},kt=async()=>{if(a)try{await v(a,m),$.success(t("settings.mcp.page.toast.connected"))}catch(se){$.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionTestFailed"))}},yt=async()=>{if(a){Ne(!0);try{if(Za(f[a])==="connected")await j(a,m),$.success(t("settings.mcp.page.toast.disconnected"));else{await v(a,m),await g({directory:m,silent:!0});const ke=dn.getState().getStatusForDirectory(m)[a],at=Za(ke);at==="connected"?$.success(t("settings.mcp.page.toast.connected")):at==="needs_auth"?$.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):at==="failed"?$.error(Kr(ke)||t("settings.mcp.page.toast.connectionFailed")):$.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await g({directory:m,silent:!0})}catch(se){$.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Ne(!1)}}},bt=o.useCallback(()=>N?($.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[N,t]),Ze=o.useCallback(async(se=!1)=>{try{await g({directory:m,silent:se})}catch(ke){se||$.error(ke instanceof Error?ke.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[m,g,t]);o.useEffect(()=>{Ze(!0)},[Ze]),o.useEffect(()=>{Be.current=Qe,Ne(!1),Te(!1)},[Qe]);const wt=o.useCallback(async()=>{if(!(!a||!bt())){if(!pe){$.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Te(!0);try{const se=await b(a,m),ke=Za(se.status);se.warning?$.warning(se.warning):ke==="connected"?$.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ke==="needs_auth"?$.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ke==="failed"?$.error(Kr(se.status)||se.error||t("settings.mcp.page.toast.connectionTestFailed")):se.error?$.error(se.error):$.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(se){$.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Te(!1)}}},[m,pe,bt,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(B,{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 Le=f[a],He=a?u[a]:void 0,Y=Le?Za(Le):He?.status,me=Le?Kr(Le):He?.error,Ke=Za(Le)==="connected",Ee=Fg(Y,e,me),Ye=se=>{switch(se){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 se}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:N?t("settings.mcp.page.header.newServer"):a,titleAccessory:N?void 0:s.jsx(jl,{status:Y,enabled:pe,getStatusLabel:Ye,variant:"pill"}),description:N?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:N?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{variant:Ke?"outline":"default",size:"xs",className:"!font-normal",onClick:yt,disabled:Oe||!pe,children:t(Oe?"settings.mcp.page.actions.working":Ke?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),Ke&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{wt()},disabled:he||!pe,children:t(he?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:Ve.onBlurCapture,children:[!N&&p&&s.jsx(Co,{legacy:p.legacy===!0,path:p.path}),!N&&Lg(Y)&&s.jsx(Ge,{divider:!1,children:s.jsx("div",{className:Ie("rounded-lg border p-3",Og(Y)),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:It,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(jl,{status:Y,enabled:pe,getStatusLabel:Ye})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ee}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:w==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:m??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),Y==="needs_auth"&&a&&s.jsx(Eg,{serverName:a,directory:m,onConnected:kt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ke&&s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{wt()},disabled:he||!pe,children:t(he?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(Ge,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:N?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(B,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[N&&s.jsxs(St,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(We,{value:P,onChange:se=>C(se.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(Et,{value:w,onValueChange:se=>D(se),children:[s.jsxs(At,{size:Vt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(B,{name:w==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(w==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Tt,{align:"end",children:[s.jsx(mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{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(B,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:pe,onChange:se=>{re(se),et()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Ge,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(ko,{items:Pe,activeId:x,onSelect:se=>{A(se),et()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),x==="local"?s.jsx(Mg,{value:R,onChange:I,preview:se=>t("settings.mcp.page.connection.previewArgs",{count:se}),onDetectUrl:Re}):s.jsx(We,{value:E,onChange:se=>Fe(se.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(Ge,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(kn,{open:we,onOpenChange:De,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")}),oe&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",oe,")"]})]}),we?s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{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:It,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(Ht,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Et,{value:U,onValueChange:se=>{const ke=Zr.find(at=>at===se);ke&&(te(ke),et())},children:[s.jsx(At,{size:Vt,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(Lr[U])})}),s.jsx(Tt,{children:Zr.map(se=>s.jsx(mt,{value:se,children:t(Lr[se])},se))})]})]}),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:It,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(Ht,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:_,onChange:se=>q(se.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:It,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(Ht,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:X,onChange:se=>J(se.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:It,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(Ht,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(We,{type:"number",min:"1",step:"1",value:H,onChange:se=>L(se.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),s.jsx(gt,{checked:V,onChange:se=>{Z(se),et()},label:t("settings.mcp.page.advanced.codemode"),info:t("settings.mcp.page.advanced.codemodeHint"),ariaLabel:t("settings.mcp.page.advanced.codemode")}),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(yl,{value:M,onChange:z,onCommit:et,keyTransform:se=>se.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:se=>t("settings.mcp.page.toast.importedVariablesCount",{count:se}),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:It,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(Ht,{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:O,onChange:se=>Q(se.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":ue?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),ue&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:ue})]})]})]})]})})]})}),s.jsx(Ge,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:K.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",K.length,")"]}):null,settingsItem:"mcp.environment",children:K.length===0?s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>S([{key:"",value:""}]),children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(yl,{value:K,onChange:S,onCommit:et,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:se=>t("settings.mcp.page.toast.importedVariablesCount",{count:se}),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:[N&&s.jsxs(s.Fragment,{children:[s.jsx(G,{onClick:()=>{dt()},disabled:Ce||!P.trim(),size:"xs",className:"!font-normal",children:t(Ce?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(G,{variant:"ghost",onClick:ct,disabled:Ce,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!N&&s.jsx(G,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ae(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:ve,onOpenChange:se=>{se||(ee(!1),ye(""),ze(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Bt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:ne,onChange:se=>{ye(se.target.value),ze(null)},placeholder:`{
15
- "mcpServers": {
16
- "postgres": {
17
- "command": "npx",
18
- "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
- }
20
- }
21
- }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Ae&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Ae}),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(B,{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:()=>{ee(!1),ye(""),ze(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{onClick:st,disabled:!ne.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:be,onOpenChange:se=>{!se&&!fe&&ae(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Bt,{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:fe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{variant:"destructive",size:"sm",onClick:jt,disabled:fe,children:t(fe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function _g(t){return t.trim().length>0}function Ug(t){return t.trimEnd()}function $g(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 Bg=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Vg(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 Hg=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=Xe(),r=Gt(S=>S.createEntry),i=Gt(S=>S.createFile),[l,d]=o.useState("npm"),[c,h]=o.useState(""),[m,f]=o.useState(""),[u,g]=o.useState(""),[v,j]=o.useState(""),[b,k]=o.useState(a),[p,N]=o.useState(!1),P=o.useCallback(()=>{h(""),f(""),g(""),j(""),k(a)},[a]);o.useEffect(()=>{t&&(d("npm"),P())},[t,P]);const C=S=>{S!==l&&(d(S),P())},w=o.useMemo(()=>Vg(m),[m]),D=!w.ok,x=l==="file"&&u.trim()!==""&&!Bg.test(u.trim()),A=(l==="npm"||l==="path")&&c.trim()==="",R=l==="file"&&v.trim()==="",I=l==="file"&&u.trim()==="",E=p||D||l==="npm"&&A||l==="path"&&A||l==="file"&&(I||x||R),F=async()=>{if(!E){N(!0);try{let S;l==="file"?S=await i({fileName:u.trim(),content:v,scope:b}):S=await r({spec:c.trim(),options:w.ok?w.value:void 0,scope:b}),S.ok?($.success(S.message||n("settings.plugins.toast.created")),S.reloadFailed&&$.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):$.error(S.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{N(!1)}}},K=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Kt,{open:t,onOpenChange:S=>{!S&&p||e(S)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Bt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(ko,{items:K,activeId:l,onSelect:S=>C(S),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(We,{id:"plugin-spec",value:c,onChange:S=>h(S.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":A?!1:void 0,disabled:p}),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:m,onChange:S=>f(S.target.value),rows:5,className:"font-mono",hasError:D,disabled:p}),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:u,onChange:S=>g(S.target.value),placeholder:"my-plugin.ts","aria-invalid":x||void 0,disabled:p}),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:S=>j(S.target.value),rows:16,className:"font-mono",disabled:p})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(S=>{const M=b===S,z=n(S==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(S),disabled:p,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(fo,{checked:M,onChange:()=>k(S),ariaLabel:z}),s.jsx("span",{className:Ie("typography-ui-label font-normal",M?"text-foreground":"text-foreground/60"),children:z})]},S)})})]})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:p,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(G,{size:"sm",onClick:()=>{F()},disabled:E,children:[p?s.jsx(B,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},qg=t=>{const e=rt.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=Gt(n),{t:i}=Xe();if(!r)return null;const l=Gg;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(B,{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(B,{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(B,{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(B,{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(B,{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(B,{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(B,{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 Gg(t,e){return s.jsxs(sr,{children:[s.jsx(nr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(xo,{children:e})]})}const Wg=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),Ba=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("/")}`},Jg=t=>Ba(`${t.replace(/\\/g,"/")}/..`),Qg=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function Qc(t,e){if(t.startsWith("file://")){const a=Qg(t);return a?{kind:"local",path:Ba(a)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:Ba(`${Jg(e)}/${t}`)}:null:Wg(t)?{kind:"local",path:Ba(t)}:{kind:"package",target:t}}function Yc(t){return t?{kind:"local",path:Ba(t)}:null}const Yg=(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=Ba(e.source.path);return a===t.path||a.startsWith(`${t.path}/`)};function Zc(t,e){return e.filter(a=>Yg(t,a))}function Zg(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 Xc(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 ed(t){const e=rt.c(12),a=Gt(Xg),n=bo(ta());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=Zc(t,a.plugins);i="known",l=Zg(h),d=Xc(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 Xg(t){return t.runtime}function td(t){const e=rt.c(4);let a;if(e[0]!==t){const i=bo(ta());a=t?.kind==="package"?wc(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],Gt(r)}const zr=t=>{const e=rt.c(28),{target:a}=t,{t:n}=Xe(),r=ed(a),i=td(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(B,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground"}),e[0]=f):f=e[0];let u;e[1]!==n?(u=n("settings.plugins.update.running"),e[1]=n,e[2]=u):u=e[2];let g;e[3]!==u?(g={icon:f,label:u},e[3]=u,e[4]=g):g=e[4],l=g;break e}if(r.load.kind==="failed"){let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[5]=f):f=e[5];let u;e[6]!==n?(u=n("settings.plugins.status.failed.title"),e[6]=n,e[7]=u):u=e[7];let g;e[8]!==u?(g={icon:f,label:u},e[8]=u,e[9]=g):g=e[9],l=g;break e}if(r.load.kind==="notReported"){let f;e[10]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(B,{name:"time",className:"h-3 w-3 text-muted-foreground"}),e[10]=f):f=e[10];let u;e[11]!==n?(u=n("settings.plugins.status.notReported.title"),e[11]=n,e[12]=u):u=e[12];let g;e[13]!==u?(g={icon:f,label:u},e[13]=u,e[14]=g):g=e[14],l=g;break e}if(r.update==="available"){let f;e[15]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(B,{name:"arrow-up-s",className:"h-3 w-3 text-[var(--status-success)]"}),e[15]=f):f=e[15];let u;e[16]!==n?(u=n("settings.plugins.update.available.title"),e[16]=n,e[17]=u):u=e[17];let g;e[18]!==u?(g={icon:f,label:u},e[18]=u,e[19]=g):g=e[19],l=g;break e}l=null}const d=l;if(!d)return null;let c;e[20]!==d.icon||e[21]!==d.label?(c=s.jsx(nr,{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(xo,{children:d.label}),e[23]=d.label,e[24]=h):h=e[24];let m;return e[25]!==c||e[26]!==h?(m=s.jsxs(sr,{children:[c,h]}),e[25]=c,e[26]=h,e[27]=m):m=e[27],m},sd=t=>{const e=rt.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,d=l===void 0?"sidebar":l,c=cs(),h=o.useRef(null),[m,f]=o.useState(!1),[u,g]=o.useState(!1),v=d==="background"||c?"bg-background":"bg-sidebar",j=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),g(!1);return}if(!(E.scrollHeight>E.clientHeight+1)){f(!1),g(!1);return}f(E.scrollTop>1),g(E.scrollTop+E.clientHeight<E.scrollHeight-1)},e[0]=b):b=e[0];const k=b;let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{k()},e[1]=p):p=e[1];let N;e[2]!==r?(N=[r,k],e[2]=r,e[3]=N):N=e[3],o.useEffect(p,N);let P,C;e[4]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const E=h.current;if(!E)return;const F=()=>k();return E.addEventListener("scroll",F,{passive:!0}),()=>E.removeEventListener("scroll",F)},C=[k],e[4]=P,e[5]=C):(P=e[4],C=e[5]),o.useEffect(P,C);let w;e[6]!==v||e[7]!==i?(w=Ie("flex h-full flex-col",v,i),e[6]=v,e[7]=i,e[8]=w):w=e[8];let D;e[9]!==r?(D=s.jsx(vs,{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]!==j||e[12]!==m?(x=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${j} 0%, transparent 100%)`}}),e[11]=j,e[12]=m,e[13]=x):x=e[13];let A;e[14]!==j||e[15]!==u?(A=u&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${j} 0%, transparent 100%)`}}),e[14]=j,e[15]=u,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 I;return e[21]!==n||e[22]!==a||e[23]!==R||e[24]!==w?(I=s.jsxs("div",{className:w,children:[a,R,n]}),e[21]=n,e[22]=a,e[23]=R,e[24]=w,e[25]=I):I=e[25],I},Vi=t=>{const e=rt.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:d,className:c}=t,h=r===void 0?!1:r,m=d&&d.length>0,f=h?"bg-interactive-selection":"hover:bg-interactive-hover";let u;e[0]!==c||e[1]!==f?(u=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]=u):u=e[2];let g;e[3]!==a?(g=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=g):g=e[4];let v;e[5]!==l||e[6]!==g?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,g]}),e[5]=l,e[6]=g,e[7]=v):v=e[7];let j;e[8]!==n?(j=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=j):j=e[9];let b;e[10]!==i||e[11]!==v||e[12]!==j?(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,j]}),e[10]=i,e[11]=v,e[12]=j,e[13]=b):b=e[13];let k;e[14]!==d||e[15]!==m?(k=m&&s.jsxs(_n,{children:[s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:d.map(eh)})]}),e[14]=d,e[15]=m,e[16]=k):k=e[16];let p;e[17]!==b||e[18]!==k?(p=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,k]}),e[17]=b,e[18]=k,e[19]=p):p=e[19];let N;return e[20]!==u||e[21]!==p?(N=s.jsx("div",{className:u,children:p}),e[20]=u,e[21]=p,e[22]=N):N=e[22],N};function eh(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(B,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const th=t=>t.parsedKind==="npm"?"code-box":"folder",sh=t=>{const e=rt.c(165),{onItemSelect:a,onAddClick:n}=t,{t:r}=Xe(),{entries:i,files:l,selectedId:d,setSelected:c,deleteEntry:h,deleteFile:m,loadPlugins:f}=Gt(Us(nh)),u=Gt(ah),g=Gt(ih),v=Gt(rh),j=Gt(oh),b=Gt(lh),k=Gt(ch),p=Gt(dh),N=Gt(uh),P=Gt(mh);let C;e[0]===Symbol.for("react.memo_cache_sentinel")?(C=bo(ta()),e[0]=C):C=e[0];const w=C,D=b.kind==="failed"&&b.scope===w,x=b.kind==="ready"&&b.scope===w?b.plugins:null;let A;if(e[1]!==i||e[2]!==l){A=new Map;for(const Se of i)A.set(Se.id,Qc(Se.spec,Se.sourcePath));for(const Se of l)A.set(Se.id,Yc(Se.absolutePath));e[1]=i,e[2]=l,e[3]=A}else A=e[3];const R=A;let I;e[4]!==P||e[5]!==x||e[6]!==R?(I=Se=>{const qe=R.get(Se);return!x||qe?.kind!=="package"||P[wc(w,qe.target)]?.kind==="running"?null:Xc(Zc(qe,x))==="available"?qe.target:null},e[4]=P,e[5]=x,e[6]=R,e[7]=I):I=e[7];const E=I,[F,K]=o.useState(null),[S,M]=o.useState(!1),[z,_]=o.useState(!1);let q,X;e[8]!==f?(q=()=>{f()},X=[f],e[8]=f,e[9]=q,e[10]=X):(q=e[9],X=e[10]),o.useEffect(q,X);let J,H;e[11]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{const Se=()=>_(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Se),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Se)},H=[],e[11]=J,e[12]=H):(J=e[11],H=e[12]),o.useEffect(J,H);let L;if(e[13]!==i||e[14]!==E||e[15]!==u){L={userEntries:0,projectEntries:0};for(const Se of i){const qe=u[Se.spec];(qe?.kind==="npm-ok"&&qe.hasUpdate||E(Se.id)!==null)&&(Se.scope==="user"?L.userEntries=L.userEntries+1:Se.scope==="project"&&(L.projectEntries=L.projectEntries+1))}e[13]=i,e[14]=E,e[15]=u,e[16]=L}else L=e[16];const V=L;let Z;e[17]!==i?(Z=i.filter(ph),e[17]=i,e[18]=Z):Z=e[18];const U=Z;let te;e[19]!==i?(te=i.filter(gh),e[19]=i,e[20]=te):te=e[20];const O=te;let Q;e[21]!==l?(Q=l.filter(hh),e[21]=l,e[22]=Q):Q=e[22];const ce=Q;let de;e[23]!==l?(de=l.filter(fh),e[23]=l,e[24]=de):de=e[24];const pe=de,re=i.length+l.length,Ce=re===0;let ie;e[25]!==n?(ie=()=>{n?n():_(!0)},e[25]=n,e[26]=ie):ie=e[26];const be=ie;let ae;e[27]!==a||e[28]!==c?(ae=Se=>{c(Se),a?.()},e[27]=a,e[28]=c,e[29]=ae):ae=e[29];const fe=ae;let xe;e[30]!==i||e[31]!==u||e[32]!==r||e[33]!==j?(xe=async Se=>{const qe=i.find(Zt=>Zt.id===Se);if(!qe)return;const vt=u[qe.spec];if(!vt||vt.kind!=="npm-ok"||!vt.hasUpdate||!vt.latestVersion)return;const Ct=vt.latestVersion;(await j(Se)).ok?$.success(r("settings.plugins.toast.updatedToLatest",{version:Ct})):$.error(r("settings.plugins.toast.refreshFailed"))},e[30]=i,e[31]=u,e[32]=r,e[33]=j,e[34]=xe):xe=e[34];const Oe=xe;let Ne;e[35]!==r||e[36]!==N?(Ne=async(Se,qe)=>{await N(Se)?$.success(r("settings.plugins.update.toast.done",{name:qe})):$.error(r("settings.plugins.update.toast.failed",{name:qe}))},e[35]=r,e[36]=N,e[37]=Ne):Ne=e[37];const he=Ne;let Te;e[38]!==p||e[39]!==v||e[40]!==r?(Te=async()=>{$.info(r("settings.plugins.toast.refreshing"));const[Se,qe]=await Promise.all([v({force:!0}),p()]);Se||$.error(r("settings.plugins.toast.refreshFailed")),qe||$.error(r("settings.plugins.toast.checkFailed"))},e[38]=p,e[39]=v,e[40]=r,e[41]=Te):Te=e[41];const we=Te;let De;e[42]!==h||e[43]!==m||e[44]!==F||e[45]!==r?(De=async()=>{if(!F)return;M(!0);const Se=F.kind==="entry"?await h(F.id):await m(F.id);Se.ok?$.success(Se.message||r("settings.plugins.sidebar.toast.deleted",{name:F.label})):$.error(r("settings.plugins.sidebar.toast.deleteFailed")),K(null),M(!1)},e[42]=h,e[43]=m,e[44]=F,e[45]=r,e[46]=De):De=e[46];const ve=De;let ee;e[47]!==he||e[48]!==fe||e[49]!==Oe||e[50]!==E||e[51]!==u||e[52]!==R||e[53]!==d||e[54]!==r?(ee=Se=>{const qe=u[Se.spec],vt=qe?.kind==="npm-ok"&&qe.hasUpdate&&!!qe.latestVersion,Ct=E(Se.id),Jt=[];return vt?Jt.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Oe(Se.id)}}):Ct&&Jt.push({label:r("settings.plugins.update.action"),icon:"arrow-up-s",onClick:()=>{he(Ct,Se.spec)}}),Jt.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>K({kind:"entry",id:Se.id,label:Se.spec})}),s.jsx(Vi,{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:Se.spec}),s.jsx(zr,{target:R.get(Se.id)??null}),s.jsx(qg,{spec:Se.spec})]}),metadata:Se.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===Se.id,onSelect:()=>fe(Se.id),icon:s.jsx(B,{name:th(Se),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Jt},Se.id)},e[47]=he,e[48]=fe,e[49]=Oe,e[50]=E,e[51]=u,e[52]=R,e[53]=d,e[54]=r,e[55]=ee):ee=e[55];const ne=ee;let ye;e[56]!==fe||e[57]!==R||e[58]!==d||e[59]!==r?(ye=Se=>Se.kind==="package"?s.jsx(Vi,{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:Se.fileName}),s.jsx(zr,{target:R.get(Se.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.package"),selected:!1,onSelect:xh,icon:s.jsx(B,{name:"folder",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"})},Se.id):s.jsx(Vi,{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:Se.fileName}),s.jsx(zr,{target:R.get(Se.id)??null})]}),metadata:r("settings.plugins.sidebar.kind.file"),selected:d===Se.id,onSelect:()=>fe(Se.id),icon:s.jsx(B,{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:()=>K({kind:"file",id:Se.id,label:Se.fileName})}]},Se.id),e[56]=fe,e[57]=R,e[58]=d,e[59]=r,e[60]=ye):ye=e[60];const Ae=ye;let ze;e[61]!==r?(ze=(Se,qe,vt)=>{const Ct=vt===void 0?0:vt;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:[Se,Ct>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(Ct===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ct})})]}),qe]})},e[61]=r,e[62]=ze):ze=e[62];const Qe=ze;let Be;e[63]!==r?(Be=r("settings.plugins.sidebar.title"),e[63]=r,e[64]=Be):Be=e[64];let _e;e[65]!==Be?(_e=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:Pn,children:Be})}),e[65]=Be,e[66]=_e):_e=e[66];let Me;e[67]!==r||e[68]!==re?(Me=r("settings.plugins.sidebar.total",{count:re}),e[67]=r,e[68]=re,e[69]=Me):Me=e[69];let nt;e[70]!==D||e[71]!==r?(nt=D?s.jsxs("span",{className:"ml-2 inline-flex items-center gap-1",children:[s.jsx(B,{name:"question",className:"size-3"}),r("settings.plugins.status.sidebar.unavailable")]}):null,e[70]=D,e[71]=r,e[72]=nt):nt=e[72];let pt;e[73]!==Me||e[74]!==nt?(pt=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[Me,nt]}),e[73]=Me,e[74]=nt,e[75]=pt):pt=e[75];let lt;e[76]!==we?(lt=()=>{we()},e[76]=we,e[77]=lt):lt=e[77];const ut=g||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=g||k?"size-4 animate-spin":"size-4";let ue;e[82]!==st?(ue=s.jsx(B,{name:"refresh",className:st}),e[82]=st,e[83]=ue):ue=e[83];let oe;e[84]!==lt||e[85]!==ut||e[86]!==ht||e[87]!==Ue||e[88]!==ue?(oe=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:lt,disabled:ut,"aria-label":ht,title:Ue,children:ue}),e[84]=lt,e[85]=ut,e[86]=ht,e[87]=Ue,e[88]=ue,e[89]=oe):oe=e[89];let Pe;e[90]!==r?(Pe=r("settings.plugins.sidebar.actions.addTitle"),e[90]=r,e[91]=Pe):Pe=e[91];let Re;e[92]!==r?(Re=r("settings.plugins.sidebar.actions.addTitle"),e[92]=r,e[93]=Re):Re=e[93];let Fe;e[94]===Symbol.for("react.memo_cache_sentinel")?(Fe=s.jsx(B,{name:"add",className:"size-4"}),e[94]=Fe):Fe=e[94];let $e;e[95]!==be||e[96]!==Pe||e[97]!==Re?($e=s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:be,"aria-label":Pe,title:Re,children:Fe}),e[95]=be,e[96]=Pe,e[97]=Re,e[98]=$e):$e=e[98];let W;e[99]!==oe||e[100]!==$e?(W=s.jsxs("div",{className:"flex items-center gap-1",children:[oe,$e]}),e[99]=oe,e[100]=$e,e[101]=W):W=e[101];let Ve;e[102]!==pt||e[103]!==W?(Ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[pt,W]}),e[102]=pt,e[103]=W,e[104]=Ve):Ve=e[104];let et;e[105]!==_e||e[106]!==Ve?(et=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[_e,Ve]}),e[105]=_e,e[106]=Ve,e[107]=et):et=e[107];let dt;e[108]!==Ce||e[109]!==O||e[110]!==pe||e[111]!==ne||e[112]!==Ae||e[113]!==Qe||e[114]!==r||e[115]!==V||e[116]!==U||e[117]!==ce?(dt=Ce?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{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:[U.length>0&&Qe(r("settings.plugins.sidebar.group.userEntries"),U.map(ne),V.userEntries),ce.length>0&&Qe(r("settings.plugins.sidebar.group.userFiles"),ce.map(Ae)),O.length>0&&Qe(r("settings.plugins.sidebar.group.projectEntries"),O.map(ne),V.projectEntries),pe.length>0&&Qe(r("settings.plugins.sidebar.group.projectFiles"),pe.map(Ae))]}),e[108]=Ce,e[109]=O,e[110]=pe,e[111]=ne,e[112]=Ae,e[113]=Qe,e[114]=r,e[115]=V,e[116]=U,e[117]=ce,e[118]=dt):dt=e[118];let ct;e[119]!==et||e[120]!==dt?(ct=s.jsx(sd,{variant:"background",header:et,children:dt}),e[119]=et,e[120]=dt,e[121]=ct):ct=e[121];let jt;e[122]!==z?(jt=s.jsx(Hg,{open:z,onOpenChange:_}),e[122]=z,e[123]=jt):jt=e[123];const kt=F!==null;let yt;e[124]!==S?(yt=Se=>{!Se&&!S&&K(null)},e[124]=S,e[125]=yt):yt=e[125];let bt;e[126]!==r?(bt=r("settings.plugins.sidebar.deleteDialog.title"),e[126]=r,e[127]=bt):bt=e[127];let Ze;e[128]!==bt?(Ze=s.jsx($t,{children:bt}),e[128]=bt,e[129]=Ze):Ze=e[129];const wt=F?.label??"";let Le;e[130]!==r||e[131]!==wt?(Le=r("settings.plugins.sidebar.deleteDialog.description",{name:wt}),e[130]=r,e[131]=wt,e[132]=Le):Le=e[132];let He;e[133]!==Le?(He=s.jsx(Bt,{children:Le}),e[133]=Le,e[134]=He):He=e[134];let Y;e[135]!==Ze||e[136]!==He?(Y=s.jsxs(Ut,{children:[Ze,He]}),e[135]=Ze,e[136]=He,e[137]=Y):Y=e[137];let me;e[138]===Symbol.for("react.memo_cache_sentinel")?(me=()=>K(null),e[138]=me):me=e[138];let Ke;e[139]!==r?(Ke=r("settings.common.actions.cancel"),e[139]=r,e[140]=Ke):Ke=e[140];let Ee;e[141]!==S||e[142]!==Ke?(Ee=s.jsx(G,{size:"sm",variant:"ghost",onClick:me,disabled:S,children:Ke}),e[141]=S,e[142]=Ke,e[143]=Ee):Ee=e[143];let Ye;e[144]!==S||e[145]!==r?(Ye=r(S?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[144]=S,e[145]=r,e[146]=Ye):Ye=e[146];let se;e[147]!==ve||e[148]!==S||e[149]!==Ye?(se=s.jsx(G,{size:"sm",variant:"destructive",onClick:ve,disabled:S,children:Ye}),e[147]=ve,e[148]=S,e[149]=Ye,e[150]=se):se=e[150];let ke;e[151]!==Ee||e[152]!==se?(ke=s.jsxs(as,{children:[Ee,se]}),e[151]=Ee,e[152]=se,e[153]=ke):ke=e[153];let at;e[154]!==Y||e[155]!==ke?(at=s.jsxs(zt,{className:"max-w-md",children:[Y,ke]}),e[154]=Y,e[155]=ke,e[156]=at):at=e[156];let Mt;e[157]!==kt||e[158]!==yt||e[159]!==at?(Mt=s.jsx(Kt,{open:kt,onOpenChange:yt,children:at}),e[157]=kt,e[158]=yt,e[159]=at,e[160]=Mt):Mt=e[160];let Wt;return e[161]!==ct||e[162]!==jt||e[163]!==Mt?(Wt=s.jsxs(s.Fragment,{children:[ct,jt,Mt]}),e[161]=ct,e[162]=jt,e[163]=Mt,e[164]=Wt):Wt=e[164],Wt};function nh(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function ah(t){return t.registryInfo}function ih(t){return t.isLoadingRegistry}function rh(t){return t.loadRegistryInfo}function oh(t){return t.updateToLatest}function lh(t){return t.runtime}function ch(t){return t.isCheckingUpdates}function dh(t){return t.checkUpdates}function uh(t){return t.updatePackage}function mh(t){return t.packageUpdates}function ph(t){return t.scope==="user"}function gh(t){return t.scope==="project"}function hh(t){return t.scope==="user"}function fh(t){return t.scope==="project"}function xh(){}const bh=({entryId:t,spec:e})=>{const{t:a}=Xe(),n=Gt(f=>f.registryInfo[e]),r=Gt(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,u=n.currentVersion??"",g=async()=>{l(!0);try{(await r(t)).ok?$.success(a("settings.plugins.toast.updatedToLatest",{version:f})):$.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(B,{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:u,latest:f})})]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{g()},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(B,{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",m=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{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:m})]})]})},wl=t=>{const e=rt.c(68),{target:a,name:n}=t,{t:r}=Xe(),i=ed(a),l=td(a),d=Gt(vh),c=Gt(yh);if(i.kind==="loading")return null;if(i.kind==="unknown"){let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(B,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=P):P=e[0];let C;e[1]!==r?(C=r("settings.plugins.status.unknown.title"),e[1]=r,e[2]=C):C=e[2];let w;e[3]!==C?(w=s.jsx("p",{className:"typography-label text-foreground",children:C}),e[3]=C,e[4]=w):w=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]!==w||e[10]!==x?(A=s.jsxs("div",{className:"flex-1 min-w-0",children:[w,x]}),e[9]=w,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 I;e[14]!==r?(I=r("settings.plugins.status.retry"),e[14]=r,e[15]=I):I=e[15];let E;e[16]!==R||e[17]!==I?(E=s.jsx(G,{variant:"outline",size:"sm",onClick:R,children:I}),e[16]=R,e[17]=I,e[18]=E):E=e[18];let F;return e[19]!==A||e[20]!==E?(F=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]=F):F=e[21],F}const{load:h,update:m}=i,f=i.target.kind==="package"?i.target.target:null,u=m==="updating"||l?.kind==="running";let g;e[22]!==n||e[23]!==f||e[24]!==r||e[25]!==c?(g=async()=>{if(!f)return;await c(f)?$.success(r("settings.plugins.update.toast.done",{name:n})):$.error(r("settings.plugins.update.toast.failed",{name:n}))},e[22]=n,e[23]=f,e[24]=r,e[25]=c,e[26]=g):g=e[26];const v=g;let j;e:{switch(h.kind){case"active":{let P;e[27]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(B,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=P):P=e[27];let C;e[28]!==h.version||e[29]!==r?(C=h.version?r("settings.plugins.status.loadedVersion",{version:h.version}):r("settings.plugins.status.loaded"),e[28]=h.version,e[29]=r,e[30]=C):C=e[30];let w;e[31]!==C?(w=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[P,C]}),e[31]=C,e[32]=w):w=e[32],j=w;break e}case"notReported":{let P;e[33]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(B,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=P):P=e[33];let C;e[34]!==r?(C=r("settings.plugins.status.notReported.title"),e[34]=r,e[35]=C):C=e[35];let w;e[36]!==C?(w=s.jsx("p",{className:"typography-label text-foreground",children:C}),e[36]=C,e[37]=w):w=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]!==w||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:[w,x]})]}),e[42]=w,e[43]=x,e[44]=A):A=e[44],j=A;break e}case"failed":{let P;e[45]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(B,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=P):P=e[45];let C;e[46]!==r?(C=r("settings.plugins.status.failed.title"),e[46]=r,e[47]=C):C=e[47];let w;e[48]!==C?(w=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:C}),e[48]=C,e[49]=w):w=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]!==w||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:[w,D,x]})]}),e[55]=w,e[56]=D,e[57]=x,e[58]=A):A=e[58],j=A;break e}}j=void 0}const b=j,k=f!==null&&(m!=="none"||l!==null);let p;e[59]!==v||e[60]!==u||e[61]!==l||e[62]!==k||e[63]!==r?(p=k?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{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:u,children:u?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}),r("settings.plugins.update.running")]}):r("settings.plugins.update.action")})]}):null,e[59]=v,e[60]=u,e[61]=l,e[62]=k,e[63]=r,e[64]=p):p=e[64];let N;return e[65]!==b||e[66]!==p?(N=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,p]}),e[65]=b,e[66]=p,e[67]=N):N=e[67],N};function vh(t){return t.loadRuntime}function yh(t){return t.updatePackage}function Yi(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 Zi(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function kl(t,e){if(t.trim()===e.trim())return!0;const a=Yi(t),n=Yi(e);return a.ok&&n.ok&&Zi(a.value)===Zi(n.value)}function jh(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Zi(t.options),fileName:"",content:""}}function wh(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Nl=t=>{const e=rt.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},kh=()=>{const t=rt.c(147),{t:e}=Xe(),n=an(Nh)?.trim()||ta(),r=Gt(Sh),i=Gt(Ch),l=r===n&&i===jn(),d=Gt(Ih),c=Gt(Ph),h=Gt(Ah),m=Gt(Th),f=Gt(Eh),u=Gt(Dh),g=Gt(Mh),v=Gt(Rh);let j;t[0]!==c||t[1]!==d?(j=d?c.find(q=>q.id===d)??null:null,t[0]=c,t[1]=d,t[2]=j):j=t[2];const b=j;let k;t[3]!==h||t[4]!==d?(k=d?h.find(q=>q.id===d)??null:null,t[3]=h,t[4]=d,t[5]=k):k=t[5];const p=k;let N;t[6]!==b?(N=b?Qc(b.spec,b.sourcePath):null,t[6]=b,t[7]=N):N=t[7];const P=N;let C;t[8]!==p?(C=p?Yc(p.absolutePath):null,t[8]=p,t[9]=C):C=t[9];const w=C,[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),I=o.useRef(null),E=JSON.stringify([n,d]);let F;t[11]!==l||t[12]!==n||t[13]!==E||t[14]!==v||t[15]!==b||t[16]!==p||t[17]!==f||t[18]!==x?(F=()=>{let q=!1;if(!l){I.current=null,f(null);return}const X=(J,H)=>{if(Gt.getState().selectedId!==J||ta()!==n)return;const L=I.current,V=Gt.getState().draft,Z=L?.id===J&&L.directory===n&&V!==null&&(V.spec!==L.value.spec||!kl(V.optionsJson,L.value.optionsJson)||V.content!==L.value.content);I.current={id:J,directory:n,value:H},Z||f(H)};return b?(X(b.id,jh(b)),()=>{q=!0}):p?(x(I.current?.id!==p.id||I.current.directory!==n),(async()=>{const J=await v(p.id);if(q||ta()!==n)return;x(!1);const H=J?.content??"";R.current.set(E,H),X(p.id,wh(p,H))})(),()=>{q=!0}):(I.current=null,f(null),()=>{q=!0})},t[11]=l,t[12]=n,t[13]=E,t[14]=v,t[15]=b,t[16]=p,t[17]=f,t[18]=x,t[19]=F):F=t[19];let K;t[20]!==l||t[21]!==n||t[22]!==E||t[23]!==v||t[24]!==b||t[25]!==p||t[26]!==f?(K=[b,p,v,f,l,n,E],t[20]=l,t[21]=n,t[22]=E,t[23]=v,t[24]=b,t[25]=p,t[26]=f,t[27]=K):K=t[27],o.useEffect(F,K);let S;t[28]!==l||t[29]!==n||t[30]!==m||t[31]!==E||t[32]!==b||t[33]!==p||t[34]!==e||t[35]!==u||t[36]!==g?(S=async()=>{if(!m||!l||ta()!==n)return Rs;if(b&&m.mode==="entry"){const q=m.spec.trim();if(q===b.spec&&kl(m.optionsJson,Zi(b.options)))return Rs;if(!q)return xs(e("settings.plugins.validation.specRequired"));const J=Yi(m.optionsJson);if(!J.ok)return xs(e("settings.plugins.page.field.options.invalidJson"));const H=await u(b.id,{spec:q,options:J.value});return H.ok?H.reloadFailed?xs(H.warning||H.message||e("settings.plugins.toast.reloadFailed")):In:xs(H.message||e("settings.plugins.toast.reloadFailed"))}if(p&&m.mode==="file"){const q=R.current.get(E)??"";if(m.content===q)return Rs;const X=await g(p.id,{content:m.content});return X.ok?(R.current.set(E,m.content),X.reloadFailed?xs(X.warning||X.message||e("settings.plugins.toast.reloadFailed")):In):xs(X.message||e("settings.plugins.toast.reloadFailed"))}return Rs},t[28]=l,t[29]=n,t[30]=m,t[31]=E,t[32]=b,t[33]=p,t[34]=e,t[35]=u,t[36]=g,t[37]=S):S=t[37];const z=qa(S);if(!d){let q;t[38]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(B,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t[38]=q):q=t[38];let X;t[39]!==e?(X=e("settings.plugins.page.empty.select"),t[39]=e,t[40]=X):X=t[40];let J;t[41]!==X?(J=s.jsx("p",{className:"typography-body",children:X}),t[41]=X,t[42]=J):J=t[42];let H;t[43]!==e?(H=e("settings.plugins.page.empty.add"),t[43]=e,t[44]=H):H=t[44];let L;t[45]!==H?(L=s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:H}),t[45]=H,t[46]=L):L=t[46];let V;return t[47]!==J||t[48]!==L?(V=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[q,J,L]})}),t[47]=J,t[48]=L,t[49]=V):V=t[49],V}if(b&&m&&m.mode==="entry"){let q;t[50]!==m.optionsJson?(q=Yi(m.optionsJson),t[50]=m.optionsJson,t[51]=q):q=t[51];const J=q.ok;let H;t[52]!==e?(H=e("settings.plugins.page.header.entry"),t[52]=e,t[53]=H):H=t[53];let L;t[54]!==b.scope||t[55]!==e?(L=b.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[54]=b.scope,t[55]=e,t[56]=L):L=t[56];let V;t[57]!==b.scope||t[58]!==L?(V=s.jsx(Nl,{scope:b.scope,label:L}),t[57]=b.scope,t[58]=L,t[59]=V):V=t[59];const Z=z.onBlurCapture;let U;t[60]!==b.spec||t[61]!==P?(U=s.jsx(wl,{target:P,name:b.spec}),t[60]=b.spec,t[61]=P,t[62]=U):U=t[62];let te;t[63]!==b.id||t[64]!==b.spec?(te=s.jsx(bh,{entryId:b.id,spec:b.spec}),t[63]=b.id,t[64]=b.spec,t[65]=te):te=t[65];let O;t[66]!==U||t[67]!==te?(O=s.jsx(Ge,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[U,te]})}),t[66]=U,t[67]=te,t[68]=O):O=t[68];let Q;t[69]!==e?(Q=e("settings.plugins.page.field.spec"),t[69]=e,t[70]=Q):Q=t[70];const ce=m.spec;let de;t[71]!==m||t[72]!==f?(de=we=>f({...m,spec:we.target.value}),t[71]=m,t[72]=f,t[73]=de):de=t[73];let pe;t[74]!==e?(pe=e("settings.plugins.page.field.spec.placeholder"),t[74]=e,t[75]=pe):pe=t[75];let re;t[76]!==m.spec||t[77]!==de||t[78]!==pe?(re=s.jsx(We,{value:ce,onChange:de,placeholder:pe,className:"font-mono typography-meta",spellCheck:!1}),t[76]=m.spec,t[77]=de,t[78]=pe,t[79]=re):re=t[79];let Ce;t[80]!==Q||t[81]!==re?(Ce=s.jsx(Ge,{title:Q,settingsItem:"plugins.spec",children:re}),t[80]=Q,t[81]=re,t[82]=Ce):Ce=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=m.optionsJson;let ae;t[85]!==m||t[86]!==f?(ae=we=>f({...m,optionsJson:we.target.value}),t[85]=m,t[86]=f,t[87]=ae):ae=t[87];const fe=!J&&"border-[var(--status-error-border)]";let xe;t[88]!==fe?(xe=Ie("font-mono typography-meta min-h-[200px]",fe),t[88]=fe,t[89]=xe):xe=t[89];let Oe;t[90]!==m.optionsJson||t[91]!==ae||t[92]!==xe?(Oe=s.jsx(As,{value:be,onChange:ae,rows:10,className:xe,spellCheck:!1,placeholder:"{ }"}),t[90]=m.optionsJson,t[91]=ae,t[92]=xe,t[93]=Oe):Oe=t[93];let Ne;t[94]!==J||t[95]!==e?(Ne=!J&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[94]=J,t[95]=e,t[96]=Ne):Ne=t[96];let he;t[97]!==ie||t[98]!==Oe||t[99]!==Ne?(he=s.jsxs(Ge,{title:ie,settingsItem:"plugins.options",children:[Oe,Ne]}),t[97]=ie,t[98]=Oe,t[99]=Ne,t[100]=he):he=t[100];let Te;return t[101]!==z.onBlurCapture||t[102]!==V||t[103]!==O||t[104]!==Ce||t[105]!==he||t[106]!==H?(Te=s.jsxs(ns,{title:H,titleAccessory:V,onBlurCapture:Z,children:[O,Ce,he]}),t[101]=z.onBlurCapture,t[102]=V,t[103]=O,t[104]=Ce,t[105]=he,t[106]=H,t[107]=Te):Te=t[107],Te}if(p&&m&&m.mode==="file"){let q;t[108]!==e?(q=e("settings.plugins.page.header.file"),t[108]=e,t[109]=q):q=t[109];let X;t[110]!==p.scope||t[111]!==e?(X=p.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[110]=p.scope,t[111]=e,t[112]=X):X=t[112];let J;t[113]!==p.scope||t[114]!==X?(J=s.jsx(Nl,{scope:p.scope,label:X}),t[113]=p.scope,t[114]=X,t[115]=J):J=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 L;t[117]!==p.fileName?(L=s.jsx("span",{className:H,children:p.fileName}),t[117]=p.fileName,t[118]=L):L=t[118];let V;t[119]!==J||t[120]!==L?(V=s.jsxs(s.Fragment,{children:[J,L]}),t[119]=J,t[120]=L,t[121]=V):V=t[121];const Z=z.onBlurCapture;let U;t[122]!==p.fileName||t[123]!==w?(U=s.jsx(Ge,{divider:!1,children:s.jsx(wl,{target:w,name:p.fileName})}),t[122]=p.fileName,t[123]=w,t[124]=U):U=t[124];let te;t[125]!==e?(te=e("settings.plugins.page.field.content"),t[125]=e,t[126]=te):te=t[126];let O;t[127]!==m||t[128]!==f?(O=re=>f({...m,content:re.target.value}),t[127]=m,t[128]=f,t[129]=O):O=t[129];let Q;t[130]!==z?(Q=re=>{re.key==="Enter"&&(re.metaKey||re.ctrlKey)&&(re.preventDefault(),z.requestSave())},t[130]=z,t[131]=Q):Q=t[131];let ce;t[132]!==m.content||t[133]!==D||t[134]!==O||t[135]!==Q?(ce=s.jsx(As,{value:m.content,onChange:O,onKeyDown:Q,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:D}),t[132]=m.content,t[133]=D,t[134]=O,t[135]=Q,t[136]=ce):ce=t[136];let de;t[137]!==te||t[138]!==ce?(de=s.jsx(Ge,{title:te,settingsItem:"plugins.content",children:ce}),t[137]=te,t[138]=ce,t[139]=de):de=t[139];let pe;return t[140]!==z.onBlurCapture||t[141]!==V||t[142]!==U||t[143]!==de||t[144]!==q?(pe=s.jsxs(ns,{title:q,titleAccessory:V,onBlurCapture:Z,children:[U,de]}),t[140]=z.onBlurCapture,t[141]=V,t[142]=U,t[143]=de,t[144]=q,t[145]=pe):pe=t[145],pe}let _;return t[146]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(B,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[146]=_):_=t[146],_};function Nh(t){return t.getActiveProject()?.path}function Sh(t){return t.loadedDirectory}function Ch(t){return t.loadedRuntimeKey}function Ih(t){return t.selectedId}function Ph(t){return t.entries}function Ah(t){return t.files}function Th(t){return t.draft}function Eh(t){return t.setDraft}function Dh(t){return t.updateEntry}function Mh(t){return t.updateFile}function Rh(t){return t.readFile}const Fh="<built-in>",li=t=>t?.path===Fh,ro=t=>!!t&&!li(t)&&t.renamable===!0,Oh=t=>{const e=rt.c(157),{onItemSelect:a}=t,{t:n}=Xe(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[m,f]=o.useState(!1),[u,g]=o.useState(null),{selectedSkillName:v,setSelectedSkill:j,setSkillDraft:b,deleteSkill:k,renameSkill:p,getSkillDetail:N}=sn(Us(Lh)),P=Ws();let C;e[0]!==P?(C=Le=>go(Le,P),e[0]=P,e[1]=C):C=e[1];const w=sn(C),D=sn(Kh);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]!==j||e[8]!==b||e[9]!==w?(R=()=>{let Le="new-skill",He=1;for(;w.some(Y=>Y.name===Le);)Le=`new-skill-${He}`,He++;b({name:Le,scope:"user",source:"opencode",description:""}),j(Le),a?.()},e[6]=a,e[7]=j,e[8]=b,e[9]=w,e[10]=R):R=e[10];const I=R;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=async Le=>{li(Le)||h(Le)},e[11]=E):E=e[11];const F=E;let K;e[12]!==c||e[13]!==k||e[14]!==P||e[15]!==n?(K=async()=>{if(!c)return;if(li(c)){h(null);return}f(!0),await k(c.name,P)?($.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),h(null)):$.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),f(!1)},e[12]=c,e[13]=k,e[14]=P,e[15]=n,e[16]=K):K=e[16];const S=K;let M;e[17]!==N||e[18]!==j||e[19]!==b||e[20]!==P||e[21]!==w||e[22]!==n?(M=async Le=>{if(li(Le))return;const He=Le.name;let Y=1,me=`${He}-copy`;for(;w.some(Ee=>Ee.name===me);)Y++,me=`${He}-copy-${Y}`;const Ke=await N(Le.name,P);if(!Ke){$.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:me,scope:Le.scope||"user",source:Le.source||"opencode",description:(Ke.sources.md.fields.includes("description"),""),instructions:""}),j(me)},e[17]=N,e[18]=j,e[19]=b,e[20]=P,e[21]=w,e[22]=n,e[23]=M):M=e[23];const z=M;let _;e[24]===Symbol.for("react.memo_cache_sentinel")?(_=Le=>{ro(Le)&&(d(Le.name),i(Le))},e[24]=_):_=e[24];const q=_;let X;e[25]!==r||e[26]!==l||e[27]!==p||e[28]!==j||e[29]!==P||e[30]!==w||e[31]!==n?(X=async()=>{if(!r)return;if(!ro(r)){i(null);return}const Le=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Le){$.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Le===r.name){i(null);return}if(w.some(Y=>Y.name===Le)){$.error(n("settings.skills.page.toast.skillExists"));return}await p(r.name,Le,P)?($.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Le})),j(Le)):$.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=p,e[28]=j,e[29]=P,e[30]=w,e[31]=n,e[32]=X):X=e[32];const J=X;let H;e[33]!==w?(H=w.filter(zh),e[33]=w,e[34]=H):H=e[34];const L=H;let V;e[35]!==w?(V=w.filter(_h),e[35]=w,e[36]=V):V=e[36];const Z=V;let U;e[37]===Symbol.for("react.memo_cache_sentinel")?(U=function(He){const Y={},me=[];for(const Ee of He)Ee.group?(Y[Ee.group]||(Y[Ee.group]=[]),Y[Ee.group].push(Ee)):me.push(Ee);const Ke=Object.keys(Y).sort(Uh).map(Ee=>({name:Ee,skills:[...Y[Ee]].sort($h)}));return me.sort(Bh),{sortedGroups:Ke,ungrouped:me}},e[37]=U):U=e[37];const te=U;let O;e[38]!==L?(O=te(L),e[38]=L,e[39]=O):O=e[39];const Q=O;let ce;e[40]!==Z?(ce=te(Z),e[40]=Z,e[41]=ce):ce=e[41];const de=ce;let pe;e[42]===Symbol.for("react.memo_cache_sentinel")?(pe=Ie("flex h-full flex-col","bg-background"),e[42]=pe):pe=e[42];let re;e[43]!==n?(re=n("settings.skills.sidebar.title"),e[43]=n,e[44]=re):re=e[44];let Ce;e[45]!==re?(Ce=s.jsx("h2",{className:`${Pn} mb-3`,children:re}),e[45]=re,e[46]=Ce):Ce=e[46];let ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(fi,{className:"mb-3"}),e[47]=ie):ie=e[47];let be;e[48]!==w.length||e[49]!==n?(be=n("settings.skills.sidebar.total",{count:w.length}),e[48]=w.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 fe;e[53]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[53]=fe):fe=e[53];let xe;e[54]!==I?(xe=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:I,children:fe}),e[54]=I,e[55]=xe):xe=e[55];let Oe;e[56]!==ae||e[57]!==xe?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ae,xe]}),e[56]=ae,e[57]=xe,e[58]=Oe):Oe=e[58];let Ne;e[59]!==Ce||e[60]!==Oe?(Ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ce,ie,Oe]}),e[59]=Ce,e[60]=Oe,e[61]=Ne):Ne=e[61];let he;e[62]!==Q||e[63]!==de||e[64]!==z||e[65]!==a||e[66]!==u||e[67]!==L||e[68]!==v||e[69]!==j||e[70]!==w.length||e[71]!==n||e[72]!==Z?(he=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{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:[L.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")}),Q.sortedGroups.map(Le=>{const{name:He,skills:Y}=Le;return s.jsx(no,{label:He,count:Y.length,storageKey:"project-skills",children:Y.map(me=>s.jsx(Oi,{skill:me,isSelected:v===me.name,onSelect:()=>{j(me.name),a?.()},onRename:()=>q(me),onDelete:()=>F(me),onDuplicate:()=>z(me),isMenuOpen:u===me.name,onMenuOpenChange:Ke=>g(Ke?me.name:null)},me.name))},He)}),Q.ungrouped.map(Le=>s.jsx(Oi,{skill:Le,isSelected:v===Le.name,onSelect:()=>{j(Le.name),a?.()},onRename:()=>q(Le),onDelete:()=>F(Le),onDuplicate:()=>z(Le),isMenuOpen:u===Le.name,onMenuOpenChange:He=>g(He?Le.name:null)},Le.name))]}),Z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Le=>{const{name:He,skills:Y}=Le;return s.jsx(no,{label:He,count:Y.length,storageKey:"user-skills",children:Y.map(me=>s.jsx(Oi,{skill:me,isSelected:v===me.name,onSelect:()=>{j(me.name),a?.()},onRename:()=>q(me),onDelete:()=>F(me),onDuplicate:()=>z(me),isMenuOpen:u===me.name,onMenuOpenChange:Ke=>g(Ke?me.name:null)},me.name))},He)}),de.ungrouped.map(Le=>s.jsx(Oi,{skill:Le,isSelected:v===Le.name,onSelect:()=>{j(Le.name),a?.()},onRename:()=>q(Le),onDelete:()=>F(Le),onDuplicate:()=>z(Le),isMenuOpen:u===Le.name,onMenuOpenChange:He=>g(He?Le.name:null)},Le.name))]})]})}),e[62]=Q,e[63]=de,e[64]=z,e[65]=a,e[66]=u,e[67]=L,e[68]=v,e[69]=j,e[70]=w.length,e[71]=n,e[72]=Z,e[73]=he):he=e[73];const Te=c!==null;let we;e[74]!==m?(we=Le=>{!Le&&!m&&h(null)},e[74]=m,e[75]=we):we=e[75];let De;e[76]!==n?(De=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=De):De=e[77];let ve;e[78]!==De?(ve=s.jsx($t,{children:De}),e[78]=De,e[79]=ve):ve=e[79];const ee=c?.name??"";let ne;e[80]!==n||e[81]!==ee?(ne=n("settings.skills.sidebar.deleteDialog.description",{name:ee}),e[80]=n,e[81]=ee,e[82]=ne):ne=e[82];let ye;e[83]!==ne?(ye=s.jsx(Bt,{children:ne}),e[83]=ne,e[84]=ye):ye=e[84];let Ae;e[85]!==ve||e[86]!==ye?(Ae=s.jsxs(Ut,{children:[ve,ye]}),e[85]=ve,e[86]=ye,e[87]=Ae):Ae=e[87];let ze;e[88]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>h(null),e[88]=ze):ze=e[88];let Qe;e[89]!==n?(Qe=n("settings.common.actions.cancel"),e[89]=n,e[90]=Qe):Qe=e[90];let Be;e[91]!==m||e[92]!==Qe?(Be=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ze,disabled:m,children:Qe}),e[91]=m,e[92]=Qe,e[93]=Be):Be=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]!==S||e[97]!==m||e[98]!==_e?(Me=s.jsx(G,{size:"sm",onClick:S,disabled:m,children:_e}),e[96]=S,e[97]=m,e[98]=_e,e[99]=Me):Me=e[99];let nt;e[100]!==Be||e[101]!==Me?(nt=s.jsxs(as,{children:[Be,Me]}),e[100]=Be,e[101]=Me,e[102]=nt):nt=e[102];let pt;e[103]!==Ae||e[104]!==nt?(pt=s.jsxs(zt,{className:"max-w-md",children:[Ae,nt]}),e[103]=Ae,e[104]=nt,e[105]=pt):pt=e[105];let lt;e[106]!==Te||e[107]!==we||e[108]!==pt?(lt=s.jsx(Kt,{open:Te,onOpenChange:we,children:pt}),e[106]=Te,e[107]=we,e[108]=pt,e[109]=lt):lt=e[109];const ut=r!==null;let ht;e[110]===Symbol.for("react.memo_cache_sentinel")?(ht=Le=>!Le&&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($t,{children:Ue}),e[113]=Ue,e[114]=st):st=e[114];const ue=r?.name??"";let oe;e[115]!==n||e[116]!==ue?(oe=n("settings.skills.sidebar.renameDialog.description",{name:ue}),e[115]=n,e[116]=ue,e[117]=oe):oe=e[117];let Pe;e[118]!==oe?(Pe=s.jsx(Bt,{children:oe}),e[118]=oe,e[119]=Pe):Pe=e[119];let Re;e[120]!==st||e[121]!==Pe?(Re=s.jsxs(Ut,{children:[st,Pe]}),e[120]=st,e[121]=Pe,e[122]=Re):Re=e[122];let Fe;e[123]===Symbol.for("react.memo_cache_sentinel")?(Fe=Le=>d(Le.target.value),e[123]=Fe):Fe=e[123];let $e;e[124]!==n?($e=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=$e):$e=e[125];let W;e[126]!==J?(W=Le=>{Le.key==="Enter"&&J()},e[126]=J,e[127]=W):W=e[127];let Ve;e[128]!==l||e[129]!==$e||e[130]!==W?(Ve=s.jsx(We,{value:l,onChange:Fe,placeholder:$e,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:W}),e[128]=l,e[129]=$e,e[130]=W,e[131]=Ve):Ve=e[131];let et;e[132]===Symbol.for("react.memo_cache_sentinel")?(et=()=>i(null),e[132]=et):et=e[132];let dt;e[133]!==n?(dt=n("settings.common.actions.cancel"),e[133]=n,e[134]=dt):dt=e[134];let ct;e[135]!==dt?(ct=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:et,children:dt}),e[135]=dt,e[136]=ct):ct=e[136];let jt;e[137]!==n?(jt=n("settings.common.actions.rename"),e[137]=n,e[138]=jt):jt=e[138];let kt;e[139]!==J||e[140]!==jt?(kt=s.jsx(G,{size:"sm",onClick:J,children:jt}),e[139]=J,e[140]=jt,e[141]=kt):kt=e[141];let yt;e[142]!==ct||e[143]!==kt?(yt=s.jsxs(as,{children:[ct,kt]}),e[142]=ct,e[143]=kt,e[144]=yt):yt=e[144];let bt;e[145]!==Re||e[146]!==Ve||e[147]!==yt?(bt=s.jsxs(zt,{children:[Re,Ve,yt]}),e[145]=Re,e[146]=Ve,e[147]=yt,e[148]=bt):bt=e[148];let Ze;e[149]!==ut||e[150]!==bt?(Ze=s.jsx(Kt,{open:ut,onOpenChange:ht,children:bt}),e[149]=ut,e[150]=bt,e[151]=Ze):Ze=e[151];let wt;return e[152]!==Ne||e[153]!==he||e[154]!==lt||e[155]!==Ze?(wt=s.jsxs("div",{className:pe,children:[Ne,he,lt,Ze]}),e[152]=Ne,e[153]=he,e[154]=lt,e[155]=Ze,e[156]=wt):wt=e[156],wt},Oi=t=>{const e=rt.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:h}=t,{t:m}=Xe();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=di(),e[0]=f):f=e[0];const u=f;let g;e[1]!==a?(g=li(a),e[1]=a,e[2]=g):g=e[2];const v=g;let j;e[3]!==a?(j=ro(a),e[3]=a,e[4]=j):j=e[4];const b=j,[k,p]=o.useState(!1);let N;e[5]!==b||e[6]!==i||e[7]!==d||e[8]!==l||e[9]!==m?(N=z=>s.jsxs(s.Fragment,{children:[b?s.jsxs(z,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}):null,s.jsxs(z,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(z,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[5]=b,e[6]=i,e[7]=d,e[8]=l,e[9]=m,e[10]=N):N=e[10];const P=N,C=!v&&k,w=n?"bg-interactive-selection":"hover:bg-interactive-hover";let D;e[11]!==w?(D=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",w),e[11]=w,e[12]=D):D=e[12];let x;e[13]!==v?(x=!u&&!v?z=>{z.preventDefault(),p(!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 I;e[20]!==r||e[21]!==R?(I=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]=I):I=e[22];let E;e[23]!==v||e[24]!==c||e[25]!==h||e[26]!==P?(E=v?null:s.jsxs(_n,{open:c,onOpenChange:z=>{z&&p(!1),h(z)},children:[s.jsx(zn,{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(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Kn,{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 F;e[28]!==I||e[29]!==E?(F=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,E]}),e[28]=I,e[29]=E,e[30]=F):F=e[30];let K;e[31]!==F||e[32]!==A?(K=s.jsx(pa,{render:A,children:F}),e[31]=F,e[32]=A,e[33]=K):K=e[33];let S;e[34]!==v||e[35]!==P?(S=v?null:s.jsx(ua,{className:"w-fit min-w-20",children:P(ma)}),e[34]=v,e[35]=P,e[36]=S):S=e[36];let M;return e[37]!==K||e[38]!==S||e[39]!==C?(M=s.jsxs(ga,{open:C,onOpenChange:p,children:[K,S]}),e[37]=K,e[38]=S,e[39]=C,e[40]=M):M=e[40],M};function Lh(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Kh(t){return t.loadSkills}function zh(t){return t.scope==="project"}function _h(t){return t.scope==="user"}function Uh(t,e){return t.localeCompare(e)}function $h(t,e){return t.name.localeCompare(e.name)}function Bh(t,e){return t.name.localeCompare(e.name)}const Vh=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Hh=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},qh=({open:t,onOpenChange:e})=>{const{t:a}=Xe(),n=Fn(S=>S.scanRepo),r=Fn(S=>S.loadCatalog),i=Fn(S=>S.loadSource),l=Fn(S=>S.setSelectedSource),d=Fn(S=>S.isScanning),c=ra(S=>S.defaultGitIdentityId),h=ra(S=>S.loadDefaultGitIdentityId),[m,f]=o.useState(""),[u,g]=o.useState(""),[v,j]=o.useState(""),[b,k]=o.useState(null),[p,N]=o.useState(null),[P,C]=o.useState(!1),[w,D]=o.useState([]),[x,A]=o.useState(null),R=o.useRef(0),I=o.useCallback(S=>{R.current+=1,C(!1),N(null),S?.clearIdentity&&(D([]),A(null))},[]);o.useEffect(()=>{t&&(R.current+=1,f(""),g(""),j(""),N(null),C(!1),D([]),A(null),h(),k(null),(async()=>{const S=await An();k(S?S.skillCatalogs??[]:null)})())},[t,h]);const E=o.useMemo(()=>{const S=u.trim(),M=v.trim();return(b??[]).some(z=>{const _=(z.source||"").trim(),q=(z.subpath||"").trim();return _===S&&q===M})},[b,u,v]),F=async()=>{const S=u.trim();if(!S){$.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||f(Hh(S)),C(!1),N(null);const M=R.current+1;R.current=M;const z=await n({source:S,subpath:v.trim()||void 0,gitIdentityId:x||void 0});if(R.current!==M)return;if(!z.ok){if(z.error?.kind==="authRequired"){if(cs()){$.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const q=z.error.identities||[];if(D(q),!x&&q.length>0){const X=c&&c!=="global"&&q.some(J=>J.id===c)?c:q[0].id;A(X)}$.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}$.error(z.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const _=z.items?.length||0;if(N(_),_===0){$.error(a("settings.skills.catalog.add.toast.noSkillsFound")),C(!1);return}D([]),C(!0),$.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:_}))},K=async()=>{const S=m.trim(),M=u.trim(),z=v.trim();if(!S){$.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!M){$.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!P){$.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(E){$.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const _={id:Vh(),label:S,source:M,...z?{subpath:z}:{},...x?{gitIdentityId:x}:{}};if(b===null){$.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const q=[...b,_];try{if(!(await ft({skillCatalogs:q})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(q),$.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(_.id,{refresh:!0}),l(_.id),e(!1)}catch(X){$.error(X instanceof Error?X.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Bt,{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:m,onChange:S=>f(S.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(Ht,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(We,{value:u,onChange:S=>{g(S.target.value),I({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:S=>{j(S.target.value),I({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),w.length>0&&!cs()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children: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(Ht,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Et,{value:x||"",onValueChange:S=>{A(S),I()},children:[s.jsx(At,{className:"w-fit",children:s.jsx("span",{children:w.find(S=>S.id===x)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Tt,{align:"start",children:w.map(S=>s.jsx(mt,{value:S.id,children:S.name},S.id))})]})]}):null,p!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:p})}):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:()=>{F()},disabled:d||!u.trim(),children:[s.jsx(B,{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:()=>{K()},disabled:!P||E||b===null||!m.trim()||!u.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},Gh=t=>{const e=rt.c(85),{open:a,onOpenChange:n,conflicts:r,onConfirm:i}=t,{t:l}=Xe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,h]=o.useState(d);let m,f;e[1]!==r||e[2]!==a?(m=()=>{if(!a)return;const O={};for(const Q of r)O[Q.skillName]="skip";h(O)},f=[a,r],e[1]=r,e[2]=a,e[3]=m,e[4]=f):(m=e[3],f=e[4]),o.useEffect(m,f);let u;e[5]!==r?(u=O=>{const Q={};for(const ce of r)Q[ce.skillName]=O;h(Q)},e[5]=r,e[6]=u):u=e[6];const g=u;let v;e[7]!==r||e[8]!==c?(v=r.length>0&&r.every(O=>c[O.skillName]),e[7]=r,e[8]=c,e[9]=v):v=e[9];const j=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($t,{children:b}),e[12]=b,e[13]=k):k=e[13];let p;e[14]!==l?(p=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=p):p=e[15];let N;e[16]!==p?(N=s.jsx(Bt,{children:p}),e[16]=p,e[17]=N):N=e[17];let P;e[18]!==k||e[19]!==N?(P=s.jsxs(Ut,{children:[k,N]}),e[18]=k,e[19]=N,e[20]=P):P=e[20];let C;e[21]!==r.length||e[22]!==l?(C=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=C):C=e[23];let w;e[24]!==C?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[24]=C,e[25]=w):w=e[25];let D;e[26]!==g?(D=()=>g("skip"),e[26]=g,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]!==g?(R=()=>g("overwrite"),e[33]=g,e[34]=R):R=e[34];let I;e[35]!==l?(I=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=I):I=e[36];let E;e[37]!==R||e[38]!==I?(E=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:R,children:I}),e[37]=R,e[38]=I,e[39]=E):E=e[39];let F;e[40]!==A||e[41]!==E?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[A,E]}),e[40]=A,e[41]=E,e[42]=F):F=e[42];let K;e[43]!==w||e[44]!==F?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,F]}),e[43]=w,e[44]=F,e[45]=K):K=e[45];let S;if(e[46]!==r||e[47]!==c||e[48]!==l){let O;e[50]!==c||e[51]!==l?(O=Q=>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:Q.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:Q.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:Q.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Et,{value:c[Q.skillName]||"skip",onValueChange:ce=>h(de=>({...de,[Q.skillName]:ce})),children:[s.jsx(At,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[Q.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Tt,{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")})]})]})]},Q.skillName),e[50]=c,e[51]=l,e[52]=O):O=e[52],S=r.map(O),e[46]=r,e[47]=c,e[48]=l,e[49]=S}else S=e[49];let M;e[53]!==S?(M=s.jsx("div",{className:"space-y-2",children:S}),e[53]=S,e[54]=M):M=e[54];let z;e[55]!==K||e[56]!==M?(z=s.jsxs("div",{className:"space-y-3",children:[K,M]}),e[55]=K,e[56]=M,e[57]=z):z=e[57];let _;e[58]!==n?(_=()=>n(!1),e[58]=n,e[59]=_):_=e[59];let q;e[60]!==l?(q=l("settings.common.actions.cancel"),e[60]=l,e[61]=q):q=e[61];let X;e[62]!==_||e[63]!==q?(X=s.jsx(G,{size:"sm",variant:"ghost",onClick:_,children:q}),e[62]=_,e[63]=q,e[64]=X):X=e[64];let J;e[65]!==c||e[66]!==i?(J=()=>i(c),e[65]=c,e[66]=i,e[67]=J):J=e[67];const H=!j;let L;e[68]!==l?(L=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=L):L=e[69];let V;e[70]!==J||e[71]!==H||e[72]!==L?(V=s.jsx(G,{size:"sm",onClick:J,disabled:H,children:L}),e[70]=J,e[71]=H,e[72]=L,e[73]=V):V=e[73];let Z;e[74]!==X||e[75]!==V?(Z=s.jsxs(as,{children:[X,V]}),e[74]=X,e[75]=V,e[76]=Z):Z=e[76];let U;e[77]!==P||e[78]!==z||e[79]!==Z?(U=s.jsxs(zt,{className:"max-w-2xl",children:[P,z,Z]}),e[77]=P,e[78]=z,e[79]=Z,e[80]=U):U=e[80];let te;return e[81]!==n||e[82]!==a||e[83]!==U?(te=s.jsx(Kt,{open:a,onOpenChange:n,children:U}),e[81]=n,e[82]=a,e[83]=U,e[84]=te):te=e[84],te},Po=[{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 ci(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 nd(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Po.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const Wh=t=>{const e=rt.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=Xe(),l=Fn(Jh),d=Fn(Qh),[c,h]=o.useState("user"),[m,f]=o.useState("opencode"),u=an(Yh),g=an(Zh),[v,j]=o.useState(null),[b,k]=o.useState(!1);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=[],e[0]=p):p=e[0];const[N,P]=o.useState(p),[C,w]=o.useState(null);let D,x;e[1]!==g||e[2]!==a?(D=()=>{a&&(h("user"),f("opencode"),j(g),k(!1),P([]),w(null))},x=[a,g],e[1]=g,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 I;e[7]!==i?(I=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]=I):I=e[8];const E=I;let F;e:{if(u.length===0){F=null;break e}if(v&&u.some(Me=>Me.id===v)){F=v;break e}if(g&&u.some(Me=>Me.id===g)){F=g;break e}F=u[0]?.id??null}const K=F;let S;e:{if(c!=="project"){S=null;break e}const Me=K;if(!Me){S=null;break e}let nt;if(e[9]!==Me||e[10]!==u){let lt;e[12]!==Me?(lt=ut=>ut.id===Me,e[12]=Me,e[13]=lt):lt=e[13],nt=u.find(lt),e[9]=Me,e[10]=u,e[11]=nt}else nt=e[11];S=nt?.path??null}const M=S;let z;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(z=async Me=>{const nt=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(nt.ok){$.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(nt.error?.kind==="conflicts"){w({source:Me.source,subpath:Me.subpath,scope:Me.scope,targetSource:Me.targetSource,skillDir:Me.skillDir,directoryOverride:Me.directoryOverride??null}),P(nt.error.conflicts),k(!0);return}if(nt.error?.kind==="authRequired"){$.error(nt.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}$.error(nt.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r?.gitIdentityId,e[16]=n,e[17]=i,e[18]=z):z=e[18];const _=z;if(!r)return null;let q;e[19]!==i?(q=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=q):q=e[20];let X;e[21]!==q?(X=s.jsx($t,{children:q}),e[21]=q,e[22]=X):X=e[22];let J;e[23]!==i?(J=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=J):J=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 L;e[27]!==i?(L=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=L):L=e[28];let V;e[29]!==J||e[30]!==H||e[31]!==L?(V=s.jsxs(Bt,{children:[J," ",H," ",L]}),e[29]=J,e[30]=H,e[31]=L,e[32]=V):V=e[32];let Z;e[33]!==X||e[34]!==V?(Z=s.jsxs(Ut,{children:[X,V]}),e[33]=X,e[34]=V,e[35]=Z):Z=e[35];let U;e[36]!==i?(U=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=U):U=e[37];let te;e[38]!==U?(te=s.jsx("span",{className:"typography-ui-label text-foreground",children:U}),e[38]=U,e[39]=te):te=e[39];let O;e[40]!==c||e[41]!==m?(O=ci(c,m),e[40]=c,e[41]=m,e[42]=O):O=e[42];let Q;e[43]===Symbol.for("react.memo_cache_sentinel")?(Q=Me=>{const nt=nd(Me);h(nt.scope),f(nt.source==="agents"?"agents":"opencode")},e[43]=Q):Q=e[43];let ce;e[44]!==c?(ce=c==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=ce):ce=e[45];let de;e[46]!==m?(de=m==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=de):de=e[47];let pe;e[48]!==R||e[49]!==c||e[50]!==m?(pe=R(ci(c,m)),e[48]=R,e[49]=c,e[50]=m,e[51]=pe):pe=e[51];let re;e[52]!==pe?(re=s.jsx("span",{children:pe}),e[52]=pe,e[53]=re):re=e[53];let Ce;e[54]!==ce||e[55]!==de||e[56]!==re?(Ce=s.jsxs(At,{className:"w-fit gap-1.5",children:[ce,de,re]}),e[54]=ce,e[55]=de,e[56]=re,e[57]=Ce):Ce=e[57];let ie;e[58]!==E||e[59]!==R?(ie=Po.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(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),Me.source==="agents"?s.jsx(B,{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(Tt,{align:"start",children:ie}),e[61]=ie,e[62]=be):be=e[62];let ae;e[63]!==O||e[64]!==Ce||e[65]!==be?(ae=s.jsxs(Et,{value:O,onValueChange:Q,children:[Ce,be]}),e[63]=O,e[64]=Ce,e[65]=be,e[66]=ae):ae=e[66];let fe;e[67]!==te||e[68]!==ae?(fe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[te,ae]}),e[67]=te,e[68]=ae,e[69]=fe):fe=e[69];let xe;e[70]!==u||e[71]!==K||e[72]!==c||e[73]!==i?(xe=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")}),u.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Et,{value:K??"",onValueChange:Me=>j(Me),disabled:u.length===1,children:[s.jsx(At,{className:"w-fit",children:s.jsx(_t,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Tt,{align:"start",children:u.map(Xh)})]})]}),e[70]=u,e[71]=K,e[72]=c,e[73]=i,e[74]=xe):xe=e[74];let Oe;e[75]!==r.warnings?(Oe=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]=Oe):Oe=e[76];let Ne;e[77]!==fe||e[78]!==xe||e[79]!==Oe?(Ne=s.jsxs("div",{className:"mt-2 space-y-3",children:[fe,xe,Oe]}),e[77]=fe,e[78]=xe,e[79]=Oe,e[80]=Ne):Ne=e[80];let he;e[81]!==n?(he=()=>n(!1),e[81]=n,e[82]=he):he=e[82];let Te;e[83]!==i?(Te=i("settings.common.actions.cancel"),e[83]=i,e[84]=Te):Te=e[84];let we;e[85]!==he||e[86]!==Te?(we=s.jsx(G,{size:"sm",variant:"ghost",onClick:he,children:Te}),e[85]=he,e[86]=Te,e[87]=we):we=e[87];const De=d||!r.installable||c==="project"&&!M;let ve;e[88]!==M||e[89]!==_||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(ve=()=>{_({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:M})},e[88]=M,e[89]=_,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=ve):ve=e[95];let ee;e[96]!==d||e[97]!==i?(ee=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=ee):ee=e[98];let ne;e[99]!==De||e[100]!==ve||e[101]!==ee?(ne=s.jsx(G,{size:"sm",disabled:De,onClick:ve,children:ee}),e[99]=De,e[100]=ve,e[101]=ee,e[102]=ne):ne=e[102];let ye;e[103]!==we||e[104]!==ne?(ye=s.jsxs(as,{children:[we,ne]}),e[103]=we,e[104]=ne,e[105]=ye):ye=e[105];let Ae;e[106]!==Z||e[107]!==Ne||e[108]!==ye?(Ae=s.jsxs(zt,{className:"max-w-md",children:[Z,Ne,ye]}),e[106]=Z,e[107]=Ne,e[108]=ye,e[109]=Ae):Ae=e[109];let ze;e[110]!==n||e[111]!==a||e[112]!==Ae?(ze=s.jsx(Kt,{open:a,onOpenChange:n,children:Ae}),e[110]=n,e[111]=a,e[112]=Ae,e[113]=ze):ze=e[113];let Qe;e[114]!==C||e[115]!==_?(Qe=Me=>{C&&(_({source:C.source,subpath:C.subpath,scope:C.scope,targetSource:C.targetSource,skillDir:C.skillDir,conflictDecisions:Me,directoryOverride:C.directoryOverride??null}),k(!1))},e[114]=C,e[115]=_,e[116]=Qe):Qe=e[116];let Be;e[117]!==N||e[118]!==b||e[119]!==Qe?(Be=s.jsx(Gh,{open:b,onOpenChange:k,conflicts:N,onConfirm:Qe}),e[117]=N,e[118]=b,e[119]=Qe,e[120]=Be):Be=e[120];let _e;return e[121]!==ze||e[122]!==Be?(_e=s.jsxs(s.Fragment,{children:[ze,Be]}),e[121]=ze,e[122]=Be,e[123]=_e):_e=e[123],_e};function Jh(t){return t.installSkills}function Qh(t){return t.isInstalling}function Yh(t){return t.projects}function Zh(t){return t.activeProjectId}function Xh(t){return s.jsx(mt,{value:t.id,children:t.label||t.path},t.id)}const ef=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,tf=t=>{const e=t.trim();return ef.test(e)?`https://github.com/${e}`:null},sf=t=>{const e=tf(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Li=null;const nf=t=>{const e=vo();return(!Li||Li.locale!==e)&&(Li={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Li.formatter.format(t)},af=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)}},rf=t=>{const e=rt.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:d}=t,c=a.stars??null;let h,m,f,u,g,v,j,b,k,p;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 w=a.repoUpdatedAt?af(a.repoUpdatedAt):null;b="button",k=l,p=n;const D=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==D?(m=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]=m):m=e[20],g="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(B,{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?(j=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]=j):j=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(B,{name:"star",className:"h-3 w-3"}),nf(c)]}),e[32]=c,e[33]=d,e[34]=f):f=e[34],u=w&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:w.key==="common.relative.justNow"?d(w.key):d("settings.skills.catalog.page.source.updated",{time:d(w.key,{count:w.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]=m,e[11]=f,e[12]=u,e[13]=g,e[14]=v,e[15]=j,e[16]=b,e[17]=k,e[18]=p}else h=e[9],m=e[10],f=e[11],u=e[12],g=e[13],v=e[14],j=e[15],b=e[16],k=e[17],p=e[18];let N;e[35]!==h||e[36]!==f||e[37]!==u?(N=s.jsxs("span",{className:h,children:[f,u]}),e[35]=h,e[36]=f,e[37]=u,e[38]=N):N=e[38];let P;e[39]!==N||e[40]!==g||e[41]!==v||e[42]!==j?(P=s.jsxs("span",{className:g,children:[v,j,N]}),e[39]=N,e[40]=g,e[41]=v,e[42]=j,e[43]=P):P=e[43];let C;return e[44]!==m||e[45]!==P||e[46]!==b||e[47]!==k||e[48]!==p?(C=s.jsx("button",{type:b,onClick:k,"aria-pressed":p,className:m,children:P}),e[44]=m,e[45]=P,e[46]=b,e[47]=k,e[48]=p,e[49]=C):C=e[49],C},of=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=Xe(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:d,loadCatalog:c,loadSource:h,isLoadingCatalog:m,isLoadingSource:f,loadedSourceIds:u,lastCatalogError:g}=Fn(Us(_=>({sources:_.sources,itemsBySource:_.itemsBySource,selectedSourceId:_.selectedSourceId,setSelectedSource:_.setSelectedSource,loadCatalog:_.loadCatalog,loadSource:_.loadSource,isLoadingCatalog:_.isLoadingCatalog,isLoadingSource:_.isLoadingSource,loadedSourceIds:_.loadedSourceIds,lastCatalogError:_.lastCatalogError}))),[v,j]=o.useState(""),[b,k]=o.useState(!1),[p,N]=o.useState(!1),[P,C]=o.useState(null),[w,D]=o.useState(!1),[x,A]=o.useState(!1),R=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const _=r.filter(J=>!u[J.id]);if(_.length===0)return;let q=!1;return(async()=>{for(const J of _){if(q)return;await h(J.id)}})(),()=>{q=!0}},[r,u,h]),o.useEffect(()=>{!l||u[l]||h(l)},[l,u,h]),o.useEffect(()=>{const _=q=>{(q.metaKey||q.ctrlKey)&&q.key.toLowerCase()==="k"&&(q.preventDefault(),R.current?.focus())};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]);const I=v.trim().length>0,E=o.useMemo(()=>I?mi(r.flatMap(_=>i[_.id]||[]),v,_=>[_.skillName,_.frontmatterName,_.description]):l?i[l]||[]:[],[r,i,l,v,I]),F=o.useMemo(()=>r.find(_=>_.id===l)||null,[r,l]),K=!!(l&&l.startsWith("custom:")),S=async()=>{if(!(!l||!K)){D(!0);try{const _=await An();if(!_)return;const X=(_.skillCatalogs??[]).filter(J=>J.id!==l);await ft({skillCatalogs:X}),await c({refresh:!0}),A(!1)}finally{D(!1)}}},M=I?n("settings.skills.catalog.page.list.searchTitle"):F?.label??"",z=!I&&l!==null&&!u[l]&&(f||m);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(ko,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:_=>e(_),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(B,{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:_=>j(_.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:()=>{j(""),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(B,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(Ge,{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(_=>s.jsx(rf,{source:_,isActive:_.id===l,isLoading:f&&!u[_.id],skillsCount:u[_.id]?(i[_.id]||[]).length:null,onSelect:()=>d(_.id),t:n},_.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(B,{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")})]})]})]})}),g&&s.jsx(Ge,{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:g.message})]})}),s.jsxs(Ge,{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&&!I?h(l,{refresh:!0}):c({refresh:!0})},disabled:m||f,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(B,{name:"refresh",className:Ie("h-3.5 w-3.5",(m||f)&&"animate-spin")})}),K&&!I&&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:w,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),z||f&&E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(B,{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(_=>{const q=_.installed?.isInstalled,X=_.installed?.scope,J=sf(_);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:_.skillName}),q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:X||n("settings.skills.catalog.page.badge.unknown")})}),!_.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")})]}),_.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:_.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:[J?s.jsxs("a",{href:J,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(B,{name:"github",className:"h-3 w-3 shrink-0"}),_.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:_.repoSource}),_.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:_.skillDir})]})]}),_.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:_.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[J&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(J,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"})}),q?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:X||""}),children:s.jsx(B,{name:"check",className:"h-4 w-4"})}):s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",disabled:!_.installable,onClick:()=>{C(_),N(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${_.sourceId}:${_.skillDir}`)})})]})]}),s.jsx(qh,{open:b,onOpenChange:k}),s.jsx(Wh,{open:p,onOpenChange:N,item:P}),s.jsx(Kt,{open:x,onOpenChange:_=>{w||A(_)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Bt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>A(!1),disabled:w,children:n("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{S()},disabled:w,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},lf=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(of,{mode:"external",onModeChange:gf,showModeTabs:!1}),t[0]=e):e=t[0],e},cf="SKILL.md",df="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Hi=(t,e)=>{const a=Im({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},uf=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),ad=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=Pm(e[1]);if(uf(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},mf=(t,e)=>{const a=ad(t);return Hi(e,a.instructions)},pf=()=>{const{t}=Xe(),{currentTheme:e}=ha(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:d,setSkillDraft:c,setSelectedSkill:h}=sn(Us(oe=>({selectedSkillName:oe.selectedSkillName,getSkillByName:oe.getSkillByName,getSkillDetail:oe.getSkillDetail,createSkill:oe.createSkill,updateSkill:oe.updateSkill,skillDraft:oe.skillDraft,setSkillDraft:oe.setSkillDraft,setSelectedSkill:oe.setSelectedSkill}))),m=Ws(),f=sn(oe=>go(oe,m)),u=a?n(a,m):null,g=!!(d&&d.name===a&&!u),v=!!(a&&!u&&!d),j=u?.path==="<built-in>";o.useEffect(()=>{v&&h(null)},[v,h]);const[b,k]=o.useState(""),[p,N]=o.useState("user"),[P,C]=o.useState("opencode"),[w,D]=o.useState(""),[x,A]=o.useState(""),[R,I]=o.useState(()=>Hi("","")),[E,F]=o.useState("edit"),[K,S]=o.useState([]),[M,z]=o.useState([]),[_,q]=o.useState(!1),[X,J]=o.useState(!1),[H,L]=o.useState(""),[V,Z]=o.useState(""),[U,te]=o.useState(!1),[O,Q]=o.useState(""),[ce,de]=o.useState(""),[pe,re]=o.useState(null),[Ce,ie]=o.useState(!1),[be,ae]=o.useState(""),[fe,xe]=o.useState(null),[Oe,Ne]=o.useState(!1),he=pe?ce!==be:O.trim()!=="",Te=o.useCallback(oe=>{switch(oe){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]),we=o.useCallback(oe=>{switch(oe){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]),De=JSON.stringify([m,a,u?.path,g]),ve=o.useRef(null),ee=o.useRef({key:De,markdown:R});ee.current={key:De,markdown:R};const ne=o.useRef("");o.useEffect(()=>{let oe=!1;const Pe=(Fe,$e)=>{if(ee.current.key!==De)return;const W=Hi(Fe,$e),Ve=ve.current===De&&ee.current.markdown!==ne.current;ve.current=De,ne.current=W,Ve||(D(Fe),A($e),I(W))};return(async()=>{if(g&&d){J(!1);const Fe=d.description||"",$e=d.instructions||"";k(d.name||""),N(d.scope||"user"),C(d.source==="agents"?"agents":"opencode"),Pe(Fe,$e),L(""),Z(""),S([]),z(d.pendingFiles||[])}else if(a&&u){J(ve.current!==De);try{const Fe=await r(a,m);if(!oe&&ee.current.key===De&&Fe){const $e=Fe.sources.md,W=$e.description||"",Ve=$e.instructions||"";Pe(W,Ve),L(W),Z(Ve),S($e.supportingFiles||[])}}catch(Fe){console.error("Failed to load skill details:",Fe)}finally{oe||J(!1)}}})(),()=>{oe=!0}},[u,g,a,m,f,d,r,De]);const ye=ge(oe=>oe.editorFontSize),Ae=o.useMemo(()=>{const oe=[rl(e,{fontSize:ye})],Pe=zo(cf);return Pe&&oe.push(Pe),oe.push(ll.lineWrapping),oe},[e,ye]),ze=o.useMemo(()=>{const oe=O.trim()||"supporting-file.md",Pe=Ld(oe),Re=!!Pe&&Pe!=="markdown",Fe=[rl(e,Re?{syntaxColors:!1,fontSize:ye}:{fontSize:ye})],$e=zo(oe);return $e&&Fe.push($e),Re&&Pe&&Fe.push(Am({language:Pe,themeName:e.metadata.id,theme:Em(e)})),Fe.push(ll.lineWrapping),Fe},[e,O,ye]),Qe=o.useCallback(oe=>{D(oe),I(Pe=>mf(Pe,oe))},[]),Be=o.useCallback(oe=>{I(oe);const Pe=ad(oe);D(Pe.description??""),A(Pe.instructions)},[]),_e=oe=>oe?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(oe)||oe.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),Me=o.useCallback(async()=>{const oe=a?.trim();return g||j||!oe||w===H&&x===V?Rs:w.trim()?await l(oe,{name:oe,description:w.trim(),instructions:x.trim()||void 0,targetPath:u?.path},m)?(ee.current.key===De&&(ne.current=Hi(w,x),L(w),Z(x)),In):xs(t("settings.skills.page.toast.updateSkillFailed")):xs(t("settings.skills.page.toast.descriptionRequired"))},[w,x,g,j,H,V,u?.path,a,m,De,t,l]),nt=qa(Me),pt=async()=>{const oe=b.trim().replace(/\s+/g,"-").toLowerCase(),Pe=_e(oe);if(Pe){$.error(Pe);return}if(!w.trim()){$.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f.some(Re=>Re.name===oe)){$.error(t("settings.skills.page.toast.skillExists"));return}q(!0);try{const Re={name:oe,description:w.trim(),instructions:x.trim()||void 0,scope:p,source:P,supportingFiles:M.length>0?M:void 0};await i(Re,m)?(c(null),z([]),h(oe),$.success(t("settings.skills.page.toast.skillCreated"))):$.error(t("settings.skills.page.toast.createSkillFailed"))}catch(Re){console.error("Error creating skill:",Re),$.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{q(!1)}},lt=()=>{c(null),h(null)},ut=()=>{re(null),Q(""),de(""),ae(""),te(!0)},ht=async oe=>{if(re(oe),Q(oe),g){const Re=M.find(Fe=>Fe.path===oe)?.content||"";de(Re),ae(Re),te(!0);return}if(a){ie(!0),te(!0);try{const{readSupportingFile:Pe}=sn.getState(),Re=await Pe(a,oe,m);de(Re||""),ae(Re||"")}catch{$.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),ae("")}finally{ie(!1)}}},Ue=async()=>{if(!O.trim()){$.error(t("settings.skills.page.toast.fileNameRequired"));return}const oe=O.trim(),Pe=pe!==null;if(g){if(Pe)z($e=>$e.map(W=>W.path===pe?{path:oe,content:ce}:W)),$.success(t("settings.skills.page.toast.fileUpdated",{path:oe}));else{if(M.some($e=>$e.path===oe)){$.error(t("settings.skills.page.toast.fileExists"));return}z($e=>[...$e,{path:oe,content:ce}]),$.success(t("settings.skills.page.toast.fileAdded",{path:oe}))}te(!1),re(null);return}if(!a){$.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Re}=sn.getState();if(await Re(a,oe,ce,m)){$.success(Pe?t("settings.skills.page.toast.fileUpdated",{path:oe}):t("settings.skills.page.toast.fileCreated",{path:oe})),te(!1),re(null);const $e=await r(a,m);$e&&S($e.sources.md.supportingFiles||[])}else $.error(t(Pe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},st=oe=>{if(g){z(Pe=>Pe.filter(Re=>Re.path!==oe)),$.success(t("settings.skills.page.toast.fileRemoved",{path:oe}));return}a&&xe(oe)},ue=async()=>{if(!fe||!a)return;Ne(!0);const{deleteSupportingFile:oe}=sn.getState();if(await oe(a,fe,m)){$.success(t("settings.skills.page.toast.fileDeleted",{path:fe}));const Re=await r(a,m);Re&&S(Re.sources.md.supportingFiles||[]),xe(null)}else $.error(t("settings.skills.page.toast.deleteFileFailed"));Ne(!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(B,{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")})]})}):X?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:g?t("settings.skills.page.title.newSkill"):a,description:u?t("settings.skills.page.subtitle.skillLocation",{location:Te(ci(u.scope,u.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:nt.onBlurCapture,children:[s.jsxs(Ge,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[g&&s.jsxs(St,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(We,{value:b,onChange:oe=>k(oe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Et,{value:ci(p,P),onValueChange:oe=>{const Pe=nd(oe);N(Pe.scope),C(Pe.source==="agents"?"agents":"opencode")},children:[s.jsxs(At,{size:Vt,className:"w-fit gap-1.5",children:[p==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),P==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Te(ci(p,P))})]}),s.jsx(Tt,{align:"start",children:Po.map(oe=>s.jsx(mt,{value:oe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[oe.scope==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),oe.source==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Te(oe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:we(oe.value)})]})},oe.value))})]})]}),s.jsx(Rt,{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:w,onChange:oe=>Qe(oe.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:j})})]}),s.jsx(Ge,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Tm,{currentMode:E==="preview"?"preview":"edit",onToggle:()=>F(oe=>oe==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:Ie("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",df),onKeyDown:oe=>{oe.key==="Enter"&&(oe.metaKey||oe.ctrlKey)&&(oe.preventDefault(),nt.requestSave())},children:E==="preview"?s.jsx(vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Kd,{content:R,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(ol,{value:R,onChange:Be,readOnly:j,extensions:Ae,className:"h-full",enableSearch:!0})})}),s.jsx(Ge,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ut,disabled:j,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const oe=g?M:K;return oe.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:oe.map(Pe=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ht(Pe.path),children:[s.jsx(B,{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:Pe.path}),g&&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")}),!j&&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:Re=>{Re.stopPropagation(),st(Pe.path)},children:s.jsx(B,{name:"delete-bin",className:"h-3 w-3"})})]},Pe.path))})})()}),g&&s.jsx(Ge,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{onClick:()=>{pt()},disabled:_||!b.trim()||!w.trim(),size:"xs",className:"!font-normal",children:t(_?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(G,{variant:"ghost",onClick:lt,disabled:_,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(Kt,{open:fe!==null,onOpenChange:oe=>{!oe&&!Oe&&xe(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Bt,{children:t("settings.skills.page.deleteFileDialog.description",{path:fe??""})})]}),s.jsxs(as,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>xe(null),disabled:Oe,children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:ue,disabled:Oe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:U,onOpenChange:oe=>{if(oe){te(!0);return}if(pe!==null&&ce!==be){Ue();return}te(!1),re(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Ut,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(pe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Bt,{children:t(pe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ce?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:It,children:t("settings.skills.page.fileDialog.field.filePath")}),!pe&&s.jsx(Ht,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(We,{value:O,onChange:oe=>Q(oe.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:pe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${It} 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(ol,{value:ce,onChange:de,extensions:ze,className:"h-full",enableSearch:!0})})]})]}),s.jsx(as,{className:"mt-4",children:pe?s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Ce,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{te(!1),re(null)},children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:()=>{Ue()},disabled:Ce||!he,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},Sl=t=>{const e=rt.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(lf,{}):s.jsx(pf,{}),e[0]=n,e[1]=r):r=e[1],r};function gf(){}const hf=t=>{const e=rt.c(38),{onItemSelect:a}=t,{t:n}=Xe(),r=an(ff),i=ge(xf),l=ge(bf),{currentTheme:d}=ha();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[0]=c):c=e[0];const h=c,m=vf;let f,u;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)},u=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=f,e[5]=u):(f=e[4],u=e[5]),o.useEffect(f,u);let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=Ie("border-b px-3","pt-4 pb-3"),e[6]=g):g=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let j;e[9]!==v?(j=s.jsx("h2",{className:`${Pn} mb-3`,children:v}),e[9]=v,e[10]=j):j=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 p;e[16]!==n?(p=!h&&s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(B,{name:"add",className:"size-4"})}),e[16]=n,e[17]=p):p=e[17];let N;e[18]!==k||e[19]!==p?(N=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,p]}),e[18]=k,e[19]=p,e[20]=N):N=e[20];let P;e[21]!==N||e[22]!==j?(P=s.jsxs("div",{className:g,children:[j,N]}),e[21]=N,e[22]=j,e[23]=P):P=e[23];let C;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?_d[x.icon]:null,I=x.color?Ud[x.color]??null:null,E=R?s.jsx(B,{name:R,className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}):s.jsx(B,{name:"folder",className:Ie("h-4 w-4",A?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}),F=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($d,{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(Vi,{title:x.label||x.path,icon:F,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],C=r.map(D),e[24]=d,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=C}else C=e[29];let w;return e[35]!==P||e[36]!==C?(w=s.jsx(sd,{variant:"background",header:P,children:C}),e[35]=P,e[36]=C,e[37]=w):w=e[37],w};function ff(t){return t.projects}function xf(t){return t.settingsProjectsSelectedId}function bf(t){return t.setSettingsProjectsSelectedId}function vf(){zd.requestDirectoryDialog()}const yf=()=>{const t=rt.c(30),{t:e}=Xe(),a=an(jf),n=an(wf),r=ge(kf),i=ge(Nf);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 m;t[8]!==d||t[9]!==n?(m=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]=m):m=t[10];const f=m;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 p;t[15]!==k?(p=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=p):p=t[16];let N;return t[17]!==b||t[18]!==p?(N=s.jsx(ns,{title:b,showSaveStatus:!0,children:p}),t[17]=b,t[18]=p,t[19]=N):N=t[19],N}let u;t[20]!==d.label||t[21]!==e?(u=d.label??e("settings.projects.page.title.default"),t[20]=d.label,t[21]=e,t[22]=u):u=t[22];const g=u;let v;t[23]!==f||t[24]!==d?(v=s.jsx(ym,{project:d,onIdentitySave:f}),t[23]=f,t[24]=d,t[25]=v):v=t[25];let j;return t[26]!==g||t[27]!==d.path||t[28]!==v?(j=s.jsx(ns,{title:g,description:d.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=g,t[27]=d.path,t[28]=v,t[29]=j):j=t[29],j};function jf(t){return t.projects}function wf(t){return t.updateProjectMeta}function kf(t){return t.settingsProjectsSelectedId}function Nf(t){return t.setSettingsProjectsSelectedId}const Sf=Gs({clientToken:es().trim().min(1)}),Cf=Gs({error:Cm("Invalid or expired pairing session")}),If=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&Cf.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const a=Sf.safeParse(e);return a.success?{kind:"success",token:a.data.clientToken}:{kind:"invalid-response"}};function Pf(t){const e=rt.c(42),{t:a}=Xe(),[n,r]=tt.useState(null),i=tt.useRef(null),l=tt.useRef(null);let d,c;e[0]!==t?(d=()=>(l.current=t,r(null),()=>{l.current=null;const S=i.current;i.current=null,S?.(null)}),c=[t],e[0]=t,e[1]=d,e[2]=c):(d=e[1],c=e[2]),tt.useEffect(d,c);let h;e[3]!==t?(h=(S,M)=>{const z=M===void 0?"settings.common.actions.saveChanges":M;return!t||l.current!==t||i.current?Promise.resolve(null):new Promise(_=>{i.current=_,r({messageKey:S,actionKey:z})})},e[3]=t,e[4]=h):h=e[4];const m=h;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=S=>{const M=i.current;i.current=null,r(null),M?.(S)},e[5]=f):f=e[5];const u=f,g=n!==null;let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=S=>{S||u(!1)},e[6]=v):v=e[6];let j;e[7]!==a?(j=a("settings.remoteInstances.page.title"),e[7]=a,e[8]=j):j=e[8];let b;e[9]!==j?(b=s.jsx($t,{children:j}),e[9]=j,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 p;e[14]!==k?(p=s.jsx(Bt,{children:k}),e[14]=k,e[15]=p):p=e[15];let N;e[16]!==b||e[17]!==p?(N=s.jsxs(Ut,{children:[b,p]}),e[16]=b,e[17]=p,e[18]=N):N=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P=()=>u(!1),e[19]=P):P=e[19];let C;e[20]!==a?(C=a("settings.common.actions.cancel"),e[20]=a,e[21]=C):C=e[21];let w;e[22]!==C?(w=s.jsx(G,{variant:"outline",autoFocus:!0,onClick:P,children:C}),e[22]=C,e[23]=w):w=e[23];let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=()=>u(!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]!==w||e[31]!==A?(R=s.jsxs(as,{children:[w,A]}),e[30]=w,e[31]=A,e[32]=R):R=e[32];let I;e[33]!==N||e[34]!==R?(I=s.jsxs(zt,{children:[N,R]}),e[33]=N,e[34]=R,e[35]=I):I=e[35];let E;e[36]!==I||e[37]!==g?(E=s.jsx(Kt,{open:g,onOpenChange:v,children:I}),e[36]=I,e[37]=g,e[38]=E):E=e[38];const F=E;let K;return e[39]!==m||e[40]!==F?(K={confirm:m,dialog:F},e[39]=m,e[40]=F,e[41]=K):K=e[41],K}const qi=()=>Math.floor(2e4+Math.random()*3e4),Af=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")},Tf=()=>{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"},Cl=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}},Il=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"}},Ef=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ao=t=>!!(t&&Ef.has(t)),Pl=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Ao(t)?"connecting":"idle",Al=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"}},Df=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},Tl={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Mf=t=>t==="noRuntime"?Tl.noRuntime:t==="noOpencode"?Tl.noOpencode:null,El=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ao(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Rf=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}`,Ff=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:qi(),remoteHost:"127.0.0.1",remotePort:80}),Of=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",en=t=>{const e=rt.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(Ht,{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 ${It}`,children:[r,i]}),e[4]=r,e[5]=i,e[6]=l):l=e[6],l},Lf=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"}},Dl=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Kf=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},zf=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}`},oo=(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}),_f=t=>t.trim().toLowerCase()==="authorization",_r=t=>{const e={};for(const a of t){const n=a.name.trim(),r=a.value.trim();n&&r&&!_f(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},Uf=t=>Object.entries(t||{}).map(([e,a])=>oo(e,a)),id=()=>{if(typeof window>"u")return null;const e=pi()||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}},Ml=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},$f=async()=>{const t=Oa(pi())||window.location.origin;if(!os()||!gi()||(await An())?.desktopLanAccessActive!==!0)return t;const a=await Oc(),n=id();return!a||!n?t:`http://${a}:${n}`},Ki=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Bf=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}},Vf=()=>{const{t}=Xe(),e=ge(T=>T.timeFormatPreference),{clientAuth:a}=yo(),n=os(),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),m=Is(T=>T.error),f=Is(T=>T.load),u=Is(T=>T.loadImports),g=Is(T=>T.refreshStatuses),v=Is(T=>T.upsertInstance),j=Is(T=>T.createFromCommand),b=Is(T=>T.removeInstance),k=Is(T=>T.connect),p=Is(T=>T.disconnect),N=Is(T=>T.retry),P=ge(T=>T.settingsRemoteInstancesSelectedId),C=ge(T=>T.setSettingsRemoteInstancesSelectedId),{confirm:w,dialog:D}=Pf(P),x=o.useMemo(()=>P&&r.find(T=>T.id===P)||null,[r,P]),[A,R]=o.useState(null),[I,E]=o.useState(!1),[F,K]=o.useState(!1),[S,M]=o.useState(null),[z,_]=o.useState([]),[q,X]=o.useState(null),[J,H]=o.useState(""),[L,V]=o.useState(!1),[Z,U]=o.useState({}),[te,O]=o.useState(!1),[Q,ce]=o.useState(!1),[de,pe]=o.useState(()=>Date.now()),[re,Ce]=o.useState([]),[ie,be]=o.useState({}),[ae,fe]=o.useState("local"),[xe,Oe]=o.useState(!1),[Ne,he]=o.useState(!1),[Te,we]=o.useState(""),[De,ve]=o.useState(""),[ee,ne]=o.useState(""),[ye,Ae]=o.useState([]),[ze,Qe]=o.useState(""),[Be,_e]=o.useState(null),[Me,nt]=o.useState(!1),[pt,lt]=o.useState(!1),[ut,ht]=o.useState(!1),[Ue,st]=o.useState(null),[ue,oe]=o.useState(""),[Pe,Re]=o.useState(""),[Fe,$e]=o.useState(""),[W,Ve]=o.useState([]),[et,dt]=o.useState([]),[ct,jt]=o.useState([]),[kt,yt]=o.useState(!1),[bt,Ze]=o.useState(""),[wt,Le]=o.useState(null),[He,Y]=o.useState(null),[me,Ke]=o.useState(null),[Ee,Ye]=o.useState(null),[se,ke]=o.useState(!1),[at,Mt]=o.useState(!1),[Wt,Se]=o.useState("configure"),[qe,vt]=o.useState(!1),[Ct,Jt]=o.useState("relay"),[Zt,ts]=o.useState(!0),[Xt,Fs]=o.useState(null),Js=o.useMemo(()=>et.filter(T=>!!T.revokedAt).length,[et]),[pn,Os]=o.useState(!1),[Ls,rn]=o.useState("saved"),[Qs,Ys]=o.useState(""),[Ks,Tn]=o.useState(""),[Dt,qt]=o.useState(""),[Lt,Pt]=o.useState(!1);o.useEffect(()=>{f(),u()},[f,u]);const is=o.useCallback(async()=>{Oe(!0),_e(null);try{const T=await Jo();Ce(T.hosts||[]),fe(T.defaultHostId||"local")}catch(T){_e(T instanceof Error?T.message:String(T))}finally{Oe(!1)}},[]);o.useEffect(()=>{is()},[is]);const ss=o.useCallback(async(T,le=ae)=>{he(!0),_e(null);try{return await Qo({hosts:T,defaultHostId:le,initialHostChoiceCompleted:!0}),Ce(T),fe(le),!0}catch(Je){return _e(Je instanceof Error?Je.message:String(Je)),!1}finally{he(!1)}},[ae]),or=o.useCallback(async()=>{const T=Yo(De);if(!T){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=T.persistedUrl,ot={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Te.trim()||Ja(le),url:le,apiUrl:le,...ee.trim()?{clientToken:ee.trim()}:{},..._r(ye)?{requestHeaders:_r(ye)}:{}};await ss([ot,...re],ae)&&(we(""),ve(""),ne(""),Ae([]),nt(!1),T.redeemUrl&&Ki(T.redeemUrl))},[ae,ye,re,Te,ee,De,ss,t]),lr=o.useCallback(async()=>{_e(null);const T=$u(ze);if(!T){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const le=await Bu().catch(()=>""),Je=JSON.stringify({pairingId:T.pairingId,secret:T.secret,clientLabel:T.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Tf(),...le?{dedupeKey:`desktop:${le}`}:{}}),ot={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Je};let Ft=null;const bs=async Yt=>{const Cs=await If(Yt);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},Zs=[...T.candidates].sort((Yt,Cs)=>(Yt.type==="relay"?1:0)-(Cs.type==="relay"?1:0));let ms=null;for(const Yt of Zs){if(Yt.type==="relay"){const Pa=Vu({relayUrl:Yt.relayUrl,serverId:Yt.serverId,hostEncPubJwk:Yt.hostEncPubJwk,...Yt.grant?{grant:Yt.grant}:{}});try{const Aa=await Pa.fetch("/api/client-auth/pairing/redeem",{...ot,signal:AbortSignal.timeout(15e3)}),Ta=await bs(Aa);if(Ta){ms={kind:"relay",relay:{relayUrl:Yt.relayUrl,serverId:Yt.serverId,hostEncPubJwk:Yt.hostEncPubJwk},token:Ta};break}}catch{}finally{Pa.close()}continue}const Cs=Oa(Yt.url);if(Cs)try{const Pa=await fetch(`${Cs}/api/client-auth/pairing/redeem`,{...ot,signal:AbortSignal.timeout(15e3)}),Aa=await bs(Pa);if(Aa){ms={kind:"direct",url:Cs,token:Aa};break}}catch{}}if(!ms){_e(Ft||t("mobile.connect.error.unreachable"));return}const zs=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Dn=T.candidates.find(Yt=>Yt.type==="relay"),fn=ms.kind==="relay"?ms.relay:Dn?{relayUrl:Dn.relayUrl,serverId:Dn.serverId,hostEncPubJwk:Dn.hostEncPubJwk}:void 0,Ca=T.candidates.filter(Yt=>Yt.type!=="relay").map(Yt=>Oa(Yt.url)).find(Yt=>!!Yt),Ia=ms.kind==="direct"?ms.url:Ca,{token:Ot}=ms,Qt=Ia||(fn?Hu(fn.serverId):null);if(!Qt){_e(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const xn={url:Qt,apiUrl:Ia||void 0,clientToken:Ot,...fn?{relay:fn}:{}},cn=re.find(Yt=>fn?Yt.relay?.serverId===fn.serverId:!Yt.relay&&Oa(Yt.apiUrl||Yt.url)===Qt);if(cn){const Yt=re.map(Cs=>Cs.id===cn.id?{...Cs,label:T.label||Cs.label,...xn}:Cs);if(!await ss(Yt,ae))return}else if(!await ss([{id:zs(),label:T.label||Ja(Qt),...xn},...re],ae))return;Qe(""),_e(null),lt(!1)},[ze,ae,re,ss,t]),cr=o.useCallback(async T=>{const le=re.filter(ot=>ot.id!==T);await ss(le,ae===T?"local":ae)&&Ue===T&&st(null)},[ae,Ue,re,ss]),dr=o.useCallback(T=>{st(T.id),oe(T.label),Re(T.apiUrl||T.url),$e(T.clientToken||""),Ve(Uf(T.requestHeaders)),_e(null)},[]),bi=o.useCallback(async()=>{if(!Ue)return;const T=Yo(Pe);if(!T){_e(t("desktopHostSwitcher.error.invalidUrl"));return}const le=T.persistedUrl,Je=re.map(ot=>ot.id===Ue?{...ot,label:ue.trim()||Ja(le),url:le,apiUrl:le,clientToken:Fe.trim()||void 0,requestHeaders:_r(W)}:ot);await ss(Je,ae)&&(st(null),T.redeemUrl&&Ki(T.redeemUrl))},[ae,W,ue,Fe,Pe,Ue,re,ss,t]),ur=o.useCallback(async()=>{const T=Ks.trim();if(!T){$.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const le=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await j(le,T,Dt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),C(le),Os(!1),Tn(""),qt(""),$.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Je){$.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Je instanceof Error?Je.message:String(Je)})}},[j,C,Ks,Dt,t]),vi=o.useCallback(()=>{Ys(""),rn(l.length>0?"saved":"manual"),Os(!0)},[l.length]),mr=o.useCallback(async T=>{await ss(re,T)},[re,ss]);o.useEffect(()=>{if(!n||re.length===0)return;let T=!1;return Promise.all(re.map(async le=>{const Je=()=>Yu(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 ot=Oa(qu(le));if(!ot)return[le.id,le.relay?await Je():{status:"unreachable",latencyMs:0}];const Ft=await Gu(ot,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ft.status==="unreachable"&&le.relay){const bs=await Je();if(bs.status==="ok")return[le.id,bs]}return[le.id,Ft]})).then(le=>{T||be(Object.fromEntries(le))}),()=>{T=!0}},[re,n]);const $s=o.useCallback(async T=>{if(a){T?.silent||yt(!0),T?.silent||Le(null);try{const[le,Je]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);dt(le),Je&&jt(Je)}catch(le){T?.silent||Le(le instanceof Error?le.message:String(le))}finally{T?.silent||yt(!1)}}},[a]),Ga=o.useRef(!1);o.useEffect(()=>{if(!(!at||Wt!=="result"||!me)){if(ct.some(T=>T.id===me)){Ga.current=!0;return}Ga.current&&(Ke(null),Mt(!1),et.some(T=>T.pairingId===me)&&$.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[at,Wt,me,ct,et,t]);const yi=o.useCallback(async T=>{if(a)try{await a.cancelPairing(T),jt(le=>le.filter(Je=>Je.id!==T)),await $s({silent:!0})}catch(le){Le(le instanceof Error?le.message:String(le))}},[a,$s]);o.useEffect(()=>{if(!a)return;$s();const T=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||$s({silent:!0})},5e3);return()=>window.clearInterval(T)},[a,$s]);const ji=o.useCallback(async()=>{if(a?.getPairingTransports)try{const ot=await a.getPairingTransports();return{localUrl:ot.local,lanUrl:ot.lan,relayAvailable:ot.relayAvailable}}catch{}const T=id(),le=T?`http://127.0.0.1:${T}`:Ml(window.location.origin)?window.location.origin:null;let Je=null;try{const ot=Oa(await $f());Je=ot&&!Ml(ot)?ot:null}catch{}return{localUrl:le,lanUrl:Je,relayAvailable:!0}},[a]),pr=o.useCallback(async()=>{Le(null),Y(null),Ye(null),ke(!1),Ke(null),Se("configure"),ts(!0),Mt(!0);const T=await ji();Fs(T),Jt(T.relayAvailable?"relay":T.lanUrl?"lan":"local")},[ji]),gr=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Xt)){Le(null),vt(!0);try{const T=bt.trim()||void 0;let le,Je,ot=!0;Ct==="local"?(le=Xt.localUrl??void 0,Je=!1):Ct==="lan"?(le=Xt.lanUrl??void 0,Je=Zt):Zt&&Xt.lanUrl?(le=Xt.lanUrl,Je=!0):(ot=!1,Je=!0);const{pairing:Ft,server:bs}=await a.createPairingSession({label:T,allowedClientKinds:["mobile","desktop"],serverUrl:le,includeRelay:Je,includeDirect:ot}),Zs=Wu({pairingId:Ft.id,secret:Ft.secret,label:bs.label,fingerprint:Ft.fingerprint??void 0,expiresAt:Ft.expiresAt,candidates:bs.candidates}),ms=Ju(Zs);Y(ms),Ye(await Vc.toDataURL(ms,{width:1024,margin:2,errorCorrectionLevel:"L"})),ke(!1),Ga.current=!1,Ke(Ft.id),Se("result"),await $s({silent:!0})}catch(T){Le(T instanceof Error?T.message:String(T))}finally{vt(!1)}}},[a,Xt,Ct,Zt,bt,$s]),wi=o.useCallback(()=>{He&&oi(He).then(T=>{T.ok&&(ke(!0),window.setTimeout(()=>ke(!1),2e3))})},[He]),hr=o.useCallback(async T=>{if(!a)return;const le=T.clientKind==="desktop-local";Le(null);try{if(await a.revokeClient(T.id),le&&os()){const Je=await Jo();await Qo({hosts:Je.hosts,defaultHostId:Je.defaultHostId,initialHostChoiceCompleted:Je.initialHostChoiceCompleted,localClientToken:null}),dt(ot=>ot.map(Ft=>Ft.id===T.id?{...Ft,revokedAt:new Date().toISOString()}:Ft)),Qu({apiBaseUrl:pi(),clientToken:null,runtimeKey:"local"});return}await $s()}catch(Je){Le(Je instanceof Error?Je.message:String(Je))}},[a,$s]),fr=o.useCallback(async()=>{if(a){Le(null);try{await a.purgeRevokedClients(),await $s()}catch(T){Le(T instanceof Error?T.message:String(T))}}},[a,$s]);o.useEffect(()=>{R(x)},[x]),o.useEffect(()=>{Pt(!1)},[P]),o.useEffect(()=>{if(!P)return;const T=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||g()},2e3);return()=>{window.clearInterval(T)}},[g,P]),o.useEffect(()=>{let T=null,le=Date.now();const Je=()=>{const Ft=Date.now();Ft-le>=1e3&&(pe(Ft),le=Ft),T=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(T=requestAnimationFrame(Je));const ot=()=>{document.visibilityState==="visible"&&T===null?T=requestAnimationFrame(Je):document.visibilityState!=="visible"&&T!==null&&(cancelAnimationFrame(T),T=null)};return document.addEventListener("visibilitychange",ot),()=>{document.removeEventListener("visibilitychange",ot),T!==null&&cancelAnimationFrame(T)}},[]);const js=P?i[P]:null,on=js?.phase,fa=on==="ready",En=on==="degraded",Un=Ao(on),ln=fa||(Un||En),xr=js?Math.max(0,de-js.updatedAtMs):0,xa=En&&xr>12e3,ba=Pl(on),Qn=ba==="error"?Df(js?.detail):null,Wa=Mf(Qn),br=o.useMemo(()=>!A||!x?!1:JSON.stringify(A)!==JSON.stringify(x),[A,x]),ds=o.useCallback(T=>{R(le=>le&&T(le))},[]),vr=o.useCallback(async()=>{if(!A)return;const T=Bf(A);if(!T.sshCommand.trim()){$.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(T.remoteOpenchamber.mode==="external"&&!T.remoteOpenchamber.preferredPort){$.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Pt(!0);return}if(T.remoteOpenchamber.mode==="managed"&&T.remoteOpenchamber.bindHost==="0.0.0.0"&&!T.auth.openchamberPassword?.value?.trim()){$.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Pt(!0),window.setTimeout(()=>ja.current?.focus(),0);return}if(!(T.localForward.bindHost==="0.0.0.0"&&!await w("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(T.auth.sshPassword?.enabled&&T.auth.sshPassword.value?.trim()&&T.auth.sshPassword.store!=="settings"){const le=await w("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 w("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),$.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(le){$.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:le instanceof Error?le.message:String(le)})}}},[w,A,t,v]),va=o.useCallback(async(T,le)=>{const Je=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await j(Je,`ssh ${le}`,T),C(Je),$.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(ot){return $.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:ot instanceof Error?ot.message:String(ot)}),!1}},[j,C,t]),ya=o.useCallback(()=>{L||(X(null),H(""))},[L]),yr=o.useCallback((T,le)=>{if(Os(!1),le){X(T),H(Of(T));return}va(T,T)},[va]),ki=o.useMemo(()=>mi(l,Qs,T=>[T.host,T.sshCommand]),[l,Qs]),jr=o.useCallback(T=>{const le=(T||"").trim();if(!le){$.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ki(le)},[t]),$n=o.useCallback(async()=>{const T=q,le=J.trim();if(T){if(!le){$.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await va(T,le)&&(X(null),H(""))}finally{V(!1)}}},[va,J,q,t]),gn=o.useCallback(async()=>{if(x)try{await k(x.id);return}catch(T){if(!Af(T)||!await w("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw T;const Je={...x,localForward:{...x.localForward,preferredLocalPort:qi()}};await v(Je),await k(Je.id),$.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[w,k,x,t,v]),ja=o.useRef(null),Ni=o.useRef(null),wa=o.useCallback(async T=>{if(x){if(T==="localPort"){const le={...x,localForward:{...x.localForward,preferredLocalPort:qi()}};try{await v(le),await k(le.id),$.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Je){$.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Je instanceof Error?Je.message:String(Je)})}return}Pt(!0),window.setTimeout(()=>{if(T==="uiPassword"){ja.current?.focus();return}Ni.current?.scrollIntoView({block:"center"})},0)}},[k,x,t,v]),ka=o.useCallback(async T=>(await Bd(T,600)).map(Je=>zf(Je)),[]),wr=o.useCallback(async()=>{if(A){E(!0),K(!0),M(null);try{const T=await ka(A.id);_(T)}catch(T){_([]),M(T instanceof Error?T.message:String(T))}finally{K(!1)}}},[A,ka]);o.useEffect(()=>{if(!I||!A)return;let T=!1;const le=async()=>{try{const ot=await ka(A.id);T||(_(ot),M(null))}catch(ot){T||M(ot instanceof Error?ot.message:String(ot))}};le();const Je=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||le()},1e3);return()=>{T=!0,window.clearInterval(Je)}},[A,I,ka]);const je=o.useMemo(()=>z.join(`
27
- `),[z]),us=o.useCallback(()=>{if(!je.trim()){$.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}oi(je).then(T=>{T.ok&&$.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[je,t]),Na=o.useCallback(async()=>{if(A)try{await Vd(A.id),_([]),$.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(T){$.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:T instanceof Error?T.message:String(T)})}},[A,t]),Si=o.useCallback(async()=>{if(!js?.localUrl){$.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const T=js.localUrl.trim();if(!T){$.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ki(T)},[js?.localUrl,t]),Ci=o.useCallback(()=>{if(!A)return;if(!ln&&A.remoteOpenchamber.mode==="external"&&!A.remoteOpenchamber.preferredPort){$.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Pt(!0);return}if(!ln&&A.remoteOpenchamber.mode==="managed"&&A.remoteOpenchamber.bindHost==="0.0.0.0"&&!A.auth.openchamberPassword?.value?.trim()){$.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Pt(!0),window.setTimeout(()=>ja.current?.focus(),0);return}O(!0),(ln?p(A.id):gn()).catch(le=>{const Je=ln?fa?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";$.error(t(Je),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{O(!1)})},[ln,gn,p,A,fa,t]),Ii=o.useCallback(()=>{if(!A||Un)return;ce(!0),(En?p(A.id).then(()=>gn()):N(A.id)).catch(le=>{$.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{ce(!1)})},[gn,p,A,Un,En,N,t]),Pi=t(Un?"settings.remoteInstances.page.actions.connecting":En?xa?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ai=!te&&!Q&&(on==="error"||on==="idle"||!on||En&&xa)&&!Un,kr=t(fa?"settings.remoteInstances.sidebar.actions.disconnect":ln?"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(Ge,{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:()=>{pr()},children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[Js>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{fr()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,kt&&et.length===0&&ct.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):et.length===0&&ct.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[ct.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:()=>{yi(T.id)},children:t("settings.common.actions.cancel")})]},`pending-${T.id}`)),et.map(T=>{const le=T.clientKind==="desktop-local",Je=T.lastUsedAt?Date.parse(T.lastUsedAt):Number.NaN,ot=!T.revokedAt&&(le||Number.isFinite(Je)&&Date.now()-Je<9e4),Ft=T.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):ot?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:Hd(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":ot?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:T.label}),Cl(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:Cl(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",ot&&!T.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ft})]})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{hr(T)},disabled:!!T.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},T.id)})]})]}),wt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:wt}):null]}):null,n?s.jsxs(Ge,{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),lt(!0)},disabled:Ne,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_e(null),nt(!0)},disabled:Ne,children:[s.jsx(B,{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:xe?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):re.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):re.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",ot=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?ot?"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:Ja(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",ot?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Je),ot&&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"):Ja(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:()=>{mr(T.id)},disabled:Ne||ae===T.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ae===T.id?s.jsx(B,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(B,{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:()=>dr(T),disabled:Ne,children:[s.jsx(B,{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:()=>{cr(T.id)},disabled:Ne,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},T.id)})}),Be&&!pt&&!Me&&!Ue?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Be}):null]}):null,n?s.jsx(Kt,{open:Me,onOpenChange:nt,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Bt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),or()},children:[s.jsx(We,{className:"h-8",value:Te,onChange:T=>we(T.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:Ne}),s.jsx(We,{className:"h-8",value:De,onChange:T=>ve(T.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:Ne,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(We,{className:"h-8",value:ee,onChange:T=>ne(T.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:Ne}),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(Ht,{children:t("settings.remoteInstances.direct.headers.description")})]}),ye.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=>Ae(Je=>Je.map(ot=>ot.id===T.id?{...ot,name:le.target.value}:ot)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:Ne}),s.jsx(We,{className:"h-8 font-mono text-xs",value:T.value,onChange:le=>Ae(Je=>Je.map(ot=>ot.id===T.id?{...ot,value:le.target.value}:ot)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:Ne}),s.jsx("button",{type:"button",onClick:()=>Ae(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:Ne,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},T.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ae(T=>[...T,oo()]),disabled:Ne,children:[s.jsx(B,{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:()=>nt(!1),disabled:Ne,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:Ne||!De.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),Be?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null]})]})}):null,n?s.jsx(Kt,{open:!!Ue,onOpenChange:T=>{T||st(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Bt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),bi()},children:[s.jsx(We,{className:"h-8",value:ue,onChange:T=>oe(T.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:Ne}),s.jsx(We,{className:"h-8",value:Pe,onChange:T=>Re(T.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:Ne,autoFocus:!0}),s.jsx(We,{className:"h-8",value:Fe,onChange:T=>$e(T.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:Ne}),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(Ht,{children:t("settings.remoteInstances.direct.headers.description")})]}),W.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=>Ve(Je=>Je.map(ot=>ot.id===T.id?{...ot,name:le.target.value}:ot)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:Ne}),s.jsx(We,{className:"h-8 font-mono text-xs",value:T.value,onChange:le=>Ve(Je=>Je.map(ot=>ot.id===T.id?{...ot,value:le.target.value}:ot)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:Ne}),s.jsx("button",{type:"button",onClick:()=>Ve(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:Ne,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},T.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ve(T=>[...T,oo()]),disabled:Ne,children:[s.jsx(B,{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:Ne,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:Ne,children:t("settings.common.actions.saveChanges")})]}),Be?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null]})]})}):null,n?s.jsx(Kt,{open:pt,onOpenChange:T=>{ut||lt(T)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Bt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":ut,onSubmit:async T=>{if(T.preventDefault(),!(ut||Ne)){ht(!0);try{await lr()}catch{_e(t("mobile.connect.error.unreachable"))}finally{ht(!1)}}},children:[s.jsx(We,{className:"h-8",value:ze,onChange:T=>{Qe(T.target.value),_e(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:Ne||ut,"aria-describedby":Be?"direct-import-error":void 0,autoFocus:!0}),Be?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lt(!1),disabled:Ne||ut,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:Ne||ut||!ze.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:at,onOpenChange:Mt,children:s.jsxs(zt,{className:Wt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t(Wt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Bt,{children:t(Wt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),Wt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:T=>{T.preventDefault(),gr()},children:[s.jsx(We,{className:"h-8",value:bt,onChange:T=>Ze(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:!!Xt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Xt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Xt?.localUrl}].map(T=>{const le=Ct===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&&Jt(T.key)},role:"presentation",children:[s.jsx(fo,{checked:le,disabled:!T.available,onChange:()=>Jt(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)})}),Ct==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Xr,{checked:Zt,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,Ct==="relay"&&Xt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Xr,{checked:Zt,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]}),wt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:wt}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Mt(!1),disabled:qe,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:qe||!Xt,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,He?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:He}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:wi,children:[s.jsx(B,{name:se?"check":"file-copy",className:Ie("h-3.5 w-3.5",se&&"text-[var(--status-success)]")}),t(se?"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:()=>Mt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Ge,{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:vi,children:[s.jsx(B,{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,ot=le?.phase,Ft=ot==="ready",bs=Pl(ot),Zs=bs==="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 ${El(ot)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Je})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Al(bs)),bs==="connecting"?` · ${t(Il(ot))}`:"",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:()=>jr(le?.localUrl),children:[s.jsx(B,{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?p(T.id):k(T.id)).catch(zs=>$.error(t(Ft?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:zs instanceof Error?zs.message:String(zs)}))},children:[Ft?s.jsx(B,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(B,{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:()=>C(T.id),children:[s.jsx(B,{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(zs=>$.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:zs instanceof Error?zs.message:String(zs)}))},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),Zs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:Zs}):null]},T.id)})}):null,n?s.jsx(Kt,{open:pn,onOpenChange:Os,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Bt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(mn,{value:Ls,onChange:rn,"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")}]}),Ls==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(We,{className:"h-8",value:Qs,onChange:T=>Ys(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")}):ki.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:ki.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:()=>{yr(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(),ur()},children:[s.jsx(We,{className:"h-8",value:Dt,onChange:T=>qt(T.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:h}),s.jsx(We,{className:"h-8",value:Ks,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:()=>Os(!1),disabled:h,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:h||!Ks.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!q,onOpenChange:T=>{T||ya()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Bt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),$n()},children:[s.jsx(We,{value:J,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:ya,disabled:L,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:L,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const hn=A.remoteOpenchamber.mode==="managed",Bn=hn&&A.remoteOpenchamber.bindHost==="0.0.0.0",Sa=Bn&&!A.auth.openchamberPassword?.value?.trim(),Nr=A.nickname?.trim()||A.sshParsed?.destination||A.id;return s.jsx(Kt,{open:!!A,onOpenChange:T=>{T||C(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Yr} truncate`,children:Nr}),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 ${El(on)}`}),s.jsx("span",{className:"text-foreground",children:t(Al(ba))}),ba==="connecting"?s.jsx("span",{children:t(Il(on))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,xa?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Ge,{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:ln?"outline":"default",size:"xs",className:"!font-normal",onClick:Ci,disabled:te||Q,children:[ln?s.jsx(B,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"plug-2",className:"h-3.5 w-3.5"}),kr]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ii,disabled:!Ai,children:[s.jsx(B,{name:"refresh",className:`h-3.5 w-3.5 ${Un||En&&!xa?"animate-spin":""}`}),Pi]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{wr()},children:[s.jsx(B,{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(()=>{C(null),$.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(le=>{$.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:le instanceof Error?le.message:String(le)})})},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ba==="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}),Wa?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(Wa)}):null,Qn&&!Wa?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{wa(Qn)},children:t(Qn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Qn==="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(Ge,{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(en,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Et,{value:A.remoteOpenchamber.mode,onValueChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,mode:T==="external"?"external":"managed"}})),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Tt,{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:Lt,onOpenChange:Pt,children:[s.jsxs(Nn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:kc,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(B,{name:Lt?"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(fs,{containerClassName:"w-fit",min:5,max:240,step:1,className:Ie(ys,"tabular-nums"),value:A.connectionTimeoutSec,onValueChange:T=>{ds(le=>({...le,connectionTimeoutSec:Number.isFinite(T)?T:le.connectionTimeoutSec}))}})]}),s.jsxs(Ge,{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:Ni,children:s.jsx(en,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(fs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(ys,"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(en,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Et,{value:A.remoteOpenchamber.installMethod,onValueChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,installMethod:T==="npm"||T==="bun"?T:"auto"}})),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Tt,{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(en,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(_a,{checked:Bn,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")})]}),Bn?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(en,{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(_a,{checked:A.remoteOpenchamber.keepRunning,onCheckedChange:T=>ds(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,keepRunning:T}}))})})]}):null]}),s.jsxs(Ge,{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(en,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Et,{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(At,{size:Vt,className:"w-fit min-w-[240px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Tt,{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(en,{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(fs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(ys,"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:qi()}})),children:s.jsx(B,{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(Ge,{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(en,{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(en,{label:t(Bn?"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",Sa&&"border-[var(--status-error)]"),type:"password",ref:ja,"aria-invalid":Sa,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")})]}),Sa?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(Ge,{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=Ot=>{ds(Qt=>({...Qt,portForwards:Qt.portForwards.map((xn,cn)=>cn===le?Ot(xn):xn)}))},ot=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.",bs=T.type==="remote"?"Remote listen":"Remote target",Zs=T.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",ms=Dl(T.localHost||"localhost",T.localPort),zs=Dl(T.remoteHost||"localhost",T.remotePort),Dn=T.type==="local"&&typeof T.localPort=="number"&&T.localPort>0,fn=Dn?`http://${Kf(T.localHost)}:${T.localPort}`:"",Ca=!!Z[T.id],Ia=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:Ca,onOpenChange:Ot=>{U(Qt=>({...Qt,[T.id]:Ot}))},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(B,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ca?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Rf(T)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ia})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_a,{checked:T.enabled,onCheckedChange:Ot=>Je(Qt=>({...Qt,enabled:Ot})),"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(Ot=>({...Ot,portForwards:Ot.portForwards.filter(Qt=>Qt.id!==T.id)})),children:s.jsx(B,{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(en,{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(Lf(T.type))})]})})}),s.jsxs(Et,{value:T.type,onValueChange:Ot=>Je(Qt=>({...Qt,type:Ot==="dynamic"||Ot==="remote"?Ot:"local"})),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Tt,{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(en,{label:ot,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:Ot=>Je(Qt=>({...Qt,localHost:Ot.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(fs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(ys,"tabular-nums"),value:T.localPort,onValueChange:Ot=>{Je(Qt=>({...Qt,localPort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{Je(Ot=>({...Ot,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(en,{label:bs,hint:Zs})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:T.remoteHost||"",onChange:Ot=>Je(Qt=>({...Qt,remoteHost:Ot.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(fs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(ys,"tabular-nums"),value:T.remotePort,onValueChange:Ot=>{Je(Qt=>({...Qt,remotePort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{Je(Ot=>({...Ot,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(B,{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")})]}):T.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:zs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(B,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(B,{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(B,{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(B,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(B,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:zs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Dn?s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(fn).then(Ot=>{Ot||$.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(B,{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=Ff();ds(le=>({...le,portForwards:[...le.portForwards,T]})),U(le=>({...le,[T.id]:!0}))},children:[s.jsx(B,{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:()=>{vr()},disabled:!br||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:()=>{oi(js.localUrl||"").then(T=>{T.ok&&$.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(B,{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:()=>{Si()},children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,m?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:m}):null]})}),D,s.jsx(Kt,{open:I,onOpenChange:E,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Bt,{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:us,disabled:F||!je.trim(),children:[s.jsx(B,{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:()=>{Na()},disabled:F,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),F?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):S?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:S}):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:z.length>0?z.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!q,onOpenChange:T=>{T||ya()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Bt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:T=>{T.preventDefault(),$n()},children:[s.jsx(We,{value:J,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:ya,disabled:L,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:L,children:t("settings.common.actions.create")})]})]})]})})]})})},Hf="__add_provider__",qf=()=>{const t=un.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Gf=({onItemSelect:t})=>{const{t:e}=Xe(),a=Ws(),n=it(v=>Nc(v,a)),r=it(v=>v.selectedProviderId),i=it(v=>v.setSelectedProvider),l=an(v=>v.activeProjectId),[d,c]=o.useState({}),h=o.useMemo(()=>a||qf(),[l,a]),m=it(v=>v.loadProviders);o.useEffect(()=>{a&&m({directory:a,source:"settings:providers"})},[m,a]),o.useEffect(()=>{if(n.length===0){c({});return}let v=!1;return(async()=>{const b=n.map(async k=>{try{const p=h?`?directory=${encodeURIComponent(h)}`:"",N=await Nt(`/api/provider/${encodeURIComponent(k.id)}/source${p}`,{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const P=await N.json().catch(()=>null),C=P?.sources??P?.data?.sources;if(!C||v)return;c(w=>({...w,[k.id]:C}))}catch{}});await Promise.all(b)})(),()=>{v=!0}},[h,n]);const f="bg-background",u=o.useMemo(()=>n.filter(v=>!!d[v.id]?.project?.exists),[n,d]),g=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(fi,{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(Hf),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{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(B,{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:[g.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")}),g.map(v=>s.jsx(Rl,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]}),u.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",g.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),u.map(v=>s.jsx(Rl,{provider:v,selectedProviderId:r,onSelect:()=>{i(v.id),t?.()}},v.id))]})]})})]})},Rl=t=>{const e=rt.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 m;e[2]!==a.id?(m=s.jsx(sa,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=m):m=e[3];const f=a.name||a.id;let u;e[4]!==f?(u=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:f}),e[4]=f,e[5]=u):u=e[5];let g;e[6]!==i?(g=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=g):g=e[7];let v;e[8]!==r||e[9]!==m||e[10]!==u||e[11]!==g?(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:[m,u,g]}),e[8]=r,e[9]=m,e[10]=u,e[11]=g,e[12]=v):v=e[12];let j;return e[13]!==a.id||e[14]!==h||e[15]!==v?(j=s.jsx("div",{className:h,children:v},d),e[13]=a.id,e[14]=h,e[15]=v,e[16]=j):j=e[16],j},Wf=t=>t,Jf=(t,e,a)=>t&&!e&&!a,ea=(t,e)=>t.find(a=>a.id===e),ii=t=>t==="opencode-go"?"opencode":t,Fl=(t,e)=>{const a=ea(t,e)?.connections,n=ii(e);if(n===e)return a;const r=ea(t,n)?.connections;if(!(!a&&!r))return[...a??[],...r??[]]},Ol=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Qf=t=>(t?.methods??[]).find(e=>e.type==="key"),Ll=t=>t===void 0||Qf(t)!==void 0,Yf=t=>(t?.connections??[]).filter(e=>e.type==="credential"),Kl=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,Zf=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),Xf=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,To={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},Xn="__custom_provider__",ex=/^[a-z0-9][a-z0-9-_]*$/,rd=/^https?:\/\//,tx=/^\{env:([^}]+)\}$/,Xi=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},od=t=>t.settings&&typeof t.settings=="object"?t.settings:t.options&&typeof t.options=="object"?t.options:{};let sx=0;const er=()=>`row-${sx++}`,Eo=()=>({row:er(),id:"",name:"",variants:""});function nx(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 ax(t){const e=t.split(/[,\s]+/).map(a=>a.trim()).filter(Boolean);return e.filter((a,n)=>e.indexOf(a)===n)}function ix(t){return Object.fromEntries((t??[]).map(({id:e,...a})=>[e,a]))}const Do=()=>({row:er(),key:"",value:""}),rx=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Eo()],headers:[Do()]});function ox(t){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 lx(t){const e=t.trim();if(!e)return{};const n=e.match(tx)?.[1]?.trim();return n?{env:n}:{key:e}}function cx(t){const e=od(t),a=typeof e.baseURL=="string"?e.baseURL.trim():"";if(a&&rd.test(a))return!0;const n=new Set(Object.values(To));return n.has(Xi(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(Xi(i)??""))}function zl(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&cx(t):!1}function _l(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function dx(t){const e=od(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,m])=>({row:er(),key:h,value:m})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([h,m])=>{const f=m&&typeof m=="object"?m:{};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:void 0}}):[],l=i.length>0?i.map(h=>{const m=typeof h?.modelID=="string"&&h.modelID?h.modelID:typeof h?.id=="string"?h.id:"",f=ix(h?.variants);return{row:er(),id:m,name:typeof h?.name=="string"?h.name:m,variants:Object.keys(f).join(", "),savedVariants:f}}):[Eo()],d=Array.isArray(t.env)?t.env.find(h=>typeof h=="string"&&h.trim().length>0)?.trim():void 0,c=i.map(h=>Xi(h)).find(h=>!!h);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:ox(Xi(t)??c),baseURL:a,apiKey:d?`{env:${d}}`:"",models:l,headers:r.length>0?r:[Do()]}}function ux(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:r,key:i}=lx(t.form.apiKey),l=t.disabledProviders??[],d=t.editingProviderID?.trim(),c=e?ex.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"),m=n?rd.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),u=!!(r||i||d&&t.allowExistingAuth&&d===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),g=l.includes(e),j=c||!!(d&&d===e)?void 0:t.existingProviderIDs.has(e)&&!g?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(R=>{const I=R.id.trim(),E=I?b.has(I)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(I):t.t("settings.providers.page.custom.error.required"),F=R.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:E,name:F}}),p=k.every(R=>!R.id&&!R.name),N=Object.fromEntries(t.form.models.map(R=>{const I=R.id.trim(),E={modelID:I,name:R.name.trim()},F=ax(R.variants);return(F.length>0||R.savedVariants!==void 0)&&(E.variants=F.map(K=>({id:K,...R.savedVariants?.[K]??nx(t.form.protocol,K)}))),[I,E]})),P=new Set,C=t.form.headers.map(R=>{const I=R.key.trim(),E=R.value.trim();if(!I&&!E)return{};const F=I?P.has(I.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void P.add(I.toLowerCase()):t.t("settings.providers.page.custom.error.required"),K=E?void 0:t.t("settings.providers.page.custom.error.required");return{key:F,value:K}}),w=C.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??j,name:h,baseURL:m,apiKey:u};return!c&&!j&&!h&&!m&&!u&&p&&w?{err:x,models:k,headers:C,result:{providerID:e,name:a,apiKey:i,config:mx({protocol:t.form.protocol,name:a,env:r,baseURL:n,headers:D,models:N})}}:{err:x,models:k,headers:C}}function mx(t){const e={package:To[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 px(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function gx(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Ul=t=>{const e=rt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:d,authFailureHint:c,onSubmit:h,onCancel:m,onDisconnect:f}=t;let u;e[0]!==n?(u=n===void 0?[]:n,e[0]=n,e[1]=u):u=e[1];const g=u,v=r===void 0?!1:r,j=i===void 0?"create":i,b=d===void 0?!1:d,k=c===void 0?null:c,{t:p}=Xe(),N=j==="edit";let P;e[2]!==l?(P=()=>l??rx(),e[2]=l,e[3]=P):P=e[3];const[C,w]=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[I,E]=o.useState(R);let F;e[6]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[6]=F):F=e[6];const[K,S]=o.useState(F),M=o.useRef(null);let z,_;e[7]!==l||e[8]!==N?(z=()=>{l&&(N&&M.current===l.providerID||(M.current=N?l.providerID:null,w(l),A({}),E([]),S([])))},_=[l,N],e[7]=l,e[8]=N,e[9]=z,e[10]=_):(z=e[9],_=e[10]),o.useEffect(z,_);let q;e[11]===Symbol.for("react.memo_cache_sentinel")?(q=(Dt,qt)=>{w(Lt=>({...Lt,[Dt]:qt})),A(Lt=>({...Lt,[Dt]:void 0}))},e[11]=q):q=e[11];const X=q;let J;e[12]===Symbol.for("react.memo_cache_sentinel")?(J=(Dt,qt,Lt)=>{w(Pt=>({...Pt,models:Pt.models.map((is,ss)=>ss===Dt?{...is,[qt]:Lt}:is)})),E(Pt=>{const is=[...Pt];return is[Dt]={...is[Dt]??{},[qt]:void 0},is})},e[12]=J):J=e[12];const H=J;let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=(Dt,qt,Lt)=>{w(Pt=>({...Pt,headers:Pt.headers.map((is,ss)=>ss===Dt?{...is,[qt]:Lt}:is)})),S(Pt=>{const is=[...Pt];return is[Dt]={...is[Dt]??{},[qt]:void 0},is})},e[13]=L):L=e[13];const V=L;let Z;e[14]!==b||e[15]!==v||e[16]!==g||e[17]!==a||e[18]!==C||e[19]!==N||e[20]!==h||e[21]!==p?(Z=async Dt=>{if(Dt.preventDefault(),v)return;const qt=ux({form:C,t:((Lt,Pt)=>p(Lt,Pt)),existingProviderIDs:a,disabledProviders:g,editingProviderID:N?C.providerID:void 0,allowExistingAuth:N&&b});A(qt.err),E(qt.models),S(qt.headers),qt.result&&await h(qt.result)},e[14]=b,e[15]=v,e[16]=g,e[17]=a,e[18]=C,e[19]=N,e[20]=h,e[21]=p,e[22]=Z):Z=e[22];const U=Z;let te;e[23]!==N||e[24]!==p?(te=p(N?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=N,e[24]=p,e[25]=te):te=e[25];let O;e[26]!==p?(O=p("settings.providers.page.custom.description"),e[26]=p,e[27]=O):O=e[27];let Q;e[28]!==O?(Q=s.jsx("p",{className:Ss,children:O}),e[28]=O,e[29]=Q):Q=e[29];let ce;e[30]!==k?(ce=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=ce):ce=e[31];let de;e[32]!==p?(de=p("settings.providers.page.custom.field.providerID.label"),e[32]=p,e[33]=de):de=e[33];let pe;e[34]!==p?(pe=p("settings.providers.page.custom.field.providerID.info"),e[34]=p,e[35]=pe):pe=e[35];const re=C.providerID;let Ce;e[36]===Symbol.for("react.memo_cache_sentinel")?(Ce=Dt=>X("providerID",Dt.target.value),e[36]=Ce):Ce=e[36];let ie;e[37]!==p?(ie=p("settings.providers.page.custom.field.providerID.placeholder"),e[37]=p,e[38]=ie):ie=e[38];const be=!N,ae=N||v,fe=!!x.providerID;let xe;e[39]!==p?(xe=p("settings.providers.page.custom.field.providerID.label"),e[39]=p,e[40]=xe):xe=e[40];let Oe;e[41]!==C.providerID||e[42]!==ie||e[43]!==be||e[44]!==ae||e[45]!==fe||e[46]!==xe?(Oe=s.jsx(We,{value:re,onChange:Ce,placeholder:ie,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:be,disabled:ae,"aria-invalid":fe,"aria-label":xe}),e[41]=C.providerID,e[42]=ie,e[43]=be,e[44]=ae,e[45]=fe,e[46]=xe,e[47]=Oe):Oe=e[47];let Ne;e[48]!==x.providerID?(Ne=x.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.providerID}):null,e[48]=x.providerID,e[49]=Ne):Ne=e[49];let he;e[50]!==de||e[51]!==pe||e[52]!==Oe||e[53]!==Ne?(he=s.jsxs(Rt,{label:de,info:pe,children:[Oe,Ne]}),e[50]=de,e[51]=pe,e[52]=Oe,e[53]=Ne,e[54]=he):he=e[54];let Te;e[55]!==p?(Te=p("settings.providers.page.custom.field.protocol.label"),e[55]=p,e[56]=Te):Te=e[56];let we;e[57]!==p?(we=p("settings.providers.page.custom.field.protocol.info"),e[57]=p,e[58]=we):we=e[58];const De=C.protocol;let ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(ve=Dt=>{Dt in To&&w(qt=>({...qt,protocol:Dt,models:qt.models.map(hx)}))},e[59]=ve):ve=e[59];let ee;e[60]!==p?(ee=p("settings.providers.page.custom.field.protocol.label"),e[60]=p,e[61]=ee):ee=e[61];let ne;e[62]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(_t,{}),e[62]=ne):ne=e[62];let ye;e[63]!==ee?(ye=s.jsx(At,{"aria-label":ee,className:"w-full",children:ne}),e[63]=ee,e[64]=ye):ye=e[64];let Ae;e[65]!==p?(Ae=p("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=p,e[66]=Ae):Ae=e[66];let ze;e[67]!==Ae?(ze=s.jsx(mt,{value:"openai-chat",children:Ae}),e[67]=Ae,e[68]=ze):ze=e[68];let Qe;e[69]!==p?(Qe=p("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=p,e[70]=Qe):Qe=e[70];let Be;e[71]!==Qe?(Be=s.jsx(mt,{value:"openai-responses",children:Qe}),e[71]=Qe,e[72]=Be):Be=e[72];let _e;e[73]!==p?(_e=p("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=p,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 nt;e[77]!==ze||e[78]!==Be||e[79]!==Me?(nt=s.jsxs(Tt,{children:[ze,Be,Me]}),e[77]=ze,e[78]=Be,e[79]=Me,e[80]=nt):nt=e[80];let pt;e[81]!==v||e[82]!==C.protocol||e[83]!==ye||e[84]!==nt?(pt=s.jsxs(Et,{value:De,onValueChange:ve,disabled:v,children:[ye,nt]}),e[81]=v,e[82]=C.protocol,e[83]=ye,e[84]=nt,e[85]=pt):pt=e[85];let lt;e[86]!==Te||e[87]!==we||e[88]!==pt?(lt=s.jsx(Rt,{label:Te,info:we,children:pt}),e[86]=Te,e[87]=we,e[88]=pt,e[89]=lt):lt=e[89];let ut;e[90]!==p?(ut=p("settings.providers.page.custom.field.name.label"),e[90]=p,e[91]=ut):ut=e[91];let ht;e[92]!==p?(ht=p("settings.providers.page.custom.field.name.info"),e[92]=p,e[93]=ht):ht=e[93];const Ue=C.name;let st;e[94]===Symbol.for("react.memo_cache_sentinel")?(st=Dt=>X("name",Dt.target.value),e[94]=st):st=e[94];let ue;e[95]!==p?(ue=p("settings.providers.page.custom.field.name.placeholder"),e[95]=p,e[96]=ue):ue=e[96];const oe=!!x.name;let Pe;e[97]!==p?(Pe=p("settings.providers.page.custom.field.name.label"),e[97]=p,e[98]=Pe):Pe=e[98];let Re;e[99]!==C.name||e[100]!==ue||e[101]!==oe||e[102]!==Pe?(Re=s.jsx(We,{value:Ue,onChange:st,placeholder:ue,className:"h-8 rounded-md px-3","aria-invalid":oe,"aria-label":Pe}),e[99]=C.name,e[100]=ue,e[101]=oe,e[102]=Pe,e[103]=Re):Re=e[103];let Fe;e[104]!==x.name?(Fe=x.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.name}):null,e[104]=x.name,e[105]=Fe):Fe=e[105];let $e;e[106]!==ut||e[107]!==ht||e[108]!==Re||e[109]!==Fe?($e=s.jsxs(Rt,{label:ut,info:ht,children:[Re,Fe]}),e[106]=ut,e[107]=ht,e[108]=Re,e[109]=Fe,e[110]=$e):$e=e[110];let W;e[111]!==p?(W=p("settings.providers.page.custom.field.baseURL.label"),e[111]=p,e[112]=W):W=e[112];let Ve;e[113]!==p?(Ve=p("settings.providers.page.custom.field.baseURL.info"),e[113]=p,e[114]=Ve):Ve=e[114];const et=C.baseURL;let dt;e[115]===Symbol.for("react.memo_cache_sentinel")?(dt=Dt=>X("baseURL",Dt.target.value),e[115]=dt):dt=e[115];let ct;e[116]!==p?(ct=p("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=p,e[117]=ct):ct=e[117];const jt=!!x.baseURL;let kt;e[118]!==p?(kt=p("settings.providers.page.custom.field.baseURL.label"),e[118]=p,e[119]=kt):kt=e[119];let yt;e[120]!==C.baseURL||e[121]!==ct||e[122]!==jt||e[123]!==kt?(yt=s.jsx(We,{value:et,onChange:dt,placeholder:ct,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":jt,"aria-label":kt}),e[120]=C.baseURL,e[121]=ct,e[122]=jt,e[123]=kt,e[124]=yt):yt=e[124];let bt;e[125]!==x.baseURL?(bt=x.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.baseURL}):null,e[125]=x.baseURL,e[126]=bt):bt=e[126];let Ze;e[127]!==W||e[128]!==Ve||e[129]!==yt||e[130]!==bt?(Ze=s.jsxs(Rt,{label:W,info:Ve,children:[yt,bt]}),e[127]=W,e[128]=Ve,e[129]=yt,e[130]=bt,e[131]=Ze):Ze=e[131];let wt;e[132]!==p?(wt=p("settings.providers.page.custom.field.apiKey.label"),e[132]=p,e[133]=wt):wt=e[133];let Le;e[134]!==b||e[135]!==N||e[136]!==p?(Le=p(N&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=N,e[136]=p,e[137]=Le):Le=e[137];const He=C.apiKey;let Y;e[138]===Symbol.for("react.memo_cache_sentinel")?(Y=Dt=>X("apiKey",Dt.target.value),e[138]=Y):Y=e[138];let me;e[139]!==b||e[140]!==N||e[141]!==p?(me=p(N&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=N,e[141]=p,e[142]=me):me=e[142];const Ke=!!x.apiKey;let Ee;e[143]!==p?(Ee=p("settings.providers.page.custom.field.apiKey.label"),e[143]=p,e[144]=Ee):Ee=e[144];let Ye;e[145]!==C.apiKey||e[146]!==me||e[147]!==Ke||e[148]!==Ee?(Ye=s.jsx(We,{type:"password",value:He,onChange:Y,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ke,"aria-label":Ee}),e[145]=C.apiKey,e[146]=me,e[147]=Ke,e[148]=Ee,e[149]=Ye):Ye=e[149];let se;e[150]!==x.apiKey?(se=x.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.apiKey}):null,e[150]=x.apiKey,e[151]=se):se=e[151];let ke;e[152]!==wt||e[153]!==Le||e[154]!==Ye||e[155]!==se?(ke=s.jsxs(Rt,{label:wt,info:Le,children:[Ye,se]}),e[152]=wt,e[153]=Le,e[154]=Ye,e[155]=se,e[156]=ke):ke=e[156];let at;e[157]!==te||e[158]!==Q||e[159]!==ce||e[160]!==he||e[161]!==lt||e[162]!==$e||e[163]!==Ze||e[164]!==ke?(at=s.jsxs(Ge,{title:te,divider:!1,settingsItem:"providers.custom",contentClassName:Ms,children:[Q,ce,he,lt,$e,Ze,ke]}),e[157]=te,e[158]=Q,e[159]=ce,e[160]=he,e[161]=lt,e[162]=$e,e[163]=Ze,e[164]=ke,e[165]=at):at=e[165];let Mt;e[166]!==p?(Mt=p("settings.providers.page.custom.models.title"),e[166]=p,e[167]=Mt):Mt=e[167];let Wt;if(e[168]!==C.models||e[169]!==I||e[170]!==p){let Dt;e[172]!==C.models.length||e[173]!==I||e[174]!==p?(Dt=(qt,Lt)=>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:It,children:p("settings.providers.page.custom.models.idLabel")}),s.jsx(We,{value:qt.id,onChange:Pt=>H(Lt,"id",Pt.target.value),placeholder:p("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":p("settings.providers.page.custom.models.idLabel")}),I[Lt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Lt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:It,children:p("settings.providers.page.custom.models.nameLabel")}),s.jsx(We,{value:qt.name,onChange:Pt=>H(Lt,"name",Pt.target.value),placeholder:p("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":p("settings.providers.page.custom.models.nameLabel")}),I[Lt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Lt]?.name}):null]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:It,children:p("settings.providers.page.custom.models.variantsLabel")}),s.jsx(Ht,{children:p("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(We,{value:qt.variants,onChange:Pt=>H(Lt,"variants",Pt.target.value),placeholder:p("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":p("settings.providers.page.custom.models.variantsLabel")})]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:C.models.length<=1,onClick:()=>{C.models.length<=1||(w(Pt=>({...Pt,models:Pt.models.filter((is,ss)=>ss!==Lt)})),E(Pt=>Pt.filter((is,ss)=>ss!==Lt)))},"aria-label":p("settings.providers.page.custom.models.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},qt.row),e[172]=C.models.length,e[173]=I,e[174]=p,e[175]=Dt):Dt=e[175],Wt=C.models.map(Dt),e[168]=C.models,e[169]=I,e[170]=p,e[171]=Wt}else Wt=e[171];let Se;e[176]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>{w(fx),E(xx)},e[176]=Se):Se=e[176];let qe;e[177]!==p?(qe=p("settings.providers.page.custom.models.add"),e[177]=p,e[178]=qe):qe=e[178];let vt;e[179]!==qe?(vt=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Se,children:qe}),e[179]=qe,e[180]=vt):vt=e[180];let Ct;e[181]!==Mt||e[182]!==Wt||e[183]!==vt?(Ct=s.jsxs(Ge,{title:Mt,contentClassName:Ms,children:[Wt,vt]}),e[181]=Mt,e[182]=Wt,e[183]=vt,e[184]=Ct):Ct=e[184];let Jt;e[185]!==p?(Jt=p("settings.providers.page.custom.headers.title"),e[185]=p,e[186]=Jt):Jt=e[186];let Zt;e[187]!==p?(Zt=p("settings.providers.page.custom.headers.description"),e[187]=p,e[188]=Zt):Zt=e[188];let ts;e[189]!==Zt?(ts=s.jsx("p",{className:Ss,children:Zt}),e[189]=Zt,e[190]=ts):ts=e[190];let Xt;if(e[191]!==C.headers||e[192]!==K||e[193]!==p){let Dt;e[195]!==C.headers.length||e[196]!==K||e[197]!==p?(Dt=(qt,Lt)=>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:It,children:p("settings.providers.page.custom.headers.keyLabel")}),s.jsx(We,{value:qt.key,onChange:Pt=>V(Lt,"key",Pt.target.value),placeholder:p("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":p("settings.providers.page.custom.headers.keyLabel")}),K[Lt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:K[Lt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:It,children:p("settings.providers.page.custom.headers.valueLabel")}),s.jsx(We,{value:qt.value,onChange:Pt=>V(Lt,"value",Pt.target.value),placeholder:p("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":p("settings.providers.page.custom.headers.valueLabel")}),K[Lt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:K[Lt]?.value}):null]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:C.headers.length<=1,onClick:()=>{C.headers.length<=1||(w(Pt=>({...Pt,headers:Pt.headers.filter((is,ss)=>ss!==Lt)})),S(Pt=>Pt.filter((is,ss)=>ss!==Lt)))},"aria-label":p("settings.providers.page.custom.headers.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},qt.row),e[195]=C.headers.length,e[196]=K,e[197]=p,e[198]=Dt):Dt=e[198],Xt=C.headers.map(Dt),e[191]=C.headers,e[192]=K,e[193]=p,e[194]=Xt}else Xt=e[194];let Fs;e[199]===Symbol.for("react.memo_cache_sentinel")?(Fs=()=>{w(bx),S(vx)},e[199]=Fs):Fs=e[199];let Js;e[200]!==p?(Js=p("settings.providers.page.custom.headers.add"),e[200]=p,e[201]=Js):Js=e[201];let pn;e[202]!==Js?(pn=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Fs,children:Js}),e[202]=Js,e[203]=pn):pn=e[203];let Os;e[204]!==Jt||e[205]!==ts||e[206]!==Xt||e[207]!==pn?(Os=s.jsxs(Ge,{title:Jt,contentClassName:Ms,children:[ts,Xt,pn]}),e[204]=Jt,e[205]=ts,e[206]=Xt,e[207]=pn,e[208]=Os):Os=e[208];let Ls;e[209]!==v||e[210]!==m||e[211]!==p?(Ls=m?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:m,disabled:v,children:p("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=m,e[211]=p,e[212]=Ls):Ls=e[212];let rn;e[213]!==v||e[214]!==f||e[215]!==p?(rn=f?s.jsx(G,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{f()},disabled:v,children:p("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=f,e[215]=p,e[216]=rn):rn=e[216];let Qs;e[217]!==v||e[218]!==N||e[219]!==p?(Qs=p(v?"settings.providers.page.actions.saving":N?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=v,e[218]=N,e[219]=p,e[220]=Qs):Qs=e[220];let Ys;e[221]!==v||e[222]!==Qs?(Ys=s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:Qs}),e[221]=v,e[222]=Qs,e[223]=Ys):Ys=e[223];let Ks;e[224]!==Ls||e[225]!==rn||e[226]!==Ys?(Ks=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Ls,rn,Ys]}),e[224]=Ls,e[225]=rn,e[226]=Ys,e[227]=Ks):Ks=e[227];let Tn;return e[228]!==U||e[229]!==at||e[230]!==Ct||e[231]!==Os||e[232]!==Ks?(Tn=s.jsxs("form",{onSubmit:U,className:"space-y-0",children:[at,Ct,Os,Ks]}),e[228]=U,e[229]=at,e[230]=Ct,e[231]=Os,e[232]=Ks,e[233]=Tn):Tn=e[233],Tn};function hx(t){return t.savedVariants?{...t,savedVariants:{}}:t}function fx(t){return{...t,models:[...t.models,Eo()]}}function xx(t){return[...t,{}]}function bx(t){return{...t,headers:[...t.headers,Do()]}}function vx(t){return[...t,{}]}const yx=t=>new Intl.NumberFormat(vo(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),$l=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=yx(t);return e.endsWith(".0")?e.slice(0,-2):e},Xa="__add_provider__",ld=t=>typeof t=="object"&&t!==null,jx=t=>{if(typeof t=="string")return{id:t};if(!ld(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}},wx=t=>{let e=[];Array.isArray(t)?e=t:ld(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(r=>jx(r)).filter(r=>!!r),n=new Set;return a.filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))},kx=es(),Bl=t=>kx.safeParse(t?.settings?.apiKey).data??null,Nx=()=>{const{t}=Xe(),e=Ws(),a=it(ue=>Nc(ue,e)),n=it(ue=>ue.selectedProviderId),r=it(ue=>ue.setSelectedProvider),i=it(ue=>ue.getModelMetadata),l=ge(ue=>ue.hiddenModels),d=ge(ue=>ue.toggleHiddenModel),c=ge(ue=>ue.hideAllModels),h=ge(ue=>ue.showAllModels),[m,f]=o.useState(null),[u,g]=o.useState(!1),[v,j]=o.useState({}),[b,k]=o.useState(null),[p,N]=o.useState(""),[P,C]=o.useState([]),[w,D]=o.useState(!1),[x,A]=o.useState(null),[R,I]=o.useState(""),[E,F]=o.useState(""),[K,S]=o.useState(!1),[M,z]=o.useState({}),[_,q]=o.useState(0),[X,J]=o.useState(0),[H,L]=o.useState(!1),[V,Z]=o.useState(null),[U,te]=o.useState(null),[O,Q]=o.useState(null),[ce,de]=o.useState(null),[pe,re]=o.useState(null),[Ce,ie]=o.useState(null),be=n===Xa,ae=be&&R===Xn,fe=!!(U&&n&&U===n&&!be);o.useEffect(()=>{!n&&a.length>0&&r(a[0].id)},[a,n,r]),o.useEffect(()=>{if(!n)return;let ue=!0;return(async()=>{g(!0);try{const{data:Pe}=await un.getSdkClient().integration.list();if(!ue)return;f(Pe)}catch(Pe){if(!ue)return;console.error("Failed to load provider integrations:",Pe),$.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{ue&&g(!1)}})(),()=>{ue=!1}},[n,X,t]),o.useEffect(()=>{if(!Wf(be))return;let ue=!0;return(async()=>{D(!0),A(null);try{const[{data:Pe},Re]=await Promise.all([un.getSdkClient().integration.list(),Gd(un.getDirectory()??null).catch(()=>null)]);if(!ue)return;const Fe=new Set((Re??[]).map($e=>$e.id));C(wx(Pe.filter($e=>!$e.id.startsWith("mcp_")&&!Fe.has($e.id)&&$e.connections.length===0)))}catch(Pe){if(!ue)return;console.error("Failed to load available providers:",Pe),A(t("settings.providers.page.state.unableToLoadProviderList"))}finally{ue&&D(!1)}})(),()=>{ue=!1}},[be,t]);const xe=o.useMemo(()=>new Set(a.map(ue=>ue.id)),[a]),Oe=o.useMemo(()=>P.filter(ue=>!xe.has(ue.id)).sort((ue,oe)=>{const Pe=(ue.name||ue.id).toLowerCase(),Re=(oe.name||oe.id).toLowerCase();return Pe.localeCompare(Re)}),[P,xe]);o.useEffect(()=>{n===Xa&&R&&R!==Xn&&!Oe.some(ue=>ue.id===R)&&I("")},[n,R,Oe]),o.useEffect(()=>{if(n===Xa){L(!0),Z(null),te(null),Q(null),de(null),re(null);return}L(!1),Z(null),U&&U!==n&&(te(null),Q(null),de(null),re(null))},[n,U]),o.useEffect(()=>{if(!n||n===Xa)return;const ue=M[n];if(!ue||m===null)return;const oe=a.find(Fe=>Fe.id===n),Pe=Kl({connections:Fl(m,n),optionsApiKey:Bl(oe)}),Re=!!(oe&&zl(oe,ue));Xf({hasCredentials:Pe,userDismissed:V===n,isEditableCustomProvider:Re})&&L(!0)},[n,M,a,m,V]),o.useEffect(()=>{if(!n||n===Xa)return;let ue=!1;return(async()=>{try{const Pe=e?`?directory=${encodeURIComponent(e)}`:"",Re=await Nt(`/api/provider/${encodeURIComponent(n)}/source${Pe}`,{method:"GET",headers:{Accept:"application/json"}}),Fe=await Re.json().catch(()=>null);if(!Re.ok)throw new Error(Fe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const $e=Fe?.sources??Fe?.data?.sources;!ue&&$e&&z(W=>({...W,[n]:$e}))}catch(Pe){ue||console.error("Failed to load provider sources:",Pe)}})(),()=>{ue=!0}},[n,_,e,t]);const Ne=o.useCallback(()=>{q(ue=>ue+1)},[]),he=o.useCallback(()=>{J(ue=>ue+1)},[]),Te=o.useCallback(ue=>{f(oe=>(oe??[]).map(Pe=>Pe.id===ue&&Pe.connections.length===0?{...Pe,connections:[{type:"credential",id:`pending:${ue}`,label:ue,method:"key"}]}:Pe)),Z(null),L(!1),r(ue),Ne(),he()},[he,Ne,r]),we=a.find(ue=>ue.id===n),De=n?M[n]:void 0,ve=async ue=>{const oe=v[ue]?.trim()??"";if(!oe){$.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Pe=`api:${ue}`;k(Pe);try{await un.getSdkClient().integration.connect.key({integrationID:ue,key:oe}),$.success(t("settings.providers.page.toast.apiKeySaved")),j(Re=>({...Re,[ue]:""})),Te(ue)}catch(Re){console.error("Failed to save API key:",Re),$.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},ee=async ue=>{const oe=`custom:${ue.providerID}`;k(oe),ie(ue.providerID),re(null);try{const Pe=px(ue);Pe&&await un.getSdkClient().integration.connect.key(Pe);const Re=gx(ue,{scope:U?ce??_l(M[U]):"user"}),Fe=await Nt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Re)}),$e=await Fe.json().catch(()=>null);if(!Fe.ok)throw Pe&&re(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error($e?.error||t("settings.providers.page.toast.customProviderSaveFailed"));$.success(t("settings.providers.page.toast.customProviderSaved",{provider:ue.name})),I(""),te(null),Q(null),de(null),re(null),ie(null),Te(ue.providerID)}catch(Pe){console.error("Failed to save custom provider:",Pe),$.error(Pe instanceof Error&&Pe.message?Pe.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},ne=ue=>{L(!1),Te(ue)},ye=async ue=>{const oe=`disconnect:${ue}`;k(oe);try{const Pe=Yf(ea(m??[],ue)),Re=un.getSdkClient();for(const Fe of Pe)await Re.credential.remove({credentialID:Fe.id});$.success(t("settings.providers.page.toast.providerDisconnected")),Z(null),Ne(),he()}catch(Pe){console.error("Failed to disconnect provider:",Pe),$.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},Ae=async ue=>{ue&&(await ye(ue),te(null),Q(null),de(null),re(null),ie(null),I(""))};if(!be&&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(B,{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(be)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(Ge,{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")}),w?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(_n,{open:K,onOpenChange:ue=>{S(ue),ue||F("")},children:[s.jsx(zn,{asChild:!0,children:s.jsxs("button",{type:"button",className:qs,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R&&R!==Xn?s.jsx(sa,{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===Xn?t("settings.providers.page.custom.optionLabel"):R?Oe.find(ue=>ue.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Kn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:ue=>ue.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:ue=>ue.stopPropagation(),children:[s.jsx(B,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:E,onChange:ue=>F(ue.target.value),onKeyDown:ue=>ue.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(vs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const ue=t("settings.providers.page.custom.optionLabel"),oe=qd([ue,"other","custom"],E),Pe=mi(Oe,E,Re=>[Re.name||Re.id,Re.id]);return Pe.length===0&&!oe?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:[Pe.map(Re=>s.jsxs(wn,{onSelect:()=>{I(Re.id),S(!1),F("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(sa,{providerId:Re.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Re.name||Re.id})]}),R===Re.id&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Re.id)),oe?s.jsxs(wn,{onSelect:()=>{I(Xn),S(!1),F("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(B,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ue})]}),R===Xn&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Xn):null]})})()})]})]})]})}),ae?s.jsx(Ul,{mode:"create",existingProviderIDs:xe,busy:b?.startsWith("custom:")??!1,authFailureHint:pe,onCancel:()=>{I(""),re(null),ie(null)},onDisconnect:pe&&Ce?()=>{Ae(Ce)}:void 0,onSubmit:ee}):R?s.jsx(Ge,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:u?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const ue=ea(m??[],R),oe=Ol(ea(m??[],ii(R))),Pe=Ll(ue);return s.jsxs(s.Fragment,{children:[Pe?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Ht,{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:Re=>j(Fe=>({...Fe,[R]: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:()=>ve(R),disabled:b===`api:${R}`,children:b===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,oe.length>0?s.jsx(io,{integrationId:ii(R),methods:oe,onConnected:()=>ne(R),className:Ie(Pe&&"border-t border-[var(--surface-subtle)] pt-2")},R):null]})})()})}):null]});if(!we)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(B,{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(we.models)?we.models:[],Qe=ea(m??[],we.id),Be=Ol(ea(m??[],ii(we.id))),_e=Ll(Qe),Me=m!==null,nt=!!De,pt=nt&&zl(we,De),lt=Kl({connections:Fl(m??[],we.id),optionsApiKey:Bl(we)}),ut=Jf(Me,lt,pt),ht=Zf({modelCount:ze.length,integrationsLoaded:Me,hasCredentials:lt,isEditableCustomProvider:pt}),Ue=!_e&&Be.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),st=mi(ze,p,ue=>[typeof ue?.name=="string"?ue.name:"",typeof ue?.id=="string"?ue.id:""]);return fe&&pt&&O?s.jsx(ns,{title:we.name||we.id,titleLeading:s.jsx(sa,{providerId:we.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:we.id}),showSaveStatus:!1,children:s.jsx(Ul,{mode:"edit",existingProviderIDs:xe,initialValues:O,allowExistingAuth:lt||!nt,busy:b?.startsWith("custom:")??!1,authFailureHint:pe,onCancel:()=>{te(null),Q(null),de(null),re(null),ie(null)},onDisconnect:()=>{Ae(we.id)},onSubmit:ee})}):s.jsxs(ns,{title:we.name||we.id,titleLeading:s.jsx(sa,{providerId:we.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:we.id}),showSaveStatus:!1,children:[s.jsx(Ge,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[pt?s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{re(null),Q(dx(we)),de(_l(De)),te(we.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const ue=!H;L(ue),Z(ue?null:we.id)},children:t(H?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:H?u?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:[_e?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(Ht,{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[we.id]??"",onChange:ue=>j(oe=>({...oe,[we.id]:ue.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:()=>ve(we.id),disabled:b===`api:${we.id}`,children:b===`api:${we.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Be.length>0&&s.jsx(io,{integrationId:ii(we.id),methods:Be,onConnected:()=>ne(we.id),className:Ie(_e&&"border-t border-[var(--surface-subtle)] pt-2")},we.id)]}):ut?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(B,{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(Ht,{children:Ue})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(B,{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(Ht,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(Ge,{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:lt||De?.user.exists||De?.project.exists||De?.custom?.exists?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[lt?t("settings.providers.page.connectionDetails.source.authCredentials"):null,De?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,De?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,De?.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:()=>ye(we.id),disabled:b===`disconnect:${we.id}`,children:b===`disconnect:${we.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),ht?s.jsxs(Ge,{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 ue=ze.map(oe=>typeof oe?.id=="string"?oe.id:"").filter(oe=>oe.length>0);c(we.id,ue)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>h(we.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(B,{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:p,onChange:ue=>N(ue.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),st.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:st.map(ue=>{const oe=typeof ue?.id=="string"?ue.id:"",Pe=typeof ue?.name=="string"?ue.name:oe,Re=oe?i(we.id,oe):void 0,Fe=l.some(et=>et.providerID===we.id&&et.modelID===oe),$e=$l(Re?.limit?.context),W=$l(Re?.limit?.output),Ve=[];return Re?.tool_call&&Ve.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Re?.reasoning&&Ve.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Re?.attachment&&Ve.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",Fe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Pe}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[($e||W)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[$e?`${$e} ${t("settings.providers.page.models.tokenBadge.context")}`:"",$e&&W?" · ":"",W?`${W} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),Ve.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ve.map(({key:et,icon:dt,label:ct})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:ct,"aria-label":ct,children:s.jsx(B,{name:dt,className:"h-3 w-3"})},et))}),s.jsx("button",{type:"button",onClick:()=>d(we.id,oe),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(Fe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Fe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Fe?s.jsx(B,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},oe)})})]}):null]})},Sx=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)},Cx=t=>{const e=rt.c(75),{onItemSelect:a}=t,{t:n}=Xe(),r=rs(Ix),i=rs(Px),l=rs(Ax),d=rs(Tx),c=rs(Ex),h=rs(Dx),m=rs(Mx),f=rs(Rx);let u,g;e[0]!==f?(u=()=>{f()},g=[f],e[0]=f,e[1]=u,e[2]=g):(u=e[1],g=e[2]),o.useEffect(u,g);const v=Fx;let j;e[3]!==m?(j=Q=>{Q!=="usage"&&Q!=="remaining"||(m(Q),v({usageDisplayMode:Q}))},e[3]=m,e[4]=j):j=e[4];const b=j;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 p;e[6]!==n?(p=n("settings.usage.sidebar.title"),e[6]=n,e[7]=p):p=e[7];let N;e[8]!==p?(N=s.jsx("h2",{className:`${Pn} mb-3`,children:p}),e[8]=p,e[9]=N):N=e[9];let P;e[10]!==n?(P=n("settings.usage.sidebar.total",{count:Wi.length}),e[10]=n,e[11]=P):P=e[11];let C;e[12]!==P?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[12]=P,e[13]=C):C=e[13];let w;e[14]!==d?(w=()=>d(),e[14]=d,e[15]=w):w=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 I;e[22]!==R?(I=s.jsx(B,{name:"refresh",className:R}),e[22]=R,e[23]=I):I=e[23];let E;e[24]!==c||e[25]!==D||e[26]!==x||e[27]!==I||e[28]!==w?(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:w,"aria-label":D,title:x,disabled:c,children:I})}),e[24]=c,e[25]=D,e[26]=x,e[27]=I,e[28]=w,e[29]=E):E=e[29];let F;e[30]!==E||e[31]!==C?(F=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,E]}),e[30]=E,e[31]=C,e[32]=F):F=e[32];let K;e[33]!==n?(K=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=K):K=e[34];let S;e[35]!==K?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:K}),e[35]=K,e[36]=S):S=e[36];let M;e[37]!==n?(M=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=M):M=e[38];let z;e[39]!==M?(z=s.jsx(At,{className:"w-fit",children:s.jsx(_t,{placeholder:M})}),e[39]=M,e[40]=z):z=e[40];let _;e[41]!==n?(_=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=_):_=e[42];let q;e[43]!==_?(q=s.jsx(mt,{value:"usage",children:_}),e[43]=_,e[44]=q):q=e[44];let X;e[45]!==n?(X=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=X):X=e[46];let J;e[47]!==X?(J=s.jsx(mt,{value:"remaining",children:X}),e[47]=X,e[48]=J):J=e[48];let H;e[49]!==q||e[50]!==J?(H=s.jsxs(Tt,{children:[q,J]}),e[49]=q,e[50]=J,e[51]=H):H=e[51];let L;e[52]!==b||e[53]!==z||e[54]!==H||e[55]!==h?(L=s.jsxs(Et,{value:h,onValueChange:b,children:[z,H]}),e[52]=b,e[53]=z,e[54]=H,e[55]=h,e[56]=L):L=e[56];let V;e[57]!==S||e[58]!==L?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[S,L]}),e[57]=S,e[58]=L,e[59]=V):V=e[59];let Z;e[60]!==F||e[61]!==V||e[62]!==N?(Z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,F,V]}),e[60]=F,e[61]=V,e[62]=N,e[63]=Z):Z=e[63];let U;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?(U=Wi.map(Q=>{const ce=r.find(be=>be.providerId===Q.id),de=Sx(ce?.usage),pe=Sc(de),re=Q.id===i,Ce=ce?.configured,ie=Ce?pe==="critical"?{backgroundColor:"var(--status-error)"}:pe==="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",re?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(Q.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(sa,{providerId:Q.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:Q.name}),Ce===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},Q.id)}),e[64]=a,e[65]=r,e[66]=i,e[67]=l,e[68]=n,e[69]=U):U=e[69];let te;e[70]!==U?(te=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:U}),e[70]=U,e[71]=te):te=e[71];let O;return e[72]!==Z||e[73]!==te?(O=s.jsxs("div",{className:k,children:[Z,te]}),e[72]=Z,e[73]=te,e[74]=O):O=e[74],O};function Ix(t){return t.results}function Px(t){return t.selectedProviderId}function Ax(t){return t.setSelectedProvider}function Tx(t){return t.fetchAllQuotas}function Ex(t){return t.isLoading}function Dx(t){return t.displayMode}function Mx(t){return t.setDisplayMode}function Rx(t){return t.loadSettings}async function Fx(t){try{await ft(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ox=t=>{const e=rt.c(17),{percent:a,tonePercent:n,className:r}=t;let i;e[0]!==a?(i=Wd(a)??0,e[0]=a,e[1]=i):i=e[1];const l=i,d=n??a;let c;e[2]!==d?(c=Sc(d),e[2]=d,e[3]=c):c=e[3];const h=c;let m;e[4]!==h?(m=h==="critical"?{backgroundColor:"var(--status-error)"}:h==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=h,e[5]=m):m=e[5];const f=m;let u;e[6]!==r?(u=Ie("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=u):u=e[7];const g=`${l}%`;let v;e[8]!==f||e[9]!==g?(v={...f,width:g},e[8]=f,e[9]=g,e[10]=v):v=e[10];let j;e[11]!==l||e[12]!==v?(j=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]=j):j=e[13];let b;return e[14]!==u||e[15]!==j?(b=s.jsx("div",{className:u,children:j}),e[14]=u,e[15]=j,e[16]=b):b=e[16],b},Ur=t=>{const e=rt.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,m=rs(Lx),f=ge(Kx),u=m==="remaining"?n.remainingPercent:n.usedPercent,g=u!==null,v=m==="remaining"?"remaining":"used";let j;e[0]!==u||e[1]!==n.valueLabel?(j=Jd(n.valueLabel,u),e[0]=u,e[1]=n.valueLabel,e[2]=j):j=e[2];const b=j,k=n.resetAfterFormatted??n.resetAtFormatted;let p;e[3]!==k||e[4]!==f||e[5]!==n.resetAt?(p=Qd(n.resetAt,k,f),e[3]=k,e[4]=f,e[5]=n.resetAt,e[6]=p):p=e[6];const N=p,P=N?`Resets ${N}`:"";let C;e[7]!==a?(C=Yd(a),e[7]=a,e[8]=C):C=e[8];const w=C;let D;e[9]!==d||e[10]!==c||e[11]!==h?(D=c&&s.jsx(Xr,{checked:h,onChange:z=>d?.(z),ariaLabel:"Show in dropdown"}),e[9]=d,e[10]=c,e[11]=h,e[12]=D):D=e[12];let x;e[13]!==w?(x=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:w}),e[13]=w,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 I;e[20]!==R||e[21]!==D?(I=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]=I):I=e[22];const E=b==="-"?"":b;let F;e[23]!==E?(F=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:E}),e[23]=E,e[24]=F):F=e[24];let K;e[25]!==I||e[26]!==F?(K=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[I,F]}),e[25]=I,e[26]=F,e[27]=K):K=e[27];let S;e[28]!==v||e[29]!==u||e[30]!==g||e[31]!==P||e[32]!==n.usedPercent?(S=g?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(Ox,{percent:u,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]=u,e[30]=g,e[31]=P,e[32]=n.usedPercent,e[33]=S):S=e[33];let M;return e[34]!==K||e[35]!==S?(M=s.jsxs("div",{className:"py-3",children:[K,S]}),e[34]=K,e[35]=S,e[36]=M):M=e[36],M};function Lx(t){return t.displayMode}function Kx(t){return t.timeFormatPreference}const zx=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,_x=({providerId:t,providerName:e})=>{const{t:a}=Xe(),[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 u=>{if(!u.ok)throw new Error;const g=await u.json();r(g),l({})}).catch(()=>r({configured:!1}))},[h]);const m=async(u,g,v)=>{c(!0);try{const j=await Nt(u,{method:g,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),b=await j.json().catch(()=>null);if(!j.ok)throw new Error(b?.error);b?.configured!==void 0&&r(b),l({}),$.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(j){$.error(j instanceof Error&&j.message?j.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},f=(u,g,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[g,s.jsx(We,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[u]??"",onChange:j=>l(b=>({...b,[u]:j.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:zx})]}),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:()=>m(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:()=>m(`${h}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(G,{variant:"outline",size:"xs",disabled:d,onClick:()=>m(`${h}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(G,{variant:"destructive",size:"xs",disabled:d,onClick:()=>m(h,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Vl=(t,e)=>{if(!t)return"-";try{return Cc(t,e,{fallback:"-"})}catch{return"-"}},Ux=()=>{const{t}=Xe(),e=ge(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),m=rs(M=>M.dropdownProviderIds),f=rs(M=>M.setDropdownProviderIds),u=rs(M=>M.selectedModels),g=rs(M=>M.toggleModelSelected),v=rs(M=>M.applyDefaultSelections);Zd(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const M=a.find(z=>z.configured)?.providerId;r(M??Wi[0]?.id??null)},[a,n,r]);const j=a.find(M=>M.providerId===n)??null,k=Wi.find(M=>M.id===n)?.name??n??t("settings.usage.sidebar.title"),p=j?.usage,N=n?h[n]:void 0,P=N?p?t("header.services.usageRefreshFailedStale",{error:N}):N:j?.configured&&!j.ok?j.error:null,C=n?m.includes(n):!1,w=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",D=o.useCallback(M=>{if(!n)return;const z=M?Array.from(new Set([...m,n])):m.filter(_=>_!==n);f(z),ft({usageDropdownProviders:z})},[m,n,f]),x=o.useMemo(()=>p?.models?Object.entries(p.models).map(([M,z])=>({name:M,windows:z})).filter(M=>Object.keys(M.windows.windows).length>0):[],[p?.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:Xd(x,M=>M.name,n),[x,n]),R=o.useMemo(()=>{if(!n)return[];const M=tu(n);return eu(M)},[n]),[I,E]=o.useState(()=>({})),F=o.useCallback(M=>{E(z=>({...z,[M]:!z[M]}))},[]),K=o.useCallback(M=>{if(!n)return;g(n,M);const z=u[n]??[],q=z.includes(M)?z.filter(J=>J!==M):[...z,M],X={...u,[n]:q};ft({usageSelectedModels:X})},[n,u,g]),S=n?u[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(sa,{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")}):j?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:j.planLabel,time:Vl(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Vl(c,e)}),showSaveStatus:!0,children:[s.jsx(Ge,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:C,onChange:D,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!j&&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})]}),j&&!j.configured&&!w&&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(_x,{providerId:n,providerName:k}),p?.windows&&Object.keys(p.windows).length>0&&s.jsx(Ge,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(p.windows).map(([M,z])=>s.jsx(Ur,{title:M,window:z},M))})}),x.length>0&&s.jsxs(Ge,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[R.map(M=>{const z=A.get(M.id)??[];if(z.length===0)return null;const _=I[M.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!_,onOpenChange:()=>F(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:["(",z.length,")"]})]}),_?s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{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:z.map(q=>{const X=Object.entries(q.windows.windows);if(X.length===0)return null;const[J,H]=X[0],L=S.includes(q.name);return s.jsx(Ur,{title:J,subtitle:_o(q.name),window:H,showToggle:!0,toggleEnabled:L,onToggle:()=>K(q.name)},q.name)})})})]})},M.id)}),(()=>{const M=A.get(null)??[];if(M.length===0)return null;const z=I.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!z,onOpenChange:()=>F("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,")"]})]}),z?s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{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(_=>{const q=Object.entries(_.windows.windows);if(q.length===0)return null;const[X,J]=q[0],H=S.includes(_.name);return s.jsx(Ur,{title:X,subtitle:_o(_.name),window:J,showToggle:!0,toggleEnabled:H,onToggle:()=>K(_.name)},_.name)})})})]})})})()]}),j?.configured&&p&&Object.keys(p.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")})})},$x="git.commit.generate",lo=Sm(t=>({selectedPromptId:$x,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Bx=t=>{const e=rt.c(24),{onItemSelect:a}=t,{t:n}=Xe(),r=lo(Vx),i=lo(Hx);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 m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=[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]=m):m=e[4];const f=m;let u;e[5]!==n?(u=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=u):u=e[6];let g;e[7]!==u?(g=s.jsx("h2",{className:Pn,children:u}),e[7]=u,e[8]=g):g=e[8];let v;e[9]!==n?(v=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=v):v=e[10];let j;e[11]!==v?(j=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:v}),e[11]=v,e[12]=j):j=e[12];let b;e[13]!==g||e[14]!==j?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[g,j]}),e[13]=g,e[14]=j,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==r||e[18]!==i||e[19]!==n?(k=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:f.map(N=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(N.groupKey)}),N.items.map(P=>{const C=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",C?"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)})]},N.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=k):k=e[20];let p;return e[21]!==b||e[22]!==k?(p=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,k]}),e[21]=b,e[22]=k,e[23]=p):p=e[23],p};function Vx(t){return t.selectedPromptId}function Hx(t){return t.setSelectedPromptId}const Hl={"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"}]}},ql=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),$r=t=>t.endsWith(".visible"),qx=()=>{const{t}=Xe(),e=o.useCallback(w=>t(w),[t]),a=lo(w=>w.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[d,c]=o.useState({}),[h,m]=o.useState({}),[f,u]=o.useState({}),[g,v]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{r(!0);try{const x=await iu();if(!w)return;l(x)}catch(x){console.warn("Failed to load magic prompts:",x),$.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&r(!1)}})(),()=>{w=!1}},[t]);const j=Hl[a]??Hl["git.commit.generate"],b=o.useCallback(w=>ql(i,w)?i[w]:Ir(w),[i]),k=o.useCallback(w=>d[w]??b(w),[d,b]),p=o.useCallback((w,D)=>{c(x=>x[w]===D?x:{...x,[w]:D})},[]),N=o.useCallback(async w=>{const D=k(w);if($r(w)&&D.trim().length===0){$.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(x=>({...x,[w]:!0}));try{const x=D===Ir(w)?await Uo(w):await su(w,D);l(x.overrides),$.success(t("settings.magicPrompts.page.toast.saved"))}catch(x){const A=x instanceof Error?x.message:String(x);$.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:A})}finally{m(x=>({...x,[w]:!1}))}},[k,t]),P=o.useCallback(async w=>{u(D=>({...D,[w]:!0}));try{const D=await Uo(w);l(D.overrides),c(x=>({...x,[w]:Ir(w)})),$.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(D){const x=D instanceof Error?D.message:String(D);$.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:x})}finally{u(D=>({...D,[w]:!1}))}},[t]),C=o.useCallback(async()=>{v(!0);try{const w=await nu();l(w.overrides),c({}),$.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const D=w instanceof Error?w.message:String(w);$.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(j.titleKey),titleAccessory:s.jsx(Ht,{contentClassName:"max-w-xs",children:e(j.descriptionKey)}),headerEnd:s.jsx(G,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{C()},disabled:g||Object.keys(i).length===0,children:t(g?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:j.blocks.map((w,D)=>{const x=au(w.id),A=b(w.id),R=k(w.id),I=ql(i,w.id),E=R!==A,F=$r(w.id)&&R.trim().length===0,K=h[w.id]===!0,S=f[w.id]===!0;return s.jsxs(Ge,{title:e(w.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:$r(w.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:R,onChange:M=>p(w.id,M.target.value),className:"min-h-[220px] font-mono text-sm"}),F&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(E?"settings.magicPrompts.page.status.unsavedChanges":I?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"outline",size:"sm",onClick:()=>{P(w.id)},disabled:!I||K||S,children:t(S?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(G,{size:"sm",onClick:()=>{N(w.id)},disabled:!E||K||S||F,children:t(K?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})})},Gx=t=>{const e=rt.c(89),{onItemSelect:a}=t,{t:n}=Xe(),[r,i]=o.useState(null),[l,d]=o.useState(null),[c,h]=o.useState(null),{selectedSnippetName:m,snippets:f,setSelectedSnippet:u,setSnippetDraft:g,deleteSnippet:v,loadSnippets:j}=Ji(Us(Wx));let b,k;e[0]!==j?(b=()=>{j()},k=[j],e[0]=j,e[1]=b,e[2]=k):(b=e[1],k=e[2]),o.useEffect(b,k);let p;e[3]!==a||e[4]!==u||e[5]!==g||e[6]!==f?(p=async()=>{const ae=new Set(f.map(Jx));let fe="new-snippet",xe=1;for(;ae.has(fe);)fe=`new-snippet-${xe++}`;g({name:fe,scope:"global"}),u(fe),a?.()},e[3]=a,e[4]=u,e[5]=g,e[6]=f,e[7]=p):p=e[7];const N=p;let P;e[8]!==r||e[9]!==v||e[10]!==n?(P=async()=>{if(!r)return;await v(r.name)?($.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):$.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=v,e[10]=n,e[11]=P):P=e[11];const C=P;let w;e[12]!==f?(w=[...f].sort(Qx),e[12]=f,e[13]=w):w=e[13];const D=w;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 I;e[19]!==f.length||e[20]!==n?(I=n("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=n,e[21]=I):I=e[21];let E;e[22]!==I?(E=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[22]=I,e[23]=E):E=e[23];let F;e[24]!==n?(F=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=F):F=e[25];let K;e[26]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[26]=K):K=e[26];let S;e[27]!==N||e[28]!==F?(S=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:N,"aria-label":F,children:K}),e[27]=N,e[28]=F,e[29]=S):S=e[29];let M;e[30]!==E||e[31]!==S?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,S]}),e[30]=E,e[31]=S,e[32]=M):M=e[32];let z;e[33]!==M||e[34]!==R?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[R,M]}),e[33]=M,e[34]=R,e[35]=z):z=e[35];let _;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==u||e[41]!==D||e[42]!==n){let ae;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==u||e[49]!==n?(ae=fe=>s.jsxs(ga,{open:c===fe.name,onOpenChange:xe=>h(xe?fe.name:null),children:[s.jsxs(pa,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===fe.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:xe=>{xe.preventDefault(),h(fe.name)}}),children:[s.jsxs("button",{onClick:()=>{u(fe.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:["#",fe.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.${fe.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:fe.description||fe.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(_n,{open:l===fe.name,onOpenChange:xe=>{xe&&h(null),d(xe?fe.name:null)},children:[s.jsx(zn,{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:fe.name}),children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Kn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(wn,{onClick:xe=>{xe.stopPropagation(),i(fe)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(ua,{className:"w-fit min-w-20",children:s.jsxs(ma,{onClick:xe=>{xe.stopPropagation(),i(fe)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${fe.source}:${fe.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=m,e[48]=u,e[49]=n,e[50]=ae):ae=e[50],_=D.map(ae),e[36]=a,e[37]=l,e[38]=c,e[39]=m,e[40]=u,e[41]=D,e[42]=n,e[43]=_}else _=e[43];let q;e[51]!==_?(q=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:_}),e[51]=_,e[52]=q):q=e[52];const X=r!==null;let J;e[53]===Symbol.for("react.memo_cache_sentinel")?(J=ae=>{ae||i(null)},e[53]=J):J=e[53];let H;e[54]!==n?(H=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=H):H=e[55];let L;e[56]!==H?(L=s.jsx($t,{children:H}),e[56]=H,e[57]=L):L=e[57];const V=r?.name??"";let Z;e[58]!==n||e[59]!==V?(Z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=Z):Z=e[60];let U;e[61]!==Z?(U=s.jsx(Bt,{children:Z}),e[61]=Z,e[62]=U):U=e[62];let te;e[63]!==L||e[64]!==U?(te=s.jsxs(Ut,{children:[L,U]}),e[63]=L,e[64]=U,e[65]=te):te=e[65];let O;e[66]===Symbol.for("react.memo_cache_sentinel")?(O=()=>i(null),e[66]=O):O=e[66];let Q;e[67]!==n?(Q=n("settings.common.actions.cancel"),e[67]=n,e[68]=Q):Q=e[68];let ce;e[69]!==Q?(ce=s.jsx(G,{size:"sm",variant:"ghost",onClick:O,children:Q}),e[69]=Q,e[70]=ce):ce=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let pe;e[73]!==C||e[74]!==de?(pe=s.jsx(G,{size:"sm",onClick:C,children:de}),e[73]=C,e[74]=de,e[75]=pe):pe=e[75];let re;e[76]!==ce||e[77]!==pe?(re=s.jsxs(as,{children:[ce,pe]}),e[76]=ce,e[77]=pe,e[78]=re):re=e[78];let Ce;e[79]!==te||e[80]!==re?(Ce=s.jsxs(zt,{className:"max-w-md",children:[te,re]}),e[79]=te,e[80]=re,e[81]=Ce):Ce=e[81];let ie;e[82]!==X||e[83]!==Ce?(ie=s.jsx(Kt,{open:X,onOpenChange:J,children:Ce}),e[82]=X,e[83]=Ce,e[84]=ie):ie=e[84];let be;return e[85]!==z||e[86]!==q||e[87]!==ie?(be=s.jsxs("div",{className:x,children:[z,q,ie]}),e[85]=z,e[86]=q,e[87]=ie,e[88]=be):be=e[88],be};function Wx(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Jx(t){return t.name}function Qx(t,e){return t.name.localeCompare(e.name)}const Yx=()=>{const{t}=Xe(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=Ji(Us(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,m]=o.useState(""),[f,u]=o.useState("global"),[g,v]=o.useState(""),[j,b]=o.useState(""),[k,p]=o.useState(""),[N,P]=o.useState(!1),C=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||""};m(x.draftName),u(x.draftScope),v(x.description),b(x.aliases),p(x.content),C.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),p(x.content),C.current=x}},[d,c,e,n]);const w=o.useMemo(()=>{const x=C.current;return x?c&&h!==x.draftName||c&&f!==x.draftScope?!0:g!==x.description||j!==x.aliases||k!==x.content:!1},[j,k,g,h,f,c]),D=async()=>{const x=c?h.trim().replace(/\s+/g,"-"):e?.trim();if(!x){$.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){$.error(t("settings.snippets.page.toast.contentRequired"));return}const A=j.split(",").map(R=>R.trim()).filter(Boolean);P(!0);try{if(!(c?await l(x,k,{aliases:A,description:g,scope:f}):await i(x,{content:k,aliases:A,description:g}))){$.error(t("settings.snippets.page.toast.saveFailed"));return}$.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(Ge,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(St,{label:"#",children:[s.jsx(We,{value:h,onChange:x=>m(x.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Et,{value:f,onValueChange:x=>u(x),children:[s.jsx(At,{size:Vt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{})}),s.jsxs(Tt,{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(Rt,{label:t("settings.common.field.description"),children:s.jsx(We,{value:g,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(Rt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(We,{value:j,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(Ge,{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(Ht,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:k,onChange:x=>p(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:N||!w,size:"xs",className:"!font-normal",children:t(N?"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(B,{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")})]})})},cd=()=>{const{t}=Xe(),e=it(f=>f.settingsGitmojiEnabled),a=it(f=>f.setSettingsGitmojiEnabled),n=Zu(),r=ge(f=>f.gitChangesViewMode),i=ge(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 u=await An();u&&(u.gitmojiEnabled!==void 0&&a(u.gitmojiEnabled),u.gitChangesViewMode!==void 0&&i(u.gitChangesViewMode))}catch(u){console.warn("Failed to load git settings:",u)}finally{d(!1)}})()},[i,a]);const h=o.useCallback(async f=>{a(f);try{await ft({gitmojiEnabled:f})}catch(u){console.warn("Failed to save gitmoji setting:",u)}},[a]),m=o.useCallback(f=>{f!==r&&(i(f),ft({gitChangesViewMode:f}))},[r,i]);return l?null:s.jsx(Ge,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:ls,children:[s.jsx(ws,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(tn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(f=>s.jsx(ks,{selected:r===f.id,onSelect:()=>{m(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:Xu,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Gl=[{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)"}],Zx=[{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"}],Xx=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:r}=Xe(),i=ra(U=>U.getProfileById),l=ra(U=>U.createProfile),d=ra(U=>U.updateProfile),c=ra(U=>U.deleteProfile),h=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),m=a==="new"||n!=null,f=a==="global",[u,g]=o.useState(""),[v,j]=o.useState(""),[b,k]=o.useState(""),[p,N]=o.useState("ssh"),[P,C]=o.useState(""),[w,D]=o.useState(!1),[x,A]=o.useState(""),[R,I]=o.useState(""),[E,F]=o.useState("keyword"),[K,S]=o.useState("branch"),[M,z]=o.useState(!1),[_,q]=o.useState(!1),[X,J]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const U=n.host.split("/"),te=U.length>=3?U[U.length-1]:n.host;g(te),j(n.username),k(""),N("token"),C(""),D(!1),A(""),I(n.host),F("string"),S("code")}else if(m)g(""),j(""),k(""),N("ssh"),C(""),D(!1),A(""),I(""),F("keyword"),S("branch");else if(h)g(h.name),j(h.userName),k(h.userEmail),N(h.authType||"ssh"),C(h.sshKey||""),D(h.signCommits===!0),A(h.signingKey||""),I(h.host||""),F(h.color||"keyword"),S(h.icon||"branch");else if(f){const U=i("global");U&&(g(U.name),j(U.userName),k(U.userEmail),N(U.authType||"ssh"),C(U.sshKey||""),D(!1),A(""),I(U.host||""),F(U.color||"keyword"),S(U.icon||"branch"))}}},[t,a,h,m,n,f,i]);const H=async()=>{if(!v.trim()||!b.trim()){$.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(p==="token"&&!R.trim()){$.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(w&&!x.trim()){$.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}z(!0);try{const U={name:u.trim()||v.trim(),userName:v.trim(),userEmail:b.trim(),authType:p,sshKey:p==="ssh"&&P.trim()||null,signCommits:w,signingKey:x.trim()||null,host:p==="token"&&R.trim()||null,color:E,icon:K};let te;if(m)te=await l(U);else if(a)te=await d(a,U);else return;te?($.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):$.error(r(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(U){console.error("Error saving profile:",U),$.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{z(!1)}},L=async()=>{if(!(!a||m)){J(!0);try{await c(a)?($.success(r("settings.gitIdentities.editor.toast.profileDeleted")),q(!1),e(!1)):$.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(U){console.error("Error deleting profile:",U),$.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{J(!1)}}},V=o.useMemo(()=>Gl.find(te=>te.key===E)?.cssVar||"var(--syntax-keyword)",[E]),Z=n?r("settings.gitIdentities.editor.title.importCredential"):m?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(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:Z}),s.jsx(Bt,{children:r(f?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!f&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${It} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(We,{value:u,onChange:U=>g(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:Gl.map(U=>s.jsx("button",{type:"button",onClick:()=>F(U.key),className:Ie("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",E===U.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:U.cssVar},title:U.label},U.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:Zx.map(U=>{const te=U.Icon;return s.jsx("button",{type:"button",onClick:()=>S(U.key),className:Ie("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",K===U.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:U.label,children:s.jsx(B,{name:te,className:"w-3.5 h-3.5",style:{color:K===U.key?V:"var(--surface-muted-foreground)"}})},U.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:It,children:r("settings.gitIdentities.editor.field.userName")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Ht,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(We,{value:v,onChange:U=>j(U.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:It,children:r("settings.gitIdentities.editor.field.emailAddress")}),!f&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Ht,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(We,{type:"email",value:b,onChange:U=>k(U.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":p==="ssh",onClick:()=>N("ssh"),children:[s.jsx(B,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":p==="token",onClick:()=>N("token"),children:[s.jsx(B,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),p==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:It,children:r("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Ht,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(We,{value:P,onChange:U=>C(U.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:w,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:It,children:r("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(We,{value:x,onChange:U=>A(U.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!w,className:"h-8 font-mono text-xs"})]})]}),p==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:It,children:r("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Ht,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(We,{value:R,onChange:U=>I(U.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&&!m&&s.jsxs(G,{variant:"outline",size:"sm",onClick:()=>q(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(B,{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":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:_,onOpenChange:U=>{X||q(U)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx($t,{children:r("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Bt,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:h?.name||u})})]}),s.jsxs(as,{children:[s.jsx(G,{variant:"ghost",onClick:()=>q(!1),disabled:X,children:r("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{L()},disabled:X,children:r("settings.common.actions.delete")})]})]})})]})},eb={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},tb={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},sb=()=>{const t=rt.c(112),{t:e}=Xe(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:h,setDefaultGitIdentityId:m,getUnimportedCredentials:f}=ra(Us(ab)),[u,g]=o.useState(!1),[v,j]=o.useState(null),[b,k]=o.useState(null),[p,N]=o.useState(null),[P,C]=o.useState(!1);let w,D;t[0]!==h||t[1]!==c||t[2]!==d||t[3]!==l?(w=()=>{l(),d(),c(),h()},D=[l,d,c,h],t[0]=h,t[1]=c,t[2]=d,t[3]=l,t[4]=w,t[5]=D):(w=t[4],D=t[5]),o.useEffect(w,D);let x,A,R,I,E,F,K,S,M,z,_,q,X,J;if(t[6]!==r||t[7]!==p||t[8]!==i||t[9]!==f||t[10]!==n||t[11]!==a||t[12]!==m||t[13]!==e){const De=f();let ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(ve=(_e,Me)=>{j(_e),k(Me??null),g(!0)},t[28]=ve):ve=t[28];const ee=ve;let ne;t[29]!==r||t[30]!==m||t[31]!==e?(ne=async _e=>{const Me=r===_e?null:_e;if(!await m(Me)){$.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}$.success(e(Me?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=m,t[31]=e,t[32]=ne):ne=t[32];const ye=ne;let Ae;t[33]!==p||t[34]!==i||t[35]!==e?(Ae=async()=>{if(!p)return;C(!0),await i(p.id)?($.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:p.name})),N(null)):$.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),C(!1)},t[33]=p,t[34]=i,t[35]=e,t[36]=Ae):Ae=t[36],R=Ae,A=ns,t[37]!==e?(E=e("settings.page.git.title"),t[37]=e,t[38]=E):E=t[38],F=!0,x=Ge,t[39]!==e?(q=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=q):q=t[40],X=!1;let ze,Qe;t[41]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>ee("new"),Qe=s.jsx(B,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=ze,t[42]=Qe):(ze=t[41],Qe=t[42]);let Be;t[43]!==e?(Be=e("settings.common.badge.new"),t[43]=e,t[44]=Be):Be=t[44],t[45]!==Be?(J=s.jsxs(G,{size:"sm",variant:"outline",onClick:ze,children:[Qe," ",Be]}),t[45]=Be,t[46]=J):J=t[46],I="git.identities",K="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",S=n&&s.jsx(Wl,{profile:n,isDefault:r==="global",onEdit:()=>ee("global"),onToggleDefault:()=>ye("global"),isReadOnly:!0,hasBorder:a.length>0||De.length>0}),M=a.map((_e,Me)=>s.jsx(Wl,{profile:_e,isDefault:r===_e.id,onEdit:()=>ee(_e.id),onToggleDefault:()=>ye(_e.id),onDelete:()=>N(_e),hasBorder:Me<a.length-1||De.length>0},_e.id)),z=!n&&a.length===0&&De.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(B,{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")})]}),_=De.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")})}),De.map((_e,Me)=>s.jsx(nb,{credential:_e,onImport:()=>ee("new",{host:_e.host,username:_e.username}),hasBorder:Me<De.length-1},`${_e.host}-${_e.username}`))]}),t[6]=r,t[7]=p,t[8]=i,t[9]=f,t[10]=n,t[11]=a,t[12]=m,t[13]=e,t[14]=x,t[15]=A,t[16]=R,t[17]=I,t[18]=E,t[19]=F,t[20]=K,t[21]=S,t[22]=M,t[23]=z,t[24]=_,t[25]=q,t[26]=X,t[27]=J}else x=t[14],A=t[15],R=t[16],I=t[17],E=t[18],F=t[19],K=t[20],S=t[21],M=t[22],z=t[23],_=t[24],q=t[25],X=t[26],J=t[27];let H;t[47]!==K||t[48]!==S||t[49]!==M||t[50]!==z||t[51]!==_?(H=s.jsxs("div",{className:K,children:[S,M,z,_]}),t[47]=K,t[48]=S,t[49]=M,t[50]=z,t[51]=_,t[52]=H):H=t[52];let L;t[53]!==x||t[54]!==I||t[55]!==H||t[56]!==q||t[57]!==X||t[58]!==J?(L=s.jsx(x,{title:q,divider:X,headerAction:J,settingsItem:I,children:H}),t[53]=x,t[54]=I,t[55]=H,t[56]=q,t[57]=X,t[58]=J,t[59]=L):L=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(cd,{}),t[60]=V):V=t[60];let Z;t[61]!==A||t[62]!==E||t[63]!==F||t[64]!==L?(Z=s.jsxs(A,{title:E,showSaveStatus:F,children:[L,V]}),t[61]=A,t[62]=E,t[63]=F,t[64]=L,t[65]=Z):Z=t[65];let U;t[66]!==b||t[67]!==u||t[68]!==v?(U=s.jsx(Xx,{open:u,onOpenChange:g,profileId:v,importData:b}),t[66]=b,t[67]=u,t[68]=v,t[69]=U):U=t[69];const te=p!==null;let O;t[70]!==P?(O=De=>{P||De||N(null)},t[70]=P,t[71]=O):O=t[71];let Q;t[72]!==e?(Q=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=Q):Q=t[73];let ce;t[74]!==Q?(ce=s.jsx($t,{children:Q}),t[74]=Q,t[75]=ce):ce=t[75];const de=p?.name??"";let pe;t[76]!==e||t[77]!==de?(pe=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=pe):pe=t[78];let re;t[79]!==pe?(re=s.jsx(Bt,{children:pe}),t[79]=pe,t[80]=re):re=t[80];let Ce;t[81]!==ce||t[82]!==re?(Ce=s.jsxs(Ut,{children:[ce,re]}),t[81]=ce,t[82]=re,t[83]=Ce):Ce=t[83];let ie;t[84]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>N(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 fe;t[90]!==R?(fe=()=>{R()},t[90]=R,t[91]=fe):fe=t[91];let xe;t[92]!==e?(xe=e("settings.common.actions.delete"),t[92]=e,t[93]=xe):xe=t[93];let Oe;t[94]!==P||t[95]!==fe||t[96]!==xe?(Oe=s.jsx(G,{size:"sm",variant:"destructive",onClick:fe,disabled:P,children:xe}),t[94]=P,t[95]=fe,t[96]=xe,t[97]=Oe):Oe=t[97];let Ne;t[98]!==ae||t[99]!==Oe?(Ne=s.jsxs(as,{children:[ae,Oe]}),t[98]=ae,t[99]=Oe,t[100]=Ne):Ne=t[100];let he;t[101]!==Ce||t[102]!==Ne?(he=s.jsxs(zt,{className:"max-w-md",children:[Ce,Ne]}),t[101]=Ce,t[102]=Ne,t[103]=he):he=t[103];let Te;t[104]!==te||t[105]!==O||t[106]!==he?(Te=s.jsx(Kt,{open:te,onOpenChange:O,children:he}),t[104]=te,t[105]=O,t[106]=he,t[107]=Te):Te=t[107];let we;return t[108]!==Z||t[109]!==U||t[110]!==Te?(we=s.jsxs(s.Fragment,{children:[Z,U,Te]}),t[108]=Z,t[109]=U,t[110]=Te,t[111]=we):we=t[111],we},Wl=t=>{const e=rt.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:d,hasBorder:c}=t,{t:h}=Xe(),[m,f]=o.useState(!1),u=eb[a.icon||"branch"]||"git-branch",g=tb[a.color||""],v=a.authType||"ssh";let j;e[0]!==r?(j=L=>{L.currentTarget===L.target&&(L.key!=="Enter"&&L.key!==" "||(L.preventDefault(),r()))},e[0]=r,e[1]=j):j=e[1];const b=j;let k;e[2]!==n||e[3]!==d||e[4]!==l||e[5]!==i||e[6]!==h?(k=L=>s.jsxs(s.Fragment,{children:[s.jsx(L,{onClick:V=>{V.stopPropagation(),i()},children:h(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&l&&s.jsxs(L,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{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 p=k,N=c&&"border-b border-[var(--surface-subtle)]";let P;e[8]!==N?(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",N),e[8]=N,e[9]=P):P=e[9];let C;e[10]===Symbol.for("react.memo_cache_sentinel")?(C=L=>{L.preventDefault(),f(!0)},e[10]=C):C=e[10];let w;e[11]!==b||e[12]!==r||e[13]!==P?(w=s.jsx("div",{className:P,onClick:r,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:C}),e[11]=b,e[12]=r,e[13]=P,e[14]=w):w=e[14];let D;e[15]!==g?(D={color:g},e[15]=g,e[16]=D):D=e[16];let x;e[17]!==u||e[18]!==D?(x=s.jsx(B,{name:u,className:"w-4 h-4 shrink-0",style:D}),e[17]=u,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 I;e[24]!==n||e[25]!==h?(I=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:h("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=h,e[26]=I):I=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 F;e[30]!==R||e[31]!==I||e[32]!==E||e[33]!==A?(F=s.jsxs("div",{className:"flex items-center gap-1.5",children:[A,R,I,E]}),e[30]=R,e[31]=I,e[32]=E,e[33]=A,e[34]=F):F=e[34];const K=v==="token"&&a.host?a.host:a.userEmail;let S;e[35]!==K?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:K}),e[35]=K,e[36]=S):S=e[36];let M;e[37]!==F||e[38]!==S?(M=s.jsxs("div",{className:"min-w-0",children:[F,S]}),e[37]=F,e[38]=S,e[39]=M):M=e[39];let z;e[40]!==M||e[41]!==x?(z=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[x,M]}),e[40]=M,e[41]=x,e[42]=z):z=e[42];let _;e[43]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(zn,{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:ib,children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=_):_=e[43];let q;e[44]!==p?(q=s.jsxs(_n,{children:[_,s.jsx(Kn,{align:"end",className:"w-fit min-w-28",children:p(wn)})]}),e[44]=p,e[45]=q):q=e[45];let X;e[46]!==z||e[47]!==q||e[48]!==w?(X=s.jsxs(pa,{render:w,children:[z,q]}),e[46]=z,e[47]=q,e[48]=w,e[49]=X):X=e[49];let J;e[50]!==p?(J=s.jsx(ua,{className:"w-fit min-w-28",children:p(ma)}),e[50]=p,e[51]=J):J=e[51];let H;return e[52]!==m||e[53]!==X||e[54]!==J?(H=s.jsxs(ga,{open:m,onOpenChange:f,children:[X,J]}),e[52]=m,e[53]=X,e[54]=J,e[55]=H):H=e[55],H},nb=t=>{const e=rt.c(21),{credential:a,onImport:n,hasBorder:r}=t,{t:i}=Xe();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("/"),m=r&&"border-b border-[var(--surface-subtle)]";let f;e[2]!==m?(f=Ie("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=f):f=e[3];let u;e[4]!==c?(u=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=u):u=e[5];const g=h?a.host:a.username;let v;e[6]!==g?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:g}),e[6]=g,e[7]=v):v=e[7];let j;e[8]!==u||e[9]!==v?(j=s.jsxs("div",{className:"min-w-0",children:[u,v]}),e[8]=u,e[9]=v,e[10]=j):j=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(B,{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 p;e[14]!==n||e[15]!==k?(p=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]=p):p=e[16];let N;return e[17]!==p||e[18]!==f||e[19]!==j?(N=s.jsxs("div",{className:f,children:[j,p]}),e[17]=p,e[18]=f,e[19]=j,e[20]=N):N=e[20],N};function ab(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 ib(t){return t.stopPropagation()}const dd=({guest:t})=>{const{t:e}=Xe(),a=t.integration,n=Er(O=>O.byId[t.id]),r=Er(O=>O.setStatus),i=o.useMemo(()=>Ic(t.id,t.icon,Lc().authenticatedAsset),[t.id,t.icon]),l=Er(O=>O.refresh),[d,c]=o.useState(!1),[h,m]=o.useState(!1),[f,u]=o.useState(!1),[g,v]=o.useState(""),[j,b]=o.useState(""),[k,p]=o.useState(""),[N,P]=o.useState(""),[C,w]=o.useState({}),[D,x]=o.useState(!1),A=o.useRef(null),[R]=o.useState(jn),I=o.useRef(!0),E=()=>I.current&&jn()===R,F=o.useCallback(()=>{A.current!=null&&(window.clearInterval(A.current),A.current=null),u(!1)},[]);if(o.useEffect(()=>(I.current=!0,l(t.id),()=>{I.current=!1,F()}),[t.id,l,F]),o.useEffect(()=>{n&&w(n.settings)},[n]),!a)return null;const K=a.auth,S=K==="token"&&a.token?.scheme==="basic",M=!!n?.connection.connected,z=n?.connection.account.trim()||"",_=f?e("settings.integrations.guests.status.waiting"):M?z||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),q=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",X=f||d,J=a.name,H=async()=>{if(!E())return!1;const O=g.trim();if(!O)return n?.hasClient?!0:($.error(e("settings.integrations.guests.toast.clientRequired")),!1);hs("saving");const Q=await zm(t.id,O,j.trim()||void 0);return E()?Q?(r(t.id,Q),b(""),hs("saved"),!0):(hs("error"),$.error(e("settings.integrations.guests.toast.saveFailed",{name:J})),!1):!1},L=async(O=C)=>{if(!E())return!1;const Q=n?.settings??{};if((a.settings??[]).every(re=>(O[re.id]??"").trim()===(Q[re.id]??"")))return!0;hs("saving");const pe=await Dm(t.id,O);return E()?pe?(r(t.id,pe),hs("saved"),!0):(hs("error"),$.error(e("settings.integrations.guests.toast.saveFailed",{name:J})),!1):!1},V=async()=>{if(!E())return!1;const O=k.trim();if(!O)return M?!0:($.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const Q=N.trim();if(S&&!Q)return $.error(e("settings.integrations.guests.toast.usernameRequired")),!1;hs("saving");const ce=await Km(t.id,O,S?Q:void 0);return E()?ce?(r(t.id,ce),p(""),P(""),hs("saved"),!0):(hs("error"),$.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},Z=async()=>{if(!E())return;F(),m(!0);const O=n?.connection??{connected:!1,account:""};try{if(K==="token"){if(await V()){if((a.settings??[]).length>0&&!await L()||!E())return;$.success(e("settings.integrations.guests.toast.connected",{name:J}))}return}if(K==="oauth"&&!n?.hasClient&&!await H())return;const Q=await Rm(t.id);if(!E())return;if(!Q){$.error(e("settings.integrations.guests.toast.startFailed",{name:J}));return}u(!0),c(!0),yn(Q);const ce=Date.now()+Fm;A.current=window.setInterval(()=>{(async()=>{if(!E()){F();return}if(Date.now()>ce){F(),$.error(e("settings.integrations.guests.toast.authorizationFailed",{name:J}));return}const de=await l(t.id);E()&&de&&Om(O,de.connection)&&(F(),$.success(e("settings.integrations.guests.toast.connected",{name:J})),os()&&Kc())})()},Lm)}catch(Q){if(!E())return;console.error("Failed to start guest connect:",Q),$.error(e("settings.integrations.guests.toast.startFailed",{name:J})),F()}finally{E()&&m(!1)}},U=async()=>{if(E()){m(!0);try{F();const O=await Mm(t.id);if(!E())return;if(!O){$.error(e("settings.integrations.guests.toast.disconnectFailed",{name:J}));return}r(t.id,O),$.success(e("settings.integrations.guests.toast.disconnected",{name:J}))}catch(O){if(!E())return;console.error("Failed to disconnect guest:",O),$.error(e("settings.integrations.guests.toast.disconnectFailed",{name:J}))}finally{E()&&m(!1)}}},te=async()=>{const O=n?.redirectUri??"";!O||!(await oi(O)).ok||(x(!0),window.setTimeout(()=>x(!1),1500))};return s.jsx(kn,{open:X,onOpenChange:O=>{if(f){c(!0);return}c(O)},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(Pc,{icon:Ac(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:J}),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",q),children:_}),s.jsx(B,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",X&&"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:[K==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Rt,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:g,onChange:O=>v(O.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}),s.jsx(Rt,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(We,{type:"password",value:j,onChange:O=>b(O.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})})]}):null,S?s.jsx(Rt,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(We,{value:N,onChange:O=>P(O.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,K==="token"?s.jsx(Rt,{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:O=>p(O.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})}):null,(a.settings??[]).map(O=>s.jsx(Rt,{label:O.label,controlClassName:"w-full max-w-none",children:s.jsx(We,{value:C[O.id]??"",onChange:Q=>{w(ce=>({...ce,[O.id]:Q.target.value}))},onBlur:()=>{L()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:h})},O.id)),K==="oauth"?s.jsxs(Rt,{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:()=>{te()},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:()=>{U()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(G,{type:"button",size:"sm",disabled:h||f,onClick:()=>{Z()},children:[h?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},rb=t=>{const e=rt.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:r}=Xe(),i=Vs(ob),l=Vs(lb);let d;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0],o.useEffect(cb,d),cs()||zc())return null;let c,h,m,f,u,g,v,j;if(e[1]!==n||e[2]!==i||e[3]!==l||e[4]!==r){j=Symbol.for("react.early_return_sentinel");e:{const k=i.filter(db);if(k.length===0){j=null;break e}c=Ge,e[13]!==r?(h=r("settings.integrations.guests.title"),e[13]=r,e[14]=h):h=e[14],e[15]!==r?(m=r("settings.integrations.guests.info"),e[15]=r,e[16]=m):m=e[16],f=n,u="integrations.guests",g="space-y-3";let p;e[17]!==l?(p=N=>s.jsx(dd,{guest:N},`${l}:${N.id}`),e[17]=l,e[18]=p):p=e[18],v=k.map(p)}e[1]=n,e[2]=i,e[3]=l,e[4]=r,e[5]=c,e[6]=h,e[7]=m,e[8]=f,e[9]=u,e[10]=g,e[11]=v,e[12]=j}else c=e[5],h=e[6],m=e[7],f=e[8],u=e[9],g=e[10],v=e[11],j=e[12];if(j!==Symbol.for("react.early_return_sentinel"))return j;let b;return e[19]!==c||e[20]!==h||e[21]!==m||e[22]!==f||e[23]!==u||e[24]!==g||e[25]!==v?(b=s.jsx(c,{title:h,info:m,divider:f,settingsItem:u,contentClassName:g,children:v}),e[19]=c,e[20]=h,e[21]=m,e[22]=f,e[23]=u,e[24]=g,e[25]=v,e[26]=b):b=e[26],b};function ob(t){return t.guests}function lb(t){return t.runtimeKey}function cb(){On()}function db(t){return t.source!=="bundled"&&t.integration&&jo(t)}const ub=({embedded:t=!1})=>{const{t:e}=Xe(),{isMobile:a}=Jn(),n=Ua()?.github,r=qn(S=>S.status),i=qn(S=>S.isLoading),l=qn(S=>S.hasChecked),d=qn(S=>S.refreshStatus),c=qn(S=>S.setStatus),h=o.useCallback(async S=>{await yn(S)},[]),[m,f]=o.useState(!1),[u,g]=o.useState(null),[v,j]=o.useState(null),b=o.useRef(null),k=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),j(null)},[]);o.useEffect(()=>((async()=>{try{l||await d(n)}catch(S){console.warn("Failed to load GitHub auth status:",S)}})(),()=>{k()}),[l,d,n,k]);const p=o.useCallback(async()=>{f(!0);try{const S=n?await n.authStart():await(async()=>{const z=await Nt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),_=await z.json().catch(()=>null);if(!z.ok||!_||!("deviceCode"in _))throw new Error(_?.error||z.statusText);return _})();g(S),j(Math.max(1,S.interval)*1e3);const M=S.verificationUriComplete||S.verificationUri;h(M)}catch(S){console.error("Failed to start GitHub connect:",S),$.error(e("settings.github.page.toast.startConnectFailed"))}finally{f(!1)}},[h,n,e]),N=o.useCallback(async S=>{if(n)return n.authComplete(S);const M=await Nt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:S})}),z=await M.json().catch(()=>null);if(!M.ok||!z)throw new Error(z?.error||M.statusText);return z},[n]);o.useEffect(()=>{if(!(!u?.deviceCode||!v)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const S=await N(u.deviceCode);if(S.connected){$.success(e("settings.github.page.toast.connected")),g(null),k(),await d(n,{force:!0});return}S.status==="slow_down"&&j(M=>M?M+5e3:5e3),(S.status==="expired_token"||S.status==="access_denied")&&($.error(S.error||e("settings.github.page.toast.authorizationFailed")),g(null),k())}catch(S){console.warn("GitHub polling failed:",S)}})()},v),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[u,v,N,d,n,k,e]);const P=o.useCallback(async S=>{f(!0);try{if(n)await n.authSetGhCliDisabled(S);else{const M=await Nt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:S})}),z=await M.json().catch(()=>null);if(!M.ok)throw new Error(z?.error||M.statusText)}$.success(e(S?"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),$.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{f(!1)}},[d,n,e]),C=o.useCallback(async()=>{f(!0);try{if(k(),g(null),n)await n.authDisconnect();else{const S=await Nt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!S.ok)throw new Error(S.statusText)}$.success(e("settings.github.page.toast.disconnected")),await d(n,{force:!0})}catch(S){console.error("Failed to disconnect GitHub:",S),$.error(e("settings.github.page.toast.disconnectFailed"))}finally{f(!1)}},[d,n,k,e]),w=o.useCallback(async S=>{if(S){f(!0);try{const M=n?await n.authActivate(S):await(async()=>{const z=await Nt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:S})}),_=await z.json().catch(()=>null);if(!z.ok||!_)throw new Error(_?.error||z.statusText);return _})();c(M),$.success(e("settings.github.page.toast.accountSwitched"))}catch(M){console.error("Failed to switch GitHub account:",M),$.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(S=>!S.current),I=r?.ghCli??null,E=I?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),F=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(B,{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})}),I?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),I?.active?s.jsx(G,{size:"sm",variant:"outline",onClick:()=>P(!0),disabled:m,className:Ie(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(G,{size:"sm",variant:"outline",onClick:C,disabled:m,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:p,disabled:m,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(S=>{const M=S.user,z=S.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(B,{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:z})]})]})]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>w(S.id),disabled:m,children:e("settings.github.page.actions.switchTo")})]},S.id)})})]})]}),D&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(G,{size:"sm",variant:"outline",onClick:p,disabled:m,className:Ie(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),u&&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:u.userCode}),s.jsx(G,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.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:m,onClick:()=>{k(),g(null)},children:e("settings.common.actions.cancel")})]})]})]}),K=I?.available&&!I?.active&&(!I.user||I.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className: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:[I.user?.avatarUrl?s.jsx("img",{src:I.user.avatarUrl,alt:I.user.login?e("settings.github.page.avatarAlt.withLogin",{login:I.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!I.disabled&&I.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:I.user.name?.trim()||I.user.login||"GitHub"}),!I.disabled&&I.user?.login&&s.jsxs("div",{className:Ie("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(B,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:I.user.login}),I.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),I.user.email&&s.jsx("span",{children:I.user.email})]}),s.jsx("div",{className:Ie("typography-meta text-muted-foreground",I.disabled?"opacity-60":void 0),children:I.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>P(!I.disabled),disabled:m,className:Ie(a?"w-full":void 0),children:I.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[F,K?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Cn,{children:e("settings.github.page.ghCli.title")}),K]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(Ge,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:F}),K?s.jsx(Ge,{title:e("settings.github.page.ghCli.title"),children:K}):null]})},mb=()=>{const t=rt.c(37),{t:e}=Xe(),a=qn(pb),n=qn(gb),r=qn(hb),[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,m=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(B,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=f):f=t[6];let u;t[7]!==e?(u=e("settings.integrations.github.title"),t[7]=e,t[8]=u):u=t[8];let g;t[9]!==u?(g=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:u}),t[9]=u,t[10]=g):g=t[10];let v;t[11]!==e?(v=e("settings.integrations.github.description"),t[11]=e,t[12]=v):v=t[12];let j;t[13]!==v?(j=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:v}),t[13]=v,t[14]=j):j=t[14];let b;t[15]!==g||t[16]!==j?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[g,j]}),t[15]=g,t[16]=j,t[17]=b):b=t[17];let k;t[18]!==m?(k=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",m),t[18]=m,t[19]=k):k=t[19];let p;t[20]!==h||t[21]!==k?(p=s.jsx("span",{"aria-live":"polite",className:k,children:h}),t[20]=h,t[21]=k,t[22]=p):p=t[22];const N=i&&"rotate-180";let P;t[23]!==N?(P=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",N),t[23]=N,t[24]=P):P=t[24];let C;t[25]!==P?(C=s.jsx(B,{name:"arrow-down-s",className:P}),t[25]=P,t[26]=C):C=t[26];let w;t[27]!==C||t[28]!==b||t[29]!==p?(w=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,p,C]}),t[27]=C,t[28]=b,t[29]=p,t[30]=w):w=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(ub,{embedded:!0})}),t[31]=D):D=t[31];let x;t[32]!==w?(x=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[w,D]}),t[32]=w,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 pb(t){return t.status}function gb(t){return t.isLoading}function hb(t){return t.hasChecked}const zi="__none__",_i="__inherit__";function fb({linear:t,connected:e,organizationId:a}){const{t:n}=Xe(),r=an(b=>b.projects),[i,l]=o.useState(null),[d,c]=o.useState(!1),[h,m]=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 u=o.useCallback(async b=>{const k={};for(const p of b.teams??[])p.projectPath&&(k[p.id]=p.projectPath);m(!0),hs("saving");try{const p=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(p.connected===!1){l(null),hs("error");return}l(p),c(!1),hs("saved")}catch(p){console.error("Failed to save Linear mapping:",p),hs("error")}finally{m(!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 g=b=>r.find(p=>p.path===b)?.label?.trim()||b,v=b=>!b||b===zi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):g(b),j=b=>!b||b===_i?n("settings.integrations.linear.mapping.teams.useDefault"):g(b);return s.jsxs("div",{className:Ms,children:[r.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(St,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Et,{value:i.defaultProjectPath||zi,disabled:h||r.length===0,onValueChange:b=>{u({...i,defaultProjectPath:b===zi?null:b})},children:[s.jsx(At,{size:Vt,className:nn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(_t,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:v})}),s.jsxs(Tt,{children:[s.jsx(mt,{value:zi,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:g(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:Ms,children:(i.teams??[]).map(b=>s.jsx(St,{label:`${b.key} · ${b.name}`,children:s.jsxs(Et,{value:b.projectPath||_i,disabled:h||r.length===0,onValueChange:k=>{u({...i,teams:(i.teams??[]).map(p=>p.id===b.id?{...p,projectPath:k===_i?null:k}:p)})},children:[s.jsx(At,{size:Vt,className:nn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(_t,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:j})}),s.jsxs(Tt,{children:[s.jsx(mt,{value:_i,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:g(k.path)},k.id))]})]})},b.id))})})]})}function xb({linear:t,connected:e}){const{t:a}=Xe(),[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 m=!1;return t.preferencesGet().then(f=>{m||(r(f.sessionComments),l(!1))}).catch(()=>{m||l(!0)}),()=>{m=!0}},[e,t]);const h=o.useCallback(async m=>{const f=n;r(m),c(!0);try{const u=await t.preferencesSet({sessionComments:m});r(u.sessionComments),hs("saved")}catch{r(f),hs("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:Ms,children:s.jsx(St,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(_a,{checked:n===!0,disabled:n===null||d,onCheckedChange:m=>{h(m)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const bb=3*6e4,vb=1500;function Jl(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 yb(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const jb=()=>{const{t}=Xe(),e=Ua()?.linear,a=Ea(I=>I.status),n=Ea(I=>I.isLoading),r=Ea(I=>I.hasChecked),i=Ea(I=>I.refreshStatus),l=Ea(I=>I.setStatus),[d,c]=o.useState(!1),[h,m]=o.useState(!1),[f,u]=o.useState(!1),g=o.useRef(null),v=o.useCallback(()=>{g.current!=null&&(window.clearInterval(g.current),g.current=null),m(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{v()}},[r,i,e,v]);const j=o.useCallback(async()=>{if(!e)return;v(),c(!0);const I=Jl(Ea.getState().status);try{const E=await e.authStart(os()?"desktop":"web");m(!0),u(!0),yn(E.authorizationUrl);const F=Date.now()+bb;g.current=window.setInterval(()=>{(async()=>{if(Date.now()>F){v(),$.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const K=await i(e,{force:!0});yb(I,Jl(K))&&(v(),$.success(t("settings.integrations.linear.toast.connected")),Kc())})()},vb)}catch(E){console.error("Failed to start Linear connect:",E),$.error(t("settings.integrations.linear.toast.startConnectFailed")),v()}finally{c(!1)}},[i,e,v,t]),b=o.useCallback(async I=>{if(!(!e||!I)){c(!0);try{const E=await e.authActivate(I);l(E),$.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(E){console.error("Failed to switch Linear workspace:",E),$.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(),$.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(I){console.error("Failed to disconnect Linear:",I),$.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[i,e,v,t]);if(!e)return null;const p=!!a?.connected,N=a?.user,P=a?.organization,w=(a?.workspaces??[]).filter(I=>!I.current),D=N?.displayName?.trim()||N?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),x=h?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):p?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)]":p?"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:I=>{if(h){u(!0);return}u(I)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(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(B,{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(B,{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:[p?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[N?.avatarUrl?s.jsx("img",{src:N.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(B,{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,N?.email].filter(Boolean).join(" · ")})]})]}):h?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,p?s.jsxs(s.Fragment,{children:[s.jsx(fb,{linear:e,connected:p,organizationId:P?.id??null}),s.jsx(xb,{linear:e,connected:p}),w.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:w.map(I=>{const E=I.user,F=I.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:F}),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(I.id)},disabled:d,children:t("settings.integrations.linear.actions.switchTo")})]},I.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{j()},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:()=>{j()},disabled:d||n&&!r,children:[d?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},wb=()=>{const t=rt.c(23),{t:e}=Xe();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=cs(),t[0]=a):a=t[0];const n=!a,r=!!Ua()?.linear,i=Vs(kb),l=Vs(Nb);let d,c,h,m,f,u;if(t[1]!==i||t[2]!==l||t[3]!==e){const j=!cs()&&!zc()?i.filter(Sb):[];c=n||r||j.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?(m=e("settings.page.integrations.description"),t[12]=e,t[13]=m):m=t[13],f=!0,u=c?s.jsxs(Ge,{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(mb,{}):null,r?s.jsx(jb,{}):null,j.map(b=>s.jsx(dd,{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]=m,t[8]=f,t[9]=u}else d=t[4],c=t[5],h=t[6],m=t[7],f=t[8],u=t[9];let g;t[14]!==c?(g=s.jsx(rb,{divider:c}),t[14]=c,t[15]=g):g=t[15];let v;return t[16]!==d||t[17]!==h||t[18]!==m||t[19]!==f||t[20]!==u||t[21]!==g?(v=s.jsxs(d,{title:h,description:m,showSaveStatus:f,children:[u,g]}),t[16]=d,t[17]=h,t[18]=m,t[19]=f,t[20]=u,t[21]=g,t[22]=v):v=t[22],v};function kb(t){return t.guests}function Nb(t){return t.runtimeKey}function Sb(t){return t.source==="bundled"&&t.integration&&jo(t)}const Fa="__default__",Cb=500,Ib=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),Pb=(t,e)=>{const a=rt.c(9),n=it(Eb);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=m=>m.id===t,a[5]=t,a[6]=c):c=a[6],i=n.find(c)?.models.find(m=>m.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},ud=t=>{const e=rt.c(33),{providerID:a,modelID:n,value:r,onChange:i,ariaLabel:l,className:d}=t,{t:c}=Xe(),h=Pb(a,n);let m;e[0]!==c?(m=A=>A===Fa?c("settings.routing.thinking.default"):A.charAt(0).toUpperCase()+A.slice(1),e[0]=c,e[1]=m):m=e[1];const f=m,u=r??Fa;let g;e[2]!==i?(g=A=>i(A===Fa?null:A),e[2]=i,e[3]=g):g=e[3];const v=h.length===0;let j;e[4]!==d?(j=Ie(nn,d),e[4]=d,e[5]=j):j=e[5];const b=r??Fa;let k;e[6]!==f||e[7]!==b?(k=f(b),e[6]=f,e[7]=b,e[8]=k):k=e[8];let p;e[9]!==k?(p=s.jsx(_t,{children:k}),e[9]=k,e[10]=p):p=e[10];let N;e[11]!==l||e[12]!==j||e[13]!==p?(N=s.jsx(At,{size:Vt,className:j,"aria-label":l,children:p}),e[11]=l,e[12]=j,e[13]=p,e[14]=N):N=e[14];let P;e[15]!==f?(P=f(Fa),e[15]=f,e[16]=P):P=e[16];let C;e[17]!==P?(C=s.jsx(mt,{value:Fa,children:P}),e[17]=P,e[18]=C):C=e[18];let w;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],w=h.map(A),e[19]=f,e[20]=h,e[21]=w}else w=e[21];let D;e[24]!==C||e[25]!==w?(D=s.jsxs(Tt,{children:[C,w]}),e[24]=C,e[25]=w,e[26]=D):D=e[26];let x;return e[27]!==D||e[28]!==u||e[29]!==g||e[30]!==v||e[31]!==N?(x=s.jsxs(Et,{value:u,onValueChange:g,disabled:v,children:[N,D]}),e[27]=D,e[28]=u,e[29]=g,e[30]=v,e[31]=N,e[32]=x):x=e[32],x},Ab=t=>{const e=rt.c(49),{category:a,expanded:n,onToggle:r,onChange:i,onReset:l,onRemove:d}=t,{t:c}=Xe();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 m=h;let f;e[4]!==a.agent||e[5]!==m?(f=[m,a.agent].filter(Boolean),e[4]=a.agent,e[5]=m,e[6]=f):f=e[6];const u=f.join(" · "),g=!a.enabled&&"opacity-60";let v;e[7]!==g?(v=Ie("py-1",g),e[7]=g,e[8]=v):v=e[8];const j=n?"arrow-down-s":"arrow-right-s";let b;e[9]!==j?(b=s.jsx(B,{name:j,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[9]=j,e[10]=b):b=e[10];const k=a.name||a.id;let p;e[11]!==k?(p=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:k}),e[11]=k,e[12]=p):p=e[12];let N;e[13]!==u?(N=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:u}),e[13]=u,e[14]=N):N=e[14];let P;e[15]!==n||e[16]!==r||e[17]!==b||e[18]!==p||e[19]!==N?(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,p,N]}),e[15]=n,e[16]=r,e[17]=b,e[18]=p,e[19]=N,e[20]=P):P=e[20];const C=a.enabled;let w;e[21]!==i?(w=E=>i({enabled:E}),e[21]=i,e[22]=w):w=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]!==w||e[28]!==D?(x=s.jsx(_a,{checked:C,onCheckedChange:w,"aria-label":D}),e[26]=a.enabled,e[27]=w,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(Rt,{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(Rt,{label:c("settings.routing.category.agent"),info:c("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(ho,{agentName:a.agent??"",onChange:E=>i({agent:E||null}),filter:Db,className:Ie(qs,"w-full")})}),s.jsx(Rt,{label:c("settings.routing.category.model"),info:c("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(la,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(E,F)=>i({model:{providerID:E,modelID:F},variant:null}),className:Ie(qs,"w-full"),placeholder:c("settings.routing.model.useFallback")})}),s.jsx(Rt,{label:c("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(ud,{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(Rt,{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 I;return e[45]!==A||e[46]!==R||e[47]!==v?(I=s.jsxs("div",{className:v,children:[A,R]}),e[45]=A,e[46]=R,e[47]=v,e[48]=I):I=e[48],I},Tb=()=>{const{t}=Xe(),e=Xs(O=>O.available),a=Xs(O=>O.autoReady),n=Xs(O=>O.tokenPresent),r=Xs(O=>O.jevSource),i=Xs(O=>O.config),l=Xs(O=>O.builtins),d=Xs(O=>O.loaded),c=Xs(O=>O.loadError),h=Xs(O=>O.load),m=Xs(O=>O.saveConfig),f=Xs(O=>O.setToken),u=Xs(O=>O.clearToken),[g,v]=o.useState(i),[j,b]=o.useState(""),[k,p]=o.useState(!1),[N,P]=o.useState(null),[C,w]=o.useState(""),[D,x]=o.useState(null),A=o.useRef(null),R=o.useRef(null),I=o.useRef(Promise.resolve()),E=o.useRef(0);o.useEffect(()=>{h()},[h]),o.useEffect(()=>{!A.current&&E.current===0&&v(i)},[i]);const F=o.useCallback(()=>{const O=A.current;if(!O||(A.current=null,O.runtimeKey!==jn()))return I.current;E.current+=1,hs("saving");const Q=I.current.then(async()=>{try{if(O.runtimeKey!==jn()){hs("saved");return}await m(O.config),hs("saved")}catch{hs("error")}finally{E.current-=1}});return I.current=Q,Q},[m]);o.useEffect(()=>()=>{R.current&&clearTimeout(R.current),F()},[F]);const K=it(O=>O.settingsDefaultModel),S=it(O=>O.settingsDefaultVariant),M=o.useRef(!1);o.useEffect(()=>{if(M.current||!d||!i||i.fallback)return;const O=Ln(K);!O||_c(O.providerId,O.modelId)||(M.current=!0,z(Q=>Q.fallback?Q:{...Q,fallback:{model:{providerID:O.providerId,modelID:O.modelId},variant:S??null}}))},[d,i,K,S]);const z=o.useCallback(O=>{v(Q=>{if(!Q)return Q;const ce=O(Q);return A.current={config:ce,runtimeKey:jn()},R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,F()},Cb),ce})},[F]),_=o.useCallback((O,Q)=>{z(ce=>({...ce,categories:ce.categories.map(de=>de.id===O?{...de,...Q}:de)}))},[z]),q=async()=>{const O=j.trim();if(O){p(!0),P(null);try{await f(O),b("")}catch(Q){P(Q instanceof Error?Q.message:String(Q))}finally{p(!1)}}},X=async()=>{p(!0),P(null);try{await u()}catch(O){P(O instanceof Error?O.message:String(O))}finally{p(!1)}},J=()=>{const O=C.trim();if(!O||!g)return;const Q=Ib(O)||`category-${Date.now()}`;let ce=Q,de=2;for(;g.categories.some(pe=>pe.id===ce);)ce=`${Q}-${de++}`;z(pe=>({...pe,categories:[...pe.categories,{id:ce,builtin:!1,enabled:!0,name:O,description:"",model:null,variant:null,agent:null}]})),w(""),x(ce)},H=O=>{const Q=l.find(ce=>ce.id===O);Q&&_(O,{name:Q.name,description:Q.description,model:null,variant:null,agent:null,enabled:!0})},L=O=>{const Q=l.find(ce=>ce.id===O);Q&&z(ce=>({...ce,categories:[...ce.categories,{id:O,builtin:!0,enabled:!0,name:Q.name,description:Q.description,model:null,variant:null,agent:null}]}))},V=O=>{z(Q=>({...Q,categories:Q.categories.filter(ce=>ce.id!==O)}))},Z=g?.categories.filter(O=>O.enabled).length??0,U=l.filter(O=>!g?.categories.some(Q=>Q.id===O.id)),te=g?.enabled?g.fallback?Z<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:Bi,children:t("settings.routing.loadError",{error:c})}):null,!d||!g?null:e?s.jsxs(s.Fragment,{children:[s.jsx(Ge,{title:t("settings.routing.access.title"),divider:!1,children:s.jsxs("div",{className:Ms,children:[s.jsx("p",{className:Ss,children:t("settings.routing.access.intro")}),s.jsx("p",{className:Ss,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(St,{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:j,onChange:O=>b(O.target.value),onKeyDown:O=>{O.key==="Enter"&&q()},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:()=>{q()},disabled:k||j.trim().length===0,children:t("settings.routing.token.save")}),n?s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{X()},disabled:k,children:t("settings.routing.token.remove")}):null]})}),N?s.jsx("p",{className:Bi,children:N}):null]})}),s.jsx(Ge,{title:t("settings.routing.auto.title"),children:s.jsxs("div",{className:Ms,children:[s.jsx("div",{className:ls,children:s.jsx(gt,{settingsItem:"routing.enabled",checked:g.enabled,onChange:O=>z(Q=>({...Q,enabled:O})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:Ss,children:te}),s.jsx(St,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(la,{providerId:g.fallback?.model.providerID??"",modelId:g.fallback?.model.modelID??"",onChange:(O,Q)=>z(ce=>({...ce,fallback:{model:{providerID:O,modelID:Q},variant:null}})),className:qs,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(St,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(ud,{providerID:g.fallback?.model.providerID,modelID:g.fallback?.model.modelID,value:g.fallback?.variant??null,onChange:O=>z(Q=>Q.fallback?{...Q,fallback:{...Q.fallback,variant:O}}:Q),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(Ge,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:Ms,children:[s.jsx("p",{className:Ss,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:g.categories.map(O=>s.jsx(Ab,{category:O,expanded:D===O.id,onToggle:()=>x(Q=>Q===O.id?null:O.id),onChange:Q=>_(O.id,Q),onReset:O.builtin?()=>H(O.id):null,onRemove:()=>V(O.id)},O.id))}),U.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:U.map(O=>s.jsx(G,{size:"sm",variant:"outline",onClick:()=>L(O.id),children:t("settings.routing.category.restore",{name:O.name})},O.id))}):null,s.jsx(St,{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:C,onChange:O=>w(O.target.value),onKeyDown:O=>{O.key==="Enter"&&J()},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:J,disabled:C.trim().length===0,children:t("settings.routing.categories.add")})]})})]})}),s.jsx(Ge,{title:t("settings.routing.safety.title"),children:s.jsxs("div",{className:Ms,children:[s.jsx("p",{className:Ss,children:t("settings.routing.safety.description")}),s.jsx("div",{className:ls,children:s.jsx(gt,{settingsItem:"routing.safety-enabled",checked:g.safetyNet.enabled,onChange:O=>z(Q=>({...Q,safetyNet:{...Q.safetyNet,enabled:O}})),label:t("settings.routing.safety.enable"),ariaLabel:t("settings.routing.safety.enable"),info:t("settings.routing.safety.enableInfo")})})]})})]}):s.jsx("p",{className:Bi,children:t("settings.routing.unavailable")})]})};function Eb(t){return t.providers}function Db(t){return Tc(t.mode)}const Mb={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"}},Rb=t=>{const e=rt.c(73),{guest:a,busy:n,onApprove:r,onDecline:i,onDismiss:l}=t,{t:d}=Xe();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 m;e[2]!==a?.filesystem?(m=a?.filesystem??[],e[2]=a?.filesystem,e[3]=m):m=e[3];const f=m;let u;e[4]!==a?.service?.permissions?.exec?(u=a?.service?.permissions?.exec??[],e[4]=a?.service?.permissions?.exec,e[5]=u):u=e[5];const g=u;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 j=v,b=a?.service;let k;e[8]!==b?(k=Ec(b,"browser"),e[8]=b,e[9]=k):k=e[9];const p=k,N=a?.integration?.apiOrigin??null,P=a!==null;let C;e[10]!==n||e[11]!==l?(C=Z=>{!Z&&!n&&l()},e[10]=n,e[11]=l,e[12]=C):C=e[12];const w=a?.name??"";let D;e[13]!==d||e[14]!==w?(D=d("settings.extensions.dialog.approveTitle",{name:w}),e[13]=d,e[14]=w,e[15]=D):D=e[15];let x;e[16]!==D?(x=s.jsx($t,{children:D}),e[16]=D,e[17]=x):x=e[17];const A=a?.name??"",R=a?.version?`v${a.version}`:"";let I;e[18]!==d||e[19]!==A||e[20]!==R?(I=d("settings.extensions.dialog.approveDescription",{name:A,version:R}),e[18]=d,e[19]=A,e[20]=R,e[21]=I):I=e[21];let E;e[22]!==I?(E=s.jsx(Bt,{children:I}),e[22]=I,e[23]=E):E=e[23];let F;e[24]!==x||e[25]!==E?(F=s.jsxs(Ut,{children:[x,E]}),e[24]=x,e[25]=E,e[26]=F):F=e[26];let K;if(e[27]!==N||e[28]!==f||e[29]!==p||e[30]!==h||e[31]!==g||e[32]!==j||e[33]!==d){let Z;e[35]!==N||e[36]!==f||e[37]!==p||e[38]!==g||e[39]!==j||e[40]!==d?(Z=U=>{const te=Mb[U];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(B,{name:te.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(te.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:d(te.detailKey)}),U==="filesystem"&&f.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:f.map(Fb)}):null,U==="network"&&N?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:N})]}):null,U==="service"&&g.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:g.join(", ")})]}):null,U==="service"&&j.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:j.join(", ")})]}):null,U==="service"&&p?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:d("settings.extensions.capability.service.providesBrowser")}):null]})]},U)},e[35]=N,e[36]=f,e[37]=p,e[38]=g,e[39]=j,e[40]=d,e[41]=Z):Z=e[41],K=h.map(Z),e[27]=N,e[28]=f,e[29]=p,e[30]=h,e[31]=g,e[32]=j,e[33]=d,e[34]=K}else K=e[34];let S;e[42]!==K?(S=s.jsx("ul",{className:"space-y-3",children:K}),e[42]=K,e[43]=S):S=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 z;e[47]!==d?(z=d("settings.extensions.dialog.decline"),e[47]=d,e[48]=z):z=e[48];let _;e[49]!==n||e[50]!==M||e[51]!==z?(_=s.jsx(G,{size:"sm",variant:"ghost",disabled:n,onClick:M,children:z}),e[49]=n,e[50]=M,e[51]=z,e[52]=_):_=e[52];let q;e[53]!==a||e[54]!==r?(q=()=>a&&r(a),e[53]=a,e[54]=r,e[55]=q):q=e[55];let X;e[56]!==d?(X=d("settings.extensions.dialog.approve"),e[56]=d,e[57]=X):X=e[57];let J;e[58]!==n||e[59]!==q||e[60]!==X?(J=s.jsx(G,{size:"sm",disabled:n,onClick:q,children:X}),e[58]=n,e[59]=q,e[60]=X,e[61]=J):J=e[61];let H;e[62]!==_||e[63]!==J?(H=s.jsxs(as,{children:[_,J]}),e[62]=_,e[63]=J,e[64]=H):H=e[64];let L;e[65]!==F||e[66]!==S||e[67]!==H?(L=s.jsxs(zt,{className:"max-w-md",children:[F,S,H]}),e[65]=F,e[66]=S,e[67]=H,e[68]=L):L=e[68];let V;return e[69]!==L||e[70]!==P||e[71]!==C?(V=s.jsx(Kt,{open:P,onOpenChange:C,children:L}),e[69]=L,e[70]=P,e[71]=C,e[72]=V):V=e[72],V};function Fb(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const Ob=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}},Lb=Gs({error:So(["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:es().trim().min(1).max(64).optional(),id:es().trim().min(1).max(128).optional()}),Kb=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"}},md=async t=>{try{const e=Lb.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"}}},pd=async(t,e)=>{if(!t.ok)return{ok:!1,...await md(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:Dc(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}}},zb=async(t,e={})=>{const a=Kb(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 pd(r,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},_b=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 pd(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},Ub=async t=>{try{const e=await Nt(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await md(e)).code}}catch{return{ok:!1,code:"failed"}}},$b=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}},Bb=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}},Br=(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}`},Vb=Gs({updates:to(es().min(1),ru)}),Hb=Gs({error:So(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found"]),required:es().trim().min(1).max(64).optional()}),Ql=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=Vb.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},qb=async t=>{try{const e=Hb.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"}}},Gb=async t=>{try{const e=await Nt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await qb(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=Dc(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},Wb=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",Yl=t=>t.name.toLowerCase().endsWith(".zip"),Jb=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",Qb=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",Yb=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(", ")},Zb=t=>{const e=rt.c(27),{guest:a,binding:n,busy:r,onSaved:i}=t,{t:l}=Xe(),[d,c]=o.useState(n.override??n.resolved??""),[h,m]=o.useState(!1),[f,u]=o.useState(!n.resolved);let g;e[0]!==n.override||e[1]!==n.resolved?(g=()=>{c(n.override??n.resolved??""),n.resolved||u(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=g):g=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(g,v);let j;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==i||e[11]!==l?(j=async P=>{m(!0);const C=await _m(a.id,n.id,P);if(m(!1),!C){$.error(l("settings.extensions.toast.socketSaveFailed"));return}$.success(l("settings.extensions.toast.socketSaved",{name:a.name})),u(!1),await i()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=i,e[11]=l,e[12]=j):j=e[12];const b=j;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&u(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const p=k;let N;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==r||e[20]!==p||e[21]!==f||e[22]!==b||e[23]!==h||e[24]!==l||e[25]!==d?(N=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:p,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:()=>u(!0),children:s.jsx(B,{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]=p,e[21]=f,e[22]=b,e[23]=h,e[24]=l,e[25]=d,e[26]=N):N=e[26],N},Xb=t=>{const e=rt.c(143),{guest:a,busy:n,onReview:r,onRemove:i,onSetEnabled:l,onUpdate:d}=t,{t:c}=Xe(),[h,m]=o.useState(!1),f=a.enabled!==!1;let u;e[0]!==a?(u=eo(a),e[0]=a,e[1]=u):u=e[1];const g=u;let v,j,b,k,p,N,P,C,w,D,x,A,R,I;if(e[2]!==f||e[3]!==a||e[4]!==g||e[5]!==h||e[6]!==c){const V=Yb(a);b=!!(a.source&&a.source!=="bundled");const Z=a.source==="bundled";let U;e[21]!==a?(U=Ob(a),e[21]=a,e[22]=U):U=e[22],k=U,I=a.source==="git"?a.update:void 0;let te;e[23]!==a.icon||e[24]!==a.id?(te=Ic(a.id,a.icon,Lc().authenticatedAsset),e[23]=a.icon,e[24]=a.id,e[25]=te):te=e[25];const O=te;let Q;e[26]!==Z||e[27]!==a.source||e[28]!==c?(Q=Z?null:c(Qb(a.source)),e[26]=Z,e[27]=a.source,e[28]=c,e[29]=Q):Q=e[29];const ce=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 pe;e[33]!==Q||e[34]!==ce||e[35]!==de?(pe=[Q,ce,de].filter(Boolean),e[33]=Q,e[34]=ce,e[35]=de,e[36]=pe):pe=e[36];const re=pe.join(" · "),Ce=a.path||a.id;let ie;e[37]!==f||e[38]!==g||e[39]!==c?(ie=c(g?"settings.extensions.status.needsApproval":f?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[37]=f,e[38]=g,e[39]=c,e[40]=ie):ie=e[40];const be=ie,ae=g?"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";j=kn,R=h,p=m,x="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let fe;e[41]!==a.icon?(fe=Ac(a.icon),e[41]=a.icon,e[42]=fe):fe=e[42];let xe;e[43]!==O||e[44]!==fe?(xe=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Pc,{icon:fe,iconSrc:O,className:"size-5 text-foreground"})}),e[43]=O,e[44]=fe,e[45]=xe):xe=e[45];let Oe;e[46]!==a.name?(Oe=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[46]=a.name,e[47]=Oe):Oe=e[47];let Ne;e[48]!==re?(Ne=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:re}),e[48]=re,e[49]=Ne):Ne=e[49];let he;e[50]!==Oe||e[51]!==Ne?(he=s.jsxs("div",{className:"min-w-0 flex-1",children:[Oe,Ne]}),e[50]=Oe,e[51]=Ne,e[52]=he):he=e[52];let Te;e[53]!==Z||e[54]!==c?(Te=Z?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]=Z,e[54]=c,e[55]=Te):Te=e[55];let we;e[56]!==c||e[57]!==I?(we=I?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:I.version})}):null,e[56]=c,e[57]=I,e[58]=we):we=e[58];let De;e[59]!==ae?(De=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ae),e[59]=ae,e[60]=De):De=e[60];let ve;e[61]!==be||e[62]!==De?(ve=s.jsx("span",{"aria-live":"polite",className:De,children:be}),e[61]=be,e[62]=De,e[63]=ve):ve=e[63];const ee=h&&"rotate-180";let ne;e[64]!==ee?(ne=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ee),e[64]=ee,e[65]=ne):ne=e[65];let ye;e[66]!==ne?(ye=s.jsx(B,{name:"arrow-down-s",className:ne}),e[66]=ne,e[67]=ye):ye=e[67],e[68]!==xe||e[69]!==he||e[70]!==Te||e[71]!==we||e[72]!==ve||e[73]!==ye?(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:[xe,he,Te,we,ve,ye]}),e[68]=xe,e[69]=he,e[70]=Te,e[71]=we,e[72]=ve,e[73]=ye,e[74]=A):A=e[74],v=Sn,D="border-t border-[var(--interactive-border)] px-4 py-4",N="space-y-3",e[75]!==Ce?(P=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:Ce,children:Ce}),e[75]=Ce,e[76]=P):P=e[76],e[77]!==Z||e[78]!==c?(C=Z?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[77]=Z,e[78]=c,e[79]=C):C=e[79],w=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]=g,e[5]=h,e[6]=c,e[7]=v,e[8]=j,e[9]=b,e[10]=k,e[11]=p,e[12]=N,e[13]=P,e[14]=C,e[15]=w,e[16]=D,e[17]=x,e[18]=A,e[19]=R,e[20]=I}else v=e[7],j=e[8],b=e[9],k=e[10],p=e[11],N=e[12],P=e[13],C=e[14],w=e[15],D=e[16],x=e[17],A=e[18],R=e[19],I=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 F;e[83]!==n||e[84]!==f||e[85]!==a?(F=f?(a.service?.socketBindings??[]).map(V=>s.jsx(Zb,{guest:a,binding:V,busy:n,onSaved:On},V.id)):null,e[83]=n,e[84]=f,e[85]=a,e[86]=F):F=e[86];let K;e[87]!==n||e[88]!==a||e[89]!==d||e[90]!==c||e[91]!==I?(K=I?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:I.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]=I,e[92]=K):K=e[92];let S;e[93]!==n||e[94]!==a||e[95]!==g||e[96]!==r||e[97]!==c?(S=g?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]=g,e[96]=r,e[97]=c,e[98]=S):S=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 z;e[106]!==n||e[107]!==b||e[108]!==a.id||e[109]!==a.name||e[110]!==i||e[111]!==c?(z=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]=z):z=e[112];let _;e[113]!==k||e[114]!==c?(_=k?s.jsxs(G,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{yn(k)},children:[s.jsx(B,{name:"external-link",className:"size-4"}),c("settings.extensions.actions.openSource")]}):null,e[113]=k,e[114]=c,e[115]=_):_=e[115];let q;e[116]!==K||e[117]!==S||e[118]!==M||e[119]!==z||e[120]!==_?(q=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[K,S,M,z,_]}),e[116]=K,e[117]=S,e[118]=M,e[119]=z,e[120]=_,e[121]=q):q=e[121];let X;e[122]!==E||e[123]!==F||e[124]!==q||e[125]!==N||e[126]!==P||e[127]!==C||e[128]!==w?(X=s.jsxs("div",{className:N,children:[P,C,w,E,F,q]}),e[122]=E,e[123]=F,e[124]=q,e[125]=N,e[126]=P,e[127]=C,e[128]=w,e[129]=X):X=e[129];let J;e[130]!==v||e[131]!==X||e[132]!==D?(J=s.jsx(v,{className:D,children:X}),e[130]=v,e[131]=X,e[132]=D,e[133]=J):J=e[133];let H;e[134]!==J||e[135]!==x||e[136]!==A?(H=s.jsxs("div",{className:x,children:[A,J]}),e[134]=J,e[135]=x,e[136]=A,e[137]=H):H=e[137];let L;return e[138]!==j||e[139]!==p||e[140]!==H||e[141]!==R?(L=s.jsx(j,{open:R,onOpenChange:p,children:H}),e[138]=j,e[139]=p,e[140]=H,e[141]=R,e[142]=L):L=e[142],L},ev=()=>{const t=rt.c(174),{t:e}=Xe(),a=Vs(tv),n=Vs(sv),r=Vs(nv),i=Vs(av),[l,d]=o.useState(null),[c,h]=o.useState(!1),[m,f]=o.useState("global"),u=n==="unsupported",[g,v]=o.useState(""),[j,b]=o.useState(!1),[k,p]=o.useState(!1),N=o.useRef(!1),[P,C]=o.useState(null),[w,D]=o.useState(null),[x,A]=o.useState(!1),R=o.useRef(0),I=o.useRef(null);let E;t[0]===Symbol.for("react.memo_cache_sentinel")?(E=em(),t[0]=E):E=t[0];const F=E;let K;t[1]===Symbol.for("react.memo_cache_sentinel")?(K=[],t[1]=K):K=t[1],o.useEffect(iv,K);let S,M;t[2]!==i||t[3]!==u?(S=()=>{let Se=!1;if(d(null),h(!1),f("global"),C(null),D(null),N.current=!1,!u)return Promise.all([ou(),lu()]).then(qe=>{const[vt,Ct]=qe;Se||d({runtimeKey:i,profiles:vt,global:Ct})}).catch(()=>{Se||h(!0)}),()=>{Se=!0}},M=[i,u],t[2]=i,t[3]=u,t[4]=S,t[5]=M):(S=t[4],M=t[5]),o.useEffect(S,M);const z=l?.runtimeKey===i?l:null;let _;t[6]!==e?(_=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=_):_=t[7];const q=z?.global?.userName??"",X=z?.global?.userEmail??"";let J;t[8]!==_||t[9]!==q||t[10]!==X?(J={id:"global",name:_,userName:q,userEmail:X,icon:"fingerprint",color:"info"},t[8]=_,t[9]=q,t[10]=X,t[11]=J):J=t[11];let H;t[12]!==z?.profiles||t[13]!==J?(H=[J,...z?.profiles.filter(rv)??[]],t[12]=z?.profiles,t[13]=J,t[14]=H):H=t[14];const L=H;let V;t[15]!==L||t[16]!==m?(V=L.find(Se=>Se.id===m)??L[0],t[15]=L,t[16]=m,t[17]=V):V=t[17];const Z=V;let U,te;t[18]!==n?(U=()=>{if(n!=="ready"||N.current)return;N.current=!0;const Se=Vs.getState().runtimeKey;Ql(!1).then(qe=>{qe.ok&&Vs.getState().applyUpdates(qe.updates,Se)})},te=[n],t[18]=n,t[19]=U,t[20]=te):(U=t[19],te=t[20]),o.useEffect(U,te);let O;t[21]!==e?(O=async()=>{p(!0);const Se=Vs.getState().runtimeKey,qe=await Ql(!0);if(p(!1),!qe.ok){$.error(e("settings.extensions.toast.checkFailed"));return}Vs.getState().applyUpdates(qe.updates,Se),Object.keys(qe.updates).length===0&&$.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=O):O=t[22];const Q=O;let ce;t[23]!==e?(ce=async Se=>{b(!0);const qe=await Gb(Se.id);if(b(!1),!qe.ok){$.error(qe.code==="host-too-old"&&qe.required?e("settings.extensions.toast.hostTooOld",{version:qe.required}):e(Jb(qe.code)));return}Dr(Se.id),$.success(e("settings.extensions.toast.updated",{name:qe.guest.name,version:qe.guest.version??""})),await On(),eo(qe.guest)&&D(qe.guest)},t[23]=e,t[24]=ce):ce=t[24];const de=ce;let pe;if(t[25]!==a||t[26]!==e){const Se=async(qe,vt,Ct)=>{const Jt=Ct===void 0?{}:Ct;if(!qe.ok){if(Jt.allowConflictDialog!==!1&&(qe.code==="id-taken"||qe.code==="already-installed")){const Zt=qe.id?a.find(ts=>ts.id===qe.id):void 0;return C({source:vt,name:Zt?.name??qe.id??(vt.kind==="file"?vt.file.name:vt.input)}),!1}return qe.code==="host-too-old"?$.error(qe.required?e("settings.extensions.toast.hostTooOld",{version:qe.required}):e("settings.extensions.toast.failed"),{description:qe.diagnostic?Br(qe.diagnostic,e):void 0}):$.error(e(Wb(qe.code)),{description:qe.diagnostic?Br(qe.diagnostic,e):void 0}),!1}return v(""),C(null),$.success(qe.replaced?e("settings.extensions.toast.reinstalled",{name:qe.guest.name}):e("settings.extensions.toast.added",{name:qe.guest.name})),await On(),eo(qe.guest)&&D(qe.guest),!0};pe=async(qe,vt)=>{const Ct=vt===void 0?{}:vt,Jt=jn();qe.kind==="input"&&v(qe.input),b(!0);const Zt=qe.kind==="file"?await _b(qe.file,Ct):await zb(qe.input,{...Ct,gitIdentityId:qe.gitIdentityId});b(!1),jn()===Jt&&await Se(Zt,qe,{allowConflictDialog:!Ct.replace})},t[25]=a,t[26]=e,t[27]=pe}else pe=t[27];const re=pe;let Ce;t[28]!==g||t[29]!==re||t[30]!==Z||t[31]!==e?(Ce=async()=>{const Se=g.trim();if(!Se){$.error(e("settings.extensions.toast.invalidPath"));return}await re({kind:"input",input:Se,gitIdentityId:Z.id})},t[28]=g,t[29]=re,t[30]=Z,t[31]=e,t[32]=Ce):Ce=t[32];const ie=Ce;let be;t[33]!==re?(be=async()=>{if(!F)return;const Se=await tm("");Se.success&&Se.path&&await re({kind:"input",input:Se.path})},t[33]=re,t[34]=be):be=t[34];const ae=be;let fe;t[35]!==re?(fe=async()=>{if(!F){I.current?.click();return}const Se=await wo({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Se.success&&Se.path&&await re({kind:"input",input:Se.path})},t[35]=re,t[36]=fe):fe=t[36];const xe=fe;let Oe;t[37]!==re||t[38]!==e?(Oe=async Se=>{const qe=Se.target.files?.[0]??null;if(Se.target.value="",!!qe){if(!Yl(qe)){$.error(e("settings.extensions.toast.invalidPath"));return}await re({kind:"file",file:qe})}},t[37]=re,t[38]=e,t[39]=Oe):Oe=t[39];const Ne=Oe;let he;t[40]!==j?(he=Se=>{j||(Se.preventDefault(),R.current=R.current+1,A(!0))},t[40]=j,t[41]=he):he=t[41];const Te=he;let we;t[42]!==j?(we=Se=>{j||(Se.preventDefault(),Se.dataTransfer.dropEffect="copy")},t[42]=j,t[43]=we):we=t[43];const De=we;let ve;t[44]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>{R.current=Math.max(0,R.current-1),R.current===0&&A(!1)},t[44]=ve):ve=t[44];const ee=ve;let ne;t[45]!==j||t[46]!==re||t[47]!==e?(ne=async Se=>{if(Se.preventDefault(),R.current=0,A(!1),j)return;const qe=Se.dataTransfer.items[0],vt=qe?.getAsFile()??null,Jt=(qe?.webkitGetAsEntry()??null)?.isDirectory===!0,Zt=vt!==null&&!Jt&&Yl(vt),ts=vt&&F?sm(vt):null;if(ts&&(Jt||Zt)){await re({kind:"input",input:ts});return}if(Jt){$.error(e(F?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!vt||!Zt){$.error(e("settings.extensions.toast.invalidPath"));return}await re({kind:"file",file:vt})},t[45]=j,t[46]=re,t[47]=e,t[48]=ne):ne=t[48];const ye=ne;let Ae;t[49]!==P||t[50]!==re?(Ae=async()=>{P&&await re(P.source,{replace:!0})},t[49]=P,t[50]=re,t[51]=Ae):Ae=t[51];const ze=Ae;let Qe;t[52]!==e?(Qe=async(Se,qe)=>{b(!0);const vt=await Ub(Se);if(b(!1),!vt.ok){$.error(e("settings.extensions.toast.removeFailed"));return}Dr(Se),$.success(e("settings.extensions.toast.removed",{name:qe})),await On()},t[52]=e,t[53]=Qe):Qe=t[53];const Be=Qe;let _e;t[54]!==e?(_e=async Se=>{b(!0);const qe=await Bb(Se.id,Se.capabilities.requested);if(b(!1),!qe){$.error(e("settings.extensions.toast.approveFailed"));return}D(null),$.success(e("settings.extensions.toast.approved",{name:Se.name})),await On()},t[54]=e,t[55]=_e):_e=t[55];const Me=_e;let nt;t[56]!==Be?(nt=async Se=>{D(null),await Be(Se.id,Se.name)},t[56]=Be,t[57]=nt):nt=t[57];const pt=nt;let lt;t[58]!==e?(lt=async(Se,qe,vt)=>{b(!0);const Ct=await $b(Se,vt);if(b(!1),!Ct){$.error(e("settings.extensions.toast.enabledFailed"));return}vt||Dr(Se),$.success(vt?e("settings.extensions.toast.enabled",{name:qe}):e("settings.extensions.toast.disabled",{name:qe})),await On()},t[58]=e,t[59]=lt):lt=t[59];const ut=lt;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]!==xe||t[67]!==j||t[68]!==x||t[69]!==L||t[70]!==l||t[71]!==c||t[72]!==g||t[73]!==Te||t[74]!==De||t[75]!==ye||t[76]!==Ne||t[77]!==Z||t[78]!==e||t[79]!==u?(st=u?null:s.jsxs(Ge,{title:e("settings.extensions.add.action"),info:e("settings.extensions.add.info"),children:[s.jsx(Rt,{label:e("settings.extensions.add.label"),info:e(F?"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:Te,onDragOver:De,onDragLeave:ee,onDrop:Se=>{ye(Se)},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:g,onChange:Se=>v(Se.target.value),onKeyDown:Se=>{Se.key==="Enter"&&(Se.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",F?"pr-14":"pr-8"),disabled:j}),s.jsx("input",{ref:I,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Se=>{Ne(Se)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[F?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:j,onClick:()=>{ae()},children:s.jsx(B,{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:j,onClick:()=>{xe()},children:s.jsx(B,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(jm,{activeProfile:Z,identities:L,onSelect:Se=>f(Se.id),isApplying:j||!l&&!c,iconOnly:!0})}),s.jsxs(G,{type:"button",size:"sm",disabled:j,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{ie()},children:[s.jsx(B,{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]=xe,t[67]=j,t[68]=x,t[69]=L,t[70]=l,t[71]=c,t[72]=g,t[73]=Te,t[74]=De,t[75]=ye,t[76]=Ne,t[77]=Z,t[78]=e,t[79]=u,t[80]=st):st=t[80];let ue;t[81]!==e?(ue=e("settings.extensions.section.installed"),t[81]=e,t[82]=ue):ue=t[82];let oe;t[83]!==j||t[84]!==Q||t[85]!==k||t[86]!==n||t[87]!==e||t[88]!==u?(oe=u?null:s.jsxs(G,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:j||k||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{Q()},children:[s.jsx(B,{name:"refresh",className:Ie("h-4 w-4",k&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[83]=j,t[84]=Q,t[85]=k,t[86]=n,t[87]=e,t[88]=u,t[89]=oe):oe=t[89];let Pe;t[90]!==r||t[91]!==n||t[92]!==e?(Pe=n==="error"||r?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),r?`
29
- ${Br(r,e)}`:""]}):null,t[90]=r,t[91]=n,t[92]=e,t[93]=Pe):Pe=t[93];let Re;t[94]!==e||t[95]!==u?(Re=u?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[94]=e,t[95]=u,t[96]=Re):Re=t[96];let Fe;t[97]!==a.length||t[98]!==n||t[99]!==e?(Fe=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]=Fe):Fe=t[100];let $e;if(t[101]!==j||t[102]!==a||t[103]!==Be||t[104]!==ut||t[105]!==de){let Se;t[107]!==j||t[108]!==Be||t[109]!==ut||t[110]!==de?(Se=qe=>s.jsx(Xb,{guest:qe,busy:j,onReview:D,onRemove:Be,onSetEnabled:ut,onUpdate:de},qe.id),t[107]=j,t[108]=Be,t[109]=ut,t[110]=de,t[111]=Se):Se=t[111],$e=a.map(Se),t[101]=j,t[102]=a,t[103]=Be,t[104]=ut,t[105]=de,t[106]=$e}else $e=t[106];let W;t[112]!==ue||t[113]!==oe||t[114]!==Pe||t[115]!==Re||t[116]!==Fe||t[117]!==$e?(W=s.jsxs(Ge,{title:ue,contentClassName:"space-y-3",headerAction:oe,children:[Pe,Re,Fe,$e]}),t[112]=ue,t[113]=oe,t[114]=Pe,t[115]=Re,t[116]=Fe,t[117]=$e,t[118]=W):W=t[118];let Ve;t[119]!==Me?(Ve=Se=>{Me(Se)},t[119]=Me,t[120]=Ve):Ve=t[120];let et;t[121]!==pt?(et=Se=>{pt(Se)},t[121]=pt,t[122]=et):et=t[122];let dt;t[123]===Symbol.for("react.memo_cache_sentinel")?(dt=()=>D(null),t[123]=dt):dt=t[123];let ct;t[124]!==w||t[125]!==j||t[126]!==Ve||t[127]!==et?(ct=s.jsx(Rb,{guest:w,busy:j,onApprove:Ve,onDecline:et,onDismiss:dt}),t[124]=w,t[125]=j,t[126]=Ve,t[127]=et,t[128]=ct):ct=t[128];const jt=P!==null;let kt;t[129]!==j?(kt=Se=>{!Se&&!j&&C(null)},t[129]=j,t[130]=kt):kt=t[130];let yt;t[131]!==e?(yt=e("settings.extensions.dialog.reinstallTitle"),t[131]=e,t[132]=yt):yt=t[132];let bt;t[133]!==yt?(bt=s.jsx($t,{children:yt}),t[133]=yt,t[134]=bt):bt=t[134];const Ze=P?.name??"";let wt;t[135]!==e||t[136]!==Ze?(wt=e("settings.extensions.dialog.reinstallDescription",{name:Ze}),t[135]=e,t[136]=Ze,t[137]=wt):wt=t[137];let Le;t[138]!==wt?(Le=s.jsx(Bt,{children:wt}),t[138]=wt,t[139]=Le):Le=t[139];let He;t[140]!==bt||t[141]!==Le?(He=s.jsxs(Ut,{children:[bt,Le]}),t[140]=bt,t[141]=Le,t[142]=He):He=t[142];let Y;t[143]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>C(null),t[143]=Y):Y=t[143];let me;t[144]!==e?(me=e("settings.common.actions.cancel"),t[144]=e,t[145]=me):me=t[145];let Ke;t[146]!==j||t[147]!==me?(Ke=s.jsx(G,{size:"sm",variant:"ghost",disabled:j,onClick:Y,children:me}),t[146]=j,t[147]=me,t[148]=Ke):Ke=t[148];let Ee;t[149]!==ze?(Ee=()=>{ze()},t[149]=ze,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 se;t[153]!==j||t[154]!==Ee||t[155]!==Ye?(se=s.jsx(G,{size:"sm",disabled:j,onClick:Ee,children:Ye}),t[153]=j,t[154]=Ee,t[155]=Ye,t[156]=se):se=t[156];let ke;t[157]!==Ke||t[158]!==se?(ke=s.jsxs(as,{children:[Ke,se]}),t[157]=Ke,t[158]=se,t[159]=ke):ke=t[159];let at;t[160]!==He||t[161]!==ke?(at=s.jsxs(zt,{className:"max-w-md",children:[He,ke]}),t[160]=He,t[161]=ke,t[162]=at):at=t[162];let Mt;t[163]!==jt||t[164]!==kt||t[165]!==at?(Mt=s.jsx(Kt,{open:jt,onOpenChange:kt,children:at}),t[163]=jt,t[164]=kt,t[165]=at,t[166]=Mt):Mt=t[166];let Wt;return t[167]!==ht||t[168]!==Ue||t[169]!==st||t[170]!==W||t[171]!==ct||t[172]!==Mt?(Wt=s.jsxs(ns,{title:ht,description:Ue,children:[st,W,ct,Mt]}),t[167]=ht,t[168]=Ue,t[169]=st,t[170]=W,t[171]=ct,t[172]=Mt,t[173]=Wt):Wt=t[173],Wt};function tv(t){return t.guests}function sv(t){return t.status}function nv(t){return t.failure}function av(t){return t.runtimeKey}function iv(){On()}function rv(t){return t.id!=="global"}const _s=aa,ov=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=cu(e),n=(xe,Oe)=>t.colors[xe]??Oe,r=xe=>xe!=="transparent"&&(Bs(xe,"#000000")!==1||Bs(xe,"#ffffff")!==1),i=(xe,Oe)=>{const Ne=n(xe,Oe);return r(Ne)?Ne:Oe},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(([xe])=>t.colors[xe]),m=h?n(h[0],a.colors.surface.elevated):a.colors.surface.elevated,f=na(d,m,l),u=h?n(h[1],f):f,g=n("sideBar.background",n("panel.background",a.colors.surface.muted)),v=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),j=n("textBlockQuote.background",g),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),p=n("button.hoverBackground",k),N=t.colors["button.background"]?n("button.foreground",Ds(k,l)):Ds(k,l),P=_s(k,.5),w=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(xe=>xe&&r(xe))||_s(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(([xe])=>t.colors[xe]),I=R.find(([xe])=>[l,g,m].every(Oe=>{const Ne=Bs(n(xe,""),Oe,l);return Ne===null||Ne>1.01}))??R[0],E=I?n(I[0],a.colors.interactive.selection):a.colors.interactive.selection,F=I?n(I[1],d):d,K=n("focusBorder",n("inputOption.activeBorder",k)),S=K,M=n("editorCursor.foreground",a.colors.interactive.cursor),z=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),_=i("editorError.background",_s(z,e?.16:.12)),q=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),X=i("editorWarning.background",_s(q,e?.16:.12)),J=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),H=_s(J,e?.16:.12),L=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),V=i("editorInfo.background",_s(L,e?.16:.12)),Z=n("editorLineNumber.foreground",v),U=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),te=n("terminal.ansiBlue",k),O=n("terminal.ansiYellow",a.colors.syntax.base.number),Q=n("terminal.ansiCyan",a.colors.syntax.base.function),ce=n("terminal.ansiMagenta",d),de=n("terminal.ansiYellow",a.colors.syntax.base.type),pe=n("chat.requestBorder",w),re=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",H)),Ce=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",_)),ie=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",J)),be=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",z)),ae=n("gitDecoration.modifiedResourceForeground",L),fe=n("chat.requestBubbleBackground",n("chat.requestBackground",m));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:p,active:p,foreground:N,muted:P},surface:{background:l,foreground:d,muted:g,mutedForeground:v,elevated:m,elevatedForeground:u,overlay:b,subtle:j},interactive:{border:w,borderHover:n("toolbar.hoverOutline",w),borderFocus:K,selection:E,selectionForeground:F,focus:K,focusRing:S,cursor:M,hover:D,active:x},status:{error:z,errorForeground:Ds(z,l),errorBackground:_,errorBorder:_s(z,e?.45:.35),warning:q,warningForeground:Ds(q,l),warningBackground:X,warningBorder:_s(q,e?.45:.35),success:J,successForeground:Ds(J,l),successBackground:H,successBorder:_s(J,e?.45:.35),info:L,infoForeground:Ds(L,l),infoBackground:V,infoBorder:_s(L,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:ie,diffAddedBackground:re,diffRemoved:be,diffRemovedBackground:Ce,diffModified:ae,diffModifiedBackground:_s(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:Z,keyword:te,string:U,number:O,function:Q,variable:ce,type:de,operator:k}},tools:{border:pe,icon:n("icon.foreground",v),title:d,description:_s(v,.8),edit:{added:ie,addedBackground:re,removed:be,removedBackground:Ce,modified:ae,modifiedBackground:_s(ae,e?.16:.12),lineNumber:Z}},chat:{background:l,userMessage:d,userMessageBackground:fe,assistantMessage:d,assistantMessageBackground:l,timestamp:v,divider:w,typing:n("chat.thinkingShimmer",v),avatarBackground:n("chat.avatarBackground",l),avatarForeground:n("chat.avatarForeground",d),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",N),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",p),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",P)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",p),inlineCode:n("textPreformat.foreground",U),inlineCodeBackground:n("textPreformat.background",n("editor.background",l)),blockquote:d,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",w),listMarker:_s(k,.6)}}}},Vr=.075;function lv(t,e,a){const{surface:n,primary:r,status:i,interactive:l}=t.colors,d=n.background,c=t.metadata.variant==="dark",h=Ds(n.muted,d),m=[d,n.muted,n.elevated,Ns(l.selection,n.muted,1,d)].filter(k=>Ds(k,d)===h),f=k=>m.reduce((p,N)=>na(p,N,d),k),u=k=>[d,n.muted].every(p=>(Bs(k,p,d)??0)>=3),g=[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(g.find(u)??r.base);v!==r.base&&(r.base=v,r.foreground=Ds(v,d),r.hover=Ns(n.foreground,v,.08,d),r.active=Ns(n.foreground,v,.16,d),r.muted=aa(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=aa(v,.6))),m.some(k=>(Bs(l.focusRing,k,d)??0)<1.1)&&(l.focus=r.base,l.focusRing=r.base,l.borderFocus=r.base);const j=(k,p,N)=>m.every(P=>($o(k,p,P,d)??0)>=N);let b=f(i.info);if(!j(b,r.base,Vr)){const k=P=>j(P,r.base,Vr)&&[i.error,i.warning,i.success].every(C=>j(P,C,.1));let N=[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(!N){const P=Ns(b,d,1,d),w=[P,f(Ns(P,d,.5,d))].flatMap(D=>[.12,.18].flatMap(x=>[0,60,-60,90,-90,120,-120,180].map(A=>f(du(D,A,x)))));if(N=w.find(k),!N){const D=x=>Math.min(...[i.error,i.warning,i.success].map(A=>$o(x,A,n.muted,d)??0));N=w.filter(x=>j(x,r.base,Vr)).sort((x,A)=>D(A)-D(x))[0]}}N&&(b=N)}if(b!==i.info&&(i.info=b,i.infoForeground=Ds(b,d),i.infoBackground=aa(b,c?.16:.12),i.infoBorder=aa(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((Bs(k,d,d)??1)<1.1){const p=Ns(k,d,1,d);let P=(Bs(p,"#000000")??1)<(Bs(d,"#000000")??1)?"#000000":"#ffffff",C=p;((Bs(P,d,d)??1)<1.1||(Bs(p,d,d)??1)<1.01)&&(C=d,P=n.foreground);let w=0,D=1;for(let A=0;A<16;A++){const R=(w+D)/2,I=Ns(P,C,R,d);(Bs(I,d,d)??1)>=1.1?D=R:w=R}const x=Ns(P,C,D,d);(Bs(n.foreground,x,d)??0)>=4.5&&(t.colors.chat.userMessageBackground=x)}}}const tr=es().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),Mo=Gs({foreground:tr.optional()}),gd=Gs({scope:so([es(),hi(es())]).optional(),settings:Mo}),cv=Gs({name:es().trim().min(1).max(160).optional(),author:es().max(160).optional(),description:es().max(1024).optional(),type:So(["light","dark","hc","hc-black","hc-light"]).optional(),include:es().optional(),colors:to(es(),tr.nullable()).default({}),tokenColors:so([hi(gd),es()]).optional(),semanticHighlighting:No().optional(),semanticTokenColors:to(es(),so([tr,Mo])).optional()});function dv(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 uv(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 mv(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const r=tr.safeParse(n);if(r.success)return r.data;const i=Mo.safeParse(n);if(i.success&&i.data.foreground)return i.data.foreground}}function pv(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function gv(t,e,a,n){const r=Ds(a,a);if(e.some(c=>Ds(c,a)!==r))return t;let i=t;for(const c of e)i=na(i,c,a);let l=0,d=1;for(let c=0;c<16;c++){const h=(l+d)/2,m=aa(i,h);e.every(f=>(Bs(m,f,a)??0)>=n)?d=h:l=h}return aa(i,d)}function hd(t,e){if(new TextEncoder().encode(t).byteLength>Mc)throw new ia("size");let a;try{a=cv.parse(JSON.parse(Um(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ia("invalid")}const n=hi(gd).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ia("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 ia("background");const d=a.type?["dark","hc","hc-black"].includes(a.type):Ds(l,"#ffffff")==="#ffffff",c=d?"dark":"light",h=Ns(l,d?"#000000":"#ffffff",1),m=dv(n.data),f=n.data.filter(A=>!A.scope&&A.settings.foreground).at(-1)?.settings.foreground,u=r["editor.foreground"]??f??r.foreground??Ds(h,h),g=r["chat.list.background"]??h,v=r["interactive-session.foreground"]??r.foreground??u;r["editor.background"]=h,r["editor.foreground"]=u,r.foreground??=v,r["sideBar.background"]??=r["panel.background"]??Ns(v,g,.03,g),!r["editorWidget.background"]&&!r["dropdown.background"]&&!r["input.background"]&&(r["editorWidget.background"]=Ns(v,g,.04,g),r["editorWidget.foreground"]=na(v,r["editorWidget.background"],g)),r.descriptionForeground??=na(Ns(v,g,.6,g),g),r["widget.border"]??=r["input.border"]??r["panel.border"]??Ns(v,g,.15,g),r["toolbar.hoverBackground"]??=r["list.hoverBackground"]??Ns(v,g,.08,g),r["toolbar.activeBackground"]??=Ns(v,g,.12,g),!r["list.activeSelectionBackground"]&&!r["editor.selectionBackground"]&&(r["list.activeSelectionBackground"]=Ns(v,g,.16,g),r["list.activeSelectionForeground"]=na(v,r["list.activeSelectionBackground"],g)),r["button.background"]||(r["button.background"]=r["textLink.foreground"]??r.focusBorder??v,r["button.foreground"]=Ds(r["button.background"],g)),r.focusBorder??=r["button.background"],r["editorCursor.foreground"]??=u;const j=a.type?.startsWith("hc")??!1;j&&r.contrastBorder&&(r["widget.border"]=r.contrastBorder);const k=ov({kind:d&&j?"high-contrast":c,colors:r});if(j)k.colors.interactive.focusRing=r.focusBorder;else{const{surface:A,interactive:R}=k.colors,I=gv(R.border,[A.background,A.muted,A.elevated],A.background,d?1.15:1.2);R.border=I,r["toolbar.hoverOutline"]||(R.borderHover=I),k.colors.tools&&!r["chat.requestBorder"]&&(k.colors.tools.border=I),k.colors.chat&&(k.colors.chat.divider=I),k.colors.markdown&&!r["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=I)}const p=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},N=(A,R,I)=>mv(p,A)??uv(m,R)??I,P={background:h,foreground:u,comment:N(["comment"],["comment","comment.line","comment.block"],na(Ns(u,h,.6,h),h)),keyword:N(["keyword"],["keyword","storage","keyword.control","storage.type"],u),string:N(["string"],["string","string.quoted","string.template"],u),number:N(["number"],["constant.numeric"],u),function:N(["function"],["entity.name.function","support.function"],u),variable:N(["variable"],["variable.other.readwrite","variable"],u),type:N(["type"],["entity.name.type","support.type","support.class"],u),operator:N(["operator"],["keyword.operator"],u)},C=N(["class"],["entity.name.type.class","entity.name.class"],P.type),w=N(["property"],["variable.other.property","support.type.property-name"],P.variable),D={base:P,tokens:{className:C,interface:N(["interface"],["entity.name.type.interface"],P.type),enum:N(["enum"],["entity.name.type.enum"],C),method:N(["method"],["entity.name.function.method"],P.function),variableProperty:w,parameter:N(["parameter"],["variable.parameter"],P.variable),constant:N(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],P.number),boolean:N([],["constant.language.boolean","constant.language"],P.number),punctuation:N([],["punctuation","punctuation.separator"],P.operator),stringEscape:N([],["constant.character.escape"],P.string),commentDoc:N([],["comment.block.documentation","comment.documentation"],P.comment),keywordImport:N([],["keyword.control.import","keyword.import"],P.keyword),tag:N([],["entity.name.tag"],P.keyword),tagAttribute:N([],["entity.other.attribute-name"],w)},highlights:k.colors.syntax.highlights},x=pv(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return lv(k,i,P),uu({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:C,closed:k.colors.status.error}}})}const hv=Gs({namespace:es(),name:es(),version:es(),label:es(),icon:es().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function fv(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 Gs({items:hi(hv).max(24)}).parse(await a.json()).items}async function xv(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}=Gs({items:hi(Gs({path:es(),name:es(),text:es(),error:No()})).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=hd(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:mu(d)}}catch{return{status:"invalid",key:l,name:r.name}}})}function bv(t){const e=rt.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(B,{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 vv(t){const e=rt.c(93),{pickFile:a,fileBusy:n,onClose:r}=t,{t:i}=Xe(),l=ge(wv),{isMobile:d}=Jn(),c=l||d,{importTheme:h}=ha(),[m,f]=o.useState("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={step:"search",status:"idle",results:[]},e[0]=u):u=e[0];const[g,v]=o.useState(u);let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=new Set,e[1]=j):j=e[1];const[b,k]=o.useState(j);let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=new Set,e[2]=p):p=e[2];const[N,P]=o.useState(p),[C,w]=o.useState(!1),[D,x]=o.useState(null),A=o.useRef(null);let R,I;e[3]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const U=new AbortController;A.current=U;const te=ir(()=>U.abort());return()=>{te(),U.abort()}},I=[],e[3]=R,e[4]=I):(R=e[3],I=e[4]),o.useEffect(R,I);let E,F;e[5]!==m||e[6]!==g.step?(E=()=>{if(g.step!=="search")return;const U=new AbortController,te=m.trim(),O=setTimeout(async()=>{if(!te){v({step:"search",status:"idle",results:[]});return}v({step:"search",status:"loading",results:[]});try{const Q=await fv(te,U.signal);U.signal.aborted||v({step:"search",status:"ready",results:Q})}catch{U.signal.aborted||v({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(O),U.abort()}},F=[m,g.step],e[5]=m,e[6]=g.step,e[7]=E,e[8]=F):(E=e[7],F=e[8]),o.useEffect(E,F);let K,S;if(e[9]!==n||e[10]!==h||e[11]!==c||e[12]!==a||e[13]!==m||e[14]!==D||e[15]!==N||e[16]!==C||e[17]!==b||e[18]!==g.extension||e[19]!==g.results||e[20]!==g.status||e[21]!==g.step||e[22]!==g.variants||e[23]!==i){const U=async ae=>{const fe=A.current?.signal;if(fe){v({step:"package",status:"loading",extension:ae}),P(new Set),x(null),k(new Set);try{const xe=await xv(ae,fe);fe.aborted||v({step:"variants",extension:ae,variants:xe})}catch{fe.aborted||v({step:"package",status:"error",extension:ae})}}};let te;e[26]!==h||e[27]!==N||e[28]!==C||e[29]!==b||e[30]!==g.step||e[31]!==g.variants||e[32]!==i?(te=async()=>{if(g.step!=="variants"||C)return;const ae=A.current?.signal;if(!ae)return;w(!0),x(null);let fe=!1;for(const xe of g.variants){if(ae.aborted)break;if(!(xe.status!=="ready"||!b.has(xe.key)||N.has(xe.key)))try{if(await h(xe.definition,{activate:!1}),ae.aborted)break;P(Oe=>new Set(Oe).add(xe.key)),k(Oe=>{const Ne=new Set(Oe);return Ne.delete(xe.key),Ne})}catch{fe=!0}}ae.aborted||(w(!1),x(fe?"partial":null),fe?$a.error(i("settings.themeImport.partialError")):$a.success(i("settings.themeImport.complete")))},e[26]=h,e[27]=N,e[28]=C,e[29]=b,e[30]=g.step,e[31]=g.variants,e[32]=i,e[33]=te):te=e[33];const O=te;let Q,ce;e[34]!==N||e[35]!==b||e[36]!==g.step||e[37]!==g.variants?(Q=g.step==="variants"?g.variants.filter(ae=>ae.status==="ready"&&!N.has(ae.key)):[],ce=Q.length>0&&Q.every(ae=>b.has(ae.key)),e[34]=N,e[35]=b,e[36]=g.step,e[37]=g.variants,e[38]=Q,e[39]=ce):(Q=e[38],ce=e[39]);const de=ce;let pe;e[40]!==n||e[41]!==O||e[42]!==C||e[43]!==b||e[44]!==g.step||e[45]!==i?(pe=g.step==="variants"&&s.jsx(G,{disabled:!b.size||C||n,onClick:()=>{O()},children:i(C?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=O,e[42]=C,e[43]=b,e[44]=g.step,e[45]=i,e[46]=pe):pe=e[46];const re=C||n;let Ce;e[47]!==i?(Ce=i("settings.themeImport.chooseFile"),e[47]=i,e[48]=Ce):Ce=e[48];let ie;e[49]!==a||e[50]!==re||e[51]!==Ce?(ie=s.jsx(G,{variant:"outline",className:"self-start",disabled:re,onClick:a,children:Ce}),e[49]=a,e[50]=re,e[51]=Ce,e[52]=ie):ie=e[52];let be;e[53]!==pe||e[54]!==ie?(be=s.jsxs(s.Fragment,{children:[pe,ie]}),e[53]=pe,e[54]=ie,e[55]=be):be=e[55],K=be,S=s.jsx(s.Fragment,{children:g.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(We,{autoFocus:!0,"aria-label":i("settings.themeImport.search"),placeholder:i("settings.themeImport.search"),value:m,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:[g.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:i("common.loading")}),g.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}),g.status==="ready"&&!g.results.length&&s.jsx("p",{className:"text-muted-foreground",children:i("settings.themeImport.empty")}),g.results.map(ae=>s.jsxs(G,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{U(ae)},children:[s.jsx(bv,{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:C||g.step==="package"&&g.status==="loading",onClick:()=>v({step:"search",status:"idle",results:[]}),children:[s.jsx(B,{name:"arrow-left",className:"size-4"}),i("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:g.extension.label}),D==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.partialError")}),g.step==="package"?g.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:[g.variants.length>1&&s.jsx(G,{variant:"ghost",size:"sm",className:"self-start",disabled:C||n||!Q.length,onClick:()=>k(de?new Set:new Set(Q.map(jv))),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:g.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(yv)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[N.has(ae.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(B,{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"||C||n,label:ae.name,onChange:fe=>k(xe=>{const Oe=new Set(xe);return fe?Oe.add(ae.key):Oe.delete(ae.key),Oe})}),s.jsx("p",{className:N.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"):N.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]=m,e[14]=D,e[15]=N,e[16]=C,e[17]=b,e[18]=g.extension,e[19]=g.results,e[20]=g.status,e[21]=g.step,e[22]=g.variants,e[23]=i,e[24]=K,e[25]=S}else K=e[24],S=e[25];const M=S;if(c){let U;e[56]!==i?(U=i("settings.themeImport.catalogTitle"),e[56]=i,e[57]=U):U=e[57];let te;e[58]!==K?(te=s.jsx("div",{className:"flex flex-col gap-2",children:K}),e[58]=K,e[59]=te):te=e[59];let O;e[60]!==i?(O=i("settings.themeImport.catalogHint"),e[60]=i,e[61]=O):O=e[61];let Q;e[62]!==O?(Q=s.jsx("p",{className:"typography-meta text-muted-foreground",children:O}),e[62]=O,e[63]=Q):Q=e[63];let ce;e[64]!==M||e[65]!==Q?(ce=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[Q,M]}),e[64]=M,e[65]=Q,e[66]=ce):ce=e[66];let de;return e[67]!==r||e[68]!==te||e[69]!==ce||e[70]!==U?(de=s.jsx(Rc,{open:!0,title:U,onClose:r,footer:te,children:ce}),e[67]=r,e[68]=te,e[69]=ce,e[70]=U,e[71]=de):de=e[71],de}let z;e[72]!==r?(z=U=>{U||r()},e[72]=r,e[73]=z):z=e[73];let _;e[74]===Symbol.for("react.memo_cache_sentinel")?(_={forceRender:!0},e[74]=_):_=e[74];let q;e[75]!==i?(q=i("settings.themeImport.catalogTitle"),e[75]=i,e[76]=q):q=e[76];let X;e[77]!==q?(X=s.jsx($t,{children:q}),e[77]=q,e[78]=X):X=e[78];let J;e[79]!==i?(J=i("settings.themeImport.catalogHint"),e[79]=i,e[80]=J):J=e[80];let H;e[81]!==J?(H=s.jsx(Bt,{children:J}),e[81]=J,e[82]=H):H=e[82];let L;e[83]!==X||e[84]!==H?(L=s.jsxs(Ut,{children:[X,H]}),e[83]=X,e[84]=H,e[85]=L):L=e[85];let V;e[86]!==K||e[87]!==M||e[88]!==L?(V=s.jsxs(zt,{className:"max-w-lg",backdropProps:_,children:[L,M,K]}),e[86]=K,e[87]=M,e[88]=L,e[89]=V):V=e[89];let Z;return e[90]!==V||e[91]!==z?(Z=s.jsx(Kt,{open:!0,onOpenChange:z,children:V}),e[90]=V,e[91]=z,e[92]=Z):Z=e[92],Z}function yv(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function jv(t){return t.key}function wv(t){return t.isMobile}function kv(){const{t}=Xe(),{importTheme:e,customThemesLoading:a}=ha(),n=yo(),[r,i]=o.useState(!1),l=o.useCallback(()=>i(!1),[]),d=o.useRef(null),c=o.useRef(0),h=o.useRef(null),[m,f]=o.useState(!1);o.useEffect(()=>ir(()=>{c.current+=1,i(!1)}),[]);const u=async(j,b)=>{f(!0);try{if(j.size>Mc)throw new ia("size");const k=await j.text();if(b.key!==jn()||b.generation!==c.current)throw new ia("connection");const p=await e(hd(k,j.name));$a.success(t("settings.themeImport.success",{name:p.metadata.name})),i(!1)}catch(k){const p=k instanceof ia?k.code:"invalid";$a.error(t(`settings.themeImport.error.${p}`))}finally{f(!1)}},g=async()=>{if(m)return;const j={key:jn(),generation:c.current};if(h.current=j,!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 u({name:k.name,size:k.size,text:async()=>k.text},j)}return}d.current?.click()}catch{$a.error(t("settings.themeImport.error.invalid"))}finally{f(!1)}},v=async j=>{const b=j.target.files?.[0];j.target.value="",b&&!m&&h.current&&await u(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:m||a,onClick:()=>i(!0),children:[s.jsx(B,{name:m?"loader":"add",className:m?"size-3.5 animate-spin":"size-3.5"}),t(m?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Ht,{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(vv,{pickFile:()=>{g()},fileBusy:m,onClose:l})]})}const Zl=(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 Xl({options:t,value:e,onValueChange:a,placeholder:n,ariaLabel:r}){const{t:i}=Xe(),{deleteImportedTheme:l,customThemeIds:d}=ha(),{isMobile:c}=Jn(),[h,m]=o.useState(!1),[f,u]=o.useState(""),[g,v]=o.useState(void 0),[j,b]=o.useState(null),k=o.useRef(null),p=o.useRef(null),[N,P]=o.useState(null),[C,w]=o.useState(null),D=o.useCallback(M=>{const z=M instanceof HTMLElement?M:null,_=z?.closest('[data-slot="dialog-content"], [role="dialog"]');P(_ instanceof HTMLElement?_:null),w(z?.closest("main")??null)},[]);o.useEffect(()=>{if(h)return pu.suspend()},[h]);const x=o.useRef(e);x.current=e;const A=o.useCallback(M=>{M&&Zl(M,x.current)},[]),R=t.find(M=>M.id===e),I=o.useMemo(()=>h?mi(t,f,M=>[M.label]):t,[h,t,f]),E=M=>{a(M),m(!1)},F=async M=>{if(!j){b(M.id);try{await l(M.id),k.current?.focus()}catch{$a.error(i("settings.themeImport.deleteError"))}finally{b(null)}}},K=M=>{if(!d.includes(M.id))return null;const z=j===M.id;return s.jsx(G,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:z,"aria-label":i("settings.themeImport.delete",{name:M.label}),onPointerDown:_=>_.stopPropagation(),onClick:_=>{_.stopPropagation(),F(M)},children:s.jsx(B,{name:z?"loader":"delete-bin",className:z?"size-4 animate-spin":"size-4"})})},S=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(qs,!R&&"text-muted-foreground"),onClick:()=>{u(""),m(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R?.label??n}),s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(Rc,{open:h,title:r,onClose:()=>m(!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=>u(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:I.length===0?S:I.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(B,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),K(M)]},M.id))})]})})]}):s.jsxs($m,{open:h,onOpenChange:M=>{u(""),v(M?e:void 0),m(M)},onOpenChangeComplete:M=>{if(!M){p.current?.focus();return}k.current?.focus(),Zl(k.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs(Bm,{ref:p,"aria-label":r,"aria-haspopup":"dialog",className:Ie(qs,!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(B,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(Vm,{container:N??void 0,children:s.jsx(Hm,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:C??void 0,className:"z-[120]",children:s.jsx(qm,{role:"dialog","aria-label":r,className:Ie(yu,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(gu,{ref:A,className:"min-h-0 flex-1",shouldFilter:!1,value:g,onValueChange:v,children:[s.jsx(hu,{ref:k,"aria-label":i("settings.openchamber.visual.field.searchThemes"),placeholder:i("settings.openchamber.visual.field.searchThemes"),value:f,onValueChange:u,onKeyDown:M=>{if(fu(M)){M.stopPropagation();return}xu(M,z=>{M.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:z,bubbles:!0,cancelable:!0}))})}}),s.jsx(bu,{label:r,className:"max-h-[20rem] p-1",children:I.length===0?S:I.map(M=>s.jsxs(vu,{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(B,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,K(M)]},M.id))})]})})})})]})}const Nv=[{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"}],Sv=[{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"}],Cv=[{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"}],ei="OpenChamber - AI Coding Assistant",ec=[{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"}],tc=[{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"}],Hr=t=>t==="portrait"||t==="landscape"?t:"system",Iv=[{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"}],Pv=[{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"}],sc=[{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"}],Av=[{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"}],nc=[{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"}],ac=[{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"}],Tv=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Ev=[{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"}],Dv=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],Mv=t=>t==="markdown"?"markdown":"plain",Rv=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Fv=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],rr=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=Xe(),l=o.useCallback(y=>i(y),[i]),{isMobile:d}=Jn(),{terminal:c}=yo(),{browserTab:h}=wm(),m=nm(),f=ge(y=>y.showReasoningTraces),u=ge(y=>y.sessionRecapEnabled),g=ge(y=>y.sessionSuggestionEnabled),v=ge(y=>y.setSessionRecapEnabled),j=ge(y=>y.setSessionSuggestionEnabled),b=ge(y=>y.sessionGoalEnabled),k=ge(y=>y.setSessionGoalEnabled),p=ge(y=>y.sessionGoalDefaultBudgetEnabled),N=ge(y=>y.setSessionGoalDefaultBudgetEnabled),P=ge(y=>y.sessionGoalDefaultBudget),C=ge(y=>y.setSessionGoalDefaultBudget),w=ge(y=>y.setShowReasoningTraces),D=ge(y=>y.streamingAutoFollowEnabled),x=ge(y=>y.setStreamingAutoFollowEnabled),A=ge(y=>y.collapsibleThinkingBlocks),R=ge(y=>y.setCollapsibleThinkingBlocks),I=Zo(y=>y.animatedActivityIndicators),E=Zo(y=>y.setAnimatedActivityIndicators),F=ge(y=>y.mermaidRenderingMode),K=ge(y=>y.setMermaidRenderingMode),S=ge(y=>y.userMessageRenderingMode),M=ge(y=>y.setUserMessageRenderingMode),z=ge(y=>y.collapsibleUserMessages),_=ge(y=>y.setCollapsibleUserMessages),q=ge(y=>y.stickyUserHeader),X=ge(y=>y.promptNavigatorEnabled),J=ge(y=>y.setStickyUserHeader),H=ge(y=>y.setPromptNavigatorEnabled),L=ge(y=>y.autoSaveEnabled),V=ge(y=>y.setAutoSaveEnabled),Z=ge(y=>y.wideChatLayoutEnabled),U=ge(y=>y.setWideChatLayoutEnabled),te=ge(y=>y.codeBlockLineWrap),O=ge(y=>y.setCodeBlockLineWrap),Q=ge(y=>y.chatRenderMode),ce=ge(y=>y.setChatRenderMode),de=ge(y=>y.activityRenderMode),pe=ge(y=>y.setActivityRenderMode),re=ge(y=>y.fontSize),Ce=ge(y=>y.setFontSize),ie=ge(y=>y.terminalFontSize),be=ge(y=>y.setTerminalFontSize),ae=ge(y=>y.terminalShell),fe=ge(y=>y.setTerminalShell),xe=ge(y=>y.terminalLoginShells),Oe=ge(y=>y.setTerminalLoginShells),Ne=ge(y=>y.editorFontSize),he=ge(y=>y.setEditorFontSize),Te=ge(y=>y.uiFont),we=ge(y=>y.setUiFont),De=ge(y=>y.monoFont),ve=ge(y=>y.setMonoFont),ee=ge(y=>y.padding),ne=ge(y=>y.setPadding),ye=ge(y=>y.inputBarOffset),Ae=ge(y=>y.setInputBarOffset),ze=ge(y=>y.mobileKeyboardMode),Qe=ge(y=>y.setMobileKeyboardMode),Be=ge(y=>y.diffLayoutPreference),_e=ge(y=>y.setDiffLayoutPreference),Me=ge(y=>y.showTerminalQuickKeysOnDesktop),nt=ge(y=>y.sessionTabsEnabled),pt=ge(y=>y.setSessionTabsEnabled),lt=ge(y=>y.setShowTerminalQuickKeysOnDesktop),ut=ge(y=>y.fileEditorKeymap),ht=ge(y=>y.setFileEditorKeymap),Ue=Xo(y=>y.followUpBehavior),st=Xo(y=>y.setFollowUpBehavior),ue=Ei(y=>y.scope),oe=Ei(y=>y.entryLimit),Pe=Ei(y=>y.applyScope),Re=Ei(y=>y.applyEntryLimit),Fe=ge(y=>y.persistChatDraft),$e=ge(y=>y.setPersistChatDraft),W=ge(y=>y.inputSpellcheckEnabled),Ve=ge(y=>y.setInputSpellcheckEnabled),et=ge(y=>y.largeTextPasteBehavior),dt=ge(y=>y.setLargeTextPasteBehavior),ct=ge(y=>y.enterToSend),jt=ge(y=>y.setEnterToSend),kt=ge(y=>y.enterToSendConfigured),yt=ge(y=>y.setEnterToSendConfigured),bt=kt?ct:!d,Ze=ge(y=>y.showToolFileIcons),wt=ge(y=>y.setShowToolFileIcons),Le=ge(y=>y.showTurnChangedFiles),He=ge(y=>y.setShowTurnChangedFiles),Y=ge(y=>y.showExpandedBashTools),me=ge(y=>y.setShowExpandedBashTools),Ke=ge(y=>y.showExpandedEditTools),Ee=ge(y=>y.setShowExpandedEditTools),Ye=ge(y=>y.timeFormatPreference),se=ge(y=>y.setTimeFormatPreference),ke=ge(y=>y.weekStartPreference),at=ge(y=>y.setWeekStartPreference),Mt=ge(y=>y.showSplitAssistantMessageActions),Wt=ge(y=>y.setShowSplitAssistantMessageActions),Se=ge(y=>y.allowPromptingSubagentSessions),qe=ge(y=>y.setAllowPromptingSubagentSessions),vt=ge(y=>y.draftStartersVisible),Ct=ge(y=>y.setDraftStartersVisible),Jt=it(y=>y.settingsMessageStreamTransport),Zt=it(y=>y.setSettingsMessageStreamTransport),ts=Jt,Xt=it(y=>y.settingsDefaultFileViewerPreview),Fs=it(y=>y.setSettingsDefaultFileViewerPreview),Js=ge(y=>y.isSettingsDialogOpen),{themeMode:pn,setThemeMode:Os,availableThemes:Ls,customThemesLoading:rn,reloadCustomThemes:Qs,lightThemeId:Ys,darkThemeId:Ks,setLightThemePreference:Tn,setDarkThemePreference:Dt}=ha(),[qt,Lt]=o.useState(!1),Pt=o.useMemo(()=>os()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),is=ge(y=>y.dockBadgeEnabled),ss=ge(y=>y.setDockBadgeEnabled),or=ge(y=>y.alwaysShowScrollbars===!0),lr=ge(y=>y.setAlwaysShowScrollbars),cr=am(),dr=ge(y=>y.desktopWindowControlsPosition),bi=ge(y=>y.setDesktopWindowControlsPosition),ur=ge(y=>y.desktopWindowControlsStyle),vi=ge(y=>y.setDesktopWindowControlsStyle),[mr,$s]=o.useState(0),Ga=ge(y=>y.reportUsage),yi=ge(y=>y.setReportUsage),ji=o.useCallback(y=>{yi(y),ft({reportUsage:y})},[yi]),pr=o.useCallback(y=>{bi(y),ft({desktopWindowControlsPosition:y})},[bi]),gr=o.useCallback(y=>{vi(y),ft({desktopWindowControlsStyle:y})},[vi]),wi=(Js||d||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!wi)return;let y=null,xt=Date.now();const ps=()=>{const bn=Date.now();bn-xt>=420&&($s(Yn=>(Yn+1)%24),xt=bn),y=requestAnimationFrame(ps)};(typeof document>"u"||document.visibilityState==="visible")&&(y=requestAnimationFrame(ps));const Ts=()=>{document.visibilityState==="visible"&&y===null?y=requestAnimationFrame(ps):document.visibilityState!=="visible"&&y!==null&&(cancelAnimationFrame(y),y=null)};return document.addEventListener("visibilitychange",Ts),()=>{document.removeEventListener("visibilitychange",Ts),y!==null&&cancelAnimationFrame(y)}},[wi]);const hr=o.useCallback(y=>{M(y),ft({userMessageRenderingMode:y})},[M]),fr=o.useCallback(y=>{J(y),ft({stickyUserHeader:y})},[J]),js=o.useCallback(y=>{H(y),ft({promptNavigatorEnabled:y})},[H]),on=o.useCallback(y=>{Ct(y),ft({draftStartersVisible:y})},[Ct]),fa=o.useCallback(y=>{_(y),ft({collapsibleUserMessages:y})},[_]),En=o.useCallback(y=>{U(y),ft({wideChatLayoutEnabled:y})},[U]),Un=o.useCallback(y=>{Wt(y),ft({showSplitAssistantMessageActions:y})},[Wt]),Oo=o.useCallback(y=>{Ve(y),ft({inputSpellcheckEnabled:y})},[Ve]),ln=o.useCallback(y=>{jt(y),yt(!0),ft({enterToSend:y,enterToSendConfigured:!0})},[jt,yt]),xr=o.useCallback(y=>{ce(y),ft({chatRenderMode:y})},[ce]),xa=o.useCallback(y=>{Zt(y),ft({messageStreamTransport:y})},[Zt]),ba=o.useCallback(y=>{Pe(y),ft({inputHistoryScope:y})},[Pe]),Qn=o.useCallback(y=>{const xt=Math.round(y);im(xt)&&(Re(xt),ft({inputHistoryLimit:xt}))},[Re]),Wa=o.useCallback(y=>{pe(y),ft({activityRenderMode:y})},[pe]),br=o.useCallback(y=>{K(y),ft({mermaidRenderingMode:y})},[K]),ds=o.useCallback(y=>{wt(y),ft({showToolFileIcons:y})},[wt]),vr=o.useCallback(y=>{He(y),ft({showTurnChangedFiles:y})},[He]),va=o.useCallback(y=>{Fs(y),ft({defaultFileViewerPreview:y}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:y}}))},[Fs]),ya=o.useCallback(y=>{me(y),ft({showExpandedBashTools:y})},[me]),yr=o.useCallback(y=>{Ee(y),ft({showExpandedEditTools:y})},[Ee]),ki=o.useCallback(y=>{se(y),ft({timeFormatPreference:y})},[se]),jr=o.useCallback(y=>{at(y),ft({weekStartPreference:y})},[at]),$n=o.useMemo(()=>Ls.filter(y=>y.metadata.variant==="light").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ls]),gn=o.useMemo(()=>Ls.filter(y=>y.metadata.variant==="dark").sort((y,xt)=>y.metadata.name.localeCompare(xt.metadata.name)),[Ls]),ja=o.useMemo(()=>$n.find(y=>y.metadata.id===Ys)??$n[0],[$n,Ys]),Ni=o.useMemo(()=>gn.find(y=>y.metadata.id===Ks)??gn[0],[gn,Ks]),wa=o.useCallback((y,xt)=>{const ps=xt==="dark"?" Dark":" Light";return y.endsWith(ps)?y.slice(0,-ps.length):y},[]),ka=o.useMemo(()=>$n.map(y=>({id:y.metadata.id,label:wa(y.metadata.name,"light")})),[$n,wa]),wr=o.useMemo(()=>gn.map(y=>({id:y.metadata.id,label:wa(y.metadata.name,"dark")})),[gn,wa]),je=y=>y==="enterToSend"&&d?!1:t?t.includes(y):!0,us=cs(),Na=je("theme")&&!us,Si=je("windowControlsPosition")&&cr,Ci=je("theme")||je("timeFormat")||je("weekStart"),Ii=us?Ci:je("theme")||Si||je("pwaInstallName")||je("pwaOrientation")||je("timeFormat")||je("weekStart"),Pi=je("fontSize")||je("terminalFontSize")||je("editorFontSize")||je("spacing")||je("scrollbars")&&!Na||je("inputBarOffset")&&d,Ai=je("terminalQuickKeys")&&!d||(je("terminalShell")||je("terminalLoginShell"))&&!us||je("fileEditorKeymap")||je("autoSaveEnabled")||je("sessionTabs")&&!us&&!d,kr=je("mermaidRendering")||je("sessionGoal")&&!us||je("userMessageRendering")||je("chatRenderMode")||je("messageTransport")||je("activityRenderMode")||je("collapsibleUserMessages")||je("stickyUserHeader")||je("promptNavigatorEnabled")&&!us||je("wideChatLayout")||je("codeBlockLineWrap")||je("splitAssistantMessageActions")||je("subagentReadOnlyBanner")||je("diffLayout")||je("dotfiles")||je("fileViewerPreview")||je("reasoning")||je("followUpBehavior")||je("inputHistoryScope")||je("inputHistoryLimit")||je("persistDraft")||je("largeTextPaste")||je("showToolFileIcons")||je("expandedTools")||!d&&je("inputSpellcheck")||je("enterToSend"),hn=je("chatRenderMode")||je("activityRenderMode"),Bn=je("messageTransport"),Sa=je("userMessageRendering")||je("mermaidRendering")||je("diffLayout")&&!us||je("followUpBehavior")||je("inputHistoryScope")||je("inputHistoryLimit"),Nr=je("sessionAssist")||je("sessionGoal")&&!us||je("subagentReadOnlyBanner")||je("collapsibleUserMessages")||je("stickyUserHeader")||je("promptNavigatorEnabled")&&!us||je("wideChatLayout")||je("codeBlockLineWrap")||je("splitAssistantMessageActions")||je("dotfiles")||je("fileViewerPreview")||je("persistDraft")||je("largeTextPaste")||je("showToolFileIcons")||je("showTurnChangedFiles")||!d&&je("inputSpellcheck")||je("enterToSend")||je("reasoning")||je("expandedTools"),T=Ii||Pi||Ai,le=je("pwaInstallName")&&ca()&&h&&!os()&&!us,Je=je("pwaOrientation")&&ca()&&!os()&&!us,ot=je("mobileKeyboardMode")&&ca()&&!os()&&!us&&rm(),Ft=(je("terminalShell")||je("terminalLoginShell"))&&!us,[bs,Zs]=o.useState([]),[ms,zs]=o.useState(0);o.useEffect(()=>ir(()=>{Zs([]),zs(y=>y+1)}),[]),o.useEffect(()=>{let y=!1;if(!(!Ft||!c.listShells))return c.listShells().then(xt=>{y||Zs(xt)}).catch(()=>{y||Zs([])}),()=>{y=!0}},[Ft,c,ms]);const Dn=o.useMemo(()=>{const y=bs.filter(xt=>xt.id!=="auto");return ae==="auto"||y.some(xt=>xt.id===ae)?y:[{id:ae,name:ae,supportsLogin:!1},...y]},[bs,ae]),fn=bs.find(y=>y.id===ae)?.supportsLogin===!0,Ca=xe.includes(ae),Ia=y=>{Oe(y?[...xe.filter(xt=>xt!==ae),ae]:xe.filter(xt=>xt!==ae))},[Ot,Qt]=o.useState(""),[xn,cn]=o.useState("system"),Yt=o.useMemo(()=>{const y=nc.find(xt=>xt.id===Ye);return l(y?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Ye,l]),Cs=o.useMemo(()=>{const y=ac.find(xt=>xt.id===ke);return l(y?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ke,l]),Pa=o.useMemo(()=>{const y=ec.find(xt=>xt.id===xn);return y?l(y.labelKey):void 0},[xn,l]),Aa=o.useMemo(()=>{const y=tc.find(xt=>xt.id===ze);return y?l(y.labelKey):void 0},[ze,l]),Ta=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,Ts=y.trim().replace(/\s+/g," ").slice(0,64);if(await ft({pwaAppName:Ts}),typeof xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const bn=xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ts);Qt(bn);return}Qt(Ts||ei),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Lo=o.useCallback(async y=>{if(typeof window>"u")return;const xt=window,ps=Hr(y);if(await ft({pwaOrientation:ps}),typeof xt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ts=xt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ps);cn(Ts);return}cn(ps),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!le&&!Je&&!ot)return;let y=!1;return(async()=>{try{const ps=await An();if(!ps){y||Qt(ei);return}const bn=(ps.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Yn=Hr(ps.pwaOrientation),Ti=al(ps.mobileKeyboardMode);y||(le&&Qt(bn||ei),Je&&cn(Yn),ot&&Qe(Ti))}catch{y||(le&&Qt(ei),Je&&cn("system"),ot&&Qe("native"))}})(),()=>{y=!0}},[Qe,ot,le,Je]);const Sr=je("scrollbars")?s.jsx(gt,{checked:or,onChange:lr,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:[Ii&&s.jsxs("div",{className:"space-y-0",children:[Na&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Rn,{children:[s.jsx("div",{className:Ms,children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.colorMode"),children:Nv.map(y=>s.jsx(ks,{selected:pn===y.value,onSelect:()=>Os(y.value),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.value))})}),s.jsxs("div",{className:Ms,children:[s.jsx(Rt,{label:i("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(Xl,{options:ka,value:ja?.metadata.id??"",onValueChange:Tn,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Rt,{label:i("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(Xl,{options:wr,value:Ni?.metadata.id??"",onValueChange:Dt,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:rn||qt,onClick:()=>{const y=Date.now();Lt(!0),Qs().finally(()=>{const xt=Date.now()-y;if(xt<500){window.setTimeout(()=>{Lt(!1)},500-xt);return}Lt(!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(B,{name:"restart",className:Ie("h-3.5 w-3.5",qt&&"animate-spin")}),i(qt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Ht,{children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(kv,{})]})]}),Pt&&s.jsx(Ha,{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")})}),Sr&&s.jsx(Ha,{children:Sr})]}),Si&&s.jsx(Ge,{title:i("settings.openchamber.desktopNetwork.field.windowControls"),info:i("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Na,children:s.jsxs(Rn,{children:[s.jsx(Rt,{label:i("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(mn,{value:dr,options:Rv.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:pr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Rt,{label:i("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(mn,{value:ur,options:Fv.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:gr,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ci&&s.jsx(Ge,{title:i("settings.openchamber.visual.section.localization"),children:s.jsxs(Rn,{children:[s.jsx(Rt,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Et,{value:e,onValueChange:y=>n(y),children:[s.jsx(At,{"aria-label":i("settings.appearance.language.select"),size:Vt,className:Da,children:s.jsx(_t,{children:r(e)})}),s.jsx(Tt,{children:a.map(y=>s.jsx(mt,{value:y,children:r(y)},y))})]})}),(je("timeFormat")||je("weekStart"))&&s.jsxs("div",{className:Ms,children:[je("timeFormat")&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Et,{value:Ye,onValueChange:y=>ki(y),children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),size:Vt,className:Da,children:s.jsx(_t,{children:Yt})}),s.jsx(Tt,{children:nc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})}),je("weekStart")&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Et,{value:ke,onValueChange:y=>jr(y),children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),size:Vt,className:Da,children:s.jsx(_t,{children:Cs})}),s.jsx(Tt,{children:ac.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})})]})]})}),(le||Je||ot)&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.appInstall"),contentClassName:Ms,children:[le&&s.jsxs(St,{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:Ot,onChange:y=>{Qt(y.target.value)},onBlur:()=>{Ta(Ot)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),Ta(Ot))},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:()=>{Qt(ei),Ta("")},className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),Je&&s.jsxs(St,{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(Et,{value:xn,onValueChange:y=>{const xt=Hr(y);cn(xt),Lo(xt)},children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Vt,className:Bo,children:s.jsx(_t,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Pa})}),s.jsx(Tt,{children:ec.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{cn("system"),Lo("system")},disabled:xn==="system",className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),ot&&s.jsxs(St,{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(Et,{value:ze,onValueChange:y=>{const xt=al(y);Qe(xt),ft({mobileKeyboardMode:xt})},children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Vt,className:Bo,children:s.jsx(_t,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Aa})}),s.jsx(Tt,{children:tc.map(y=>s.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Qe("native"),ft({mobileKeyboardMode:"native"})},disabled:ze==="native",className:gs,"aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Pi&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.densityAndType"),contentClassName:Ms,children:[je("fontSize")&&!d||je("terminalFontSize")?s.jsxs(Rn,{children:[je("fontSize")&&!d&&s.jsxs(Rt,{label:i("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Et,{value:Te,onValueChange:y=>we(y),children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Vt,className:Da,children:s.jsx(_t,{children:el.find(y=>y.id===Te)?.label})}),s.jsx(Tt,{children:el.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:()=>we(tl),disabled:Te===tl,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),je("terminalFontSize")&&s.jsxs(Rt,{label:i("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Et,{value:De,onValueChange:y=>ve(y),children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),size:Vt,className:Da,children:s.jsx(_t,{children:sl.find(y=>y.id===De)?.label})}),s.jsx(Tt,{children:sl.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:()=>ve(nl),disabled:De===nl,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,je("fontSize")&&!d||je("terminalFontSize")||je("editorFontSize")?s.jsxs(Rn,{children:[je("fontSize")&&!d&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:Ma,children:[s.jsx(fs,{value:re,onValueChange:Ce,min:50,max:200,step:5,className:ys,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Ra,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ce(100),disabled:re===100,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),je("terminalFontSize")&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Ma,children:[s.jsx(fs,{value:ie,onValueChange:be,min:9,max:52,step:1,className:ys}),s.jsx("span",{className:Ra,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(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),je("editorFontSize")&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Ma,children:[s.jsx(fs,{value:Ne,onValueChange:he,min:9,max:32,step:1,className:ys}),s.jsx("span",{className:Ra,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(13),disabled:Ne===13,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,je("spacing")||je("inputBarOffset")&&d?s.jsxs(Rn,{children:[je("spacing")&&s.jsx(Rt,{label:i("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:Ma,children:[s.jsx(fs,{value:ee,onValueChange:ne,min:50,max:200,step:5,className:ys}),s.jsx("span",{className:Ra,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(100),disabled:ee===100,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),je("inputBarOffset")&&d&&s.jsx(Rt,{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:Ma,children:[s.jsx(fs,{value:ye,onValueChange:Ae,min:0,max:100,step:5,className:ys}),s.jsx("span",{className:Ra,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ae(0),disabled:ye===0,className:gs,"aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!Na&&Sr]}),je("animatedActivityIndicators")&&s.jsx(Ge,{title:i("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:ls,children:s.jsx(gt,{checked:I,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"})}),Ai&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[je("fileEditorKeymap")&&s.jsx(ws,{title:i("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(y=>s.jsx(ks,{selected:ut===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:ls,children:[je("autoSaveEnabled")&&s.jsx(gt,{checked:L,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(Rt,{label:i("settings.openchamber.visual.field.terminalShell"),info:i("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Et,{value:ae,onValueChange:y=>{om(y)&&fe(y)},children:[s.jsx(At,{"aria-label":i("settings.openchamber.visual.field.terminalShellAria"),size:Vt,className:Da,children:s.jsx(_t,{})}),s.jsxs(Tt,{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:Ca,onChange:Ia,label:i("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:i("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),je("terminalQuickKeys")&&!d&&s.jsx(gt,{checked:Me,onChange:lt,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:da("ctrl"),alt:da("alt")})})]}),je("sessionTabs")&&!us&&!d&&s.jsx(ws,{title:i("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(gt,{checked:nt,onChange:pt,label:i("settings.openchamber.visual.field.sessionTabs"),ariaLabel:i("settings.openchamber.visual.field.sessionTabsAria"),info:i("settings.openchamber.visual.field.sessionTabsInfo")})})]}),kr&&s.jsxs(s.Fragment,{children:[hn&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.chatDisplay"),divider:T,contentClassName:"space-y-6",children:[je("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:Pv.map(y=>{const xt=Q===y.id,ps=mr%12;return s.jsxs("button",{type:"button",onClick:()=>xr(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(Ts=>{const bn=Ts*3+1,Yn=ps-bn+1,Ti=Yn<=0?0:Yn===1?42:Yn===2?68:92,Pd=Ti>0;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Pd?"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:`${Ti}%`}})]},Ts)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ts=>{const bn=ps>=(Ts+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%"}})]},Ts)})})})]},y.id)})})}),je("activityRenderMode")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),children:Av.map(y=>s.jsx(ks,{selected:de===y.id,onSelect:()=>Wa(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(y.labelKey)})},y.id))})})]}),Bn&&s.jsxs(Ge,{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:sc.map(y=>({value:y.id,label:l(y.labelKey)})),onChange:xa,"aria-label":i("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const y=sc.find(xt=>xt.id===ts);return y?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(y.descriptionKey)}):null})()]}),Sa&&s.jsx(Ge,{title:i("settings.openchamber.visual.section.chatMessageOptions"),divider:hn||Bn||T,children:s.jsxs(Rn,{className:"lg:gap-y-6",children:[je("userMessageRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),children:Iv.map(y=>s.jsx(ks,{selected:Mv(S)===y.id,onSelect:()=>hr(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(y.labelKey)})},y.id))})}),je("mermaidRendering")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),children:Cv.map(y=>s.jsx(ks,{selected:F===y.id,onSelect:()=>br(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(y.labelKey)})},y.id))})}),je("diffLayout")&&!us&&s.jsx(ws,{title:i("settings.openchamber.visual.section.diffLayout"),children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),children:Sv.map(y=>s.jsx(ks,{selected:Be===y.id,onSelect:()=>_e(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(y.labelKey)})},y.id))})}),je("followUpBehavior")&&s.jsx(ws,{title:i("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(tn,{"aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),children:Tv.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))})}),je("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(tn,{"aria-label":i("settings.openchamber.visual.section.inputHistoryScopeAria"),children:Dv.map(y=>s.jsx(ks,{selected:ue===y.id,onSelect:()=>ba(y.id),label:l(y.labelKey),ariaLabel:l(y.labelKey)},y.id))})}),je("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:Ma,children:[s.jsx(fs,{value:oe,onValueChange:Qn,min:cm,max:lm,step:1,className:ys,deferExternalValueWhileFocused:!0,"aria-label":i("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Ra,children:i("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),Nr&&s.jsxs(s.Fragment,{children:[je("expandedTools")&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:hn||Bn||Sa||T,contentClassName:ls,children:[s.jsx(gt,{checked:Y,onChange:ya,label:i("settings.openchamber.visual.field.bash"),ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:Ke,onChange:yr,label:i("settings.openchamber.visual.field.editTools"),ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Ge,{title:i("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:ls,children:[s.jsx(gt,{checked:vt,onChange:on,label:i("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:i("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),je("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:u,onChange:v,label:i("settings.openchamber.visual.field.sessionRecap"),ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:g,onChange:j,label:i("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),je("subagentReadOnlyBanner")&&s.jsx(gt,{checked:Se,onChange:qe,label:i("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),je("sessionGoal")&&!us&&s.jsxs(Ge,{title:i("settings.openchamber.visual.goal.sectionTitle"),info:i("settings.openchamber.visual.goal.description"),contentClassName:ls,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:p,onChange:N,disabled:!b,label:i("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),b&&p?s.jsx(fs,{value:P,onValueChange:y=>{typeof y=="number"&&Number.isFinite(y)&&y>0&&C(Math.floor(y))},min:1e3,max:1e8,step:5e4}):null]})]}),je("reasoning")&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:ls,children:[s.jsx(gt,{checked:f,onChange:w,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(Ge,{title:i("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:ls,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"})}),(je("collapsibleUserMessages")||je("stickyUserHeader")||je("promptNavigatorEnabled")&&!us||je("wideChatLayout")||je("splitAssistantMessageActions")||je("codeBlockLineWrap"))&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:ls,children:[je("collapsibleUserMessages")&&s.jsx(gt,{checked:z,onChange:fa,label:i("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),je("stickyUserHeader")&&s.jsx(gt,{checked:q,onChange:fr,label:i("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),je("promptNavigatorEnabled")&&!us&&s.jsx(gt,{checked:X,onChange:js,label:i("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),je("wideChatLayout")&&s.jsx(gt,{checked:Z,onChange:En,label:i("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),je("splitAssistantMessageActions")&&s.jsx(gt,{checked:Mt,onChange:Un,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")}),je("codeBlockLineWrap")&&s.jsx(gt,{checked:te,onChange:O,label:i("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(je("showToolFileIcons")||je("showTurnChangedFiles")||je("dotfiles")&&!cs()||je("fileViewerPreview"))&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:ls,children:[je("showToolFileIcons")&&s.jsx(gt,{checked:Ze,onChange:ds,label:i("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),je("showTurnChangedFiles")&&s.jsx(gt,{checked:Le,onChange:vr,label:i("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),je("dotfiles")&&!cs()&&s.jsx(gt,{checked:m,onChange:dm,label:i("settings.openchamber.visual.field.showDotfiles"),ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),je("fileViewerPreview")&&s.jsx(gt,{checked:Xt,onChange:va,label:i("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(je("persistDraft")||je("largeTextPaste")||!d&&je("inputSpellcheck")||je("enterToSend"))&&s.jsxs(Ge,{title:i("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(je("persistDraft")||!d&&je("inputSpellcheck"))&&s.jsxs("div",{className:ls,children:[je("persistDraft")&&s.jsx(gt,{checked:Fe,onChange:$e,label:i("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!d&&je("inputSpellcheck")&&s.jsx(gt,{checked:W,onChange:Oo,label:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),je("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(tn,{"aria-label":i("settings.openchamber.visual.field.largeTextPasteAria"),children:Ev.map(y=>s.jsx(ks,{selected:et===y.id,onSelect:()=>dt(y.id),label:l(y.labelKey),ariaLabel:i("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(y.labelKey)})},y.id))})}),je("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(tn,{"aria-label":i("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(ks,{selected:bt,onSelect:()=>ln(!0),label:i("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(ks,{selected:!bt,onSelect:()=>ln(!1),label:i("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),je("reportUsage")&&s.jsx(Ge,{title:i("settings.openchamber.visual.section.privacy"),children:s.jsx(gt,{checked:Ga,onChange:ji,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"})})]})},Ov=1,Lv=365,ic=30,Kv=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],fd=()=>{const t=rt.c(105),{t:e}=Xe(),a=ge(zv),n=ge(_v),r=ge(Uv),i=ge($v),l=ge(Bv),d=ge(Vv),c=ge(Hv);let h;t[0]===Symbol.for("react.memo_cache_sentinel")?(h={autoRun:!1},t[0]=h):h=t[0];const{candidates:m,isRunning:f,runCleanup:u,action:g,status:v}=ju(h),j=m.length;let b;t[1]!==u||t[2]!==e?(b=async()=>{const fe=await u({force:!0}).catch(()=>($.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!fe||fe.skippedReason&&fe.skippedReason!=="no-candidates")){if(fe.completedIds.length===0&&fe.failedIds.length===0){$.message(fe.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}fe.completedIds.length>0&&$.success(fe.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:fe.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:fe.completedIds.length})),fe.failedIds.length>0&&$.error(fe.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:fe.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:fe.failedIds.length}))}},t[1]=u,t[2]=e,t[3]=b):b=t[3];const k=b;let p;t[4]!==e?(p=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=p):p=t[5];const N=r?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let P;t[6]!==e||t[7]!==N?(P=e(N),t[6]=e,t[7]=N,t[8]=P):P=t[8];let C;t[9]!==e?(C=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=C):C=t[10];let w;t[11]!==e?(w=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=w):w=t[12];let D;t[13]!==a||t[14]!==i||t[15]!==C||t[16]!==w?(D=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:C,ariaLabel:w}),t[13]=a,t[14]=i,t[15]=C,t[16]=w,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 I;t[24]!==f||t[25]!==r||t[26]!==c||t[27]!==R||t[28]!==x||t[29]!==A?(I=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]=I):I=t[30];let E;t[31]!==e?(E=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=E):E=t[32];let F;t[33]!==e?(F=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=F):F=t[34];let K;t[35]===Symbol.for("react.memo_cache_sentinel")?(K=Ie(ys,"tabular-nums"),t[35]=K):K=t[35];let S;t[36]!==n||t[37]!==l||t[38]!==F?(S=s.jsx(fs,{value:n,onValueChange:l,min:Ov,max:Lv,step:1,"aria-label":F,className:K}),t[36]=n,t[37]=l,t[38]=F,t[39]=S):S=t[39];let M;t[40]!==e?(M=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=M):M=t[41];let z;t[42]!==M?(z=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M}),t[42]=M,t[43]=z):z=t[43];let _;t[44]!==l?(_=()=>l(ic),t[44]=l,t[45]=_):_=t[45];const q=n===ic;let X;t[46]!==e?(X=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=X):X=t[47];let J;t[48]!==e?(J=e("settings.common.actions.reset"),t[48]=e,t[49]=J):J=t[49];let H;t[50]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=H):H=t[50];let L;t[51]!==_||t[52]!==q||t[53]!==X||t[54]!==J?(L=s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:_,disabled:q,className:gs,"aria-label":X,title:J,children:H}),t[51]=_,t[52]=q,t[53]=X,t[54]=J,t[55]=L):L=t[55];let V;t[56]!==E||t[57]!==S||t[58]!==z||t[59]!==L?(V=s.jsxs(St,{settingsItem:"sessions.retention-period",label:E,children:[S,z,L]}),t[56]=E,t[57]=S,t[58]=z,t[59]=L,t[60]=V):V=t[60];let Z;t[61]!==e?(Z=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=Z):Z=t[62];let U;t[63]!==r||t[64]!==e?(U=Kv.map(fe=>({value:fe.value,label:e(fe.labelKey),disabled:r&&fe.value==="archive"})),t[63]=r,t[64]=e,t[65]=U):U=t[65];let te;t[66]!==g||t[67]!==d||t[68]!==U?(te=s.jsx(mn,{value:g,onChange:d,options:U}),t[66]=g,t[67]=d,t[68]=U,t[69]=te):te=t[69];let O;t[70]!==Z||t[71]!==te?(O=s.jsx(St,{settingsItem:"sessions.retention-action",label:Z,children:te}),t[70]=Z,t[71]=te,t[72]=O):O=t[72];let Q;t[73]!==I||t[74]!==V||t[75]!==O?(Q=s.jsxs(Ha,{className:"space-y-0",children:[I,V,O]}),t[73]=I,t[74]=V,t[75]=O,t[76]=Q):Q=t[76];let ce;t[77]!==e?(ce=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=ce):ce=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 pe;t[82]!==k||t[83]!==f||t[84]!==de?(pe=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]=pe):pe=t[85];let re;t[86]!==ce||t[87]!==pe?(re=s.jsx(St,{label:ce,children:pe}),t[86]=ce,t[87]=pe,t[88]=re):re=t[88];let Ce;t[89]!==g||t[90]!==j||t[91]!==v||t[92]!==e?(Ce=v==="error"?e("sessions.sidebar.group.empty.loadFailed"):v!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):g==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:j}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:j}),t[89]=g,t[90]=j,t[91]=v,t[92]=e,t[93]=Ce):Ce=t[93];let ie;t[94]!==Ce?(ie=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ce}),t[94]=Ce,t[95]=ie):ie=t[95];let be;t[96]!==re||t[97]!==ie?(be=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[re,ie]}),t[96]=re,t[97]=ie,t[98]=be):be=t[98];let ae;return t[99]!==p||t[100]!==Q||t[101]!==be||t[102]!==P||t[103]!==D?(ae=s.jsxs(Ge,{title:p,info:P,children:[D,Q,be]}),t[99]=p,t[100]=Q,t[101]=be,t[102]=P,t[103]=D,t[104]=ae):ae=t[104],ae};function zv(t){return t.autoDeleteEnabled}function _v(t){return t.autoDeleteAfterDays}function Uv(t){return t.sessionRetentionOnlyArchived}function $v(t){return t.setAutoDeleteEnabled}function Bv(t){return t.setAutoDeleteAfterDays}function Vv(t){return t.setSessionRetentionAction}function Hv(t){return t.setSessionRetentionOnlyArchived}const rc=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(vo(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),xd=()=>{const{t}=Xe(),e=ge(D=>D.timeFormatPreference),[a,n]=o.useState(!1),[r,i]=o.useState(!0),[l,d]=o.useState(!1),[c,h]=o.useState(null),[m,f]=o.useState(!1),[u,g]=o.useState([]),[v,j]=o.useState(wu),[b,k]=o.useState(""),p=o.useMemo(()=>ku(),[]),N=o.useCallback(async()=>{i(!0),k("");try{const D=await Nu();g(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(!p.supported){D||(n(!1),i(!1));return}D||n(!0)}catch{D||n(!1)}if(!D){const x=await Pr();if(j(x),!x.enabled){g([]),i(!1);return}await N()}})(),()=>{D=!0,Vo()}},[N,p.supported]);const P=o.useCallback(async()=>{if(!v.enabled){const D=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(D),$.message(D);return}if(!a){k(p.reason),$.message(p.reason);return}if(l){Vo(),d(!1);return}k(""),d(!0);try{await Su(),j(await Pr()),await N(),$.success(t("settings.openchamber.passkeys.toast.added"))}catch(D){if(Cu(D)){$.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const x=D instanceof Error?D.message:t("settings.openchamber.passkeys.toast.addFailed");k(x),$.error(x)}finally{d(!1)}},[l,N,v.enabled,p.reason,a,t]),C=o.useCallback(async D=>{h(D),k("");try{await Iu(D),j(await Pr()),await N(),$.success(t("settings.openchamber.passkeys.toast.removed"))}catch(x){const A=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.removeFailed");k(A),$.error(A)}finally{h(null)}},[N,t]),w=o.useCallback(async()=>{f(!0),k("");try{await Pu(),window.location.reload()}catch(D){const x=D instanceof Error?D.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(x),$.error(x),f(!1)}},[t]);return s.jsxs(Ge,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(St,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(G,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{P()},disabled:r||m,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:()=>{w()},disabled:r||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(m?"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:p.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.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:u.map(D=>s.jsxs(St,{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:rc(D.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:rc(D.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{C(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})})]})},bd=()=>{const t=rt.c(14),{t:e}=Xe(),a=Ho(qv),n=Ho(Gv);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(Ge,{title:r,description:i,children:d}),t[10]=r,t[11]=i,t[12]=d,t[13]=c):c=t[13],c};function qv(t){return t.trustedSchemes}function Gv(t){return t.removeTrustedScheme}const qr=t=>{const e=Ln(t);return e||{providerId:"",modelId:""}},vd=()=>{const{t}=Xe(),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"),m=Au(ie=>ie.currentSessionId),f=qo(ie=>ie.getSessionModelSelection),u=qo(ie=>ie.getSessionAgentSelection),g=it(ie=>ie.agentSelectionSource==="manual"),j=!!(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&&m&&f(m)),b=!!(g&&m&&u(m)),k=ge(ie=>ie.showDeletionDialog),p=ge(ie=>ie.setShowDeletionDialog),N=it(ie=>ie.providers),P=it(ie=>ie.modelsMetadata),[C,w]=o.useState(),[D,x]=o.useState(),[A,R]=o.useState(),[I,E]=o.useState(!0),[F,K]=o.useState(),[S,M]=o.useState([]),[z,_]=o.useState(),[q,X]=o.useState(!0),J=o.useMemo(()=>qr(C),[C]);o.useEffect(()=>{(async()=>{try{const be=await An();if(be){const ae=be.defaultModel?.trim()||void 0,fe=be.defaultVariant?.trim()||void 0,xe=be.defaultAgent?.trim()||void 0;ae!==void 0&&w(ae),fe!==void 0&&x(fe),xe!==void 0&&R(xe),be.smallModelUseDefault!==void 0&&E(be.smallModelUseDefault);const Oe=be.smallModelOverride?.trim();Oe&&K(Oe);const Ne=be.walkthroughModelOverride?.trim();Ne&&_(Ne)}}catch(be){console.warn("Failed to load defaults settings:",be)}finally{X(!1)}})()},[]);const H=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;w(ae),x(void 0),d(void 0),l(ae),j||(r(void 0),ie&&be&&(N.find(xe=>xe.id===ie)||_c(ie,be))&&(e(ie),a(be)));try{await ft({defaultModel:ae??"",defaultVariant:""})}catch(fe){console.warn("Failed to save default model:",fe)}},[j,N,r,a,e,l,d]),L="__default__",V=o.useCallback(ie=>ie===L?t("settings.openchamber.defaults.option.default"):ie.charAt(0).toUpperCase()+ie.slice(1),[t]),Z=o.useCallback(async ie=>{const be=ie===L?void 0:ie||void 0;x(be),d(be),j||i(be??null,be);try{await ft({defaultVariant:be??""})}catch(ae){console.warn("Failed to save default variant:",ae)}},[j,i,d]),U=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]),te=o.useCallback(async ie=>{E(ie);try{await ft({smallModelUseDefault:ie})}catch(be){console.warn("Failed to save small model preference:",be)}},[]),O=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;K(ae);try{await ft({smallModelOverride:ae??""})}catch(fe){console.warn("Failed to save small model override:",fe)}},[]),Q=o.useCallback(async(ie,be)=>{const ae=ie&&be?`${ie}/${be}`:void 0;_(ae);try{await ft({walkthroughModelOverride:ae??""})}catch(fe){console.warn("Failed to save walkthrough model override:",fe)}},[]),ce=o.useCallback((ie,be)=>P.get(`${ie}/${be}`)?.structured_output!==!1,[P]),de=o.useMemo(()=>qr(F),[F]),pe=o.useMemo(()=>qr(z),[z]);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)&&M(ae.authenticatedProviders.filter(fe=>typeof fe=="string"))}catch{}})(),()=>{ie=!0}},[]);const re=o.useMemo(()=>{if(!J.providerId||!J.modelId)return[];const be=N.find(ae=>ae.id===J.providerId)?.models.find(ae=>ae.id===J.modelId);return Tu(be?.variants)},[J.modelId,J.providerId,N]),Ce=re.length>0;return q?null:s.jsx(s.Fragment,{children:s.jsx(Ge,{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")," ",J.providerId?s.jsxs("span",{className:"text-foreground",children:[J.providerId,"/",J.modelId,Ce?` (${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(St,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(la,{providerId:J.providerId,modelId:J.modelId,onChange:H,className:qs,offerAuto:!0})}),s.jsx(St,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Et,{value:D??L,onValueChange:Z,disabled:!Ce,children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:V(D??L)})}),s.jsxs(Tt,{children:[s.jsx(mt,{value:L,children:t("settings.openchamber.defaults.option.default")}),re.map(ie=>s.jsx(mt,{value:ie,children:V(ie)},ie))]})]})}),s.jsx(St,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(ho,{agentName:A||"",onChange:U,filter:ie=>Tc(ie.mode),className:qs})})]}),s.jsx(Ha,{className:ls,children:s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:k,onChange:p,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Ht,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:I,onChange:ie=>{te(ie)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),I?null:s.jsx(St,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(la,{providerId:de.providerId,modelId:de.modelId,onChange:O,allowedProviderIds:S,className:qs})}),s.jsxs(Ha,{className:ls,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Ht,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(St,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(la,{providerId:pe.providerId,modelId:pe.modelId,onChange:Q,allowedProviderIds:S,isModelAllowed:ce,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:qs})})]})]})]})})})},oc={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"}},Wv={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"},Jv=()=>{const{t}=Xe(),e=o.useMemo(()=>os(),[]),a=o.useMemo(()=>cs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!a&&!n,i=ge(L=>L.nativeNotificationsEnabled),l=ge(L=>L.setNativeNotificationsEnabled),d=ge(L=>L.notificationMode),c=ge(L=>L.setNotificationMode),h=ge(L=>L.notifyOnSubtasks),m=ge(L=>L.setNotifyOnSubtasks),f=ge(L=>L.notifyOnCompletion),u=ge(L=>L.setNotifyOnCompletion),g=ge(L=>L.notifyOnError),v=ge(L=>L.setNotifyOnError),j=ge(L=>L.notifyOnQuestion),b=ge(L=>L.setNotifyOnQuestion),k=ge(L=>L.notificationTemplates),p=ge(L=>L.setNotificationTemplates),[N,P]=o.useState("default"),[C,w]=o.useState(!1),[D,x]=o.useState(!1),[A,R]=o.useState(!1);o.useEffect(()=>{if(!r){w(!1),x(!1);return}typeof Notification<"u"&&P(Notification.permission);const L=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;w(L),(async()=>{if(!L){x(!1);return}try{const Z=await navigator.serviceWorker.getRegistration();if(!Z){x(!1);return}const U=await Z.pushManager.getSubscription();x(!!U)}catch{x(!1)}})()},[r]);const I=async L=>{if(e){l(L);return}if(!r){l(L);return}if(L&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();P(V),V==="granted"?l(!0):$.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),$.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(L&&N==="granted"))},E=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",F=(L,V,Z)=>{p(U=>({...U,[L]:{...U[L],[V]:Z}}))},K=L=>{const V="=".repeat((4-L.length%4)%4),Z=(L+V).replace(/-/g,"+").replace(/_/g,"/"),U=atob(Z),te=new Uint8Array(U.length);for(let O=0;O<U.length;O+=1)te[O]=U.charCodeAt(O);return te},S=async(L,V,Z)=>{let U=null;const te=new Promise((O,Q)=>{U=setTimeout(()=>{Q(new Error(Z))},V)});try{return await Promise.race([L,te])}finally{U&&clearTimeout(U)}},M=async L=>{if(L.active)return;const V=L.installing||L.waiting;V&&V.state!=="activated"&&await S(new Promise(Z=>{const U=()=>{V.state==="activated"&&(V.removeEventListener("statechange",U),Z())};V.addEventListener("statechange",U),U()}),15e3,"Service worker activation timed out")},z=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const L=[{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 Z of L)try{const U=Z.opts?navigator.serviceWorker.register("/sw.js",Z.opts):navigator.serviceWorker.register("/sw.js");return await S(U,1e4,`Service worker registration timed out (${Z.label})`)}catch(U){V=U}throw V instanceof Error?V:new Error("Service worker registration failed")},_=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const L=await navigator.serviceWorker.getRegistration();if(L)return L;const V=await z();try{await V.update()}catch{}return await M(V),V},q=L=>{const V=L,Z=[`type=${typeof L}`,`toString=${String(L)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let U="";try{U=JSON.stringify(L)}catch{}return{summary:Z.filter(Boolean).join(" | "),json:U,stack:typeof V?.stack=="string"?V.stack:""}},X=async()=>{const L=Ua();if(!L?.notifications){$.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await L.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?$.success(t("settings.notifications.page.toast.testNotificationSent")):$.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(V){console.error("Test notification failed:",V),$.error(t("settings.notifications.page.toast.testNotificationFailed"))}},J=async()=>{if(!C){$.error(t("settings.notifications.page.toast.pushUnsupported"));return}const L=Ua();if(!L?.push){$.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"){$.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){$.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const V=await L.push.getVapidPublicKey();if(!V?.publicKey){$.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Z=await _();await M(Z);const U=await Z.pushManager.getSubscription();if(!("pushManager"in Z)||!Z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const O=(U??await S(Z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:K(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Q=O.keys;if(!O.endpoint||!Q?.p256dh||!Q.auth)throw new Error("Push subscription missing keys");if(!(await S(L.push.subscribe({endpoint:O.endpoint,keys:{p256dh:Q.p256dh,auth:Q.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:um()}),15e3,"Push subscribe request timed out"))?.ok){$.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}x(!0),$.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(V){console.error("[Push] Enable failed:",V);const Z=q(V);$.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Z.summary})}finally{R(!1)}},H=async()=>{if(!C){x(!1);return}const L=Ua();if(!L?.push){$.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}R(!0);try{const Z=await(await _()).pushManager.getSubscription();if(!Z){x(!1);return}const U=Z.endpoint;await Z.unsubscribe(),await L.push.unsubscribe({endpoint:U}),x(!1),$.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{R(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Ge,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:ls,children:[s.jsx(gt,{checked:i&&E,onChange:L=>{I(L)},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:L=>c(L?"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:()=>{X()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1",children:[N==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),N==="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(Ge,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:ls,children:[s.jsx(gt,{checked:f,onChange:u,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:h,onChange:m,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:g,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:j,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Ge,{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(L=>s.jsxs("section",{className:"p-2",children:[s.jsx(Cn,{className:"capitalize",children:t(Wv[L])}),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[L].title,onChange:V=>F(L,"title",V.target.value),className:"h-7",placeholder:t(oc[L].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[L].message,onChange:V=>F(L,"message",V.target.value),className:"h-7",placeholder:t(oc[L].messageKey)})]})]})]},L))})})]}),r&&s.jsx(Ge,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:C?D:!1,disabled:!C||A,onChange:L=>{L?J():H()},label:t("settings.notifications.page.push.enableLabel"),description:C?void 0:t("settings.notifications.page.push.unsupportedHint"),info:C?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})})]})},Es=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",Qv=[{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"}],lc=t=>{const e=rt.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},Yv=({selectedModelId:t,onSelect:e})=>{const{t:a}=Xe(),n=tt.useCallback(u=>a(u),[a]),[r,i]=tt.useState(new Map),[l,d]=tt.useState(null),c=tt.useCallback(async()=>{try{const u=await Nt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const g=await u.json();Array.isArray(g?.models)&&i(new Map(g.models.map(v=>[v.id,v])))}catch{}},[]);tt.useEffect(()=>{c()},[c]);const h=Array.from(r.values()).some(u=>u.downloading);tt.useEffect(()=>{if(!h)return;const u=setInterval(()=>{c()},2e3);return()=>clearInterval(u)},[h,c]);const m=async u=>{d(u);try{await Nt(`/api/dictation/models/${encodeURIComponent(u)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},f=async u=>{d(u);try{await Nt(`/api/dictation/models/${encodeURIComponent(u)}`,{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:Qv.map(u=>{const g=t===u.id,v=r.get(u.id)??null;return s.jsx("div",{className:Ie("rounded-lg border border-[var(--interactive-border)] p-3",g&&"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(u.id),onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),e(u.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(fo,{checked:g,onChange:()=>e(u.id),ariaLabel:n(u.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",g?"text-foreground":"text-foreground/50"),children:n(u.labelKey)}),u.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(u.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(lc,{value:u.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(lc,{value:u.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:u.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===u.id,onClick:()=>{f(u.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(B,{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(B,{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===u.id,onClick:()=>{m(u.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(B,{name:"download",className:"h-4 w-4"})})})]})},u.id)})})},Zv=[{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)"}],co="kokoro-en-v0_19",Xv="kokoro-multi-lang-v1_1",ey=[{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)"}],ti=(t,e)=>`${t}:${e}`,ty=()=>{const[t,e]=tt.useState([]),[a,n]=tt.useState(null),r=tt.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{}},[]);tt.useEffect(()=>{r()},[r]);const i=t.some(d=>d.downloading);tt.useEffect(()=>{if(!i)return;const d=setInterval(()=>{r()},2e3);return()=>clearInterval(d)},[i,r]);const l=tt.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}},sy=t=>{const e=Zv.map(a=>({modelId:co,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===co||!a.installed)){if(a.id===Xv){for(const n of ey)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},ny=t=>{const e=rt.c(14),{models:a,requestingId:n,request:r}=t,{t:i}=Xe();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 m=a.filter(ry);if(m.length===0){c=null;break e}l="flex flex-col";let f;e[7]!==r||e[8]!==n||e[9]!==i?(f=u=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:u.description??u.id}),u.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{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(u.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})]}):u.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(B,{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 u.downloadProgress=="number"?`${u.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(u.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(B,{name:"download",className:"h-4 w-4"})}),u.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:u.downloadError}):null]},u.id),e[7]=r,e[8]=n,e[9]=i,e[10]=f):f=e[10],d=m.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},ay=[{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"}],iy=()=>{const{t}=Xe(),{isMobile:e}=Jn(),a=it(W=>W.voiceProvider),n=it(W=>W.setVoiceProvider),r=it(W=>W.speechRate),i=it(W=>W.setSpeechRate),l=it(W=>W.speechPitch),d=it(W=>W.setSpeechPitch),c=it(W=>W.speechVolume),h=it(W=>W.setSpeechVolume),m=it(W=>W.sayVoice),f=it(W=>W.setSayVoice),u=it(W=>W.localTtsVoiceId),g=it(W=>W.localTtsModelId),v=it(W=>W.setLocalTtsModelId),j=ty(),b=tt.useMemo(()=>sy(j.models),[j.models]),k=it(W=>W.ttsFollowTextLanguage),p=it(W=>W.setTtsFollowTextLanguage),N=it(W=>W.setLocalTtsVoiceId),{speak:P,stop:C,isPlaying:w,error:D}=Eu(),x=tt.useCallback(()=>{if(w){C();return}const W=b.find(Ve=>Ve.modelId===g&&Ve.speakerId===u)?.label??String(u);P(t("settings.voice.page.preview.voiceLine",{voiceName:W}),{model:g,speakerId:u,speed:it.getState().speechRate})},[w,g,u,b,P,C,t]),A=it(W=>W.browserVoice),R=it(W=>W.setBrowserVoice),I=it(W=>W.openaiVoice),E=it(W=>W.setOpenaiVoice),F=it(W=>W.openaiApiKey),K=it(W=>W.setOpenaiApiKey),S=it(W=>W.openaiCompatibleUrl),M=it(W=>W.setOpenaiCompatibleUrl),z=it(W=>W.openaiCompatibleApiKey),_=it(W=>W.setOpenaiCompatibleApiKey),q=it(W=>W.openaiCompatibleVoice),X=it(W=>W.setOpenaiCompatibleVoice),J=it(W=>W.openaiCompatibleTtsModel),H=it(W=>W.setOpenaiCompatibleTtsModel),L=it(W=>W.showMessageTTSButtons),V=it(W=>W.ttsInputMode),Z=it(W=>W.setTtsInputMode),U=it(W=>W.sttProvider),te=it(W=>W.setSttProvider),O=it(W=>W.sttServerUrl),Q=it(W=>W.setSttServerUrl),ce=it(W=>W.sttApiKey),de=it(W=>W.setSttApiKey),pe=it(W=>W.sttModel),re=it(W=>W.setSttModel),Ce=it(W=>W.sttLocalModel),ie=it(W=>W.setSttLocalModel),be=it(W=>W.sttLanguage),ae=it(W=>W.setSttLanguage),fe=it(W=>W.setShowMessageTTSButtons),xe=it(W=>W.dictationEnabled),Oe=it(W=>W.setDictationEnabled),[Ne,he]=tt.useState(!1),[Te,we]=tt.useState([]),[De,ve]=tt.useState(!1),[ee,ne]=tt.useState(null),[ye,Ae]=tt.useState(!1),[ze,Qe]=tt.useState(!1),[Be,_e]=tt.useState(null),[Me,nt]=tt.useState(!1),[pt,lt]=tt.useState(null),[ut,ht]=tt.useState([]),[Ue,st]=tt.useState(!1);tt.useEffect(()=>((async()=>{const Ve=await Ar.waitForVoices();ht(Ve)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{ht(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ue=tt.useMemo(()=>ut.filter(W=>W.lang).sort((W,Ve)=>{const et=W.lang.startsWith("en"),dt=Ve.lang.startsWith("en");if(et&&!dt)return-1;if(!et&&dt)return 1;const ct=W.lang.localeCompare(Ve.lang);return ct!==0?ct:W.name.localeCompare(Ve.name)}),[ut]),oe=tt.useCallback(()=>{if(Ue){Ar.cancelSpeech(),st(!1);return}const W=ut.find(ct=>ct.name===A),Ve=W?.name??t("settings.voice.page.preview.browserVoiceFallback"),et=t("settings.voice.page.preview.voiceLine",{voiceName:Ve});st(!0);const dt=new SpeechSynthesisUtterance(et);dt.rate=r,dt.pitch=l,dt.volume=c,W&&(dt.voice=W,dt.lang=W.lang),dt.onend=()=>st(!1),dt.onerror=()=>st(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(dt)},[A,ut,r,l,c,Ue,t]);tt.useEffect(()=>()=>{Ue&&Ar.cancelSpeech()},[Ue]),tt.useEffect(()=>{if(!L||a!=="openai"&&a!=="openai-compatible"){Ae(F.trim().length>0);return}(async()=>{try{const dt=(await(await Nt("/api/tts/status")).json()).available,ct=F.trim().length>0;Ae(dt||ct)}catch{Ae(F.trim().length>0)}})()},[F,L,a]),tt.useEffect(()=>{if(!L){he(!1),we([]);return}Nt("/api/tts/say/status").then(W=>W.json()).then(W=>{if(he(W.available),W.voices){const Ve=W.voices.filter((et,dt,ct)=>ct.findIndex(jt=>jt.name===et.name)===dt).sort((et,dt)=>et.name.localeCompare(dt.name));we(Ve)}}).catch(()=>{he(!1)})},[L]);const Pe=tt.useCallback(async()=>{if(ee){Es(ee),ne(null),ve(!1);return}ve(!0);let W=null;try{const Ve=await Nt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(r-.5)*200)})});if(!Ve.ok)throw new Error("Preview failed");const et=await Ve.blob(),dt=URL.createObjectURL(et);W=new Audio(dt),W.onended=()=>{Es(W),ne(null),ve(!1)},W.onerror=()=>{Es(W),ne(null),ve(!1)},ne(W),await W.play()}catch{Es(W),ne(null),ve(!1)}},[m,r,ee,t]);tt.useEffect(()=>()=>{Es(ee)},[ee]);const Re=tt.useCallback(async()=>{if(Be){Es(Be),_e(null),Qe(!1);return}Qe(!0);let W=null;try{const Ve=await Nt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:I}),voice:I,speed:r,apiKey:F||void 0})});if(!Ve.ok){const ct=await Ve.json().catch(()=>({error:"Unknown error"}));throw new Error(ct.error||`HTTP ${Ve.status}`)}const et=await Ve.blob(),dt=URL.createObjectURL(et);W=new Audio(dt),W.onended=()=>{Es(W),_e(null),Qe(!1)},W.onerror=()=>{Es(W),_e(null),Qe(!1)},_e(W),await W.play()}catch{Es(W),_e(null),Qe(!1)}},[I,r,Be,F,t]);tt.useEffect(()=>()=>{Es(Be)},[Be]);const Fe=tt.useCallback(async()=>{if(pt){Es(pt),lt(null),nt(!1);return}if(!S.trim())return;nt(!0);let W=null;try{const Ve=await Nt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:q,model:J||void 0,speed:r,baseURL:S,apiKey:z||void 0})});if(!Ve.ok){const ct=await Ve.json().catch(()=>({error:"Unknown error"}));throw new Error(ct.error||`HTTP ${Ve.status}`)}const et=await Ve.blob(),dt=URL.createObjectURL(et);W=new Audio(dt),W.onended=()=>{Es(W),lt(null),nt(!1)},W.onerror=()=>{Es(W),lt(null),nt(!1)},lt(W),await W.play()}catch{Es(W),lt(null),nt(!1)}},[S,q,J,z,r,pt,t]);tt.useEffect(()=>()=>{Es(pt)},[pt]);const $e="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(Ge,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(gt,{checked:L,onChange:fe,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),L&&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")},...Ne?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(B,{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(It,!ye&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Ie(Ss,!ye&&"text-[var(--status-error)]/80"),children:t(ye&&!F?"settings.voice.page.field.apiKeyHintUsingConfig":ye?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:F,onChange:W=>K(W.target.value),placeholder:"sk-...",className:Mn}),F&&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(B,{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(It,!S.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Ht,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:S,onChange:W=>M(W.target.value),placeholder:"http://localhost:8880/v1",className:Mn}),S&&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(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:"API Key"}),s.jsx("span",{className:Ss,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:z,onChange:W=>_(W.target.value),placeholder:"sk-...",className:Mn}),z&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:J,onChange:W=>H(W.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:It,children:t("settings.voice.page.field.voice")}),s.jsx(Ht,{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:q,onChange:W=>X(W.target.value),placeholder:"af_sky",className:Mn})}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Fe,title:t("settings.voice.page.actions.preview"),disabled:!S.trim(),children:Me?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(ny,{...j}),(a==="local"||a==="say")&&s.jsx(gt,{checked:k,onChange:p,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(St,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:ti(g,u),onValueChange:W=>{const Ve=b.find(et=>ti(et.modelId,et.speakerId)===W);Ve&&(v(Ve.modelId),N(Ve.speakerId))},children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:W=>b.find(Ve=>ti(Ve.modelId,Ve.speakerId)===W)?.label??W})}),s.jsx(Tt,{children:b.map(W=>s.jsx(mt,{value:ti(W.modelId,W.speakerId),children:W.label},ti(W.modelId,W.speakerId)))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:x,title:t("settings.voice.page.actions.preview"),children:w?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{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"&&ye&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:I,onValueChange:E,children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Tt,{children:ay.map(W=>s.jsx(mt,{value:W.value,children:W.label},W.value))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Re,title:t("settings.voice.page.actions.preview"),children:ze?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Ss,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Ne&&Te.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:m,onValueChange:f,children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Tt,{children:Te.map(W=>s.jsx(mt,{value:W.name,children:W.name},W.name))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:Pe,title:t("settings.voice.page.actions.preview"),children:De?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&ue.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:A||"$auto",onValueChange:W=>R(W==="$auto"?"":W),children:[s.jsx(At,{size:Vt,className:nn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Tt,{children:[s.jsx(mt,{value:"$auto",children:t("settings.voice.page.field.auto")}),ue.map(W=>s.jsxs(mt,{value:W.name,children:[W.name," (",W.lang,")"]},W.name))]})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:oe,title:t("settings.voice.page.actions.preview"),children:Ue?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(St,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:W=>i(Number(W.target.value)),className:$e}),s.jsx(fs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:Ie(ys,"tabular-nums")})]}),s.jsxs(St,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:W=>d(Number(W.target.value)),className:$e}),s.jsx(fs,{value:l,onValueChange:d,min:.5,max:2,step:.1,className:Ie(ys,"tabular-nums")})]}),s.jsxs(St,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:W=>h(Number(W.target.value)),className:$e}),e?s.jsx(fs,{value:Math.round(c*100),onValueChange:W=>h(W/100),min:0,max:100,step:10,className:Ie(ys,"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:Z,"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(Ge,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(gt,{checked:xe,onChange:Oe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),xe&&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:U,onChange:te,"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")}]})}),U==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:t("settings.voice.page.field.model")}),s.jsx(Yv,{selectedModelId:Ce,onSelect:ie})]}),U==="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(It,!O.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Ht,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"text",value:O,onChange:W=>Q(W.target.value),placeholder:"http://localhost:8001/v1",className:Mn}),O&&s.jsx("button",{type:"button",onClick:()=>Q(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:"API Key"}),s.jsx("span",{className:Ss,children:"Optional"}),s.jsxs("div",{className:Ie("relative",Ps),children:[s.jsx("input",{type:"password",value:ce,onChange:W=>de(W.target.value),placeholder:"sk-...",className:Mn}),ce&&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(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",Ps),children:s.jsx("input",{type:"text",value:pe,onChange:W=>re(W.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:It,children:t("settings.voice.page.field.language")}),s.jsx(Ht,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:be,onChange:W=>ae(W.target.value),placeholder:"auto",className:Mn})})]})]})]})]})]})};function ry(t){return t.id===co||t.installed||t.downloading}const Ui=[{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}],$i=[{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}],oy="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",ly="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Gr=[{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"}],cy=[".yml",".yaml",".json"],dy="settings.openchamber.tunnel.error.invalidConfigExtension",si=t=>{const e=t.trim().toLowerCase();return cy.some(a=>e.endsWith(a))},uy=t=>t==="ngrok"?"ngrok":"cloudflared",yd=()=>{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"},my=(t,e=yd())=>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/",Wr=(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():uy(a),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():yd(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():my(a,r);return{provider:a,dependency:n,installCommand:i}},jd=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,cc=t=>{const e=rt.c(11),{provider:a}=t;let n;e[0]!==a?(n=jd(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(B,{name:"cloud",className:c}),e[4]=c,e[5]=h):h=e[5];let m;e[6]!==r?(m=s.jsx("span",{children:r}),e[6]=r,e[7]=m):m=e[7];let f;return e[8]!==h||e[9]!==m?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[h,m]}),e[8]=h,e[9]=m,e[10]=f):f=e[10],f},Hn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",uo=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,dc=(t,e,a)=>{const n=uo(t,e,a);return t.find(r=>r.value===n)?.label||n},uc=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`},py=(t,e)=>Cc(t,e,{hour:"2-digit",precision:"second"}),Gi=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()}},gy=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=Gi(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},hy=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,fy=()=>{const{t}=Xe(),e=ge(Y=>Y.timeFormatPreference),a=o.useCallback(Y=>t(Y),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[d,c]=o.useState(null),[h,m]=o.useState(null),[f,u]=o.useState(null),[g,v]=o.useState(null),[j,b]=o.useState(!1),[k,p]=o.useState(!1),[N,P]=o.useState(!1),[C,w]=o.useState("cloudflare"),[D,x]=o.useState(()=>Wr("cloudflare")),[A,R]=o.useState([]),[I,E]=o.useState("quick"),[F,K]=o.useState(null),[S,M]=o.useState([]),[z,_]=o.useState({}),[q,X]=o.useState(""),[J,H]=o.useState({}),[L,V]=o.useState(new Set),[Z,U]=o.useState(!1),[te,O]=o.useState(""),[Q,ce]=o.useState(""),[de,pe]=o.useState(""),[re,Ce]=o.useState(1800*1e3),[ie,be]=o.useState(480*60*1e3),[ae,fe]=o.useState(""),[xe,Oe]=o.useState([]),[Ne,he]=o.useState(()=>Date.now()),[Te,we]=o.useState(null),De=t(dy),ve=o.useRef(null),ee=o.useMemo(()=>F?!si(F):!1,[F]),ne=o.useMemo(()=>S.find(Y=>Y.id===q)||S[0]||null,[S,q]),ye=o.useMemo(()=>xe.map(Y=>{const me=Y.expiresAt<=Ne,Ke=Y.status==="active"&&!me,Ee=Ke?uc(Y.expiresAt-Ne):Y.inactiveReason==="expired"||me?"expired":"inactive",Ye=Ee==="expired"?t("settings.openchamber.tunnel.state.expired"):Y.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),se=Hn(Y.mode);return{...Y,isActive:Ke,mode:se,remainingTextForSession:Ee,inactiveLabel:Ye}}),[Ne,xe,t]),Ae=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>Ne:!1,[Ne,i?.bootstrapExpiresAt,i?.connectUrl]),ze=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:d===I,[d,n,i,I]),Qe=o.useMemo(()=>!i||n!=="active"||!d?!1:d!==I,[d,n,i,I]),Be=o.useMemo(()=>{if(typeof Te=="number"&&Number.isFinite(Te)&&Te>0)return Te;if(typeof window>"u")return null;const me=pi()||window.location.href;let Ke=0;try{Ke=Number(new URL(me).port)}catch{Ke=Number(window.location.port)}return Number.isFinite(Ke)&&Ke>0?Ke:null},[Te]),_e=o.useMemo(()=>A.find(Y=>Y.provider===C)??null,[A,C]),Me=o.useMemo(()=>{const Y=new Set(_e?.modes?.map(me=>me.key).filter(me=>me==="quick"||me==="managed-remote"||me==="managed-local"));return Y.size===0?Gr:Gr.filter(me=>Y.has(me.value))},[_e]),nt=o.useMemo(()=>Me.some(Y=>Y.value==="managed-remote"||Y.value==="managed-local"),[Me]),pt=o.useMemo(()=>D.provider===C?D:Wr(C),[D,C]),lt=o.useCallback(async Y=>{await yn(Y)},[]),ut=o.useCallback((Y,me)=>(x(Wr(me,Y)),Y.available===!0),[]),ht=o.useCallback(async(Y,me)=>{try{const Ke=await Nt("/api/openchamber/tunnel/check",{query:{provider:Y},...me?{signal:me}:{}});if(!Ke.ok)return null;const Ee=await Ke.json();if(me?.aborted)return null;const Ye=ut(Ee,Y);return r(se=>se==="checking"||se==="starting"||se==="active"||se==="stopping"?se:Ye?"idle":"not-available"),Ye}catch{return null}},[ut]),Ue=o.useCallback(async Y=>{try{const[me,Ke,Ee,Ye]=await Promise.all([Nt("/api/openchamber/tunnel/check",{signal:Y}),Nt("/api/openchamber/tunnel/status",{signal:Y}),An(),Nt("/api/openchamber/tunnel/providers",{signal:Y})]),se=await me.json(),ke=await Ke.json(),at=Ee??{},Mt=Ye.ok?await Ye.json():{},Wt=ke.ttlConfig?.bootstrapTtlMs??(at.tunnelBootstrapTtlMs===void 0?1800*1e3:at.tunnelBootstrapTtlMs),Se=typeof ke.ttlConfig?.sessionTtlMs=="number"?ke.ttlConfig.sessionTtlMs:at.tunnelSessionTtlMs??480*60*1e3,qe=Hn(ke.mode??at.tunnelMode),vt=at.tunnelProvider??"cloudflare",Ct=at.managedLocalTunnelConfigPath??null,Jt=ut(se,vt),Zt=gy(ke?.managedRemoteTunnelPresets),ts=typeof ke.managedRemoteTunnelHostname=="string"?ke.managedRemoteTunnelHostname:"",Xt=Zt.length>0?Zt:ts?[{id:`legacy-${Gi(ts)}`,name:ts,hostname:Gi(ts)}]:[],Fs=Xt[0]?.id||"";if(Ce(Wt),be(Se),w(vt),R(Array.isArray(Mt?.providers)?Mt.providers:[]),E(qe),K(Ct),M(Xt),X(Fs),Oe(Array.isArray(ke.activeSessions)?ke.activeSessions:[]),c(ke.activeTunnelMode?Hn(ke.activeTunnelMode):ke.active&&ke.mode?Hn(ke.mode):null),V(new Set(Array.isArray(ke.managedRemoteTunnelTokenPresetIds)?ke.managedRemoteTunnelTokenPresetIds:[])),we(typeof ke.localPort=="number"?ke.localPort:null),ke.active&&ke.url){l({url:ke.url,connectUrl:null,bootstrapExpiresAt:typeof ke.bootstrapExpiresAt=="number"?ke.bootstrapExpiresAt:null}),r("active");return}r(Jt?"idle":"not-available")}catch{Y.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[ut,t]);o.useEffect(()=>{const Y=new AbortController;return Ue(Y.signal),()=>Y.abort()},[Ue]),o.useEffect(()=>{if(!i?.connectUrl){m(null);return}let Y=!1;return Vc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(me=>{Y||m(me)}).catch(()=>{Y||m(null)}),()=>{Y=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){fe(t("settings.openchamber.tunnel.state.noExpiry"));return}let Y=null,me=Date.now();const Ke=()=>{const se=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;se<=0?fe(t("settings.openchamber.tunnel.state.expired")):fe(uc(se))},Ee=()=>{const se=Date.now();se-me>=1e3&&(Ke(),me=se),Y=requestAnimationFrame(Ee)};Ke(),(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(Ee));const Ye=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",Ye),()=>{document.removeEventListener("visibilitychange",Ye),Y!==null&&cancelAnimationFrame(Y)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let Y=null,me=Date.now();const Ke=()=>{const Ye=Date.now();Ye-me>=1e3&&(he(Ye),me=Ye),Y=requestAnimationFrame(Ke)};(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(Ke));const Ee=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(Ke):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),Y!==null&&cancelAnimationFrame(Y)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Y=!1;const me=async()=>{try{const Ee=await Nt("/api/openchamber/tunnel/status");if(!Ee.ok||Y)return;const Ye=await Ee.json();if(Y)return;Oe(Array.isArray(Ye.activeSessions)?Ye.activeSessions:[]),V(new Set(Array.isArray(Ye.managedRemoteTunnelTokenPresetIds)?Ye.managedRemoteTunnelTokenPresetIds:[])),we(typeof Ye.localPort=="number"?Ye.localPort:null)}catch{}},Ke=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||me()},5e3);return()=>{Y=!0,window.clearInterval(Ke)}},[n]);const st=o.useCallback(async Y=>{P(!0);try{await ft(Y),Object.prototype.hasOwnProperty.call(Y,"tunnelMode")&&Y.tunnelMode&&E(Y.tunnelMode),Object.prototype.hasOwnProperty.call(Y,"tunnelProvider")&&typeof Y.tunnelProvider=="string"&&w(Y.tunnelProvider),Object.prototype.hasOwnProperty.call(Y,"managedLocalTunnelConfigPath")&&K(Y.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Y,"managedRemoteTunnelPresets")&&Y.managedRemoteTunnelPresets&&M(Y.managedRemoteTunnelPresets)}catch{$.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{P(!1)}},[t]),ue=o.useCallback(async(Y,me)=>{p(!0);try{await ft({tunnelBootstrapTtlMs:Y,tunnelSessionTtlMs:me})}catch{$.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{p(!1)}},[t]),oe=o.useCallback(async Y=>{const me=Y.token.trim();if(me)try{const Ke={...J,[Y.presetId]:me};await ft({managedRemoteTunnelPresetTokens:Ke}),V(Ee=>{const Ye=new Set(Ee);return Ye.add(Y.presetId),Ye})}catch{$.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[J,t]),Pe=o.useCallback(async Y=>{v(null),u(null);const me=A.find(Ee=>Ee.provider===Y),Ke=me?.modes?.some(Ee=>Ee.key===I)?I:Hn(me?.modes?.[0]?.key);await st({tunnelProvider:Y,tunnelMode:Ke}),ht(Y)},[A,ht,st,I]),Re=o.useCallback(async()=>{const Y=await wo({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Y.success&&typeof Y.path=="string"&&Y.path.trim().length>0){const me=Y.path.trim();if(!si(me)){$.error(De);return}K(me),await st({managedLocalTunnelConfigPath:me});return}ve.current?.click()},[De,st]),Fe=o.useCallback(Y=>{const me=Y.trim();K(me.length>0?me:null)},[]),$e=o.useCallback(async()=>{if(F&&!si(F)){$.error(De);return}await st({managedLocalTunnelConfigPath:F})},[De,F,st]),W=o.useCallback(async()=>{K(null),await st({managedLocalTunnelConfigPath:null})},[st]),Ve=o.useCallback(async Y=>{const me=Y.target.files?.[0];if(!me)return;const Ke=me.name.trim();if(Ke.length!==0){if(!si(Ke)){$.error(De);return}K(Ke),await st({managedLocalTunnelConfigPath:Ke}),Y.target.value=""}},[De,st]),et=o.useCallback(async()=>{if(u(null),v(null),I==="managed-local"&&F&&!si(F)){u(De),$.error(De);return}r("starting");try{let Y="",me="";if(I==="managed-remote"){if(!ne){r("idle"),v(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),$.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Y=ne.hostname,me=(J[ne.id]||"").trim(),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const Ke=await Nt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C,mode:I,...I==="managed-remote"&&ne?{managedRemoteTunnelPresetId:ne.id,managedRemoteTunnelPresetName:ne.name}:{},...I==="managed-remote"&&Y?{managedRemoteTunnelHostname:Y}:{},...I==="managed-remote"&&me?{managedRemoteTunnelToken:me}:{},...I==="managed-local"&&F?{configPath:F}:{}})}),Ee=await Ke.json();if(!Ke.ok||!Ee.ok){if(I==="managed-remote"&&typeof Ee.error=="string"&&Ee.error.includes("Managed remote tunnel token is required")){r("idle"),v(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),$.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ee.error||t("settings.openchamber.tunnel.toast.startFailed")),$.error(Ee.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const Ye=typeof Ee.url=="string"?Ee.url:"";if(!Ye){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),$.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?Hn(Ee.activeTunnelMode):Ee.mode?Hn(Ee.mode):I),Oe(Array.isArray(Ee.activeSessions)?Ee.activeSessions:[]),Array.isArray(Ee.managedRemoteTunnelTokenPresetIds)&&V(new Set(Ee.managedRemoteTunnelTokenPresetIds)),typeof Ee.localPort=="number"&&we(Ee.localPort),typeof Ee.mode=="string"&&E(Hn(Ee.mode)),r("active"),Ee.replacedTunnel){const se=typeof Ee.revokedBootstrapCount=="number"?Ee.revokedBootstrapCount:0,ke=typeof Ee.invalidatedSessionCount=="number"?Ee.invalidatedSessionCount:0;se===1&&ke===1?$.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):se===1?$.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ke})):ke===1?$.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:se})):$.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:se,invalidatedSessionCount:ke}))}else $.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),$.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[De,S,st,ne,J,t,C,I,F]),dt=o.useCallback(async()=>{r("stopping");try{await Nt("/api/openchamber/tunnel/stop",{method:"POST"});const Y=await Nt("/api/openchamber/tunnel/status");if(Y.ok){const me=await Y.json();Oe(Array.isArray(me.activeSessions)?me.activeSessions:[]),V(new Set(Array.isArray(me.managedRemoteTunnelTokenPresetIds)?me.managedRemoteTunnelTokenPresetIds:[])),we(typeof me.localPort=="number"?me.localPort:null)}l(null),c(null),m(null),r("idle"),$.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),$.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ct=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),b(!0),$.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{$.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),jt=o.useCallback(async Y=>{const me=Ui.find(Ke=>Ke.value===Y);me&&(Ce(me.ms),await ue(me.ms,ie))},[ue,ie]),kt=o.useCallback(async Y=>{const me=$i.find(Ke=>Ke.value===Y);!me||me.ms===null||(be(me.ms),await ue(re,me.ms))},[re,ue]),yt=o.useCallback(async Y=>{v(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await st({tunnelMode:Y,managedRemoteTunnelPresets:S})},[S,st,n]),bt=o.useCallback(async(Y,me)=>{try{await ft({managedRemoteTunnelPresets:me})}catch{$.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ze=o.useCallback(Y=>{const me=S.find(Ke=>Ke.id===Y);me&&(X(me.id),v(null),bt(me,S))},[S,bt]),wt=o.useCallback(async()=>{const Y=te.trim(),me=Gi(Q),Ke=de.trim();if(!Y){$.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!me){$.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ke){$.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(se=>se.hostname===me)){$.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ee={id:hy(),name:Y,hostname:me},Ye=[...S,Ee];M(Ye),X(Ee.id),_(se=>({...se,[Ee.id]:!0})),H(se=>({...se,[Ee.id]:Ke})),v(null),U(!1),O(""),ce(""),pe(""),await st({tunnelMode:"managed-remote",managedRemoteTunnelPresets:Ye,managedRemoteTunnelPresetTokens:{...J,[Ee.id]:Ke}}),await oe({presetId:Ee.id,presetName:Ee.name,hostname:Ee.hostname,token:Ke}),$.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[S,Q,te,de,oe,st,J,t]),Le=o.useCallback(async Y=>{const me=S.find(ke=>ke.id===Y);if(!me)return;const Ke=S.filter(ke=>ke.id!==me.id),Ee=Ke[0]?.id||"",Ye=q===me.id?Ee:q,se=Object.fromEntries(Object.entries(J).filter(([ke,at])=>ke!==me.id&&at.trim().length>0));M(Ke),X(Ye),_(ke=>{const at={...ke};return delete at[me.id],at}),H(ke=>{const at={...ke};return delete at[me.id],at}),V(ke=>{const at=new Set(ke);return at.delete(me.id),at}),v(null),await st({managedRemoteTunnelPresets:Ke,managedRemoteTunnelPresetTokens:se}),$.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[S,st,q,J,t]),He="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(Ge,{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:[ye.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(B,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Go,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ye.map(Y=>{const me=Y.mode==="quick",Ke=Y.mode==="managed-remote",Ee=me?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ke?"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=Y.isActive?me?"text-[var(--status-warning)]":Ke?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",se=t(me?"settings.openchamber.tunnel.badge.quick":Ke?"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(B,{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:se}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:py(Y.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Y.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Y.remainingTextForSession}):Y.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Y.inactiveLabel})})]},Y.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(B,{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:Go,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:It,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Et,{value:C,onValueChange:Y=>{Pe(Y)},disabled:N||n==="starting"||n==="stopping",children:[s.jsx(At,{size:Vt,className:"max-w-[16rem]",children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:jd(C)})}),s.jsxs(Tt,{children:[A.length>0?A.map(Y=>s.jsx(mt,{value:Y.provider,children:s.jsx(cc,{provider:Y.provider})},Y.provider)):s.jsx(mt,{value:"cloudflare",children:s.jsx(cc,{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:It,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Me.map(Y=>s.jsxs(sr,{children:[s.jsx(nr,{asChild:!0,children:s.jsx(G,{variant:"chip",size:"xs","aria-pressed":I===Y.value,className:"!font-normal",onClick:()=>{yt(Y.value)},disabled:N||n==="starting"||n==="stopping",children:a(Y.labelKey)})}),s.jsx(xo,{sideOffset:8,className:"max-w-xs",children:a(Y.tooltipKey)})]},Y.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(It,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Et,{value:uo(Ui,re,"1800000"),onValueChange:Y=>{jt(Y)},disabled:k||N||n==="starting"||n==="stopping",children:[s.jsx(At,{size:Vt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:dc(Ui,re,"1800000")})}),s.jsx(Tt,{children:Ui.map(Y=>s.jsx(mt,{value:Y.value,children:Y.label},Y.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(It,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Et,{value:uo($i,ie,"28800000"),onValueChange:Y=>{kt(Y)},disabled:k||N||n==="starting"||n==="stopping",children:[s.jsx(At,{size:Vt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:dc($i,ie,"28800000")})}),s.jsx(Tt,{children:$i.map(Y=>s.jsx(mt,{value:Y.value,children:Y.label},Y.value))})]})]})]}),I==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(B,{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")}),nt&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),I==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Be=="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:",Be]})]})}),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:()=>U(Y=>!Y),disabled:n==="starting"||n==="stopping"||N,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((Y,me)=>{const Ke=J[Y.id]||"",Ee=L.has(Y.id),Ye=z[Y.id]??!1;return s.jsx("div",{className:Ie(me<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(kn,{open:Ye,onOpenChange:se=>{_(ke=>({...ke,[Y.id]:se})),se&&Ze(Y.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"||N,children:[Ye?s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Y.name})]}),s.jsx(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:Y.name}),onClick:()=>{Le(Y.id)},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(B,{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:Y.hostname})]}),s.jsx(We,{type:"password",value:Ke,onChange:se=>{const ke=se.target.value;v(null),H(at=>({...at,[Y.id]:ke}))},onBlur:se=>{const ke=se.currentTarget.value.trim();ke&&oe({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:ke})},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"||Ke.trim().length===0,onClick:()=>{oe({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:Ke})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Y.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),Z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(We,{value:te,onChange:Y=>O(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),s.jsx(We,{value:Q,onChange:Y=>ce(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),s.jsx(We,{type:"password",value:de,onChange:Y=>pe(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),typeof Be=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Be]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{wt()},disabled:N||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{U(!1),O(""),ce(""),pe("")},disabled:N||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(Ht,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!ne&&g&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:g})]}),I==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:It,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Y=>{Ve(Y)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:F||"",onChange:Y=>{Fe(Y.target.value)},onBlur:()=>{$e()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||N}),s.jsx(G,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Re()},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(B,{name:"folder",className:"size-3.5"})}),F&&s.jsx(G,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{W()},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(B,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(F?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),ee&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:De})]})}),!ze&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(B,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{lt(oy)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(B,{name:"external-link",className:"size-3.5"})]})]}),I==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{lt(ly)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(B,{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(Gr.find(Y=>Y.value===I)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:It,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Et,{value:q||(S[0]?.id??""),onValueChange:Y=>{Ze(Y)},disabled:N||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(At,{size:Vt,children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:ne?.name})}),s.jsx(Tt,{fitContent:!0,children:S.map(Y=>s.jsx(mt,{value:Y.id,children:Y.name},Y.id))})]})]}),Qe&&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(B,{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:et,disabled:n==="starting"||N||I==="managed-remote"&&!ne||I==="managed-local"&&ee,className:Ie(He,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),ze&&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})]}),Ae&&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:ct,className:"shrink-0 gap-1.5",children:[j?s.jsx(B,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(B,{name:"file-copy",className:"size-3.5"}),t(j?"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:et,disabled:n==="stopping"||N||I==="managed-local"&&ee,className:He,children:[s.jsx(B,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:dt,disabled:n==="stopping"||N,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(B,{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:et,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},wd=()=>{const{t}=Xe(),[e,a]=tt.useState(""),[n,r]=tt.useState(!0),[i,l]=tt.useState(!1),d=ge(u=>u.showOpenCodeUpdateNotifications),c=ge(u=>u.setShowOpenCodeUpdateNotifications);tt.useEffect(()=>{let u=!1;return(async()=>{try{const g=await An();if(u||!g)return;a(g.opencodeBinary??"")}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const h=tt.useCallback(async()=>{if(!(typeof window>"u")&&os())try{const u=await wo();u.success&&u.path&&u.path.trim().length>0&&a(u.path.trim())}catch{}},[]),m=tt.useCallback(async()=>{l(!0);try{const u=e.trim(),g=u.length>=2&&(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))?u.slice(1,-1).trim():u;await ft({opencodeBinary:g}),await Du({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(u){if(u?.requiresManualRestart){$.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}$.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{l(!1)}},[t,e]),f=tt.useCallback(u=>{c(u),ft({showOpenCodeUpdateNotifications:u})},[c]);return s.jsx(Ge,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(St,{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||!os(),className:gs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(B,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Ha,{className:ls,children:[!Uc()&&s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:d,onChange:f,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(G,{type:"button",size:"xs",onClick:m,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})})},Jr="builtin",xy=t=>t.filter(e=>jo(e)&&Ec(e.service,"browser")),kd=()=>{const t=rt.c(84),{t:e}=Xe(),a=ge(by),n=ge(vy),r=ge(yy),i=ge(jy),l=ge(wy),d=ge(ky),c=Vs(Ny),h=ge(Sy),m=ge(Cy),f=ge(Iy);let u;t[0]!==n?(u=re=>{n(re),ft({agentControlToolEnabled:re})},t[0]=n,t[1]=u):u=t[1];const g=u;let v;t[2]!==i?(v=re=>{i(re),ft({agentWebToolEnabled:re})},t[2]=i,t[3]=v):v=t[3];const j=v;let b;t[4]===Symbol.for("react.memo_cache_sentinel")?(b=[],t[4]=b):b=t[4],tt.useEffect(Py,b);let k;t[5]!==c?(k=xy(c),t[5]=c,t[6]=k):k=t[6];const p=k;let N;t[7]!==l||t[8]!==p?(N=p.some(re=>re.id===l)?l:Jr,t[7]=l,t[8]=p,t[9]=N):N=t[9];const P=N;let C;t[10]!==d?(C=re=>{d(re),ft({browserProvider:re})},t[10]=d,t[11]=C):C=t[11];const w=C;let D;t[12]!==f?(D=re=>{f(re),ft({agentMemoryToolEnabled:re}).finally(()=>{re&&Mu.getState().refresh()})},t[12]=f,t[13]=D):D=t[13];const x=D;let A;t[14]!==e?(A=e("settings.openchamber.tools.title"),t[14]=e,t[15]=A):A=t[15];let R;t[16]!==e?(R=e("settings.openchamber.tools.field.agentControlTool"),t[16]=e,t[17]=R):R=t[17];let I;t[18]!==e?(I=e("settings.openchamber.tools.field.agentControlToolAria"),t[18]=e,t[19]=I):I=t[19];let E;t[20]!==e?(E=e("settings.openchamber.tools.field.agentControlToolInfo"),t[20]=e,t[21]=E):E=t[21];let F;t[22]!==a||t[23]!==g||t[24]!==E||t[25]!==R||t[26]!==I?(F=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:g,label:R,ariaLabel:I,info:E}),t[22]=a,t[23]=g,t[24]=E,t[25]=R,t[26]=I,t[27]=F):F=t[27];let K;t[28]!==e?(K=e("settings.openchamber.tools.field.agentWebTool"),t[28]=e,t[29]=K):K=t[29];let S;t[30]!==e?(S=e("settings.openchamber.tools.field.agentWebToolAria"),t[30]=e,t[31]=S):S=t[31];let M;t[32]!==e?(M=e("settings.openchamber.tools.field.agentWebToolInfo"),t[32]=e,t[33]=M):M=t[33];let z;t[34]!==r||t[35]!==j||t[36]!==K||t[37]!==S||t[38]!==M?(z=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:j,label:K,ariaLabel:S,info:M}),t[34]=r,t[35]=j,t[36]=K,t[37]=S,t[38]=M,t[39]=z):z=t[39];let _;t[40]!==e?(_=e("settings.openchamber.tools.browserProvider.label"),t[40]=e,t[41]=_):_=t[41];let q;t[42]!==e?(q=e("settings.openchamber.tools.browserProvider.info"),t[42]=e,t[43]=q):q=t[43];const X=!r||p.length===0;let J;t[44]!==e?(J=e("settings.openchamber.tools.browserProvider.aria"),t[44]=e,t[45]=J):J=t[45];let H;t[46]!==p||t[47]!==e?(H=s.jsx(_t,{children:re=>re===Jr?e("settings.openchamber.tools.browserProvider.option.builtin"):p.find(Ce=>Ce.id===re)?.name??null}),t[46]=p,t[47]=e,t[48]=H):H=t[48];let L;t[49]!==J||t[50]!==H?(L=s.jsx(At,{size:Vt,className:nn,"aria-label":J,children:H}),t[49]=J,t[50]=H,t[51]=L):L=t[51];let V;t[52]!==e?(V=e("settings.openchamber.tools.browserProvider.option.builtin"),t[52]=e,t[53]=V):V=t[53];let Z;t[54]!==V?(Z=s.jsx(mt,{value:Jr,children:V}),t[54]=V,t[55]=Z):Z=t[55];let U;t[56]!==p?(U=p.map(Ay),t[56]=p,t[57]=U):U=t[57];let te;t[58]!==Z||t[59]!==U?(te=s.jsxs(Tt,{children:[Z,U]}),t[58]=Z,t[59]=U,t[60]=te):te=t[60];let O;t[61]!==w||t[62]!==P||t[63]!==X||t[64]!==L||t[65]!==te?(O=s.jsxs(Et,{value:P,onValueChange:w,disabled:X,children:[L,te]}),t[61]=w,t[62]=P,t[63]=X,t[64]=L,t[65]=te,t[66]=O):O=t[66];let Q;t[67]!==_||t[68]!==q||t[69]!==O?(Q=s.jsx(St,{settingsItem:"sessions.browser-provider",label:_,info:q,children:O}),t[67]=_,t[68]=q,t[69]=O,t[70]=Q):Q=t[70];let ce;t[71]!==m||t[72]!==h||t[73]!==x||t[74]!==e?(ce=m?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:h,onChange:x,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[71]=m,t[72]=h,t[73]=x,t[74]=e,t[75]=ce):ce=t[75];let de;t[76]!==F||t[77]!==z||t[78]!==Q||t[79]!==ce?(de=s.jsxs("div",{className:ls,children:[F,z,Q,ce]}),t[76]=F,t[77]=z,t[78]=Q,t[79]=ce,t[80]=de):de=t[80];let pe;return t[81]!==de||t[82]!==A?(pe=s.jsx(Ge,{title:A,children:de}),t[81]=de,t[82]=A,t[83]=pe):pe=t[83],pe};function by(t){return t.agentControlToolEnabled}function vy(t){return t.setAgentControlToolEnabled}function yy(t){return t.agentWebToolEnabled}function jy(t){return t.setAgentWebToolEnabled}function wy(t){return t.browserProvider}function ky(t){return t.setBrowserProvider}function Ny(t){return t.guests}function Sy(t){return t.agentMemoryToolEnabled}function Cy(t){return t.agentMemoryFeatureAvailable}function Iy(t){return t.setAgentMemoryToolEnabled}function Py(){On()}function Ay(t){return s.jsx(mt,{value:t.id,children:t.name},t.id)}const Nd=()=>{const{t}=Xe(),e=os()&&gi(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,r]=tt.useState(!1),[i,l]=tt.useState(!1),[d,c]=tt.useState(!1),[h,m]=tt.useState(""),[f,u]=tt.useState(!1),[g,v]=tt.useState(!1),[j,b]=tt.useState(null),[k,p]=tt.useState(!0),[N,P]=tt.useState(!1),[C,w]=tt.useState(!1),[D,x]=tt.useState(!1),[A,R]=tt.useState(!1),[I,E]=tt.useState(!1),[F,K]=tt.useState(!1),[S,M]=tt.useState(!1),[z,_]=tt.useState(!0),[q,X]=tt.useState(!0),[J,H]=tt.useState(!1),[L,V]=tt.useState(!1),[Z,U]=tt.useState(!1),[te,O]=tt.useState(null),[Q,ce]=tt.useState(null);tt.useEffect(()=>{if(!e){p(!1);return}let ve=!1;return(async()=>{try{const ee=await An();if(!ee)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(ve)return;const ne=ee.desktopLanAccessEnabled===!0;r(ne),l(ne),c(ee.hasDesktopUiPassword===!0),m(""),u(!1),v(ee.desktopLanAccessActive===!0),b(ee.desktopLanAccessBlockedReason??null);const ye=ee.desktopMacMenuBarEnabled!==!1;_(ye),X(ye),O(null)}catch(ee){ve||O(ee instanceof Error?ee.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{ve||p(!1)}})(),()=>{ve=!0}},[e,t]),tt.useEffect(()=>{if(!e){w(!1);return}let ve=!1;return(async()=>{const ee=await mm();ve||(w(ee?.supported===!0),x(ee?.enabled===!0))})(),()=>{ve=!0}},[e]),tt.useEffect(()=>{if(!e){E(!1);return}let ve=!1;return(async()=>{const ee=await pm();ve||(E(ee?.supported===!0),K(ee?.enabled===!0))})(),()=>{ve=!0}},[e]),tt.useEffect(()=>{if(!e){H(!1);return}let ve=!1;return(async()=>{const ee=await gm();ve||(H(ee?.supported===!0),V(ee?.enabled===!0))})(),()=>{ve=!0}},[e]),tt.useEffect(()=>{if(!e||!i){ce(null);return}let ve=!1;return(async()=>{const ee=await Oc();ve||ce(ee)})(),()=>{ve=!0}},[i,e]);const de=h.trim(),pe=de.length>0||f,re=i!==n||pe||q!==z,Ce=tt.useMemo(()=>{if(typeof window>"u")return null;const ee=pi()||window.location.href;let ne=0;try{ne=Number(new URL(ee).port)}catch{ne=Number(window.location.port)}return Number.isFinite(ne)&&ne>0?ne:null},[]),ie=i&&g&&Q&&Ce?`http://${Q}:${Ce}`:null,be=de.length>0||d&&!f,ae=i&&!be,fe=n&&!g&&j==="missing-password",xe=k||N||!re||ae,Oe=tt.useCallback(ve=>{m(ve),ve.trim()&&u(!1)},[]),Ne=tt.useCallback(()=>{m(""),u(!0),l(!1)},[]),he=tt.useCallback(async()=>{if(!C||A)return;const ve=!D;x(ve),R(!0),O(null);try{const ee=await hm(ve);if(!ee?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));x(ee.enabled)}catch(ee){x(!ve),O(ee instanceof Error?ee.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{R(!1)}},[A,D,C,t]),Te=tt.useCallback(async()=>{if(!I||S)return;const ve=!F;K(ve),M(!0),O(null);try{const ee=await fm(ve);if(!ee)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!ee.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));K(ee.enabled)}catch(ee){K(!ve),O(ee instanceof Error?ee.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{M(!1)}},[S,F,I,t]),we=tt.useCallback(async()=>{if(!J||Z)return;const ve=!L;V(ve),U(!0),O(null);try{const ee=await xm(ve);if(!ee?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));V(ee.enabled)}catch(ee){V(!ve),O(ee instanceof Error?ee.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{U(!1)}},[Z,L,J,t]),De=tt.useCallback(async()=>{if(re){P(!0),O(null);try{if(!(await ft({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:f?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:q})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):f&&c(!1),m(""),u(!1),_(q),!await bm())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(ve){O(ve instanceof Error?ve.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),P(!1)}}},[q,i,re,de,f,t]);return e?s.jsx(Ge,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[C||a||I||J?s.jsxs("div",{className:ls,children:[C?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:D,onChange:ve=>{ve!==D&&he()},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:q,onChange:X,disabled:k||N,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,I?s.jsx(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:F,onChange:ve=>{ve!==F&&Te()},disabled:S,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,J?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:L,onChange:ve=>{ve!==L&&we()},disabled:Z,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(Rt,{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:ve=>Oe(ve.target.value),placeholder:t(d&&!f?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||N,required:i&&!be,"aria-invalid":ae}),d&&!f?s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:Ne,disabled:k||N,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:ls,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:i,onChange:l,disabled:k||N,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||fe?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")})}),te?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:te}):null,ie?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(re&&!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:De,disabled:xe,className:"shrink-0 !font-normal",children:t(N?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Sd=new Set(["shift","control","alt","meta"]),Ro=3,Ty=3e3;function Fo(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 Ey(t){return t.action.customizable}function mc(t){if(Fo(t)>Ro)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?ar(e.join("+")):null}function Dy(t){if(Sd.has(t.key.toLowerCase())||Fo(t,!0)>Ro)return null;const e=Ou(Lu(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),ar(a.join("+"))}function My(t){const e=t.key.toLowerCase();if(!Sd.has(e)||Fo(t,!0)>Ro)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?ar(a.join("+")):null}function pc(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Ry(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:mc(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Dy(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:mc(e)}}const Fy=t=>{const e=rt.c(117),{action:a,overrides:n,onSave:r,onOpenChange:i}=t,{t:l}=Xe();let d;e[0]!==l?(d=Ce=>l(Ce.settingsLabelKey),e[0]=l,e[1]=d):d=e[1];const c=d;let h;e[2]!==c?(h=Ce=>Ce.action.customizable?c(Ce.action):da(Ce.action.defaultBinding),e[2]=c,e[3]=h):h=e[3];const m=h;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f={chords:[],livePreview:null,settled:!1},e[4]=f):f=e[4];const[u,g]=o.useState(f),v=o.useRef(null);let j,b;e[5]!==a?(j=()=>{a&&(g({chords:[],livePreview:null,settled:!1}),v.current?.focus())},b=[a],e[5]=a,e[6]=j,e[7]=b):(j=e[6],b=e[7]),o.useEffect(j,b);const k=u.chords.length===1&&!u.settled;let p,N;e[8]!==k?(p=()=>{if(!k)return;const Ce=window.setTimeout(()=>g(pc),Ty);return()=>window.clearTimeout(Ce)},N=[k],e[8]=k,e[9]=p,e[10]=N):(p=e[9],N=e[10]),o.useEffect(p,N);let P;e[11]!==u.chords?(P=ar(u.chords.join(" ")),e[11]=u.chords,e[12]=P):P=e[12];const C=P;let w;e[13]!==a||e[14]!==C||e[15]!==n?(w=a&&C?Ru(a.id,C,n):[],e[13]=a,e[14]=C,e[15]=n,e[16]=w):w=e[16];const D=w;let x;e[17]!==D?(x=D.find(Oy),e[17]=D,e[18]=x):x=e[18];const A=x;let R,I,E,F,K,S,M,z,_,q,X,J,H,L,V;if(e[19]!==a||e[20]!==c||e[21]!==C||e[22]!==m||e[23]!==D||e[24]!==i||e[25]!==r||e[26]!==A||e[27]!==u||e[28]!==l){const Ce=D.filter(Ey);K=Ce.find(Ly);const ie=Ce.find(Ky),be=D.find(zy);let ae;e[44]!==i?(ae=()=>i(!1),e[44]=i,e[45]=ae):ae=e[45],E=ae,F=()=>{u.settled||g(pc),!(!a||!C||A||K)&&(r(a.id,C,ie?.action.id),E())};let fe;e[46]!==a||e[47]!==u?(fe=(ze,Qe)=>{ze.preventDefault(),ze.stopPropagation();const Be=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Qe==="keyup"&&Be&&u.chords.length===0){const Me=My(ze);if(Me){g({chords:[Me],livePreview:null,settled:!0});return}}const _e=Ry(u,{altKey:ze.altKey,code:ze.nativeEvent.code,ctrlKey:ze.ctrlKey,isComposing:ze.nativeEvent.isComposing,key:ze.key,metaKey:ze.metaKey,repeat:ze.repeat,shiftKey:ze.shiftKey},Qe);g(Be&&_e.chords.length>1?u:_e)},e[46]=a,e[47]=u,e[48]=fe):fe=e[48];const xe=fe;I=Kt,L=a!==null,V=_y,R=zt,S="max-w-md",M=v,z=!1;let Oe;e[49]!==a||e[50]!==c||e[51]!==l?(Oe=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=Oe):Oe=e[52];let Ne;e[53]!==Oe?(Ne=s.jsx($t,{children:Oe}),e[53]=Oe,e[54]=Ne):Ne=e[54];let he;e[55]!==l?(he=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=he):he=e[56];let Te;e[57]!==he?(Te=s.jsx(Bt,{children:he}),e[57]=he,e[58]=Te):Te=e[58],e[59]!==Ne||e[60]!==Te?(_=s.jsxs(Ut,{children:[Ne,Te]}),e[59]=Ne,e[60]=Te,e[61]=_):_=e[61];let we,De;e[62]!==xe?(we=ze=>xe(ze,"keydown"),De=ze=>xe(ze,"keyup"),e[62]=xe,e[63]=we,e[64]=De):(we=e[63],De=e[64]);let ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>g(Uy),e[65]=ve):ve=e[65];let ee;e[66]!==u.chords?(ee=u.chords.map($y),e[66]=u.chords,e[67]=ee):ee=e[67];let ne;e[68]!==u.livePreview?(ne=u.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:da(u.livePreview)}):null,e[68]=u.livePreview,e[69]=ne):ne=e[69];let ye;e[70]!==u.chords.length||e[71]!==u.livePreview||e[72]!==l?(ye=u.chords.length===0&&!u.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=u.chords.length,e[71]=u.livePreview,e[72]=l,e[73]=ye):ye=e[73];let Ae;e[74]!==ee||e[75]!==ne||e[76]!==ye?(Ae=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[ee,ne,ye]}),e[74]=ee,e[75]=ne,e[76]=ye,e[77]=Ae):Ae=e[77],e[78]!==we||e[79]!==De||e[80]!==Ae?(q=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:v,onKeyDown:we,onKeyUp:De,onBlur:ve,children:Ae}),e[78]=we,e[79]=De,e[80]=Ae,e[81]=q):q=e[81],X=u.settled&&A?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):u.settled&&K?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c(K.action)})}):null,J=u.settled&&ie&&!A&&!K?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(ie.action)})}):null,H=u.settled&&be&&!A&&!K?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:m(be)})}):null,e[19]=a,e[20]=c,e[21]=C,e[22]=m,e[23]=D,e[24]=i,e[25]=r,e[26]=A,e[27]=u,e[28]=l,e[29]=R,e[30]=I,e[31]=E,e[32]=F,e[33]=K,e[34]=S,e[35]=M,e[36]=z,e[37]=_,e[38]=q,e[39]=X,e[40]=J,e[41]=H,e[42]=L,e[43]=V}else R=e[29],I=e[30],E=e[31],F=e[32],K=e[33],S=e[34],M=e[35],z=e[36],_=e[37],q=e[38],X=e[39],J=e[40],H=e[41],L=e[42],V=e[43];let Z;e[82]!==C||e[83]!==u.settled||e[84]!==l?(Z=u.settled&&C&&Fu(C)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=C,e[83]=u.settled,e[84]=l,e[85]=Z):Z=e[85];let U;e[86]!==l?(U=l("settings.common.actions.cancel"),e[86]=l,e[87]=U):U=e[87];let te;e[88]!==E||e[89]!==U?(te=s.jsx(G,{type:"button",variant:"ghost",size:"sm",onClick:E,children:U}),e[88]=E,e[89]=U,e[90]=te):te=e[90];const O=!C||u.settled&&(!!A||!!K);let Q;e[91]!==l?(Q=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=Q):Q=e[92];let ce;e[93]!==F||e[94]!==O||e[95]!==Q?(ce=s.jsx(G,{type:"button",size:"sm",disabled:O,onClick:F,children:Q}),e[93]=F,e[94]=O,e[95]=Q,e[96]=ce):ce=e[96];let de;e[97]!==te||e[98]!==ce?(de=s.jsxs(as,{children:[te,ce]}),e[97]=te,e[98]=ce,e[99]=de):de=e[99];let pe;e[100]!==R||e[101]!==S||e[102]!==M||e[103]!==z||e[104]!==_||e[105]!==q||e[106]!==X||e[107]!==J||e[108]!==H||e[109]!==Z||e[110]!==de?(pe=s.jsxs(R,{className:S,initialFocus:M,showCloseButton:z,children:[_,q,X,J,H,Z,de]}),e[100]=R,e[101]=S,e[102]=M,e[103]=z,e[104]=_,e[105]=q,e[106]=X,e[107]=J,e[108]=H,e[109]=Z,e[110]=de,e[111]=pe):pe=e[111];let re;return e[112]!==I||e[113]!==L||e[114]!==V||e[115]!==pe?(re=s.jsx(I,{open:L,onOpenChange:V,children:pe}),e[112]=I,e[113]=L,e[114]=V,e[115]=pe,e[116]=re):re=e[116],re};function Oy(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Ly(t){return t.kind==="prefix"}function Ky(t){return t.kind==="exact"}function zy(t){return t.kind==="contextual-prefix"}function _y(t,e){t||e.cancel()}function Uy(t){return{...t,livePreview:null}}function $y(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:da(t)},`${t}-${e}`)}const By=["session","models","panels","navigation","application"],Vy=()=>{const t=rt.c(24),{t:e}=Xe(),a=ge(Hy),n=ge(qy),r=ge(Gy),i=ge(Wy),[l,d]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const C=Ku();c=cs()?C.filter(Jy):C,t[0]=c}else c=t[0];const h=c,m=Qy;let f;t[1]!==n||t[2]!==a?(f=(C,w,D)=>{const x={...a,[C]:w};D&&(x[D]=Tr),n(C,w),D&&n(D,Tr),m(x)},t[1]=n,t[2]=a,t[3]=f):f=t[3];const u=f;let g;t[4]!==r||t[5]!==a?(g=C=>{const w={...a};delete w[C],r(C),m(w)},t[4]=r,t[5]=a,t[6]=g):g=t[6];const v=g;let j;t[7]!==a||t[8]!==e?(j=C=>{const w="prefixStyle"in C&&C.prefixStyle,D=w?zu(C.id,a):Fc(C.id,a),x=da(D,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!w||!D||D===Tr)return x;const A=C.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]=j):j=t[9];const b=j;let k;t[10]!==i||t[11]!==v||t[12]!==b||t[13]!==a||t[14]!==e?(k=By.map((C,w)=>{const D=h.filter(x=>x.category===C);return D.length===0?null:s.jsx(Ge,{settingsItem:w===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${C}`),divider:w!==0,info:w===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:w===0?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),m({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:D.map(x=>s.jsxs(St,{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))})},C)}),t[10]=i,t[11]=v,t[12]=b,t[13]=a,t[14]=e,t[15]=k):k=t[15];let p;t[16]===Symbol.for("react.memo_cache_sentinel")?(p=C=>{C||d(null)},t[16]=p):p=t[16];let N;t[17]!==l||t[18]!==u||t[19]!==a?(N=s.jsx(Fy,{action:l,overrides:a,onSave:u,onOpenChange:p}),t[17]=l,t[18]=u,t[19]=a,t[20]=N):N=t[20];let P;return t[21]!==k||t[22]!==N?(P=s.jsxs(s.Fragment,{children:[k,N]}),t[21]=k,t[22]=N,t[23]=P):P=t[23],P};function Hy(t){return t.shortcutOverrides}function qy(t){return t.setShortcutOverride}function Gy(t){return t.clearShortcutOverride}function Wy(t){return t.resetAllShortcutOverrides}function Jy(t){return t.id!=="toggle_prompt_navigator"}function Qy(t){ft({shortcutOverrides:t})}const Cd=()=>{const t=rt.c(2),[e,a]=o.useState(0);let n,r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>ir(()=>a(o1)),r=[],t[0]=n,t[1]=r):(n=t[0],r=t[1]),o.useEffect(n,r),e},Yy=t=>{const e=rt.c(83),{section:a}=t,{t:n}=Xe(),{isMobile:r}=Jn(),i=Cd();let l;e[0]!==r?(l=r&&ca(),e[0]=r,e[1]=l):l=e[1];const d=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[2]=c):c=e[2];const h=c;let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=os()&&gi(),e[3]=m):m=e[3];const f=m;if(!a){let H;e[4]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(rr,{}),e[4]=H):H=e[4];let L;e[5]!==i?(L=s.jsx(vd,{},i),e[5]=i,e[6]=L):L=e[6];let V,Z,U,te,O,Q;e[7]===Symbol.for("react.memo_cache_sentinel")?(U=f&&s.jsx(Nd,{}),te=!h&&s.jsx(wd,{}),O=!h&&s.jsx(kd,{}),Q=s.jsx(fd,{}),V=s.jsx(bd,{}),Z=ca()&&!os()&&!h&&!$c()&&s.jsx(xd,{}),e[7]=V,e[8]=Z,e[9]=U,e[10]=te,e[11]=O,e[12]=Q):(V=e[7],Z=e[8],U=e[9],te=e[10],O=e[11],Q=e[12]);let ce;e[13]!==d?(ce=d&&s.jsx(Hc,{}),e[13]=d,e[14]=ce):ce=e[14];let de;return e[15]!==ce||e[16]!==L?(de=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[H,L,U,te,O,Q,V,Z,ce]}),e[15]=ce,e[16]=L,e[17]=de):de=e[17],de}let u;e[18]!==i||e[19]!==a?(u=()=>{switch(a){case"general":return s.jsx(Xy,{});case"visual":return s.jsx(e1,{});case"chat":return s.jsx(t1,{});case"sessions":return s.jsx(s1,{runtimeEndpointEpoch:i});case"shortcuts":return s.jsx(Zy,{});case"git":return s.jsx(n1,{});case"notifications":return s.jsx(a1,{});case"voice":return s.jsx(i1,{});case"tunnel":return s.jsx(r1,{});default:return null}},e[18]=i,e[19]=a,e[20]=u):u=e[20];const g=u;let v;e[21]!==n?(v=n("settings.page.general.title"),e[21]=n,e[22]=v):v=e[22];let j;e[23]!==n?(j=n("settings.page.appearance.title"),e[23]=n,e[24]=j):j=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 p;e[29]!==n?(p=n("settings.page.shortcuts.title"),e[29]=n,e[30]=p):p=e[30];let N;e[31]!==n?(N=n("settings.page.git.title"),e[31]=n,e[32]=N):N=e[32];let P;e[33]!==n?(P=n("settings.page.git.title"),e[33]=n,e[34]=P):P=e[34];let C;e[35]!==n?(C=n("settings.page.notifications.title"),e[35]=n,e[36]=C):C=e[36];let w;e[37]!==n?(w=n("settings.page.voice.title"),e[37]=n,e[38]=w):w=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]!==N||e[42]!==P||e[43]!==C||e[44]!==w||e[45]!==D||e[46]!==v||e[47]!==j||e[48]!==b||e[49]!==k||e[50]!==p?(x={general:v,visual:j,chat:b,sessions:k,shortcuts:p,git:N,github:P,notifications:C,voice:w,tunnel:D},e[41]=N,e[42]=P,e[43]=C,e[44]=w,e[45]=D,e[46]=v,e[47]=j,e[48]=b,e[49]=k,e[50]=p,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 I;e[54]!==n?(I=n("settings.page.appearance.description"),e[54]=n,e[55]=I):I=e[55];let E;e[56]!==n?(E=n("settings.page.chat.description"),e[56]=n,e[57]=E):E=e[57];let F;e[58]!==n?(F=n("settings.page.sessions.description"),e[58]=n,e[59]=F):F=e[59];let K;e[60]!==n?(K=n("settings.page.shortcuts.description"),e[60]=n,e[61]=K):K=e[61];let S;e[62]!==n?(S=n("settings.page.notifications.description"),e[62]=n,e[63]=S):S=e[63];let M;e[64]!==n?(M=n("settings.page.voice.description"),e[64]=n,e[65]=M):M=e[65];let z;e[66]!==n?(z=n("settings.page.tunnel.description"),e[66]=n,e[67]=z):z=e[67];let _;e[68]!==R||e[69]!==I||e[70]!==E||e[71]!==F||e[72]!==K||e[73]!==S||e[74]!==M||e[75]!==z?(_={general:R,visual:I,chat:E,sessions:F,shortcuts:K,git:void 0,github:void 0,notifications:S,voice:M,tunnel:z},e[68]=R,e[69]=I,e[70]=E,e[71]=F,e[72]=K,e[73]=S,e[74]=M,e[75]=z,e[76]=_):_=e[76];const q=_[a];let X;e[77]!==g?(X=g(),e[77]=g,e[78]=X):X=e[78];let J;return e[79]!==q||e[80]!==A||e[81]!==X?(J=s.jsx(ns,{title:A,description:q,showSaveStatus:!0,className:"openchamber-page-body",children:X}),e[79]=q,e[80]=A,e[81]=X,e[82]=J):J=e[82],J},Zy=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Vy,{}),t[0]=e):e=t[0],e},Xy=()=>{const t=rt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;Cd();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=os()&&gi(),t[1]=n):n=t[1];const r=n;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=ca()&&!os()&&!a&&!$c(),t[2]=i):i=t[2];const l=i;let d,c,h,m,f;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=r&&s.jsx(Nd,{}),c=l&&s.jsx(xd,{}),h=s.jsx(bd,{}),m=!a&&s.jsx(wd,{}),f=!a&&s.jsx(kd,{}),t[3]=d,t[4]=c,t[5]=h,t[6]=m,t[7]=f):(d=t[3],c=t[4],h=t[5],m=t[6],f=t[7]);let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=a?[]:["sessionTabs"],t[8]=u):u=t[8];let g;return t[9]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsxs(s.Fragment,{children:[d,c,h,m,f,s.jsx(rr,{visibleSettings:["fileEditorKeymap",...u,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=g):g=t[9],g},e1=()=>{const t=rt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(rr,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=n):n=t[1],n},t1=()=>{const t=rt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(rr,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},s1=t=>{const e=rt.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(vd,{},a),e[0]=a,e[1]=n):n=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(fd,{}),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=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(cd,{}),t[0]=e):e=t[0],e},a1=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Jv,{}),t[0]=e):e=t[0],e},i1=()=>{const t=rt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(iy,{}),t[0]=e):e=t[0],e},r1=()=>{const t=rt.c(1);if(cs())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 o1(t){return t+1}const l1=[{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"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","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.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-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.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-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&&ge.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 gc(t){return t.trim().toLocaleLowerCase()}function c1({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=gc(t);if(!i)return[];const l=a?new Set(a):null,d=i.split(/\s+/).filter(Boolean);return l1.flatMap(c=>{if(l&&!l.has(c.page))return[];const h=La(c.page);if(!h||h.isAvailable&&!h.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=n(c.titleKey),f=c.descriptionKey?n(c.descriptionKey):null,u=gc([m,f,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(g=>u.includes(g))?[{...c,title:m,description:f,pageTitle:r(c.page)}]:[]})}const hc=256,fc=280,Id="__openchamberSettingsDetail",d1=["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"],u1=["general","projects","opencode","content"],m1="__add_provider__";function p1(t,e,a){const n=cs(),r=!t&&ca();return{isVSCode:n,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:a}}function xc(t,e){return t.isAvailable?t.isAvailable(e):!0}function mo(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ni(t,e){const a=new Set(e);let n=t,r=1;for(;a.has(n);)n=`${t}-${r}`,r+=1;return n}function Qr(t){if(!mo(t))return null;const e=t[Id];if(!mo(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Bc(a),stage:n}}function g1(){return typeof window>"u"||!mo(window.history.state)?{}:window.history.state}const T1=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:r="nav",registerBackHandler:i})=>{const{t:l}=Xe(),d=Jn(),c=e??d.isMobile,h=ge(ee=>ee.settingsPage),m=ge(ee=>ee.isSettingsDialogOpen),f=ge(ee=>ee.setSettingsPage),u=ge(ee=>ee.shortcutOverrides.open_settings),g=Bc(h),[v,j]=o.useState(r),b=o.useRef(r==="nav"?g:null);o.useEffect(()=>{!c&&g==="home"&&f("general")},[c,f,g]);const[k,p]=o.useState(""),[N,P]=o.useState(null),[C,w]=o.useState(0),D=o.useRef(null),x=o.useRef(!1),A=o.useRef([]),R=o.useRef(0),I=o.useRef(!1),E=o.useMemo(()=>os(),[]),F=o.useMemo(()=>os()&&gi(),[]),K=o.useMemo(()=>os()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),S=o.useMemo(()=>os()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),M=o.useMemo(()=>os()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),z=o.useMemo(()=>Uc(),[]),_=ge(ee=>ee.routingFeatureAvailable),q=o.useMemo(()=>p1(E,c,_),[E,c,_]),X=o.useMemo(()=>{const ee=n?new Set(n):null;return km.filter(ne=>ne.slug!=="home").filter(ne=>!ee||ee.has(ne.slug)).filter(ne=>xc(ne,q)).filter(ne=>!(q.isVSCode&&ne.slug==="projects")).filter(ne=>!(c&&ne.slug==="shortcuts"))},[q,c,n]),J=o.useMemo(()=>{const ee=new Map(d1.map((ne,ye)=>[ne,ye]));return X.slice().sort((ne,ye)=>(ee.get(ne.slug)??999)-(ee.get(ye.slug)??999))},[X]),H=an(ee=>ee.activeProjectId),L=Ws();o.useEffect(()=>{if(!(!m&&!q.isVSCode&&!a)){if(g==="agents"){Gn.getState().loadAgents(L);return}if(g==="commands"){Va.getState().loadCommands(L);return}if(g==="mcp"){Wn.getState().loadMcpConfigs({directory:L});return}if(g==="plugins"){Gt.getState().loadPlugins();return}(g==="skills.installed"||g==="skills.catalog")&&(sn.getState().loadSkills(L),Fn.getState().loadCatalog()),g==="snippets"&&Ji.getState().loadSnippets()}},[H,m,a,q.isVSCode,L,g]);const V=o.useCallback(ee=>{if(f(ee),b.current=ee,!c)return;const ne=La(ee);if(!ne||ne.slug==="home"){j("nav");return}j(ne.kind==="split"?"page-sidebar":"page-content")},[c,f]),Z=o.useMemo(()=>La(g),[g]),U=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),te=o.useCallback(ee=>{switch(ee){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]),O=o.useMemo(()=>c1({query:k,runtimeCtx:{...q,isDesktopLocalOrigin:F,isMac:K,isWindows:S,isLinux:M,isWindowsArm64:z},visiblePageSlugs:n,t:l,getPageTitle:te}),[te,z,F,K,S,M,q,k,l,n]),Q=o.useCallback(ee=>{if(ee.id.startsWith("agents.")){const ne=Gn.getState(),ye=ni("new-agent",ne.agents.map(Ae=>Ae.name));return ne.setAgentDraft({name:ye,scope:"user"}),ne.setSelectedAgent(ye),ee.id==="agents.create"?"agents.name":ee.id}if(ee.id.startsWith("commands.")){const ne=Va.getState(),ye=ni("new-command",ne.commands.map(Ae=>Ae.name));return ne.setCommandDraft({name:ye,scope:"user"}),ne.setSelectedCommand(ye),ee.id==="commands.create"?"commands.name":ee.id}if(ee.id.startsWith("mcp.")){const ne=Wn.getState(),ye=ni("new-mcp-server",ne.mcpServers.map(Ae=>Ae.name));return ne.setMcpDraft({name:ye,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:!0,disabled:!1}),ne.setSelectedMcp(ye),ee.id==="mcp.create"?"mcp.server":ee.id}if(ee.id.startsWith("snippets.")){const ne=Ji.getState(),ye=ni("new-snippet",ne.snippets.map(Ae=>Ae.name));return ne.setSnippetDraft({name:ye,scope:"global"}),ne.setSelectedSnippet(ye),ee.id==="snippets.create"?"snippets.content":ee.id}if(ee.id.startsWith("skills.")){const ne=sn.getState(),ye=ni("new-skill",ne.skills.map(Ae=>Ae.name));return ne.setSkillDraft({name:ye,scope:"user",source:"opencode",description:"",instructions:""}),ne.setSelectedSkill(ye),ee.id==="skills.create"?"skills.basic-information":ee.id}return ee.id==="providers.connect"&&it.getState().setSelectedProvider(m1),ee.id==="plugins.create"?"plugins.spec":ee.id},[]),ce=o.useMemo(()=>{const ee=[],ne=new Map;for(const ye of O){let Ae=ne.get(ye.page);Ae||(Ae={page:ye.page,pageTitle:ye.pageTitle,results:[]},ne.set(ye.page,Ae),ee.push(Ae)),Ae.results.push(ye)}return ee},[O]);o.useEffect(()=>{w(0),R.current=0,I.current=!1},[k]),o.useEffect(()=>{R.current=C},[C]),o.useEffect(()=>{A.current[C]?.scrollIntoView({block:"nearest"})},[C]),o.useEffect(()=>{C>=O.length&&w(Math.max(0,O.length-1)),A.current.length=O.length},[C,O.length]);const de=o.useCallback(ee=>{const ne=Q(ee);P(ne),V(ee.page),c&&j("page-content"),ee.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,V,Q]),pe=o.useCallback(ee=>{if(k.trim()){if(ee.key==="Escape"){ee.preventDefault(),p("");return}if(O.length!==0){if(ee.key==="ArrowDown"){ee.preventDefault(),I.current=!0,w(ne=>(ne+1)%O.length);return}if(ee.key==="ArrowUp"){ee.preventDefault(),I.current=!0,w(ne=>(ne-1+O.length)%O.length);return}if(ee.key==="Enter"){ee.preventDefault();const ne=(R.current%O.length+O.length)%O.length,ye=O[ne]??O[0];ye&&de(ye)}}}},[de,k,O]);o.useEffect(()=>{const ee=N;if(!ee)return;let ne=!1;const ye=window.requestAnimationFrame(()=>{if(ne)return;const Ae=typeof CSS<"u"&&CSS.escape?CSS.escape(ee):ee.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ze=D.current?.querySelector(`[data-settings-item="${Ae}"]`);ze&&(P(null),ze.scrollIntoView({block:"center",behavior:"smooth"}),ze.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{ze.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ne=!0,window.cancelAnimationFrame(ye)}},[N,g]);const re=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:kc,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((ee,ne)=>{switch(ee){case"projects":return s.jsx(hf,{onItemSelect:ne.onItemSelect});case"agents":return s.jsx(ip,{onItemSelect:ne.onItemSelect});case"commands":return s.jsx(Qp,{onItemSelect:ne.onItemSelect});case"mcp":return s.jsx(ig,{onItemSelect:ne.onItemSelect});case"plugins":return s.jsx(sh,{onItemSelect:ne.onItemSelect});case"skills.installed":return s.jsx(Oh,{onItemSelect:ne.onItemSelect});case"providers":return s.jsx(Gf,{onItemSelect:ne.onItemSelect});case"usage":return s.jsx(Cx,{onItemSelect:ne.onItemSelect});case"magic-prompts":return s.jsx(Bx,{onItemSelect:ne.onItemSelect});case"snippets":return s.jsx(Gx,{onItemSelect:ne.onItemSelect});default:return null}},[]),ie=o.useCallback(ee=>{const ne=La(ee);if(ne&&!xc(ne,q))return re();switch(ee){case"projects":return s.jsx(yf,{});case"remote-instances":return s.jsx(Vf,{});case"agents":return s.jsx(Tp,{});case"behavior":return s.jsx(Lp,{});case"commands":return s.jsx(ng,{});case"mcp":return s.jsx(zg,{});case"plugins":return s.jsx(kh,{});case"skills.installed":return s.jsx(Sl,{view:"installed"});case"skills.catalog":return s.jsx(Sl,{view:"catalog"});case"providers":return s.jsx(Nx,{});case"web-search":return s.jsx($p,{});case"usage":return s.jsx(Ux,{});case"about":return s.jsx(ns,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Hc,{})});case"magic-prompts":return s.jsx(qx,{});case"snippets":return s.jsx(Yx,{});case"git":return s.jsx(sb,{});case"integrations":return s.jsx(wb,{});case"routing":return s.jsx(Tb,{});case"extensions":return s.jsx(ev,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const ye=U[ee]??"visual";return s.jsx(Yy,{section:ye})}default:return null}},[U,re,q,l]);o.useEffect(()=>{if(!c||v!=="nav"||g==="home"||b.current===g)return;const ee=La(g);!ee||ee.slug==="home"||(b.current=g,j(ee.kind==="split"?"page-sidebar":"page-content"))},[c,v,g]);const be=c&&v!=="nav",ae=c&&v==="page-content"&&Z?.kind==="split",fe=l(ae?"settings.view.actions.back":be?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),xe=Fc("open_settings",u===void 0?void 0:{open_settings:u}),Oe=xe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:da(xe)}):l("settings.view.actions.closeSettings"),Ne=o.useCallback(ee=>{if(typeof window>"u"||q.isVSCode)return;const ne=Qr(window.history.state);ne?.page===ee&&ne.stage==="page-content"||window.history.pushState({...g1(),[Id]:{page:ee,stage:"page-content"}},"",window.location.href)},[q.isVSCode]),he=o.useCallback(()=>{x.current=!0,j("page-content"),Ne(g)},[Ne,g]);o.useEffect(()=>{if(!c||v!=="page-content"||!x.current)return;x.current=!1;const ee=window.requestAnimationFrame(()=>{D.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(ee)}},[c,v,g]);const Te=o.useCallback(()=>{if(ae){if((typeof window<"u"?Qr(window.history.state):null)?.page===g&&!q.isVSCode){window.history.back();return}j("page-sidebar");return}j("nav")},[ae,q.isVSCode,g]);o.useEffect(()=>{if(i)return i(()=>!c||v==="nav"?!1:(Te(),!0)),()=>i(null)},[Te,c,v,i]),o.useEffect(()=>{if(!c||q.isVSCode)return;const ee=ne=>{if(La(g)?.kind!=="split")return;if(Qr(ne.state)?.page===g){j("page-content");return}j(Ae=>Ae==="page-content"?"page-sidebar":Ae)};return window.addEventListener("popstate",ee),()=>{window.removeEventListener("popstate",ee)}},[c,q.isVSCode,g]);const we=()=>{const ee=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(B,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:k,onChange:ne=>p(ne.target.value),onKeyDown:pe,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"}),ee&&s.jsx("button",{type:"button",onClick:()=>p(""),"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(B,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(vs,{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:ee?O.length>0?(()=>{let ne=0;return ce.map(ye=>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:ye.pageTitle}),ye.results.map(Ae=>{const ze=ne;ne+=1;const Qe=ze===C,Be=!!Ae.description;return s.jsxs("button",{type:"button",ref:_e=>{A.current[ze]=_e},onMouseMove:()=>{I.current=!1,w(ze)},onClick:()=>de(Ae),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",Qe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ae.title}),Be&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Ae.description})]},Ae.id)})]},ye.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const ne=new Map;for(const Ae of J){const ze=Ae.group,Qe=ne.get(ze);Qe?Qe.push(Ae):ne.set(ze,[Ae])}return u1.map(Ae=>({group:Ae,pages:ne.get(Ae)??[]})).filter(Ae=>Ae.pages.length>0).map(({group:Ae,pages:ze},Qe)=>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",Qe===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${Ae}`)}),ze.map(Be=>{const _e=g===Be.slug&&!(c&&v==="nav"),Me=Nm(Be.slug);return!Me&&Be.slug!=="mcp"?null:s.jsx(sr,{children:s.jsx(nr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>V(Be.slug),"aria-current":_e?"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",_e?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Be.slug==="mcp"?s.jsx(_u,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(B,{name:Me,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:te(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)})]},Ae))})()})})]})},De=()=>{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(Vn,{children:we()})})});if(!Z)return s.jsx("div",{className:"flex-1 bg-background"});if(v==="page-sidebar"){if(Z.kind!=="split"){const ne=ie(g);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ne})})}return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:Ce(g,{onItemSelect:he})})})}const ee=ie(g);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ee})})},ve=()=>!Z||g==="home"?null:Z.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:Ie("border-r",q.isVSCode?"bg-background":"bg-sidebar"),style:{width:fc,minWidth:fc,borderColor:"var(--interactive-border)"},children:s.jsx(Vn,{children:Ce(g,{})})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ie(g)})})]}):s.jsx(vs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ie(g)})});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:[be?s.jsx("button",{type:"button",onClick:Te,"aria-label":fe,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(B,{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"):Z?te(Z.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:Oe,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[be&&s.jsx("div",{className:Ie("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Te,"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(B,{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:Oe,className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?De():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":q.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${hc}px`,minWidth:`${hc}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Vn,{children:we()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ve()})]})})]})};export{Hc as A,T1 as S};