@vantran-se/openchamber-web 1.24.3 → 2.0.1

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 (367) hide show
  1. package/README.md +2 -8
  2. package/bin/lib/commands-connect-url.js +3 -8
  3. package/bin/lib/commands-tunnel.js +3 -0
  4. package/dist/assets/{CodeMirrorCommentWidgets-BjJHrzmU.js → CodeMirrorCommentWidgets-ntXIbhV2.js} +1 -1
  5. package/dist/assets/DiffView-CjxUovbM.js +4 -0
  6. package/dist/assets/FilesView-DFWD0RQR.js +17 -0
  7. package/dist/assets/{GitView-CDOJy5Ay.js → GitView-BWa7e5vw.js} +4 -4
  8. package/dist/assets/{GuestAttachDialog-D3S0Rjic.js → GuestAttachDialog-DdOuyZzp.js} +1 -1
  9. package/dist/assets/GuestSurfacePane-DDfzid3U.js +1 -0
  10. package/dist/assets/{JsonTreeView-D0C9nU7K.js → JsonTreeView-3sGwqexh.js} +1 -1
  11. package/dist/assets/LinearIssuesView-C6dpIdjw.js +1 -0
  12. package/dist/assets/MarkdownImageGallery-Q7YR_tl4.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-DxDV56bL.js +12 -0
  14. package/dist/assets/OnboardingScreen-rK4Stg__.js +1 -0
  15. package/dist/assets/{PatchDiff-DnEhjXcC.js → PatchDiff-DS-IMU1j.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-DyxZVVVR.js → PierreDiffViewer-DW23KWKZ.js} +1 -1
  17. package/dist/assets/PlanView-BCk_VobP.js +5 -0
  18. package/dist/assets/PluginPane-BPP1dbck.js +3 -0
  19. package/dist/assets/SettingsView-kMmrpn43.js +29 -0
  20. package/dist/assets/SettingsWindow-BpvD6IYQ.js +1 -0
  21. package/dist/assets/SubmoduleDiffSummary-BLttSS1X.js +1 -0
  22. package/dist/assets/ToolOutputDialog-CtqDqbyr.js +15 -0
  23. package/dist/assets/ToolPartDiffPreview-5FcKdyRy.js +8 -0
  24. package/dist/assets/{VirtualizedFileDiff-0pyr_mHY.js → VirtualizedFileDiff-C763hNCR.js} +4 -4
  25. package/dist/assets/{WalkthroughView-yNj4nOP5.js → WalkthroughView-lap5btCF.js} +2 -2
  26. package/dist/assets/appThemeRegistry-u4zw1l0B.js +1 -0
  27. package/dist/assets/{commitAndPush-DvJKa3Ks.js → commitAndPush-CwGJfJG-.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-DxTBMuu-.js → computeVirtualFileMetrics-DW5jjX4n.js} +1 -1
  29. package/dist/assets/de-CndEg67T.js +10 -0
  30. package/dist/assets/es-DglvPlaC.js +16 -0
  31. package/dist/assets/fr-DejPCpbS.js +14 -0
  32. package/dist/assets/index-C2r64QfD.js +1 -0
  33. package/dist/assets/index-CLcM8HKx.css +1 -0
  34. package/dist/assets/index-CvLgnuNI.js +41 -0
  35. package/dist/assets/{isDiffPlainText-D7FkBMP6.js → isDiffPlainText-D47a6hMP.js} +1 -1
  36. package/dist/assets/{isFilePlainText-CL2vsrIZ.js → isFilePlainText-B-mGgeKl.js} +1 -1
  37. package/dist/assets/ja-CVpQawCd.js +16 -0
  38. package/dist/assets/ko-Bw446h9j.js +16 -0
  39. package/dist/assets/main-Bz4WWXbr.js +2 -0
  40. package/dist/assets/main-oreqDsOV.js +896 -0
  41. package/dist/assets/{markdownCore-Dh7WEsdM.js → markdownCore-D2e5sp9y.js} +4 -4
  42. package/dist/assets/miniChat-D1v2gsBI.js +2 -0
  43. package/dist/assets/mobile-DBj3lCf2.js +2 -0
  44. package/dist/assets/{patchFileDiff-Bsba8KFp.js → patchFileDiff-BpeUOV91.js} +3 -3
  45. package/dist/assets/pl-BYNlPdhm.js +16 -0
  46. package/dist/assets/pt-BR-CL-Yfv9H.js +16 -0
  47. package/dist/assets/renderElectronMiniChatApp-DVtfEB2z.js +2 -0
  48. package/dist/assets/renderMobileApp-DFp9-xbG.js +25 -0
  49. package/dist/assets/runtimeEndpointReset-CsIpUep1.js +27 -0
  50. package/dist/assets/scheduledTasksApi-B5OHVpPM.js +1 -0
  51. package/dist/assets/{shikiHighlight-8_3csmr6.js → shikiHighlight-DNm2Z_Jc.js} +1 -1
  52. package/dist/assets/{textMateThemeFromAppTheme-CHo2fCgW.js → textMateThemeFromAppTheme-DGF2kG7g.js} +1 -1
  53. package/dist/assets/tr-DzmbxLy-.js +7 -0
  54. package/dist/assets/uk-C7vQnwro.js +16 -0
  55. package/dist/assets/useAppFontEffects-Ci3FEaPf.js +7337 -0
  56. package/dist/assets/{useInlineCommentController-DkQ_gqpn.js → useInlineCommentController-CuUuakrt.js} +2 -2
  57. package/dist/assets/useRootScrollLock-CQIsyERq.js +2 -0
  58. package/dist/assets/{vendor-codemirror-language-data-CdzUmUyZ.js → vendor-codemirror-language-data-CQa7_1cr.js} +2 -2
  59. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  60. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
  61. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  62. package/dist/assets/{vendor-zod-CgAdXWZO.js → vendor-zod-Gea9uBlY.js} +1 -1
  63. package/dist/assets/{web-components-B8IcVQAA.js → web-components-B6tKQyJN.js} +2 -2
  64. package/dist/assets/zh-CN-Cl0srS-z.js +16 -0
  65. package/dist/assets/zh-TW-DtII5bDb.js +16 -0
  66. package/dist/index.html +13 -7
  67. package/dist/mini-chat.html +5 -5
  68. package/dist/mobile.html +5 -5
  69. package/package.json +6 -5
  70. package/server/index.d.ts +1 -0
  71. package/server/index.js +246 -91
  72. package/server/lib/agent-tool/DOCUMENTATION.md +32 -15
  73. package/server/lib/agent-tool/runtime.js +135 -54
  74. package/server/lib/agent-tool/runtime.test.js +155 -87
  75. package/server/lib/browser-control/DOCUMENTATION.md +37 -2
  76. package/server/lib/browser-control/provider.js +217 -0
  77. package/server/lib/browser-control/provider.test.js +251 -0
  78. package/server/lib/context-obligatory/runtime.js +61 -50
  79. package/server/lib/context-obligatory/runtime.test.js +62 -162
  80. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  81. package/server/lib/event-stream/delta-coalescer.js +0 -0
  82. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  83. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  84. package/server/lib/event-stream/global-hub.js +10 -1
  85. package/server/lib/event-stream/global-hub.test.js +27 -26
  86. package/server/lib/event-stream/index.js +6 -0
  87. package/server/lib/event-stream/protocol.js +26 -19
  88. package/server/lib/event-stream/protocol.test.js +18 -7
  89. package/server/lib/event-stream/rebind.test.js +5 -5
  90. package/server/lib/event-stream/runtime.test.js +17 -15
  91. package/server/lib/event-stream/translate-v2.js +313 -0
  92. package/server/lib/event-stream/translate-v2.test.js +209 -0
  93. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  94. package/server/lib/fs/DOCUMENTATION.md +4 -2
  95. package/server/lib/fs/byte-range.js +35 -0
  96. package/server/lib/fs/byte-range.test.js +31 -0
  97. package/server/lib/fs/routes.js +47 -42
  98. package/server/lib/fs/routes.test.js +123 -18
  99. package/server/lib/git/service.js +12 -0
  100. package/server/lib/github/DOCUMENTATION.md +1 -1
  101. package/server/lib/github/pr-status.js +22 -2
  102. package/server/lib/github/pr-status.test.js +27 -14
  103. package/server/lib/guests/DOCUMENTATION.md +13 -0
  104. package/server/lib/guests/catalog.js +12 -0
  105. package/server/lib/guests/catalog.test.js +33 -0
  106. package/server/lib/guests/routes.js +10 -1
  107. package/server/lib/guests/service.js +192 -14
  108. package/server/lib/guests/service.test.js +201 -1
  109. package/server/lib/guests/surface.js +630 -0
  110. package/server/lib/guests/surface.test.js +486 -0
  111. package/server/lib/markdown-image-grants/routes.js +18 -5
  112. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  113. package/server/lib/message-queue/DOCUMENTATION.md +33 -22
  114. package/server/lib/message-queue/runtime.js +155 -100
  115. package/server/lib/message-queue/runtime.test.js +168 -82
  116. package/server/lib/notifications/DOCUMENTATION.md +28 -0
  117. package/server/lib/notifications/control-stream.http.test.js +68 -0
  118. package/server/lib/notifications/emitter-runtime.js +15 -0
  119. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  120. package/server/lib/notifications/push-runtime.js +5 -1
  121. package/server/lib/notifications/push-runtime.test.js +2 -2
  122. package/server/lib/notifications/routes.js +1 -1
  123. package/server/lib/notifications/runtime.js +115 -26
  124. package/server/lib/notifications/template-runtime.js +13 -15
  125. package/server/lib/notifications/template-runtime.test.js +16 -9
  126. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  127. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  128. package/server/lib/openchamber-control/actions.js +3 -2
  129. package/server/lib/openchamber-control/error.js +1 -1
  130. package/server/lib/openchamber-control/file-open.js +59 -0
  131. package/server/lib/openchamber-control/file-open.test.js +57 -0
  132. package/server/lib/openchamber-control/routes.test.js +12 -0
  133. package/server/lib/openchamber-control/service.js +102 -49
  134. package/server/lib/openchamber-control/service.test.js +84 -44
  135. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  136. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  137. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  138. package/server/lib/openchamber-sessions/routes.js +398 -328
  139. package/server/lib/openchamber-sessions/routes.test.js +777 -740
  140. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  141. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +449 -29
  143. package/server/lib/opencode/agents.js +233 -327
  144. package/server/lib/opencode/auth.js +41 -44
  145. package/server/lib/opencode/auth.test.js +92 -0
  146. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  147. package/server/lib/opencode/cli-upgrade.js +18 -0
  148. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  149. package/server/lib/opencode/commands.js +164 -145
  150. package/server/lib/opencode/compatibility.d.ts +16 -0
  151. package/server/lib/opencode/compatibility.js +88 -0
  152. package/server/lib/opencode/compatibility.test.js +62 -0
  153. package/server/lib/opencode/config-entity-routes.js +58 -29
  154. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  155. package/server/lib/opencode/config-mutation-response.js +17 -7
  156. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  157. package/server/lib/opencode/config-paths.test.js +2 -2
  158. package/server/lib/opencode/config-v2.d.ts +183 -0
  159. package/server/lib/opencode/config-v2.js +801 -0
  160. package/server/lib/opencode/config-v2.test.js +466 -0
  161. package/server/lib/opencode/credential-db.js +144 -0
  162. package/server/lib/opencode/credential-db.test.js +104 -0
  163. package/server/lib/opencode/env-runtime.js +48 -9
  164. package/server/lib/opencode/env-runtime.test.js +45 -0
  165. package/server/lib/opencode/feature-routes-runtime.js +15 -5
  166. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  167. package/server/lib/opencode/lifecycle.js +85 -30
  168. package/server/lib/opencode/lifecycle.test.js +80 -8
  169. package/server/lib/opencode/login-shell-env.js +27 -0
  170. package/server/lib/opencode/managed-config-file.js +119 -0
  171. package/server/lib/opencode/managed-config-file.test.js +152 -0
  172. package/server/lib/opencode/managed-plugin-config.js +33 -13
  173. package/server/lib/opencode/mcp.js +43 -149
  174. package/server/lib/opencode/network-runtime.js +6 -7
  175. package/server/lib/opencode/openchamber-routes.test.js +2 -5
  176. package/server/lib/opencode/plugin-routes.js +3 -3
  177. package/server/lib/opencode/plugin-routes.test.js +6 -24
  178. package/server/lib/opencode/plugins.js +91 -40
  179. package/server/lib/opencode/plugins.test.js +28 -15
  180. package/server/lib/opencode/providers.js +63 -83
  181. package/server/lib/opencode/providers.test.js +128 -59
  182. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  183. package/server/lib/opencode/proxy.js +179 -129
  184. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  185. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  186. package/server/lib/opencode/response-envelope.js +14 -0
  187. package/server/lib/opencode/response-envelope.test.js +23 -0
  188. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  189. package/server/lib/opencode/routes.js +121 -428
  190. package/server/lib/opencode/server-utils-runtime.js +10 -4
  191. package/server/lib/opencode/session-activity.js +78 -0
  192. package/server/lib/opencode/session-runtime.js +21 -10
  193. package/server/lib/opencode/session-runtime.test.js +9 -9
  194. package/server/lib/opencode/settings-helpers.js +9 -9
  195. package/server/lib/opencode/settings-helpers.test.js +7 -12
  196. package/server/lib/opencode/settings-registry.json +6 -8
  197. package/server/lib/opencode/settings-runtime.js +18 -1
  198. package/server/lib/opencode/settings-runtime.test.js +31 -2
  199. package/server/lib/opencode/shared.js +54 -22
  200. package/server/lib/opencode/shared.test.js +8 -4
  201. package/server/lib/opencode/shutdown-runtime.js +54 -7
  202. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  203. package/server/lib/opencode/skill-routes.js +23 -24
  204. package/server/lib/opencode/skills.js +7 -5
  205. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  206. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  207. package/server/lib/opencode/v1-migration-topup.js +288 -0
  208. package/server/lib/opencode/v1-migration-topup.test.js +266 -0
  209. package/server/lib/opencode/v2-install.d.ts +8 -0
  210. package/server/lib/opencode/v2-install.js +158 -0
  211. package/server/lib/opencode/v2-install.test.js +124 -0
  212. package/server/lib/opencode/watcher.js +10 -3
  213. package/server/lib/opencode/watcher.test.js +17 -21
  214. package/server/lib/opencode/websearch-config.js +66 -0
  215. package/server/lib/package-manager.js +55 -68
  216. package/server/lib/package-manager.test.js +241 -75
  217. package/server/lib/permission-auto-accept/runtime.js +38 -22
  218. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  219. package/server/lib/quota/DOCUMENTATION.md +4 -0
  220. package/server/lib/quota/providers/xai.js +4 -4
  221. package/server/lib/relay/tunnel-host.js +4 -1
  222. package/server/lib/relay/tunnel-host.test.js +7 -0
  223. package/server/lib/routing/DOCUMENTATION.md +52 -21
  224. package/server/lib/routing/defaults.js +23 -6
  225. package/server/lib/routing/jev.js +17 -7
  226. package/server/lib/routing/routes.http.test.js +68 -33
  227. package/server/lib/routing/routes.js +65 -22
  228. package/server/lib/routing/runtime.js +145 -48
  229. package/server/lib/routing/runtime.test.js +79 -55
  230. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  231. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  232. package/server/lib/scheduled-tasks/runtime.js +81 -74
  233. package/server/lib/scheduled-tasks/runtime.test.js +53 -1
  234. package/server/lib/session-assist/DOCUMENTATION.md +8 -3
  235. package/server/lib/session-assist/context.js +122 -46
  236. package/server/lib/session-assist/context.test.js +117 -49
  237. package/server/lib/session-assist/runtime.js +52 -22
  238. package/server/lib/session-assist/runtime.test.js +145 -173
  239. package/server/lib/session-goal/DOCUMENTATION.md +23 -15
  240. package/server/lib/session-goal/create.js +9 -12
  241. package/server/lib/session-goal/create.test.js +27 -28
  242. package/server/lib/session-goal/runtime.js +164 -77
  243. package/server/lib/session-goal/runtime.test.js +271 -519
  244. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  245. package/server/lib/session-knowledge/runtime.js +59 -41
  246. package/server/lib/session-knowledge/runtime.test.js +90 -20
  247. package/server/lib/small-model/DOCUMENTATION.md +154 -208
  248. package/server/lib/small-model/client.js +113 -0
  249. package/server/lib/small-model/index.js +296 -158
  250. package/server/lib/small-model/index.test.js +423 -256
  251. package/server/lib/small-model/routes.js +1 -1
  252. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  253. package/server/lib/spaces/code-in-bait.js +185 -0
  254. package/server/lib/spaces/code-in.js +641 -0
  255. package/server/lib/spaces/code-in.test.js +1048 -0
  256. package/server/lib/spaces/errors.js +8 -0
  257. package/server/lib/spaces/exec-http.js +94 -0
  258. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  259. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  260. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  261. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  262. package/server/lib/spaces/hardening.js +457 -0
  263. package/server/lib/spaces/hardening.test.js +368 -0
  264. package/server/lib/spaces/host-git.js +127 -0
  265. package/server/lib/spaces/host-git.test.js +137 -0
  266. package/server/lib/spaces/labels.js +234 -0
  267. package/server/lib/spaces/labels.test.js +219 -0
  268. package/server/lib/spaces/layout.js +184 -0
  269. package/server/lib/spaces/layout.test.js +30 -0
  270. package/server/lib/spaces/manager.js +82 -0
  271. package/server/lib/spaces/manager.test.js +114 -0
  272. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  273. package/server/lib/spaces/places/contract-suite.js +156 -0
  274. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  275. package/server/lib/spaces/places/contract.test.js +6 -0
  276. package/server/lib/spaces/places/docker-engine.js +126 -0
  277. package/server/lib/spaces/places/docker-live-support.js +202 -0
  278. package/server/lib/spaces/places/docker-tools.js +186 -0
  279. package/server/lib/spaces/places/docker.js +587 -0
  280. package/server/lib/spaces/places/docker.test.js +1610 -0
  281. package/server/lib/spaces/places/escape-suite.js +1018 -0
  282. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  283. package/server/lib/spaces/places/fake-docker.js +375 -0
  284. package/server/lib/spaces/places/memory-place.js +103 -0
  285. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  286. package/server/lib/spaces/places/registry.js +43 -0
  287. package/server/lib/spaces/places/registry.test.js +50 -0
  288. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  289. package/server/lib/spaces/run-command.js +261 -0
  290. package/server/lib/spaces/run-command.test.js +396 -0
  291. package/server/lib/spaces/space-server.js +190 -0
  292. package/server/lib/spaces/space-server.test.js +335 -0
  293. package/server/lib/spaces/tools-filler.js +82 -0
  294. package/server/lib/spaces/tools-filler.test.js +148 -0
  295. package/server/lib/spaces/tools-pack.js +49 -0
  296. package/server/lib/spaces/tools-pack.test.js +57 -0
  297. package/server/lib/spaces/tools.js +138 -0
  298. package/server/lib/spaces/tools.test.js +153 -0
  299. package/server/lib/tts/openai-sdk.js +11 -0
  300. package/server/lib/tts/service.js +7 -5
  301. package/server/lib/tts/stt.js +3 -2
  302. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  303. package/server/lib/tunnels/routes.js +7 -0
  304. package/server/lib/tunnels/routes.test.js +55 -0
  305. package/server/lib/ui-auth/ui-auth.js +38 -2
  306. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  307. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  308. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  309. package/server/lib/walkthrough/pull-request.js +61 -8
  310. package/server/lib/walkthrough/pull-request.test.js +54 -1
  311. package/server/lib/walkthrough/routes.js +20 -0
  312. package/server/lib/walkthrough/routes.test.js +19 -0
  313. package/server/opencode-proxy.test.js +190 -166
  314. package/server/opencode-worktree-readiness.test.js +5 -4
  315. package/dist/assets/DiffView-COVQhWGd.js +0 -4
  316. package/dist/assets/FilesView-B1V5JxFX.js +0 -13
  317. package/dist/assets/LinearIssuesView-D7FKg1XJ.js +0 -1
  318. package/dist/assets/MarkdownImageGallery-BrFjAVEf.js +0 -1
  319. package/dist/assets/MarkdownRendererImpl-DWepTafh.js +0 -12
  320. package/dist/assets/OnboardingScreen-Dyxxiqdt.js +0 -1
  321. package/dist/assets/PlanView-LW2z_EAP.js +0 -5
  322. package/dist/assets/PluginPane-B4tKno2h.js +0 -3
  323. package/dist/assets/SettingsView-DEaMulN9.js +0 -29
  324. package/dist/assets/SettingsWindow-FLDJXOgQ.js +0 -1
  325. package/dist/assets/SubmoduleDiffSummary-CvVwD-Vi.js +0 -1
  326. package/dist/assets/ToolOutputDialog-BiP0x2Rw.js +0 -15
  327. package/dist/assets/ToolPartDiffPreview-CkR4msKP.js +0 -8
  328. package/dist/assets/appThemeRegistry-BuUKhbYQ.js +0 -1
  329. package/dist/assets/de-DgxgFyGG.js +0 -10
  330. package/dist/assets/es-BFsZj5F_.js +0 -16
  331. package/dist/assets/fr-jdZ5KKQi.js +0 -14
  332. package/dist/assets/index-CKHjPKbq.js +0 -1
  333. package/dist/assets/index-Cbci4i1W.js +0 -40
  334. package/dist/assets/index-DqaMWNrC.css +0 -1
  335. package/dist/assets/ja-C5kKrhO4.js +0 -16
  336. package/dist/assets/ko-DXDTT_0O.js +0 -16
  337. package/dist/assets/main-CZALtVek.js +0 -896
  338. package/dist/assets/main-CgXMBNvG.js +0 -2
  339. package/dist/assets/miniChat-CwTmDixi.js +0 -2
  340. package/dist/assets/mobile-CLf2vCtO.js +0 -2
  341. package/dist/assets/pl-D-7x4Y8Q.js +0 -16
  342. package/dist/assets/pt-BR-CSBZrHa8.js +0 -16
  343. package/dist/assets/renderElectronMiniChatApp-C5gAFBk0.js +0 -2
  344. package/dist/assets/renderMobileApp-V4hYd32H.js +0 -25
  345. package/dist/assets/runtimeEndpointReset-DhlHCn-2.js +0 -25
  346. package/dist/assets/scheduledTasksApi-DzjbLd8P.js +0 -1
  347. package/dist/assets/tr-Dr-oJ22L.js +0 -7
  348. package/dist/assets/uk-9Nx83UcI.js +0 -16
  349. package/dist/assets/useAppFontEffects-khZXpFL_.js +0 -7333
  350. package/dist/assets/useRootScrollLock-DdvHf9Pt.js +0 -2
  351. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  352. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  353. package/dist/assets/zh-CN-Bxy_Hj3r.js +0 -16
  354. package/dist/assets/zh-TW-0BB4gpHM.js +0 -16
  355. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  356. package/server/lib/routing/feature-flag.js +0 -11
  357. package/server/lib/small-model/call.js +0 -851
  358. package/server/lib/small-model/call.test.js +0 -1292
  359. package/server/lib/small-model/catalog.js +0 -13
  360. package/server/lib/small-model/resolve.js +0 -131
  361. package/server/lib/small-model/resolve.test.js +0 -197
  362. package/server/lib/small-model/runtime-providers.js +0 -164
  363. package/server/lib/small-model/runtime-providers.test.js +0 -118
  364. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  365. package/server/lib/system-prompt/runtime.js +0 -49
  366. package/server/lib/system-prompt/runtime.test.js +0 -76
  367. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
@@ -1,29 +0,0 @@
1
- import{R as o,j as s,f as ct,r as Ze}from"./vendor-react-BUCujlKS.js";import{f as et,B as G,I as B,o as bn,bg as ha,t as F,O as ld,gJ as cd,eX as ze,gK as Kt,b as en,h as ye,au as dd,aq as vn,as as yn,at as ud,ap as jn,eN as oa,gL as Zl,gM as md,gN as Da,gO as Cn,c6 as Ns,c0 as _t,c1 as $t,c2 as Vt,c3 as Ht,c4 as qt,c5 as rs,W as Be,gP as ii,be as wn,eA as Mr,gQ as Oi,gR as rn,f1 as Yt,gS as cn,l as Xe,ff as Ft,ch as Tt,ci as Et,fc as Bt,cj as Ut,ck as Dt,cl as dt,gT as At,cm as Ms,e3 as na,fe as on,fi as la,fg as ln,gU as ws,e8 as ks,gV as Ds,gW as pd,cR as mt,gX as Xl,gY as gd,gZ as aa,g_ as ec,g$ as hd,g5 as La,gb as Xs,h0 as Ma,h1 as tc,h2 as Jr,e4 as Qr,h3 as ia,a9 as Ka,a8 as Vs,h4 as sc,h5 as bo,ae as fd,ey as nc,g as Ra,h6 as xd,h7 as dn,ce as kn,cp as Nn,cf as Sn,ex as bd,h8 as vd,h9 as yd,ha as Yr,aa as Zr,ab as Xr,ac,hb as Dn,a4 as $i,cu as eo,S as Ua,hc as vo,av as jd,cn as wd,d6 as kd,U as Nd,T as Sd,V as Cd,Z as to,hd as Id,he as Pd,cc as Ad,co as Rr,hf as ic,ad as si,fh as rc,P as Zn,hg as _s,eW as Hs,eG as oc,a3 as Td,n as ls,eq as Bi,y as lc,x as Ed,i as Dd,j as Md,er as Rd,p as Fd,hh as Od,hi as Ld,hj as yo,e9 as cc,hk as Kd,hl as mr,hm as jo,hn as zd,ho as Ud,hp as _d,hq as $d,g1 as Vi,hr as fs,hs as As,ht as an,hu as Ys,de as dc,bX as uc,df as mc,bY as Zs,hv as Bn,hw as pc,aD as Vn,aE as Sa,hx as nn,hy as gc,hz as En,ds as hc,hA as fc,hB as Bd,eV as Vd,eU as Hd,hC as Fr,eF as qd,hD as Xn,hE as Us,hF as Gs,fX as ea,hG as Ts,hH as Gd,hI as wo,hJ as xc,hK as ta,hL as Wd,hM as Jd,R as Qd,fb as Kn,hN as za,hO as ko,hP as Ca,hQ as Ia,bZ as ca,hR as Yd,hS as Zd,hT as Xd,hU as eu,hV as pr,hW as No,hX as tu,hY as su,hZ as nu,h_ as au,h$ as So,z as iu,m as Co,i0 as ru,i1 as gr,i2 as Io,ev as ou,i3 as Gi,i4 as lu,i5 as cu,i6 as du,i7 as uu,i8 as mu,i9 as hr,cS as pu,b_ as bc,ia as vc,ib as gu,ay as zn,az as hu}from"./useAppFontEffects-khZXpFL_.js";import{h as xt,u as ce,O as ds,dh as fu,di as Po,B as Mn,aE as In,t as yt,a1 as xu,E as cs,P as Ao,cw as To,cD as Eo,U as qa,p as bu,dj as vu,k as yu,cv as Ta,dk as ju,an as wu,cA as ku,dl as Nu,dm as Su,s as Cu,e as ri,cB as Iu,F as oi,dn as yc,_ as Pu,dp as Au,a4 as jc,a as Rn,aD as ys,d7 as wc,a$ as kc,x as Fa,ah as Tu,ai as Eu,aJ as so,dq as Du,A as Wi,Z as Mu,aO as Do,b3 as ki,aP as Ru,dr as Fu,ac as ra,ds as Ou,dt as Mo,dg as Ro,du as Fo,aM as Oo,dv as Lu,dw as Ku,dx as zu,dy as Uu,dz as Lo,b as _u,dA as Nc,dB as $u,dC as Bu,dD as Vu,dE as Hu,dF as qu,dG as Gu,ay as Wu,i as Sc}from"./index-Cbci4i1W.js";import{u as Ju,U as Ko,R as da,W as ua,X as ma,Y as pa,j as no,ai as sa,$ as Qu,v as Rs,aj as Yu,ag as Zu,ak as Ea,al as Cc,Z as Xu,_ as em}from"./runtimeEndpointReset-DhlHCn-2.js";import{u as qs,c as Ic,d as tm,p as sm}from"./vendor-zustand-BAGL70zf.js";import{o as un,s as as,b as ao,_ as io,r as Or,c as Lr,a as li}from"./vendor-zod-CgAdXWZO.js";import{s as nm,p as am}from"./vendor-yaml-3778uTud.js";import{c as zo,s as im,C as Uo,P as rm}from"./shikiHighlight-8_3csmr6.js";import{getResolvedShikiTheme as om}from"./appThemeRegistry-BuUKhbYQ.js";import{E as _o}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Pc}from"./vendor-qrcode-DTJ12-WC.js";import{u as fr,s as lm,d as cm,b as dm,A as um,c as mm,e as pm,f as gm,h as hm,i as xr,j as fm}from"./PluginPane-B4tKno2h.js";import{toast as Oa}from"./vendor-sonner-DFyL3AvE.js";import{s as xm}from"./vendor-strip-json-comments-5dJlOkP1.js";const $o=()=>{const{t}=et(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const m=await xt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!m.ok)return;const c=await m.json().catch(()=>null);if(!c||i)return;const x=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,u=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:x,tunnelUrl:u})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(G,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{bn(i.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:i.url})]},i.key))})},Bo="https://github.com/openchamber/openchamber",bm="https://discord.gg/ZYRSdnwwKA",Vo="https://x.com/openchamber_dev",vm=800,Ac=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=et(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,m]=o.useState(null),[c,x]=o.useState(null),u=Ju(qs(w=>({info:w.info,checking:w.checking,available:w.available,error:w.error,downloading:w.downloading,downloaded:w.downloaded,progress:w.progress,runtimeType:w.runtimeType,checkForUpdates:w.checkForUpdates,downloadUpdate:w.downloadUpdate,restartToUpdate:w.restartToUpdate}))),{isMobile:v}=ha(),d=l||u.info?.currentVersion||"unknown";o.useEffect(()=>{let w=!1;return(async()=>{try{const k=await xt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const p=await k.json().catch(()=>null),C=typeof p?.openchamberVersion=="string"&&p.openchamberVersion.trim().length>0?p.openchamberVersion.trim():null;w||m(C)}catch{w||m(null)}})(),()=>{w=!0}},[]),o.useEffect(()=>{let w=!1;return(async()=>{try{const k=await xt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const p=await k.json().catch(()=>null),C=typeof p?.currentVersion=="string"&&p.currentVersion.trim().length>0?p.currentVersion.trim():null;w||x(C)}catch{w||x(null)}})(),()=>{w=!0}},[]);const j=o.useRef(!1);o.useEffect(()=>{if(u.checking)r(!0),j.current=!0;else if(i){const w=setTimeout(()=>{r(!1),j.current&&!u.available&&!u.error&&(F.success(e("settings.openchamber.about.toast.latestVersion")),j.current=!1)},vm);return()=>clearTimeout(w)}},[e,u.checking,i,u.available,u.error]);const g=u.checking||i;return v?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(ld,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${cd}`,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:d})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx($o,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!u.available&&!u.error&&s.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:()=>u.checkForUpdates(),disabled:g,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[g?s.jsx(B,{name:"loader",className:"size-4 animate-spin"}):s.jsx(B,{name:"refresh",className:"size-4"}),e(g?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!g&&u.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:u.info?.version||""})]})]}),u.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:u.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:Bo,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:bm,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:Vo,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(Ko,{open:a,onOpenChange:n,info:u.info,downloading:u.downloading,downloaded:u.downloaded,progress:u.progress,error:u.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:u.runtimeType})]}):s.jsxs(ze,{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:Kt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Kt,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:[u.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")})]}),!u.checking&&u.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:u.info?.version||""})]}),!u.checking&&!u.available&&!u.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>u.checkForUpdates(),disabled:u.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),u.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:u.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Kt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx($o,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Bo,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:Vo,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(Ko,{open:a,onOpenChange:n,info:u.info,downloading:u.downloading,downloaded:u.downloaded,progress:u.progress,error:u.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:u.runtimeType})]})},ym=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Ws=()=>{const t=ct.c(4),e=ce(jm),a=en(wm),n=en(km);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=ym(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function jm(t){return t.settingsProjectPath}function wm(t){return t.projects}function km(t){return t.activeProjectId}const Tc=t=>t.trim(),ci=t=>{const e=ct.c(40),{className:a}=t,{t:n}=et(),i=en(Nm),r=Ws(),l=ce(Sm),m=ds();let c;e[0]!==i?(c=[...i].sort(Cm),e[0]=i,e[1]=c):c=e[1];const x=c;let u;e:{if(x.length===0){u=null;break e}let $;e[2]!==r||e[3]!==x?($=x.find(I=>I.path===r)??x[0],e[2]=r,e[3]=x,e[4]=$):$=e[4],u=$}const v=u;if(m||x.length===0)return null;let d;e[5]!==v||e[6]!==n?(d=v?.label&&v.label.trim().length>0?v.label:v?.path.split("/").filter(Boolean).pop()||v?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=v,e[6]=n,e[7]=d):d=e[7];const j=d;let g;e[8]!==j?(g=Tc(j),e[8]=j,e[9]=g):g=e[9];const w=g;let b;e[10]!==a?(b=ye(a),e[10]=a,e[11]=b):b=e[11];let k;e[12]!==n?(k=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=k):k=e[13];let p;e[14]!==n?(p=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=p):p=e[15];let C,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=ye("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-ring focus-visible:border-interactive-border-focus","flex items-center gap-1.5 text-left"),E=s.jsx(B,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=C,e[17]=E):(C=e[16],E=e[17]);let A;e[18]!==w?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:w}),e[18]=w,e[19]=A):A=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=N):N=e[20];let h;e[21]!==A||e[22]!==k||e[23]!==p?(h=s.jsx(vn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":k,title:p,className:C,children:[E,A,N]})}),e[21]=A,e[22]=k,e[23]=p,e[24]=h):h=e[24];const y=v?.id??"";let R;e[25]!==l||e[26]!==x?(R=$=>{if(!$)return;const I=x.find(M=>M.id===$);I&&l(I.path)},e[25]=l,e[26]=x,e[27]=R):R=e[27];let T;e[28]!==x?(T=x.map(Im),e[28]=x,e[29]=T):T=e[29];let P;e[30]!==y||e[31]!==R||e[32]!==T?(P=s.jsx(yn,{align:"start",className:"w-auto",children:s.jsx(ud,{value:y,onValueChange:R,children:T})}),e[30]=y,e[31]=R,e[32]=T,e[33]=P):P=e[33];let D;e[34]!==h||e[35]!==P?(D=s.jsxs(jn,{children:[h,P]}),e[34]=h,e[35]=P,e[36]=D):D=e[36];let V;return e[37]!==D||e[38]!==b?(V=s.jsx("div",{className:b,children:D}),e[37]=D,e[38]=b,e[39]=V):V=e[39],V};function Nm(t){return t.projects}function Sm(t){return t.setSettingsProjectPath}function Cm(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Im(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Tc(e);return s.jsx(dd,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Pm(t,e){return`opencode:sidebar-group:${t}:${e}`}const Kr=t=>{const e=ct.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,m=r===void 0?!0:r;let c;e[0]!==a||e[1]!==i?(c=Pm(i,a),e[0]=a,e[1]=i,e[2]=c):c=e[2];const x=c,u=o.useId();let v;e[3]!==m||e[4]!==x?(v=()=>{try{const P=localStorage.getItem(x);if(P!==null)return P==="true"}catch{}return m},e[3]=m,e[4]=x,e[5]=v):v=e[5];const[d,j]=Ze.useState(v);let g,w;e[6]!==d||e[7]!==x?(g=()=>{try{localStorage.setItem(x,String(d))}catch{}},w=[x,d],e[6]=d,e[7]=x,e[8]=g,e[9]=w):(g=e[8],w=e[9]),Ze.useEffect(g,w);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>j(Am),e[10]=b):b=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=ye("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),e[11]=k):k=e[11];const p=!d&&"-rotate-90";let C;e[12]!==p?(C=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",p),e[12]=p,e[13]=C):C=e[13];let E;e[14]!==C?(E=s.jsx(B,{name:"arrow-down-s",className:C}),e[14]=C,e[15]=E):E=e[15];let A;e[16]!==a?(A=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=A):A=e[17];let N;e[18]!==n?(N=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=N):N=e[19];let h;e[20]!==u||e[21]!==d||e[22]!==E||e[23]!==A||e[24]!==N?(h=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":d,"aria-controls":u,className:k,children:[E,A,N]}),e[20]=u,e[21]=d,e[22]=E,e[23]=A,e[24]=N,e[25]=h):h=e[25];const y=!d;let R;e[26]!==l||e[27]!==u||e[28]!==y?(R=s.jsx("div",{id:u,hidden:y,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]=u,e[28]=y,e[29]=R):R=e[29];let T;return e[30]!==h||e[31]!==R?(T=s.jsxs("div",{children:[h,R]}),e[30]=h,e[31]=R,e[32]=T):T=e[32],T};function Am(t){return!t}const Tm=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},Em=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},Ho=t=>{const e=Em(Tm(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},Dm=({onItemSelect:t})=>{const{t:e}=et(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,m]=o.useState(null),[c,x]=o.useState(null),[u,v]=o.useState(!1),[d,j]=o.useState(null),{selectedAgentName:g,setSelectedAgent:w,setAgentDraft:b,createAgent:k,deleteAgent:p,loadAgents:C}=oa(qs(O=>({selectedAgentName:O.selectedAgentName,setSelectedAgent:O.setSelectedAgent,setAgentDraft:O.setAgentDraft,createAgent:O.createAgent,deleteAgent:O.deleteAgent,loadAgents:O.loadAgents}))),E=Ws(),A=oa(O=>Zl(O,E));o.useEffect(()=>{C(E)},[C,E]);const N="bg-background",h=()=>{const O="new-agent";let ae=O,_=1;for(;A.some(W=>W.name===ae);)ae=`${O}-${_}`,_++;b({name:ae,scope:"user"}),w(ae),t?.()},y=async O=>{if(Da(O)){F.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}m(O),x("delete")},R=async O=>{Da(O)&&(m(O),x("reset"))},T=()=>{m(null),x(null)},P=async()=>{if(!(!l||!c)){v(!0);try{const O=await p(l.name,l.scope,E);O.ok?(O.requiresManualRestart?F.warning(e("settings.agents.page.toast.savedManualRestart")):O.restartDeferred?F.success(e("settings.view.pendingRestart.saved")):c==="delete"?F.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):F.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):c==="delete"?F.error(e("settings.agents.sidebar.toast.deleteFailed")):F.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(O){const ae=O instanceof Error?O.message:"",_=/built-in|not deletable|not found/i.test(ae);c==="delete"?F.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):F.error(e("settings.agents.sidebar.toast.resetFailed"))}v(!1)}},D=O=>{const ae=O.name;let _=1,W=`${ae}-copy`;for(;A.some(z=>z.name===W);)_++,W=`${ae}-copy-${_}`;const q=O,L=O.model?.providerID&&O.model?.modelID?`${O.model.providerID}/${O.model.modelID}`:null,K=O;b({name:W,scope:q.scope||"user",description:O.description,model:L,variant:O.variant,temperature:O.temperature,top_p:O.topP,prompt:O.prompt,mode:O.mode,permission:Ho(O.permission),disable:K.disable}),w(W),t?.()},V=O=>{r(O.name),n(O)},$=async()=>{if(!a)return;const O=i.trim().replace(/\s+/g,"-");if(!O){F.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(O===a.name){n(null);return}if(A.some(q=>q.name===O)){F.error(e("settings.agents.sidebar.toast.agentExists"));return}const ae=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,_=a,W=await k({name:O,description:a.description,model:ae,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Ho(a.permission),disable:_.disable,scope:_.scope},E);if(W.ok){const q=await p(a.name,_.scope,E);q.ok?(W.requiresManualRestart||q.requiresManualRestart?F.warning(e("settings.agents.page.toast.savedManualRestart")):F.success(e("settings.agents.sidebar.toast.agentRenamed",{name:O})),w(O)):F.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else F.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},I=O=>{switch(O){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}},M=A.filter(O=>!md(O)),H=M.filter(Da),U=M.filter(O=>!Da(O)),{groupedCustomAgents:Z,ungroupedCustomAgents:ee}=Ze.useMemo(()=>{const O={},ae=[];for(const W of U){const q=W;q.group?(O[q.group]||(O[q.group]=[]),O[q.group].push(W)):ae.push(W)}return{groupedCustomAgents:Object.keys(O).sort((W,q)=>W.localeCompare(q)).map(W=>({name:W,agents:O[W]})),ungroupedCustomAgents:ae}},[U]);return s.jsxs("div",{className:ye("flex h-full flex-col",N),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Cn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(ci,{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:M.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:h,children:s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:M.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:[H.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")}),H.map(O=>s.jsx(br,{agent:O,isSelected:g===O.name,onSelect:()=>{w(O.name),t?.()},onReset:()=>R(O),onDuplicate:()=>D(O),getAgentModeIcon:I,isMenuOpen:d===O.name,onMenuOpenChange:ae=>j(ae?O.name:null)},O.name))]}),U.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")}),Z.map(({name:O,agents:ae})=>s.jsx(Kr,{label:O,count:ae.length,storageKey:"agents",children:ae.map(_=>s.jsx(br,{agent:_,isSelected:g===_.name,onSelect:()=>{w(_.name),t?.()},onRename:()=>V(_),onDelete:()=>y(_),onDuplicate:()=>D(_),getAgentModeIcon:I,isMenuOpen:d===_.name,onMenuOpenChange:W=>j(W?_.name:null)},_.name))},O)),ee.map(O=>s.jsx(br,{agent:O,isSelected:g===O.name,onSelect:()=>{w(O.name),t?.()},onRename:()=>V(O),onDelete:()=>y(O),onDuplicate:()=>D(O),getAgentModeIcon:I,isMenuOpen:d===O.name,onMenuOpenChange:ae=>j(ae?O.name:null)},O.name))]})]})}),s.jsx(_t,{open:l!==null&&c!==null,onOpenChange:O=>{!O&&!u&&T()},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(qt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(rs,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:T,disabled:u,children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:P,disabled:u,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(_t,{open:a!==null,onOpenChange:O=>!O&&n(null),children:s.jsxs($t,{children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Be,{value:i,onChange:O=>r(O.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:O=>{O.key==="Enter"&&$()}}),s.jsxs(rs,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:$,children:e("settings.common.actions.rename")})]})]})})]})},br=t=>{const e=ct.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:m,onDuplicate:c,getAgentModeIcon:x,isMenuOpen:u,onMenuOpenChange:v}=t,{t:d}=et(),j=a;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=ii(),e[0]=g):g=e[0];const w=g,[b,k]=o.useState(!1);let p;e[1]!==r||e[2]!==c||e[3]!==m||e[4]!==l||e[5]!==d?(p=ae=>s.jsxs(s.Fragment,{children:[m&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),m()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}),s.jsxs(ae,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),l&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(B,{name:"restart",className:"h-4 w-4 mr-px"}),d("settings.common.actions.reset")]}),r&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=m,e[4]=l,e[5]=d,e[6]=p):p=e[6];const C=p,E=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==E?(A=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",E),e[7]=E,e[8]=A):A=e[8];let N;e[9]===Symbol.for("react.memo_cache_sentinel")?(N=w?void 0:ae=>{ae.preventDefault(),k(!0)},e[9]=N):N=e[9];let h;e[10]!==A?(h=s.jsx("div",{className:A,onContextMenu:N}),e[10]=A,e[11]=h):h=e[11];let y;e[12]!==a.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=y):y=e[13];let R;e[14]!==a.mode||e[15]!==x?(R=x(a.mode),e[14]=a.mode,e[15]=x,e[16]=R):R=e[16];let T;e[17]!==a||e[18]!==j.scope||e[19]!==d?(T=(j.scope||Da(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:Da(a)?d("settings.agents.sidebar.badge.system"):j.scope}),e[17]=a,e[18]=j.scope,e[19]=d,e[20]=T):T=e[20];let P;e[21]!==y||e[22]!==R||e[23]!==T?(P=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,R,T]}),e[21]=y,e[22]=R,e[23]=T,e[24]=P):P=e[24];let D;e[25]!==a.description?(D=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=D):D=e[26];let V;e[27]!==i||e[28]!==P||e[29]!==D?(V=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:[P,D]}),e[27]=i,e[28]=P,e[29]=D,e[30]=V):V=e[30];let $;e[31]!==v?($=ae=>{ae&&k(!1),v(ae)},e[31]=v,e[32]=$):$=e[32];let I;e[33]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(vn,{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]=I):I=e[33];let M;e[34]!==C?(M=s.jsx(yn,{align:"end",className:"w-fit min-w-20",children:C(wn)}),e[34]=C,e[35]=M):M=e[35];let H;e[36]!==u||e[37]!==$||e[38]!==M?(H=s.jsxs(jn,{open:u,onOpenChange:$,children:[I,M]}),e[36]=u,e[37]=$,e[38]=M,e[39]=H):H=e[39];let U;e[40]!==V||e[41]!==H?(U=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[V,H]}),e[40]=V,e[41]=H,e[42]=U):U=e[42];let Z;e[43]!==U||e[44]!==h?(Z=s.jsx(ma,{render:h,children:U}),e[43]=U,e[44]=h,e[45]=Z):Z=e[45];let ee;e[46]!==C?(ee=s.jsx(da,{className:"w-fit min-w-20",children:C(ua)}),e[46]=C,e[47]=ee):ee=e[47];let O;return e[48]!==b||e[49]!==Z||e[50]!==ee?(O=s.jsxs(pa,{open:b,onOpenChange:k,children:[Z,ee]}),e[48]=b,e[49]=Z,e[50]=ee,e[51]=O):O=e[51],O},is=t=>{const e=ct.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:m,description:c,headerEnd:x,showSaveStatus:u}=t,v=u===void 0?!1:u,d=r!=null||c!=null||x!=null||v,j=typeof r=="string"||typeof r=="number",g=l!=null||m!=null;let w;e[0]!==i?(w=ye("h-full",i),e[0]=i,e[1]=w):w=e[1];let b;e[2]!==n?(b=ye("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=b):b=e[3];let k;e[4]!==c||e[5]!==d||e[6]!==g||e[7]!==x||e[8]!==j||e[9]!==v||e[10]!==r||e[11]!==m||e[12]!==l?(k=d&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?j?g?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:ye(Mr,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:m})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Mr,children:r}):r:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Oi,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[x,v&&s.jsx(Rm,{})]})]}),e[4]=c,e[5]=d,e[6]=g,e[7]=x,e[8]=j,e[9]=v,e[10]=r,e[11]=m,e[12]=l,e[13]=k):k=e[13];let p;e[14]!==a||e[15]!==b||e[16]!==k?(p=s.jsxs("div",{className:b,children:[k,a]}),e[14]=a,e[15]=b,e[16]=k,e[17]=p):p=e[17];let C;return e[18]!==w||e[19]!==p?(C=s.jsx(Ns,{outerClassName:w,className:"w-full @container",children:p}),e[18]=w,e[19]=p,e[20]=C):C=e[20],C},Mm=500,Rm=()=>{const t=ct.c(13),{t:e}=et(),a=o.useSyncExternalStore(fu,Po,Po),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const u=setTimeout(()=>i(!0),Mm);return()=>clearTimeout(u)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let u;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(B,{name:"error-warning",className:"size-3.5"}),t[3]=u):u=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let d;return t[6]!==v?(d=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[u,s.jsx("span",{children:v})]}),t[6]=v,t[7]=d):d=t[7],d}if(a!=="saving"||!n)return null;let m;t[8]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=m):m=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let x;return t[11]!==c?(x=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[m,s.jsx("span",{children:c})]}),t[11]=c,t[12]=x):x=t[12],x},Fm=["allow","ask","deny"],ti=t=>t==="allow"||t==="ask"||t==="deny",zr=()=>({global:null,keys:{}}),Om=t=>{const e=zr();if(t==null)return e;if(typeof t=="string")return ti(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){ti(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(ti(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))ti(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},Ur=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},Lm=(t,e)=>JSON.stringify(Ur(t))===JSON.stringify(Ur(e)),Un=t=>JSON.parse(JSON.stringify(t)),Km=["edit","external_directory","doom_loop","plan_enter","plan_exit"],zm=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),qo=new Set(["write","patch","apply_patch","multiedit","invalid"]),Um=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),_m=({agent:t})=>{const{t:e}=et(),a=oa(q=>q.updateAgent),[n,i]=o.useState(zr),[r,l]=o.useState(zr),[m,c]=o.useState(!0),[x,u]=o.useState(!1),[v,d]=o.useState(!1),[j,g]=o.useState({}),[w,b]=o.useState([]),[k,p]=o.useState(""),[C,E]=o.useState(0),A=t.name,N=Ws();o.useEffect(()=>{let q=!1;return c(!0),u(!1),(async()=>{try{const L=N,K=L?`?directory=${encodeURIComponent(L)}`:"",z=await xt(`/api/config/agents/${encodeURIComponent(A)}/config${K}`,{headers:{"Cache-Control":"no-cache",...L?{"x-opencode-directory":L}:{}}});if(!z.ok)throw new Error(String(z.status));const J=await z.json().catch(()=>null);if(q)return;const oe=Om(J?.config?.permission);i(Un(oe)),l(oe)}catch{q||u(!0)}finally{q||c(!1)}})(),()=>{q=!0}},[A,C,N]),o.useEffect(()=>{let q=!1;return(async()=>{try{const L=await Mn.listToolIds({directory:N});!q&&Array.isArray(L)&&b(L.filter(K=>typeof K=="string"&&!qo.has(K)))}catch{}})(),()=>{q=!0}},[A,N]);const h=o.useMemo(()=>{const q=t.permission;if(!Array.isArray(q))return[];const L=[];for(const K of q){if(!K||typeof K!="object")continue;const{permission:z,pattern:J,action:oe}=K;typeof z=="string"&&typeof J=="string"&&ti(oe)&&L.push({permission:z,pattern:J,action:oe})}return L},[t]),y=o.useCallback(q=>{const L=h.find(z=>z.permission===q&&z.pattern==="*");if(L)return L.action;const K=h.find(z=>z.permission==="*"&&z.pattern==="*");return K?K.action:null},[h]),R=o.useCallback(q=>{const L=r.keys[q]?.patterns??[],K=new Set(L.map(z=>z.pattern));return h.filter(z=>z.permission===q&&z.pattern!=="*"&&!K.has(z.pattern))},[h,r.keys]),T=o.useMemo(()=>{const q=new Set;for(const L of w)q.add(L);for(const L of Km)q.add(L);for(const L of Object.keys(r.keys))q.add(L);for(const L of qo)q.delete(L);return Array.from(q).sort((L,K)=>L.localeCompare(K))},[w,r.keys]),P=o.useMemo(()=>!Lm(r,n),[r,n]),D=q=>{l(L=>({...L,global:q}))},V=(q,L)=>{l(K=>{const z=Un(K),J=z.keys[q]??{action:null,patterns:[]};return J.action=L,J.action===null&&J.patterns.length===0?delete z.keys[q]:z.keys[q]=J,z})},$=(q,L,K,z)=>{l(J=>{const oe=Un(J),re=oe.keys[q]??{action:null,patterns:[]};return re.patterns[L]={pattern:K,action:z},oe.keys[q]=re,oe})},I=q=>{l(L=>{const K=Un(L),z=K.keys[q]??{action:null,patterns:[]};return z.patterns.push({pattern:"",action:"allow"}),K.keys[q]=z,K}),g(L=>({...L,[q]:!0}))},M=(q,L)=>{l(K=>{const z=Un(K),J=z.keys[q];return J?(J.patterns.splice(L,1),J.action===null&&J.patterns.length===0&&delete z.keys[q],z):K})},H=()=>{const q=k.trim();!q||q==="*"||(l(L=>{if(L.keys[q])return L;const K=Un(L);return K.keys[q]={action:"ask",patterns:[]},K}),g(L=>({...L,[q]:!0})),p(""))},U=async()=>{d(!0);try{const q=Ur(r),L=await a(A,{permission:q});L.ok?(i(Un(r)),F.success(L.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):F.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{d(!1)}},Z=()=>{l(Un(n))},ee=q=>e(q==="allow"?"settings.agents.page.permissionsEditor.action.allow":q==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),O=e("settings.agents.page.permissionsEditor.action.inherit"),ae=e("settings.agents.page.permissionsEditor.action.default"),_=q=>[...q?[{value:"inherit",label:q}]:[],...Fm.map(L=>({value:L,label:ee(L)}))],W=(q,L,K,z=O)=>s.jsx(cn,{value:q??"inherit",options:_(z),onChange:J=>L(J==="inherit"?null:J),"aria-label":K});return m?s.jsx(ze,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:rn,children:e("common.loading")})}):x?s.jsx(ze,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(G,{variant:"outline",size:"xs",onClick:()=>E(q=>q+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(ze,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:P?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Z,disabled:v,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(G,{size:"xs",className:"!font-normal",onClick:()=>{U()},disabled:v,children:e(v?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Kt,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(y("*")??"allow")})})]}),W(r.global,D,e("settings.agents.page.permissionsEditor.defaultAria"),ae)]}),s.jsx("div",{children:T.map(q=>{const L=r.keys[q]??{action:null,patterns:[]},K=R(q),z=zm.has(q)||L.patterns.length>0,J=z||K.length>0,oe=j[q]===!0,re=y(q);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:J?()=>g(pe=>({...pe,[q]:!oe})):void 0,className:ye("flex min-w-0 items-center gap-1.5 text-left",!J&&"cursor-default"),"aria-expanded":J?oe:void 0,children:[s.jsx(B,{name:oe&&J?"arrow-down-s":"arrow-right-s",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",!J&&"opacity-0")}),s.jsx("span",{className:Kt,children:Um(q)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:q}),L.action===null&&re!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(re)})}),L.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(L.patterns.length)})})]}),W(L.action,pe=>V(q,pe),e("settings.agents.page.permissionsEditor.keyAria",{key:q}))]}),oe&&J&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[L.patterns.map((pe,ve)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Be,{value:pe.pattern,onChange:be=>$(q,ve,be.target.value,pe.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(cn,{value:pe.action,options:_(),onChange:be=>$(q,ve,pe.pattern,be),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:q})}),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:()=>M(q,ve),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]},ve)),z&&s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>I(q),children:[s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),K.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),K.map(pe=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:pe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ee(pe.action)})]},`${pe.pattern}-${pe.action}`))]})]})]},q)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Be,{value:k,onChange:q=>p(q.target.value),onKeyDown:q=>{q.key==="Enter"&&(q.preventDefault(),H())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:H,disabled:!k.trim(),children:[s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},$m=(t,e)=>{const a=la(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},Bm=()=>{const{t}=et(),e=Xe(W=>W.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:m}=oa(qs(W=>({selectedAgentName:W.selectedAgentName,getAgentByName:W.getAgentByName,createAgent:W.createAgent,updateAgent:W.updateAgent,agentDraft:W.agentDraft,setAgentDraft:W.setAgentDraft}))),c=Ws(),x=oa(W=>Zl(W,c)),u=a?n(a,c):null,v=!!(l&&l.name===a&&!u),[d,j]=o.useState(""),[g,w]=o.useState("user"),[b,k]=o.useState(""),[p,C]=o.useState("subagent"),[E,A]=o.useState(""),[N,h]=o.useState(""),[y,R]=o.useState(void 0),[T,P]=o.useState(void 0),[D,V]=o.useState(""),[$,I]=o.useState(!1),M=o.useRef(null),H=o.useMemo(()=>$m(e,E),[E,e]),U=H.length>0,Z=N||"__default",ee=U,O=o.useMemo(()=>N&&!H.includes(N)?[N,...H]:H,[N,H]);o.useEffect(()=>{if(v&&l){const W=l.name||"",q=l.scope||"user",L=l.description||"",K=l.mode||"subagent",z=l.model||"",J=l.variant||"",oe=l.temperature??void 0,re=l.top_p??void 0,pe=l.prompt||"";j(W),w(q),k(L),C(K),A(z),h(J),R(oe),P(re),V(pe),M.current={draftName:W,draftScope:q,description:L,mode:K,model:z,variant:J,temperature:oe,topP:re,prompt:pe};return}if(u&&a===u.name){const W=u.description||"",q=u.mode||"subagent",L=u.model?.providerID&&u.model?.modelID?`${u.model.providerID}/${u.model.modelID}`:"",K=u.variant||"",z=u.temperature??void 0,J=u.topP??void 0,oe=u.prompt||"";k(W),C(q),A(L),h(K),R(z),P(J),V(oe),M.current={draftName:"",draftScope:"user",description:W,mode:q,model:L,variant:K,temperature:z,topP:J,prompt:oe}}},[l,v,u,a]);const ae=o.useMemo(()=>{const W=M.current;return W?!!(v&&(d!==W.draftName||g!==W.draftScope)||b!==W.description||p!==W.mode||E!==W.model||N!==W.variant||y!==W.temperature||T!==W.topP||D!==W.prompt):!1},[b,d,g,v,p,E,D,y,T,N]),_=async()=>{const W=v?d.trim().replace(/\s+/g,"-"):a?.trim();if(!W){F.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(v&&x.some(q=>q.name===W)){F.error(t("settings.agents.sidebar.toast.agentExists"));return}I(!0);try{const q=E.trim(),L=N.trim(),K=D.trim(),z={name:W,...b.trim()?{description:b.trim()}:{},mode:p,model:q===""?null:q,variant:L===""?null:L||void 0,temperature:y??null,top_p:T??null,prompt:K||(v?void 0:null),...v&&g?{scope:g}:{}};let J;v?(J=await i(z,c),J.ok&&m(null)):J=await r(W,z,c),J.ok?J.requiresManualRestart?F.warning(t("settings.agents.page.toast.savedManualRestart")):J.restartDeferred?F.success(t("settings.view.pendingRestart.saved")):F.success(t(v?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):F.error(t(v?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(q){console.error("Error saving agent:",q);const L=q instanceof Error&&q.message?q.message:t("settings.agents.page.toast.saveUnexpectedError");F.error(L)}finally{I(!1)}};return a?s.jsxs(is,{title:v?t("settings.agents.page.title.new"):a,description:t(v?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[v&&s.jsxs(Ft,{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(Be,{value:d,onChange:W=>j(W.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:g,onValueChange:W=>w(W),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[100px]",children:s.jsx(Ut,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Dt,{align:"end",children:[s.jsx(dt,{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(dt,{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(At,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ms,{value:b,onChange:W=>k(W.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(At,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(cn,{"aria-label":t("settings.agents.page.field.mode"),value:p,onChange:C,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(ze,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ft,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(na,{providerId:la(E)?.providerId??"",modelId:la(E)?.modelId??"",onChange:(W,q)=>{A(W&&q?`${W}/${q}`:""),h("")},className:on})}),s.jsx(Ft,{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:ee?s.jsxs(Tt,{value:Z,onValueChange:W=>h(W==="__default"?"":W),children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:W=>W==="__default"?t("chat.modelControls.default"):W})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"__default",children:t("chat.modelControls.default")}),O.map(W=>s.jsx(dt,{value:W,children:W},W))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Be,{value:N,onChange:W=>h(W.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!N,className:"h-8 w-40 rounded-md px-3"}),N&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>h(""),className:ws,"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(Ft,{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(ks,{value:y,fallbackValue:.7,onValueChange:R,onClear:()=>R(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ds}),y!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(void 0),className:ws,"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(Ft,{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(ks,{value:T,fallbackValue:.9,onValueChange:P,onClear:()=>P(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ds}),T!==void 0&&s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(void 0),className:ws,"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.jsx(ze,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ms,{value:D,onChange:W=>V(W.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!v&&u&&s.jsx(_m,{agent:u}),s.jsx("div",{className:"pb-8",children:s.jsx(G,{onClick:_,disabled:$||!ae,size:"xs",className:"!font-normal",children:t($?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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 Vm(t,e){return t.kind==="file"?t.content:e??""}const Hm=un({content:as(),exists:ao(),path:as().min(1).optional()}),qm=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Gm=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,Ni={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Wm=(t,e)=>t==="custom"?e:hd(t),Jm=t=>t==="custom"?"custom":Xl(t)?t:"concise",Go={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"},vr=async(t,e)=>{if(!(await yt(t)).ok)throw new Error(e)},Qm=()=>{const{t}=et(),e=pd(),[a,n]=o.useState(""),[i,r]=o.useState("AGENTS.md"),[l,m]=o.useState(!1),[c,x]=o.useState(Ni.responseStyleEnabled),[u,v]=o.useState(Ni.responseStylePreset),[d,j]=o.useState(Ni.responseStyleCustomInstructions),[g,w]=o.useState(!0),[b,k]=o.useState(!1),[p,C]=o.useState(!1),[E,A]=o.useState(""),[N,h]=o.useState(!1),y=o.useRef(null);o.useEffect(()=>{const $=new AbortController;return(async()=>{try{const[M,H]=await Promise.all([In(),xt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:$.signal})]);let U=Ni,Z;M&&(U={...U,optimizeSystemPrompt:M.optimizeSystemPrompt===!0,responseStyleEnabled:M.responseStyleEnabled===!0,responseStylePreset:Jm(M.responseStylePreset),responseStyleCustomInstructions:M.responseStyleCustomInstructions??""},M.globalBehaviorPrompt!==void 0&&(Z=M.globalBehaviorPrompt));let ee={kind:"missing"};if(H.ok){const O=Hm.parse(await H.json());if($.signal.aborted)return;r(O.path??"AGENTS.md"),O.exists&&(ee={kind:"file",content:O.content})}U={...U,prompt:Vm(ee,Z)},n(U.prompt),m(U.optimizeSystemPrompt),h(U.optimizeSystemPrompt),x(U.responseStyleEnabled),v(U.responseStylePreset),j(U.responseStyleCustomInstructions),A(U.prompt),y.current={enabled:U.responseStyleEnabled,preset:U.responseStylePreset,custom:U.responseStyleCustomInstructions}}catch(M){M.name!=="AbortError"&&console.warn("Failed to load behavior settings:",M)}finally{w(!1)}})(),()=>$.abort()},[]),o.useEffect(()=>{if(g)return;const $=y.current;if($&&$.enabled===c&&$.preset===u&&$.custom===d)return;const I={enabled:c,preset:u,custom:d},M=setTimeout(async()=>{try{await vr({responseStyleEnabled:I.enabled,responseStylePreset:I.preset,responseStyleCustomInstructions:I.custom},t("settings.behavior.page.toast.saveFailed")),y.current=I}catch(H){const U=H instanceof Error?H.message:t("settings.behavior.page.toast.saveFailed");F.error(U)}},400);return()=>clearTimeout(M)},[c,u,d,g,t]);const R=Wm(u,d),T=a!==E,P=l!==N,D=async()=>{k(!0);try{const $=Gm(a),I=await xt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:$})});if(!I.ok)throw new Error(await qm(I,t("settings.behavior.page.toast.saveFailed")));const M=await I.json().catch(()=>null),H=ec(M,"behavior",{id:"agents-md"});await vr({globalBehaviorPrompt:$},t("settings.behavior.page.toast.saveFailed")),n($),A($),F.success(t(H?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch($){console.error("Failed to save behavior:",$);const I=$ instanceof Error?$.message:t("settings.behavior.page.toast.saveFailed");F.error(I)}finally{k(!1)}},V=async()=>{C(!0);try{await vr({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),h(l),aa("behavior",{id:"optimize-system-prompt"}),F.success(t("settings.view.pendingRestart.saved"))}catch($){const I=$ instanceof Error?$.message:t("settings.behavior.page.toast.saveFailed");F.error(I)}finally{C(!1)}};return s.jsxs(is,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(ze,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(mt,{checked:l,onChange:m,disabled:g||p,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(G,{type:"button",size:"xs",onClick:()=>{V()},disabled:g||p||!P,className:"!font-normal",children:t(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:i})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ms,{value:a,onChange:$=>n($.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:g,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(G,{onClick:D,disabled:b||!T||g,size:"xs",className:"!font-normal",children:t(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{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(mt,{checked:c,onChange:x,disabled:g,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ft,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Tt,{value:u,onValueChange:$=>v($),disabled:g||!c,children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{children:$=>$==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Xl($)?t(Go[$]):null})}),s.jsxs(Dt,{children:[gd.map($=>s.jsx(dt,{value:$,children:t(Go[$])},$)),s.jsx(dt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ms,{value:R,onChange:$=>j($.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:g||!c||u!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Ym=t=>{const e=ct.c(176),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,m]=o.useState(""),[c,x]=o.useState(null),[u,v]=o.useState(null),[d,j]=o.useState(!1),[g,w]=o.useState(null),{selectedCommandName:b,setSelectedCommand:k,setCommandDraft:p,createCommand:C,deleteCommand:E,loadCommands:A}=La(qs(Zm)),N=Ws();let h;e[0]!==N?(h=Je=>tc(Je,N),e[0]=N,e[1]=h):h=e[1];const y=La(h);let R;e[2]!==N?(R=Je=>Jr(Je,N),e[2]=N,e[3]=R):R=e[3];const T=Xs(R),P=Xs(Xm);let D,V;e[4]!==A||e[5]!==P||e[6]!==N?(D=()=>{A(N),P(N)},V=[A,P,N],e[4]=A,e[5]=P,e[6]=N,e[7]=D,e[8]=V):(D=e[7],V=e[8]),o.useEffect(D,V);let $;e[9]!==T?($=new Set(T.map(ep)),e[9]=T,e[10]=$):$=e[10];const I=$;let M;if(e[11]!==y||e[12]!==I){let Je;e[14]!==I?(Je=St=>!I.has(St.name),e[14]=I,e[15]=Je):Je=e[15],M=y.filter(Je),e[11]=y,e[12]=I,e[13]=M}else M=e[13];const H=M;let U,Z;e[16]!==b||e[17]!==k||e[18]!==I?(U=()=>{b&&I.has(b)&&k(null)},Z=[b,k,I],e[16]=b,e[17]=k,e[18]=I,e[19]=U,e[20]=Z):(U=e[19],Z=e[20]),o.useEffect(U,Z);let ee;e[21]!==y||e[22]!==a||e[23]!==p||e[24]!==k?(ee=()=>{let Je="new-command",St=1;for(;y.some(Oe=>Oe.name===Je);)Je=`new-command-${St}`,St++;p({name:Je,scope:"user"}),k(Je),a?.()},e[21]=y,e[22]=a,e[23]=p,e[24]=k,e[25]=ee):ee=e[25];const O=ee;let ae;e[26]!==n?(ae=async Je=>{if(Ma(Je)){F.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(Je),v("delete")},e[26]=n,e[27]=ae):ae=e[27];const _=ae;let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=async Je=>{Ma(Je)&&(x(Je),v("reset"))},e[28]=W):W=e[28];const q=W;let L;e[29]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{x(null),v(null)},e[29]=L):L=e[29];const K=L;let z;e[30]!==c||e[31]!==u||e[32]!==E||e[33]!==N||e[34]!==n?(z=async()=>{if(!c||!u)return;j(!0),await E(c.name,N)?(u==="delete"?F.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):F.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),K()):u==="delete"?F.error(n("settings.commands.sidebar.toast.deleteFailed")):F.error(n("settings.commands.sidebar.toast.resetFailed")),j(!1)},e[30]=c,e[31]=u,e[32]=E,e[33]=N,e[34]=n,e[35]=z):z=e[35];const J=z;let oe;e[36]!==y||e[37]!==p||e[38]!==k?(oe=Je=>{const St=Je.name;let Oe=1,wt=`${St}-copy`;for(;y.some(X=>X.name===wt);)Oe++,wt=`${St}-copy-${Oe}`;p({name:wt,scope:Je.scope||"user",description:Je.description,template:Je.template,agent:Je.agent,model:Je.model}),k(wt)},e[36]=y,e[37]=p,e[38]=k,e[39]=oe):oe=e[39];const re=oe;let pe;e[40]===Symbol.for("react.memo_cache_sentinel")?(pe=Je=>{m(Je.name),r(Je)},e[40]=pe):pe=e[40];const ve=pe;let be;e[41]!==y||e[42]!==C||e[43]!==E||e[44]!==i||e[45]!==l||e[46]!==k||e[47]!==N||e[48]!==n?(be=async()=>{if(!i)return;const Je=l.trim().replace(/\s+/g,"-");if(!Je){F.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Je===i.name){r(null);return}if(y.some(Oe=>Oe.name===Je)){F.error(n("settings.commands.sidebar.toast.commandExists"));return}await C({name:Je,description:i.description,template:i.template,agent:i.agent,model:i.model},N)?await E(i.name,N)?(F.success(`Command renamed to "${Je}"`),k(Je)):F.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):F.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=y,e[42]=C,e[43]=E,e[44]=i,e[45]=l,e[46]=k,e[47]=N,e[48]=n,e[49]=be):be=e[49];const te=be;let he,ie,ue,de,Pe,Ae;if(e[50]!==H||e[51]!==O||e[52]!==_||e[53]!==re||e[54]!==a||e[55]!==g||e[56]!==b||e[57]!==k||e[58]!==n){const Je=H.filter(Ma),St=H.filter(tp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Pe=ye("flex h-full flex-col","bg-background"),e[65]=Pe):Pe=e[65];let Oe;e[66]!==n?(Oe=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Oe):Oe=e[67];let wt;e[68]!==Oe?(wt=s.jsx("h2",{className:`${Cn} mb-3`,children:Oe}),e[68]=Oe,e[69]=wt):wt=e[69];let X;e[70]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(ci,{className:"mb-3"}),e[70]=X):X=e[70];let fe;e[71]!==H.length||e[72]!==n?(fe=n("settings.commands.sidebar.total",{count:H.length}),e[71]=H.length,e[72]=n,e[73]=fe):fe=e[73];let Fe;e[74]!==fe?(Fe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:fe}),e[74]=fe,e[75]=Fe):Fe=e[75];let Me;e[76]===Symbol.for("react.memo_cache_sentinel")?(Me=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Me):Me=e[76];let rt;e[77]!==O?(rt=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:O,children:Me}),e[77]=O,e[78]=rt):rt=e[78];let ot;e[79]!==Fe||e[80]!==rt?(ot=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Fe,rt]}),e[79]=Fe,e[80]=rt,e[81]=ot):ot=e[81],e[82]!==wt||e[83]!==ot?(Ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,X,ot]}),e[82]=wt,e[83]=ot,e[84]=Ae):Ae=e[84],he=Ns,ie="flex-1 min-h-0",ue="space-y-1 px-3 py-2",de=H.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:[Je.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")}),[...Je].sort(sp).map(Ge=>s.jsx(Wo,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{k(Ge.name),a?.()},onReset:()=>q(Ge),onDuplicate:()=>re(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:Nt=>w(Nt?Ge.name:null)},Ge.name))]}),St.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")}),[...St].sort(np).map(Ge=>s.jsx(Wo,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{k(Ge.name),a?.()},onRename:()=>ve(Ge),onDelete:()=>_(Ge),onDuplicate:()=>re(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:Nt=>w(Nt?Ge.name:null)},Ge.name))]})]}),e[50]=H,e[51]=O,e[52]=_,e[53]=re,e[54]=a,e[55]=g,e[56]=b,e[57]=k,e[58]=n,e[59]=he,e[60]=ie,e[61]=ue,e[62]=de,e[63]=Pe,e[64]=Ae}else he=e[59],ie=e[60],ue=e[61],de=e[62],Pe=e[63],Ae=e[64];let we;e[85]!==he||e[86]!==ie||e[87]!==ue||e[88]!==de?(we=s.jsx(he,{outerClassName:ie,className:ue,children:de}),e[85]=he,e[86]=ie,e[87]=ue,e[88]=de,e[89]=we):we=e[89];const Le=c!==null&&u!==null;let _e;e[90]!==d?(_e=Je=>{!Je&&!d&&K()},e[90]=d,e[91]=_e):_e=e[91];let Ve;e[92]!==u||e[93]!==n?(Ve=n(u==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=u,e[93]=n,e[94]=Ve):Ve=e[94];let je;e[95]!==Ve?(je=s.jsx(Ht,{children:Ve}),e[95]=Ve,e[96]=je):je=e[96];let ke;e[97]!==c?.name||e[98]!==u||e[99]!==n?(ke=u==="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]=u,e[99]=n,e[100]=ke):ke=e[100];let se;e[101]!==ke?(se=s.jsx(qt,{children:ke}),e[101]=ke,e[102]=se):se=e[102];let le;e[103]!==je||e[104]!==se?(le=s.jsxs(Vt,{children:[je,se]}),e[103]=je,e[104]=se,e[105]=le):le=e[105];let Ie;e[106]!==n?(Ie=n("settings.common.actions.cancel"),e[106]=n,e[107]=Ie):Ie=e[107];let Ne;e[108]!==d||e[109]!==Ie?(Ne=s.jsx(G,{size:"sm",variant:"ghost",onClick:K,disabled:d,children:Ie}),e[108]=d,e[109]=Ie,e[110]=Ne):Ne=e[110];let Re;e[111]!==u||e[112]!==n?(Re=n(u==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=u,e[112]=n,e[113]=Re):Re=e[113];let $e;e[114]!==J||e[115]!==d||e[116]!==Re?($e=s.jsx(G,{size:"sm",onClick:J,disabled:d,children:Re}),e[114]=J,e[115]=d,e[116]=Re,e[117]=$e):$e=e[117];let De;e[118]!==Ne||e[119]!==$e?(De=s.jsxs(rs,{children:[Ne,$e]}),e[118]=Ne,e[119]=$e,e[120]=De):De=e[120];let Ce;e[121]!==le||e[122]!==De?(Ce=s.jsxs($t,{className:"max-w-md",children:[le,De]}),e[121]=le,e[122]=De,e[123]=Ce):Ce=e[123];let Ye;e[124]!==Le||e[125]!==_e||e[126]!==Ce?(Ye=s.jsx(_t,{open:Le,onOpenChange:_e,children:Ce}),e[124]=Le,e[125]=_e,e[126]=Ce,e[127]=Ye):Ye=e[127];const xe=i!==null;let Te;e[128]===Symbol.for("react.memo_cache_sentinel")?(Te=Je=>!Je&&r(null),e[128]=Te):Te=e[128];let Ke;e[129]!==n?(Ke=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Ke):Ke=e[130];let tt;e[131]!==Ke?(tt=s.jsx(Ht,{children:Ke}),e[131]=Ke,e[132]=tt):tt=e[132];const Y=i?.name??"";let Se;e[133]!==n||e[134]!==Y?(Se=n("settings.commands.sidebar.renameDialog.description",{name:Y}),e[133]=n,e[134]=Y,e[135]=Se):Se=e[135];let Ee;e[136]!==Se?(Ee=s.jsx(qt,{children:Se}),e[136]=Se,e[137]=Ee):Ee=e[137];let We;e[138]!==tt||e[139]!==Ee?(We=s.jsxs(Vt,{children:[tt,Ee]}),e[138]=tt,e[139]=Ee,e[140]=We):We=e[140];let lt;e[141]===Symbol.for("react.memo_cache_sentinel")?(lt=Je=>m(Je.target.value),e[141]=lt):lt=e[141];let at;e[142]!==n?(at=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=at):at=e[143];let pt;e[144]!==te?(pt=Je=>{Je.key==="Enter"&&te()},e[144]=te,e[145]=pt):pt=e[145];let bt;e[146]!==l||e[147]!==at||e[148]!==pt?(bt=s.jsx(Be,{value:l,onChange:lt,placeholder:at,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:pt}),e[146]=l,e[147]=at,e[148]=pt,e[149]=bt):bt=e[149];let Q;e[150]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>r(null),e[150]=Q):Q=e[150];let qe;e[151]!==n?(qe=n("settings.common.actions.cancel"),e[151]=n,e[152]=qe):qe=e[152];let it;e[153]!==qe?(it=s.jsx(G,{size:"sm",variant:"ghost",onClick:Q,children:qe}),e[153]=qe,e[154]=it):it=e[154];let ut;e[155]!==n?(ut=n("settings.common.actions.rename"),e[155]=n,e[156]=ut):ut=e[156];let gt;e[157]!==te||e[158]!==ut?(gt=s.jsx(G,{size:"sm",onClick:te,children:ut}),e[157]=te,e[158]=ut,e[159]=gt):gt=e[159];let Ot;e[160]!==it||e[161]!==gt?(Ot=s.jsxs(rs,{children:[it,gt]}),e[160]=it,e[161]=gt,e[162]=Ot):Ot=e[162];let st;e[163]!==We||e[164]!==bt||e[165]!==Ot?(st=s.jsxs($t,{children:[We,bt,Ot]}),e[163]=We,e[164]=bt,e[165]=Ot,e[166]=st):st=e[166];let ft;e[167]!==xe||e[168]!==st?(ft=s.jsx(_t,{open:xe,onOpenChange:Te,children:st}),e[167]=xe,e[168]=st,e[169]=ft):ft=e[169];let jt;return e[170]!==Pe||e[171]!==Ae||e[172]!==we||e[173]!==Ye||e[174]!==ft?(jt=s.jsxs("div",{className:Pe,children:[Ae,we,Ye,ft]}),e[170]=Pe,e[171]=Ae,e[172]=we,e[173]=Ye,e[174]=ft,e[175]=jt):jt=e[175],jt},Wo=t=>{const e=ct.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:m,onDuplicate:c,isMenuOpen:x,onMenuOpenChange:u}=t,{t:v}=et();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ii(),e[0]=d):d=e[0];const j=d,[g,w]=o.useState(!1);let b;e[1]!==r||e[2]!==c||e[3]!==m||e[4]!==l||e[5]!==v?(b=Z=>s.jsxs(s.Fragment,{children:[m&&s.jsxs(Z,{onClick:ee=>{ee.stopPropagation(),m()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(Z,{onClick:ee=>{ee.stopPropagation(),c()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(Z,{onClick:ee=>{ee.stopPropagation(),l()},children:[s.jsx(B,{name:"restart",className:"h-4 w-4 mr-px"}),v("settings.common.actions.reset")]}),r&&s.jsxs(Z,{onClick:ee=>{ee.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),v("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=m,e[4]=l,e[5]=v,e[6]=b):b=e[6];const k=b,p=n?"bg-interactive-selection":"hover:bg-interactive-hover";let C;e[7]!==p?(C=ye("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 E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=j?void 0:Z=>{Z.preventDefault(),w(!0)},e[9]=E):E=e[9];let A;e[10]!==C?(A=s.jsx("div",{className:C,onContextMenu:E}),e[10]=C,e[11]=A):A=e[11];let N;e[12]!==a.name?(N=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=N):N=e[13];let h;e[14]!==a||e[15]!==v?(h=(a.scope||Ma(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:Ma(a)?v("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=v,e[16]=h):h=e[16];let y;e[17]!==N||e[18]!==h?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[N,h]}),e[17]=N,e[18]=h,e[19]=y):y=e[19];let R;e[20]!==a.description?(R=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=R):R=e[21];let T;e[22]!==i||e[23]!==R||e[24]!==y?(T=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:[y,R]}),e[22]=i,e[23]=R,e[24]=y,e[25]=T):T=e[25];let P;e[26]!==u?(P=Z=>{Z&&w(!1),u(Z)},e[26]=u,e[27]=P):P=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(vn,{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]=D):D=e[28];let V;e[29]!==k?(V=s.jsx(yn,{align:"end",className:"w-fit min-w-20",children:k(wn)}),e[29]=k,e[30]=V):V=e[30];let $;e[31]!==x||e[32]!==P||e[33]!==V?($=s.jsxs(jn,{open:x,onOpenChange:P,children:[D,V]}),e[31]=x,e[32]=P,e[33]=V,e[34]=$):$=e[34];let I;e[35]!==T||e[36]!==$?(I=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,$]}),e[35]=T,e[36]=$,e[37]=I):I=e[37];let M;e[38]!==I||e[39]!==A?(M=s.jsx(ma,{render:A,children:I}),e[38]=I,e[39]=A,e[40]=M):M=e[40];let H;e[41]!==k?(H=s.jsx(da,{className:"w-fit min-w-20",children:k(ua)}),e[41]=k,e[42]=H):H=e[42];let U;return e[43]!==g||e[44]!==M||e[45]!==H?(U=s.jsxs(pa,{open:g,onOpenChange:w,children:[M,H]}),e[43]=g,e[44]=M,e[45]=H,e[46]=U):U=e[46],U};function Zm(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Xm(t){return t.loadSkills}function ep(t){return t.name}function tp(t){return!Ma(t)}function sp(t,e){return t.name.localeCompare(e.name)}function np(t,e){return t.name.localeCompare(e.name)}const ap=()=>{const{t}=et(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=La(qs(D=>({selectedCommandName:D.selectedCommandName,getCommandByName:D.getCommandByName,createCommand:D.createCommand,updateCommand:D.updateCommand,commandDraft:D.commandDraft,setCommandDraft:D.setCommandDraft}))),m=Ws(),c=La(D=>tc(D,m)),x=e?a(e,m):null,u=!!(r&&r.name===e&&!x),[v,d]=o.useState(""),[j,g]=o.useState("user"),[w,b]=o.useState(""),[k,p]=o.useState(""),[C,E]=o.useState(""),[A,N]=o.useState(""),[h,y]=o.useState(!1),R=o.useRef(null);o.useEffect(()=>{if(u&&r){const D=r.name||"",V=r.scope||"user",$=r.description||"",I=r.agent||"",M=r.model||"",H=r.template||"";d(D),g(V),b($),p(I),E(M),N(H),R.current={draftName:D,draftScope:V,description:$,agent:I,model:M,template:H}}else if(x){const D=x.description||"",V=x.agent||"",$=x.model||"",I=x.template||"";b(D),p(V),E($),N(I),R.current={draftName:"",draftScope:"user",description:D,agent:V,model:$,template:I}}},[x,u,e,c,r]);const T=o.useMemo(()=>{const D=R.current;return D?!!(u&&(v!==D.draftName||j!==D.draftScope)||w!==D.description||k!==D.agent||C!==D.model||A!==D.template):!1},[k,w,v,j,u,C,A]),P=async()=>{const D=u?v.trim().replace(/\s+/g,"-"):e?.trim();if(!D){F.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!A.trim()){F.error(t("settings.commands.page.toast.templateRequired"));return}if(u&&c.some(V=>V.name===D)){F.error(t("settings.commands.sidebar.toast.commandExists"));return}y(!0);try{const V=k.trim(),$=C.trim(),I=A.trim(),M={name:D,description:w.trim()||void 0,agent:V===""?null:V,model:$===""?null:$,template:I,scope:u?j:void 0};let H;if(u?(H=await n(M,m),H&&l(null)):H=await i(D,M,m),H){const U=ia.getState().changes.some(Z=>Z.scope==="commands"&&Z.id.startsWith(`commands:${D}:`));F.success(t(U?"settings.view.pendingRestart.saved":u?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else F.error(t(u?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(V){console.error("Error saving command:",V),F.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{y(!1)}};return e?s.jsxs(is,{title:u?t("settings.commands.page.title.new"):`/${e}`,description:t(u?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[u&&s.jsxs(Ft,{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(Be,{value:v,onChange:D=>d(D.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:j,onValueChange:D=>g(D),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[100px]",children:s.jsx(Ut,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Dt,{align:"end",children:[s.jsx(dt,{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(dt,{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(Ms,{value:w,onChange:D=>b(D.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(ze,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ft,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(Qr,{agentName:k,onChange:D=>p(D),className:on})}),s.jsx(Ft,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(na,{providerId:la(C)?.providerId??"",modelId:la(C)?.modelId??"",onChange:(D,V)=>{E(D&&V?`${D}/${V}`:"")},className:on})})]}),s.jsxs(ze,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ms,{value:A,onChange:D=>N(D.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(G,{onClick:P,disabled:h||!T,size:"xs",className:"!font-normal",children:t(h?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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")})]})})},Jo=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Qo=t=>{const e=ct.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=ye("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},ip=t=>{const e=ct.c(124),{onItemSelect:a}=t,{t:n}=et(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:m,deleteMcp:c}=Ka(qs(rp)),x=Ws();let u;e[0]!==x?(u=Y=>sc(Y,x),e[0]=x,e[1]=u):u=e[1];const v=Ka(u);let d;e[2]!==x?(d=Y=>Y.getStatusForDirectory(x),e[2]=x,e[3]=d):d=e[3];const j=Vs(d),g=Vs(op),w=Vs(lp),[b,k]=o.useState(null),[p,C]=o.useState(!1),[E,A]=o.useState(null),[N,h]=o.useState(null),[y,R]=o.useState(!1);let T;e[4]!==v?(T=v.filter(cp),e[4]=v,e[5]=T):T=e[5];const P=T;let D;e[6]!==v?(D=v.filter(dp),e[6]=v,e[7]=D):D=e[7];const V=D;let $,I;e[8]!==m||e[9]!==x?($=()=>{m({directory:x})},I=[m,x],e[8]=m,e[9]=x,e[10]=$,e[11]=I):($=e[10],I=e[11]),o.useEffect($,I);let M;e[12]!==w||e[13]!==y||e[14]!==g||e[15]!==x?(M=()=>{if(y)return;R(!0);const Y=new Promise(up);Promise.all([g({directory:x,silent:!0}),Y]).then(()=>{const Se=w(x);Se&&F.error(Se)}).finally(()=>{R(!1)})},e[12]=w,e[13]=y,e[14]=g,e[15]=x,e[16]=M):M=e[16];const H=M;let U;e[17]!==v||e[18]!==a||e[19]!==l||e[20]!==r?(U=()=>{let Y="new-mcp-server",Se=1;for(;v.some(We=>We.name===Y);)Y=`new-mcp-server-${Se}`,Se++;l({name:Y,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(Y),a?.()},e[17]=v,e[18]=a,e[19]=l,e[20]=r,e[21]=U):U=e[21];const Z=U;let ee;e[22]!==c||e[23]!==b||e[24]!==x||e[25]!==n?(ee=async()=>{if(!b)return;C(!0);const Y=await c(b.name,x);Y.ok?Y.reloadFailed?F.warning(Y.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:Y.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):F.success(Y.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):F.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),C(!1)},e[22]=c,e[23]=b,e[24]=x,e[25]=n,e[26]=ee):ee=e[26];const O=ee;let ae;e[27]!==n?(ae=(Y,Se)=>s.jsxs(Se,{onClick:Ee=>{Ee.stopPropagation(),k(Y)},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]=ae):ae=e[28];const _=ae;let W;e[29]===Symbol.for("react.memo_cache_sentinel")?(W=ye("flex h-full flex-col","bg-background"),e[29]=W):W=e[29];let q;e[30]!==n?(q=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=q):q=e[31];let L;e[32]!==q?(L=s.jsx("h2",{className:Cn,children:q}),e[32]=q,e[33]=L):L=e[33];let K;e[34]!==n?(K=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=K):K=e[35];let z;e[36]!==n?(z=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=z):z=e[37];const J=y&&"animate-spin";let oe;e[38]!==J?(oe=ye("h-4 w-4",J),e[38]=J,e[39]=oe):oe=e[39];let re;e[40]!==oe?(re=s.jsx(B,{name:"refresh",className:oe}),e[40]=oe,e[41]=re):re=e[41];let pe;e[42]!==H||e[43]!==y||e[44]!==K||e[45]!==z||e[46]!==re?(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:y,onClick:H,"aria-label":K,title:z,children:re}),e[42]=H,e[43]=y,e[44]=K,e[45]=z,e[46]=re,e[47]=pe):pe=e[47];let ve;e[48]!==L||e[49]!==pe?(ve=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[L,pe]}),e[48]=L,e[49]=pe,e[50]=ve):ve=e[50];let be;e[51]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(ci,{className:"mb-3"}),e[51]=be):be=e[51];let te;e[52]!==v.length||e[53]!==n?(te=n("settings.mcp.sidebar.total",{count:v.length}),e[52]=v.length,e[53]=n,e[54]=te):te=e[54];let he;e[55]!==te?(he=s.jsx("span",{className:"typography-meta text-muted-foreground",children:te}),e[55]=te,e[56]=he):he=e[56];let ie;e[57]!==n?(ie=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=ie):ie=e[58];let ue;e[59]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[59]=ue):ue=e[59];let de;e[60]!==Z||e[61]!==ie?(de=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:Z,title:ie,children:ue}),e[60]=Z,e[61]=ie,e[62]=de):de=e[62];let Pe;e[63]!==he||e[64]!==de?(Pe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[he,de]}),e[63]=he,e[64]=de,e[65]=Pe):Pe=e[65];let Ae;e[66]!==ve||e[67]!==Pe?(Ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,be,Pe]}),e[66]=ve,e[67]=Pe,e[68]=Ae):Ae=e[68];let we;e[69]!==v.length||e[70]!==j||e[71]!==a||e[72]!==E||e[73]!==P||e[74]!==_||e[75]!==N||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==V?(we=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(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:[P.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")}),P.map(Y=>{const Se=j[Y.name],Ee=Jo(Se?.status),We=i===Y.name,lt=ii();return s.jsxs(pa,{open:N===Y.name,onOpenChange:at=>h(at?Y.name:null),children:[s.jsxs(ma,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",We?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:lt?void 0:at=>{at.preventDefault(),h(Y.name)}}),children:[s.jsxs("button",{onClick:()=>{r(Y.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(Qo,{tone:Ee,enabled:Y.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Y.name}),s.jsx("span",{title:Y.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Y.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:Y.type==="local"?Y.command?.join(" ")??"":Y.url??""})]}),s.jsxs(jn,{open:E===Y.name,onOpenChange:at=>{at&&h(null),A(at?Y.name:null)},children:[s.jsx(vn,{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(yn,{align:"end",className:"w-fit min-w-20",children:_(Y,wn)})]})]}),s.jsx(da,{className:"w-fit min-w-20",children:_(Y,ua)})]},Y.name)})]}),V.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.userServers")}),V.map(Y=>{const Se=j[Y.name],Ee=Jo(Se?.status),We=i===Y.name,lt=ii();return s.jsxs(pa,{open:N===Y.name,onOpenChange:at=>h(at?Y.name:null),children:[s.jsxs(ma,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",We?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:lt?void 0:at=>{at.preventDefault(),h(Y.name)}}),children:[s.jsxs("button",{onClick:()=>{r(Y.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(Qo,{tone:Ee,enabled:Y.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Y.name}),s.jsx("span",{title:Y.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Y.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:Y.type==="local"?Y.command?.join(" ")??"":Y.url??""})]}),s.jsxs(jn,{open:E===Y.name,onOpenChange:at=>{at&&h(null),A(at?Y.name:null)},children:[s.jsx(vn,{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(yn,{align:"end",className:"w-fit min-w-20",children:_(Y,wn)})]})]}),s.jsx(da,{className:"w-fit min-w-20",children:_(Y,ua)})]},Y.name)})]})]})}),e[69]=v.length,e[70]=j,e[71]=a,e[72]=E,e[73]=P,e[74]=_,e[75]=N,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=V,e[81]=we):we=e[81];const Le=b!==null;let _e;e[82]!==p?(_e=Y=>{!Y&&!p&&k(null)},e[82]=p,e[83]=_e):_e=e[83];let Ve;e[84]!==n?(Ve=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ve):Ve=e[85];let je;e[86]!==Ve?(je=s.jsx(Ht,{children:Ve}),e[86]=Ve,e[87]=je):je=e[87];const ke=b?.name||"";let se;e[88]!==n||e[89]!==ke?(se=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:ke}),e[88]=n,e[89]=ke,e[90]=se):se=e[90];let le;e[91]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=le):le=e[91];let Ie;e[92]!==se?(Ie=s.jsxs(qt,{children:[se," ",le,"."]}),e[92]=se,e[93]=Ie):Ie=e[93];let Ne;e[94]!==je||e[95]!==Ie?(Ne=s.jsxs(Vt,{children:[je,Ie]}),e[94]=je,e[95]=Ie,e[96]=Ne):Ne=e[96];let Re;e[97]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>k(null),e[97]=Re):Re=e[97];let $e;e[98]!==n?($e=n("settings.common.actions.cancel"),e[98]=n,e[99]=$e):$e=e[99];let De;e[100]!==p||e[101]!==$e?(De=s.jsx(G,{size:"sm",variant:"ghost",onClick:Re,disabled:p,children:$e}),e[100]=p,e[101]=$e,e[102]=De):De=e[102];let Ce;e[103]!==p||e[104]!==n?(Ce=n(p?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=p,e[104]=n,e[105]=Ce):Ce=e[105];let Ye;e[106]!==O||e[107]!==p||e[108]!==Ce?(Ye=s.jsx(G,{size:"sm",onClick:O,disabled:p,children:Ce}),e[106]=O,e[107]=p,e[108]=Ce,e[109]=Ye):Ye=e[109];let xe;e[110]!==De||e[111]!==Ye?(xe=s.jsxs(rs,{children:[De,Ye]}),e[110]=De,e[111]=Ye,e[112]=xe):xe=e[112];let Te;e[113]!==Ne||e[114]!==xe?(Te=s.jsxs($t,{className:"max-w-md",children:[Ne,xe]}),e[113]=Ne,e[114]=xe,e[115]=Te):Te=e[115];let Ke;e[116]!==Le||e[117]!==_e||e[118]!==Te?(Ke=s.jsx(_t,{open:Le,onOpenChange:_e,children:Te}),e[116]=Le,e[117]=_e,e[118]=Te,e[119]=Ke):Ke=e[119];let tt;return e[120]!==Ae||e[121]!==we||e[122]!==Ke?(tt=s.jsxs("div",{className:W,children:[Ae,we,Ke]}),e[120]=Ae,e[121]=we,e[122]=Ke,e[123]=tt):tt=e[123],tt};function rp(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function op(t){return t.refresh}function lp(t){return t.getErrorForDirectory}function cp(t){return t.scope==="project"}function dp(t){return t.scope!=="project"}function up(t){return setTimeout(t,500)}function xn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ga(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function fn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Si(t,e,a){const n=mp(a),i=typeof a.url=="string"?a.url.trim():"",r=Yo(a,"env","environment"),l=Yo(a,"headers"),m=pp(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",x=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",u=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",v=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",d=gp(a),j=hp(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:m,oauthClientId:c,oauthClientSecret:x,oauthScope:u,oauthRedirectUri:v,timeout:d,enabled:j}}function mp(t){const e=t.command,a=t.args;if(Ga(e)&&Ga(a))return[...e,...a];if(Ga(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Ga(a)?[...n,...a]:n}return Ga(a)?a:[]}function Yo(t,...e){for(const a of e){const n=t[a];if(!xn(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function pp(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!xn(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function gp(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function hp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function fp(t){const e=t.mcpServers;if(xn(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(xn(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&xn(i)});if(a.length===1){const n=a[0],i=t[n];if(Ec(i))return{name:n,entry:i}}return null}function Ec(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function xp(t,e){let a;try{const m=t.trim();if(!m)return fn("No JSON content provided");a=JSON.parse(m)}catch(m){return fn(m instanceof Error?`Invalid JSON: ${m.message}`:"Invalid JSON")}if(!xn(a))return fn("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(xn(i)){const m=Object.keys(i);if(m.length===0)return fn("mcpServers object is empty",a);if(m.length>1)return fn("Paste one server at a time. Found "+m.length+" servers in mcpServers",a);const c=m[0],x=i[c];return xn(x)?Si(c,Ci(x),x):fn("Server entry is not a valid object",a)}const r=n.mcp;if(xn(r)){const m=Object.keys(r);if(m.length===0)return fn("mcp object is empty",a);if(m.length>1)return fn("Paste one server at a time. Found "+m.length+" servers in mcp",a);const c=m[0],x=r[c];return xn(x)?Si(c,Ci(x),x):fn("Server entry in mcp is not a valid object",a)}const l=fp(n);if(l)return Si(l.name,Ci(l.entry),l.entry);if(Ec(n)){const m=Ci(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Si(c,m,n)}return fn("No recognizable MCP server configuration found in JSON",a)}function Ci(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 bp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Dc(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function vp(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:bd(a.searchParams),stateKey:nc(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const yp=t=>{const e=ct.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
4
- `),e[0]=a,e[1]=l):l=e[1];const[m,c]=o.useState(l),x=o.useRef(a);let u,v;e[2]!==a?(u=()=>{JSON.stringify(x.current)!==JSON.stringify(a)&&(x.current=a,c(a.join(`
5
- `)))},v=[a],e[2]=a,e[3]=u,e[4]=v):(u=e[3],v=e[4]),o.useEffect(u,v);let d;e[5]!==n||e[6]!==r?(d=N=>{const h=N.split(`
6
- `).filter(Pp);if(r&&h.length===1&&/^https?:\/\/\S+$/i.test(h[0].trim())){r(h[0].trim());return}n(h)},e[5]=n,e[6]=r,e[7]=d):d=e[7];const j=d;let g;e[8]!==n?(g=N=>{const y=N.clipboardData.getData("text").trim();if(!y||y.includes(`
7
- `)||!/\s/.test(y))return;const R=N.currentTarget;if(R.selectionStart!==0||R.selectionEnd!==R.value.length)return;N.preventDefault();const T=Dc(y);c(T.join(`
8
- `)),n(T)},e[8]=n,e[9]=g):g=e[9];const w=g;let b;e[10]!==j?(b=N=>{c(N.target.value),j(N.target.value)},e[10]=j,e[11]=b):b=e[11];let k;e[12]!==j||e[13]!==m?(k=()=>{const N=m.split(`
9
- `).map(Ap).join(`
10
- `);c(N),j(N)},e[12]=j,e[13]=m,e[14]=k):k=e[14];const p=Math.max(4,a.length+1);let C;e[15]!==w||e[16]!==b||e[17]!==k||e[18]!==p||e[19]!==m?(C=s.jsx(Ms,{onPaste:w,value:m,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]=w,e[16]=b,e[17]=k,e[18]=p,e[19]=m,e[20]=C):C=e[20];let E;e[21]!==i||e[22]!==a?(E=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(Tp)})})]}),e[21]=i,e[22]=a,e[23]=E):E=e[23];let A;return e[24]!==E||e[25]!==C?(A=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[C,E]}),e[24]=E,e[25]=C,e[26]=A):A=e[26],A},jp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Zo=({value:t,onChange:e,keyTransform:a=jp,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:m,importSuccess:c,clipboardReadFailed:x,keyLabel:u,valueLabel:v,valuePlaceholder:d,hideValueTitle:j,showValueTitle:g,addVariable:w,plainTextWarning:b,removeVariableAria:k})=>{const[p,C]=o.useState(new Set),E=()=>e([...t,{key:"",value:""}]),A=T=>{e(t.filter((P,D)=>D!==T)),C(P=>{const D=new Set(P);return D.delete(T),D})},N=(T,P,D)=>{const V=[...t];V[T]={...V[T],[P]:D},e(V)},h=T=>{C(P=>{const D=new Set(P);return D.has(T)?D.delete(T):D.add(T),D})},y=async()=>{try{const T=await navigator.clipboard.readText(),P=[];for(const V of T.split(`
14
- `)){const $=V.trim();if(!$||$.startsWith("#"))continue;const I=$.indexOf("=");if(I===-1)continue;const M=$.slice(0,I).trim();let H=$.slice(I+1).trim();(H.startsWith('"')&&H.endsWith('"')||H.startsWith("'")&&H.endsWith("'"))&&(H=H.slice(1,-1)),M&&P.push({key:M,value:H})}if(P.length===0){F.error(m);return}const D=[...t];for(const V of P){const $=D.findIndex(I=>I.key===V.key);$!==-1?D[$]=V:D.push(V)}e(D),F.success(c(P.length))}catch{F.error(x)}},R=t.some(T=>T.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:u}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:y,type:"button",title:l,children:[s.jsx(B,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:T.key,onChange:D=>N(P,"key",a(D.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Be,{type:p.has(P)?"text":"password",value:T.value,onChange:D=>N(P,"value",D.target.value),placeholder:d,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>h(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:p.has(P)?j:g,children:p.has(P)?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:()=>A(P),"aria-label":k,children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},P))}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:E,type:"button",children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),w]}),R&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:b})]})},yr=t=>{const e=ct.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let m,c;if(e[0]!==i||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const d={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const j=ye("typography-micro font-medium rounded-full px-2 py-0.5",d.text,d.bg);let g;e[5]!==i||e[6]!==a?(g=i(a),e[5]=i,e[6]=a,e[7]=g):g=e[7],c=s.jsxs("span",{className:j,children:["● ",g]});break e}m=ye("typography-micro font-medium",d.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=m,e[4]=c}else m=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let x;e[8]!==i||e[9]!==a?(x=i(a),e[8]=i,e[9]=a,e[10]=x):x=e[10];let u;return e[11]!==m||e[12]!==x?(u=s.jsxs("span",{className:m,children:["● ",x]}),e[11]=m,e[12]=x,e[13]=u):u=e[13],u},wp=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},kp=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Np=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),Sp=async t=>{const e=await xt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},Wa=async t=>{typeof t!="string"||!t.trim()||await xt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Ii=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},Cp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Ip=()=>{const{t}=et(),e=o.useCallback((me,ht)=>t(me,ht),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:m,updateMcp:c,deleteMcp:x}=Ka(qs(me=>({selectedMcpName:me.selectedMcpName,mcpDraft:me.mcpDraft,setMcpDraft:me.setMcpDraft,setSelectedMcp:me.setSelectedMcp,getMcpByName:me.getMcpByName,createMcp:me.createMcp,updateMcp:me.updateMcp,deleteMcp:me.deleteMcp}))),u=Ws(),v=o.useMemo(()=>ds(),[]),d=Vs(me=>me.getStatusForDirectory(u)),j=Vs(me=>me.getDiagnosticForDirectory(u)),g=Vs(me=>me.refresh),w=Vs(me=>me.connect),b=Vs(me=>me.disconnect),k=Vs(me=>me.completeAuth),p=Vs(me=>me.clearAuth),C=Vs(me=>me.testConnection),E=ia(me=>me.changes),A=Ka(me=>sc(me,u)),N=a?l(a,u):null,h=!!(n&&n.name===a&&!N),[y,R]=o.useState(""),[T,P]=o.useState("user"),[D,V]=o.useState("local"),[$,I]=o.useState([]),[M,H]=o.useState(""),[U,Z]=o.useState([]),[ee,O]=o.useState([]),[ae,_]=o.useState(!0),[W,q]=o.useState(""),[L,K]=o.useState(""),[z,J]=o.useState(""),[oe,re]=o.useState(""),[pe,ve]=o.useState(""),[be,te]=o.useState(!0),[he,ie]=o.useState(!1),[ue,de]=o.useState(!1),[Pe,Ae]=o.useState(!1),[we,Le]=o.useState(!1),[_e,Ve]=o.useState(!1),[je,ke]=o.useState(!1),[se,le]=o.useState(!1),[Ie,Ne]=o.useState(!1),[Re,$e]=o.useState(null),[De,Ce]=o.useState(null),[Ye,xe]=o.useState(""),[Te,Ke]=o.useState(!1),tt=o.useRef(0),Y=o.useRef(!1),[Se,Ee]=o.useState(!1),[We,lt]=o.useState(!1),[at,pt]=o.useState(""),[bt,Q]=o.useState(null),qe=o.useMemo(()=>Cp(a,u),[u,a]),it=o.useRef(qe),ut=o.useRef(null),gt=o.useCallback(()=>{$e(null),Ce(null),xe(""),Ke(!1),tt.current=0,Ne(!1),Ve(!1),ke(!1),Y.current=!1},[]),Ot=o.useCallback(()=>{pt(""),Q(null),lt(!0)},[]),st=o.useCallback(async()=>{try{const me=await navigator.clipboard.readText();pt(me),Q(null)}catch{F.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ft=o.useCallback(()=>{const me=xp(at,{fallbackName:y});if(!me.ok){Q(me.error);return}const kt=bp(me,{name:y,scope:T,type:D,command:$,url:M,environment:U,headers:ee,oauthEnabled:ae,oauthClientId:W,oauthClientSecret:L,oauthScope:z,oauthRedirectUri:oe,timeout:pe,enabled:be},{isNewServer:h});R(kt.name),V(kt.type),I(kt.command??[]),H(kt.url??""),Z(kt.environment??[]),O(kt.headers??[]),_(kt.oauthEnabled??!1),q(kt.oauthClientId??""),K(kt.oauthClientSecret??""),J(kt.oauthScope??""),re(kt.oauthRedirectUri??""),ve(kt.timeout??""),te(kt.enabled??!0),lt(!1),pt(""),Q(null),F.success(t("settings.mcp.page.toast.configImported"))},[at,y,T,D,$,M,U,ee,ae,W,L,z,oe,pe,be,h,t]);o.useEffect(()=>{if(h&&n){R(n.name),P(n.scope||"user"),V(n.type),I(n.command),H(n.url),Z(n.environment),O(n.headers),_(n.oauthEnabled),q(n.oauthClientId),K(n.oauthClientSecret),J(n.oauthScope),re(n.oauthRedirectUri),ve(n.timeout),te(n.enabled),Ee(!1),ut.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(N){P(N.scope==="project"?"project":"user");const me=bo(N.environment),ht=N.type==="remote"?N:null,kt=bo(ht?.headers),Xt=ht?.oauth,ss=Xt&&typeof Xt=="object"?Xt:null,Jt=Xt!==!1,ps=N.type,Ss=ps==="local"?N.command??[]:[],us=ps==="remote"?N.url??"":"",It=typeof ht?.timeout=="number"&&Number.isFinite(ht.timeout)?String(ht.timeout):"";V(ps),I(Ss),H(us),Z(me),O(kt),_(Jt),q(Jt?ss?.clientId??"":""),K(Jt?ss?.clientSecret??"":""),J(Jt?ss?.scope??"":""),re(Jt?ss?.redirectUri??"":""),ve(It),te(N.enabled),Ee(!1),ut.current={mcpType:ps,command:Ss,url:us,envEntries:me,headerEntries:kt,oauthEnabled:Jt,oauthClientId:Jt?ss?.clientId??"":"",oauthClientSecret:Jt?ss?.clientSecret??"":"",oauthScope:Jt?ss?.scope??"":"",oauthRedirectUri:Jt?ss?.redirectUri??"":"",timeout:It,enabled:N.enabled}}},[N,h,n]);const jt=o.useMemo(()=>{const me=ut.current;return me?D!==me.mcpType||be!==me.enabled||JSON.stringify($)!==JSON.stringify(me.command)||M!==me.url||JSON.stringify(U)!==JSON.stringify(me.envEntries)||JSON.stringify(ee)!==JSON.stringify(me.headerEntries)||ae!==me.oauthEnabled||W!==me.oauthClientId||L!==me.oauthClientSecret||z!==me.oauthScope||oe!==me.oauthRedirectUri||pe!==me.timeout:!1},[D,$,M,U,ee,ae,W,L,z,oe,pe,be]),Je=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]),St=o.useCallback(me=>{V("remote"),H(me),I([])},[]),Oe=o.useCallback(me=>{H(me);const ht=me.trim();ht&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ht)&&/\s/.test(ht)&&(V("local"),I(Dc(ht)),H(""))},[]),wt=async()=>{const me=h?y.trim():a??"";if(!me){F.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&A.some(kt=>kt.name===me)){F.error(t("settings.mcp.page.toast.serverNameExists"));return}if(D==="local"&&$.filter(Boolean).length===0){F.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(D==="remote"&&!M.trim()){F.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ht={name:me,scope:T,type:D,command:$,url:M,environment:U,headers:ee,oauthEnabled:ae,oauthClientId:W,oauthClientSecret:L,oauthScope:z,oauthRedirectUri:oe,timeout:pe,enabled:be};ie(!0);try{const kt=h?await m(ht,u):await c(me,ht,u);kt.ok?(await Wa(De),gt(),h&&(i(null),r(me)),await g({directory:u,silent:!0}),kt.reloadFailed?F.warning(kt.message||t(h?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:kt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):kt.restartDeferred?F.success(t("settings.view.pendingRestart.saved")):F.success(kt.message||t(h?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):F.error(t("settings.mcp.page.toast.saveFailed"))}catch(kt){F.error(kt instanceof Error?kt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ie(!1)}},X=async()=>{if(!a)return;Ae(!0);const me=await x(a,u);me.ok?(await Wa(De),gt(),me.reloadFailed?F.warning(me.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:me.warning||t("settings.mcp.page.toast.refreshListIfStale")}):F.success(me.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),de(!1)):F.error(t("settings.mcp.page.toast.deleteFailed")),Ae(!1)},fe=async()=>{if(a){Le(!0);try{if(d[a]?.status==="connected")await b(a,u),F.success(t("settings.mcp.page.toast.disconnected"));else{await w(a,u),await g({directory:u,silent:!0});const ht=Vs.getState().getStatusForDirectory(u)[a];ht?.status==="connected"?F.success(t("settings.mcp.page.toast.connected")):ht?.status==="needs_auth"?F.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht?.status==="needs_client_registration"?F.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht?.status==="failed"?F.error(ht.error||t("settings.mcp.page.toast.connectionFailed")):F.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await g({directory:u,silent:!0})}catch(me){F.error(me instanceof Error?me.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Le(!1)}}},Fe=o.useCallback(()=>h?(F.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):jt?(F.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[jt,h,t]),Me=o.useCallback(async(me=!1)=>{try{await g({directory:u,silent:me})}catch(ht){me||F.error(ht instanceof Error?ht.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,g,t]);o.useEffect(()=>{Me(!0)},[Me]),o.useEffect(()=>{it.current=qe,Le(!1),le(!1),gt()},[gt,qe]);const rt=o.useCallback(async()=>{if(!a||D!=="remote"||!Fe())return;Ve(!0);const me=qe;let ht=null;try{const kt=Vs.getState().getStatusForDirectory(u)[a]?.status;Y.current=kt==="needs_auth"||kt==="needs_client_registration";const{authorizationUrl:Xt,opened:ss,nativeFlow:Jt,completion:ps}=await fd({name:a,directory:u});if(Jt){if(it.current!==me)return;$e(null),Ce(null),Ke(!0),tt.current=0,F.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),ps?.then(()=>{it.current===me&&(Ke(!1),tt.current=0,Y.current=!1,F.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(us=>{it.current===me&&(Ke(!1),tt.current=0,Y.current=!1,F.error(Ii(us,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const Ss=nc(new URL(Xt).searchParams);if(ht=Ss,it.current!==me||($e(Xt),Ce(Ss??null),Ke(!0),tt.current=0,it.current!==me))return;ss?F.message(t(v?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):F.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(kt){await Wa(ht),it.current===me&&F.error(Ii(kt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{it.current===me&&Ve(!1)}},[u,v,D,Fe,qe,a,t,e]),ot=o.useCallback(async()=>{if(!a||!Fe())return;ke(!0);const me=qe;try{if(await p(a,u),it.current!==me)return;$e(null),Ce(null),xe(""),Ke(!1),tt.current=0,await Wa(De),F.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ht){it.current===me&&F.error(Ii(ht,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{it.current===me&&ke(!1)}},[De,p,u,Fe,qe,a,t,e]),Ge=o.useCallback(async()=>{if(!Re)return;if((await Ra(Re)).ok){F.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}F.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Re,t]),Nt=o.useCallback(async()=>{const me=vp(Ye);if(!me.code){F.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ht=me.stateKey?await Sp(me.stateKey):null,kt=me.context??ht,Xt=kt?.name??a,ss=kt?.directory??u;if(!Xt){F.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!kt&&!Fe())return;Ne(!0);const Jt=qe;try{if(await k(Xt,me.code,ss),await Wa(me.stateKey??De),it.current!==Jt)return;xe(""),$e(null),Ce(null),Ke(!1),tt.current=0,F.success(Xt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Xt}))}catch(ps){it.current===Jt&&F.error(Ii(ps,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{it.current===Jt&&Ne(!1)}},[Ye,De,k,u,Fe,qe,a,t,e]),ns=o.useCallback(async()=>{if(!(!a||!Fe())){if(!be){F.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}le(!0);try{const me=await C(a,u),ht=me.status?.status;me.warning?F.warning(me.warning):ht==="connected"?F.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ht==="needs_auth"?F.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht==="needs_client_registration"?F.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht==="failed"?F.error(me.status?.error||me.error||t("settings.mcp.page.toast.connectionTestFailed")):me.error?F.error(me.error):F.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(me){F.error(me instanceof Error?me.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{le(!1)}}},[u,be,Fe,a,t,C]);if(o.useEffect(()=>{if(!Te||!a)return;const me=window.setInterval(()=>{(async()=>{tt.current+=1,await g({directory:u,silent:!0});const ht=Vs.getState().getStatusForDirectory(u)[a];if(ht){if(Y.current&&ht.status!=="needs_auth"&&ht.status!=="needs_client_registration"){Ke(!1),tt.current=0,Y.current=!1,$e(null),xe(""),ht.status==="connected"&&F.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Y.current&&ht.status==="failed"){Ke(!1),tt.current=0,Y.current=!1,F.error(ht.error||t("settings.mcp.page.toast.authorizationFailed"));return}tt.current>=30&&(Ke(!1),tt.current=0,Y.current=!1,F.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(me)}},[u,Te,g,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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 Zt=d[a],Qe=a?j[a]:void 0,He=Zt??Qe,Ct=!h&&!He&&E.some(me=>me.scope==="mcp"&&me.id.startsWith(`mcp:${a}:`)),Pt=Zt?.status==="connected",es=Zt?.status==="needs_auth"||Zt?.status==="needs_client_registration",ts=v||!a?null:xd(a),os=async()=>{if(ts)try{await navigator.clipboard.writeText(ts),F.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{F.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},xs=wp(He?.status,e,He&&"error"in He?He.error:void 0),Fs=me=>{switch(me){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return me}};return s.jsxs(s.Fragment,{children:[s.jsxs(is,{title:h?t("settings.mcp.page.header.newServer"):a,titleAccessory:h?void 0:s.jsx(yr,{status:Ct?"awaiting_restart":He?.status,enabled:be,getStatusLabel:Fs,variant:"pill"}),description:h?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(D==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!Ct?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{variant:Pt?"outline":"default",size:"xs",className:"!font-normal",onClick:fe,disabled:we||!be,children:t(we?"settings.mcp.page.actions.working":Pt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),D==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(G,{variant:es?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:_e||!be,children:t(_e?"settings.mcp.page.actions.starting":Pt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ot()},disabled:je||!be,children:t(je?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Pt&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ns()},disabled:se||!be,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[Ct&&s.jsx(ze,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Kt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(yr,{status:"awaiting_restart",enabled:be,getStatusLabel:Fs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!h&&!Ct&&Np(He?.status,Re,es,Te)&&s.jsx(ze,{divider:!1,children:s.jsxs("div",{className:ye("rounded-lg border p-3",kp(He?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Kt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(yr,{status:He?.status,enabled:be,getStatusLabel:Fs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:xs}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Pt&&s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},disabled:se||!be,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),He?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(dn,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),ts&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:ts}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{os()},children:[s.jsx(B,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(At,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Be,{value:W,onChange:me=>{q(me.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(At,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Be,{type:"password",value:L,onChange:me=>{K(me.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Re&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Re}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{bn(Re)},children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ge()},children:[s.jsx(B,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),v&&D==="remote"&&(es||Te||Re)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(dn,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Ms,{value:Ye,onChange:me=>xe(me.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:Ie,children:t(Ie?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Te&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(ze,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:h?s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Ot,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:[h&&s.jsxs(Ft,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Be,{value:y,onChange:me=>R(me.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Tt,{value:T,onValueChange:me=>P(me),children:[s.jsxs(Et,{size:Bt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(B,{name:T==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(T==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Dt,{align:"end",children:[s.jsx(dt,{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(dt,{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(mt,{checked:be,onChange:te,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(ze,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(no,{items:Je,activeId:D,onSelect:me=>V(me),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),D==="local"?s.jsx(yp,{value:$,onChange:I,preview:me=>t("settings.mcp.page.connection.previewArgs",{count:me}),onDetectUrl:St}):s.jsx(Be,{value:M,onChange:me=>Oe(me.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(D==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),D==="remote"&&s.jsx(ze,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(kn,{open:Se,onOpenChange:Ee,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")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",ee.length," ",t("settings.mcp.page.advanced.headers"),pe?` · ${pe}ms`:"",")"]})]}),Se?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.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Kt,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Yt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Be,{type:"number",min:"1",step:"1",value:pe,onChange:me=>ve(me.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(dn,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ee.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ee.length,")"]})]}),s.jsx(Zo,{value:ee,onChange:O,keyTransform:me=>me.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:me=>t("settings.mcp.page.toast.importedVariablesCount",{count:me}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(ze,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:U.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",U.length,")"]}):null,settingsItem:"mcp.environment",children:U.length===0?s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Z([{key:"",value:""}]),children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Zo,{value:U,onChange:Z,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:me=>t("settings.mcp.page.toast.importedVariablesCount",{count:me}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(G,{onClick:wt,disabled:he||!jt&&!h,size:"xs",className:"!font-normal",children:t(he?"settings.common.actions.saving":h?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!h&&s.jsx(G,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>de(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(_t,{open:We,onOpenChange:me=>{me||(lt(!1),pt(""),Q(null))},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(qt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ms,{value:at,onChange:me=>{pt(me.target.value),Q(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"}),bt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:bt}),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:st,type:"button",children:[s.jsx(B,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(rs,{children:[s.jsx(G,{variant:"outline",onClick:()=>{lt(!1),pt(""),Q(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{onClick:ft,disabled:!at.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(_t,{open:ue,onOpenChange:me=>{!me&&!Pe&&de(!1)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(qt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(rs,{children:[s.jsx(G,{variant:"outline",onClick:()=>de(!1),disabled:Pe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(G,{variant:"destructive",size:"sm",onClick:X,disabled:Pe,children:t(Pe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Pp(t){return t.trim().length>0}function Ap(t){return t.trimEnd()}function Tp(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 Li=()=>{try{const e=en.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=Mn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Ep=800,Dp=5e3,Mp="__default__",_r=new Map,jr=new Map,Rp=1500,Mc=t=>t?.trim()||Mp,Fp=t=>{_r.delete(Mc(t))},js=Ic()(tm(sm((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=Li(),i=Mc(n),r=Date.now(),l=_r.get(i)??0,m=e().entries.length>0||e().files.length>0;if(!a?.force&&m&&r-l<Dp)return!0;const c=jr.get(i);if(!a?.force&&c)return c;const x=(async()=>{t({isLoading:!0});try{const u=await xt(_n("/api/config/plugins",n),{headers:Ja(n)});if(!u.ok)throw new Error("Failed to load plugins");const v=await Ki(u);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),_r.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(u){return console.error("[PluginsStore] Failed to load plugins:",u),t({isLoading:!1}),!1}})();jr.set(i,x);try{return await x}finally{jr.delete(i)}},loadRegistryInfo:async a=>{const n=Lp(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=Li(),r={...e().registryInfo};for(const l of Kp(n)){const m=await xt(Op(l,a?.force===!0,i),{headers:Ja(i)});if(!m.ok)throw new Error("Failed to load plugin registry info");const c=await Ki(m);for(const x of c.results??[])r[x.spec]=x}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await Pa("Creating plugin entry…",async i=>await xt(_n("/api/config/plugins/entry",i),{method:"POST",headers:Pi(i),body:JSON.stringify(Xo(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(m=>m.id===a)?.spec,r=n.spec??i,l=await Pa("Updating plugin entry…",async m=>await xt(_n(`/api/config/plugins/entry/${encodeURIComponent(a)}`,m),{method:"PATCH",headers:Pi(m),body:JSON.stringify(Xo(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await Pa("Deleting plugin entry…",async r=>await xt(_n(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Ja(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=Li(),i=await xt(_n(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ja(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await Ki(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>Pa("Creating plugin file…",async n=>await xt(_n("/api/config/plugins/file",n),{method:"POST",headers:Pi(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>Pa("Updating plugin file…",async i=>await xt(_n(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:Pi(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await Pa("Deleting plugin file…",async i=>await xt(_n(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Ja(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:xu(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function _n(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function Op(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function Lp(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Kp(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>Rp?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Ja(t){return t?{"x-opencode-directory":t}:void 0}function Pi(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function Xo(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function Pa(t,e,a,n){try{const i=Li(),r=await e(i),l=await Ki(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return Fp(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):ec(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(vd(t),await yd({message:l.message,delayMs:l.reloadDelayMs??Ep,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function Ki(t){return await t.json()}const zp=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Up(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 _p=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=et(),i=js(I=>I.createEntry),r=js(I=>I.createFile),[l,m]=o.useState("npm"),[c,x]=o.useState(""),[u,v]=o.useState(""),[d,j]=o.useState(""),[g,w]=o.useState(""),[b,k]=o.useState(a),[p,C]=o.useState(!1),E=o.useCallback(()=>{x(""),v(""),j(""),w(""),k(a)},[a]);o.useEffect(()=>{t&&(m("npm"),E())},[t,E]);const A=I=>{I!==l&&(m(I),E())},N=o.useMemo(()=>Up(u),[u]),h=!N.ok,y=l==="file"&&d.trim()!==""&&!zp.test(d.trim()),R=(l==="npm"||l==="path")&&c.trim()==="",T=l==="file"&&g.trim()==="",P=l==="file"&&d.trim()==="",D=p||h||l==="npm"&&R||l==="path"&&R||l==="file"&&(P||y||T),V=async()=>{if(!D){C(!0);try{let I;l==="file"?I=await r({fileName:d.trim(),content:g,scope:b}):I=await i({spec:c.trim(),options:N.ok?N.value:void 0,scope:b}),I.ok?(I.restartDeferred?F.success(n("settings.view.pendingRestart.saved")):F.success(I.message||n("settings.plugins.toast.created")),I.reloadFailed&&F.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):F.error(I.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{C(!1)}}},$=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(_t,{open:t,onOpenChange:I=>{!I&&p||e(I)},children:s.jsxs($t,{className:"max-w-xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:n("settings.plugins.dialog.add.title")}),s.jsx(qt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(no,{items:$,activeId:l,onSelect:I=>A(I),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(Be,{id:"plugin-spec",value:c,onChange:I=>x(I.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":R?!1:void 0,disabled:p}),R&&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(Ms,{id:"plugin-options",value:u,onChange:I=>v(I.target.value),rows:5,className:"font-mono",hasError:h,disabled:p}),h&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(Be,{id:"plugin-filename",value:d,onChange:I=>j(I.target.value),placeholder:"my-plugin.ts","aria-invalid":y||void 0,disabled:p}),y&&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(Ms,{id:"plugin-content",value:g,onChange:I=>w(I.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(I=>{const M=b===I,H=n(I==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(I),disabled:p,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Yr,{checked:M,onChange:()=>k(I),ariaLabel:H}),s.jsx("span",{className:ye("typography-ui-label font-normal",M?"text-foreground":"text-foreground/60"),children:H})]},I)})})]})]}),s.jsxs(rs,{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:()=>{V()},disabled:D,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")]})]})]})})},$p=t=>{const e=ct.c(33),{spec:a}=t;let n;e[0]!==a?(n=m=>m.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=js(n),{t:r}=et();if(!i)return null;const l=Bp;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=m):m=e[2];let c;e[3]!==i.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[m,i.latestVersion]}),e[3]=i.latestVersion,e[4]=c):c=e[4];let x;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==c?(x=l(c,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=c,e[9]=x):x=e[9],x}case"npm-missing-version":{let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=m):m=e[10];let c;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(c=l(m,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=c):c=e[14],c}case"npm-missing-package":{let m;e[15]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=m):m=e[15];let c;return e[16]!==i.name||e[17]!==r?(c=l(m,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=c):c=e[18],c}case"npm-malformed":{let m;e[19]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=m):m=e[19];let c;return e[20]!==r?(c=l(m,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=c):c=e[21],c}case"npm-network":{let m;e[22]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=m):m=e[22];let c;return e[23]!==r?(c=l(m,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=c):c=e[24],c}case"path-missing":{let m;e[25]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=m):m=e[25];let c;return e[26]!==i.absolutePath||e[27]!==r?(c=l(m,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=c):c=e[28],c}case"path-unreadable":{let m;e[29]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(B,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=m):m=e[29];let c;return e[30]!==i.absolutePath||e[31]!==r?(c=l(m,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function Bp(t,e){return s.jsxs(Zr,{children:[s.jsx(Xr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(ac,{children:e})]})}const Rc=t=>{const e=ct.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,m=l===void 0?"sidebar":l,c=ds(),x=o.useRef(null),[u,v]=o.useState(!1),[d,j]=o.useState(!1),g=m==="background"||c?"bg-background":"bg-sidebar",w=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const D=x.current;if(!D){v(!1),j(!1);return}if(!(D.scrollHeight>D.clientHeight+1)){v(!1),j(!1);return}v(D.scrollTop>1),j(D.scrollTop+D.clientHeight<D.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 C;e[2]!==i?(C=[i,k],e[2]=i,e[3]=C):C=e[3],o.useEffect(p,C);let E,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const D=x.current;if(!D)return;const V=()=>k();return D.addEventListener("scroll",V,{passive:!0}),()=>D.removeEventListener("scroll",V)},A=[k],e[4]=E,e[5]=A):(E=e[4],A=e[5]),o.useEffect(E,A);let N;e[6]!==g||e[7]!==r?(N=ye("flex h-full flex-col",g,r),e[6]=g,e[7]=r,e[8]=N):N=e[8];let h;e[9]!==i?(h=s.jsx(Ns,{ref:x,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=h):h=e[10];let y;e[11]!==w||e[12]!==u?(y=u&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${w} 0%, transparent 100%)`}}),e[11]=w,e[12]=u,e[13]=y):y=e[13];let R;e[14]!==w||e[15]!==d?(R=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${w} 0%, transparent 100%)`}}),e[14]=w,e[15]=d,e[16]=R):R=e[16];let T;e[17]!==R||e[18]!==h||e[19]!==y?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,y,R]}),e[17]=R,e[18]=h,e[19]=y,e[20]=T):T=e[20];let P;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==N?(P=s.jsxs("div",{className:N,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=N,e[25]=P):P=e[25],P},$r=t=>{const e=ct.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:m,className:c}=t,x=i===void 0?!1:i,u=m&&m.length>0,v=x?"bg-interactive-selection":"hover:bg-interactive-hover";let d;e[0]!==c||e[1]!==v?(d=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,c),e[0]=c,e[1]=v,e[2]=d):d=e[2];let j;e[3]!==a?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=j):j=e[4];let g;e[5]!==l||e[6]!==j?(g=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,j]}),e[5]=l,e[6]=j,e[7]=g):g=e[7];let w;e[8]!==n?(w=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=w):w=e[9];let b;e[10]!==r||e[11]!==g||e[12]!==w?(b=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:[g,w]}),e[10]=r,e[11]=g,e[12]=w,e[13]=b):b=e[13];let k;e[14]!==m||e[15]!==u?(k=u&&s.jsxs(jn,{children:[s.jsx(vn,{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(yn,{align:"end",className:"w-fit min-w-20",children:m.map(Vp)})]}),e[14]=m,e[15]=u,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 C;return e[20]!==d||e[21]!==p?(C=s.jsx("div",{className:d,children:p}),e[20]=d,e[21]=p,e[22]=C):C=e[22],C};function Vp(t){const e=t.icon;return s.jsxs(wn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ye(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 Hp=t=>t.parsedKind==="npm"?"code-box":"folder",qp=t=>{const e=ct.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=et(),{entries:r,files:l,selectedId:m,setSelected:c,deleteEntry:x,deleteFile:u,loadPlugins:v}=js(qs(Gp)),d=js(Wp),j=js(Jp),g=js(Qp),w=js(Yp),[b,k]=o.useState(null),[p,C]=o.useState(!1),[E,A]=o.useState(!1);let N,h;e[0]!==v?(N=()=>{v()},h=[v],e[0]=v,e[1]=N,e[2]=h):(N=e[1],h=e[2]),o.useEffect(N,h);let y,R;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const st=()=>A(!0);return window.addEventListener("openchamber:settings-open-plugin-add",st),()=>window.removeEventListener("openchamber:settings-open-plugin-add",st)},R=[],e[3]=y,e[4]=R):(y=e[3],R=e[4]),o.useEffect(y,R);let T;if(e[5]!==r||e[6]!==d){T={userEntries:0,projectEntries:0};for(const st of r){const ft=d[st.spec];ft?.kind==="npm-ok"&&ft.hasUpdate&&(st.scope==="user"?T.userEntries=T.userEntries+1:st.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=r,e[6]=d,e[7]=T}else T=e[7];const P=T;let D;e[8]!==r?(D=r.filter(Zp),e[8]=r,e[9]=D):D=e[9];const V=D;let $;e[10]!==r?($=r.filter(Xp),e[10]=r,e[11]=$):$=e[11];const I=$;let M;e[12]!==l?(M=l.filter(eg),e[12]=l,e[13]=M):M=e[13];const H=M;let U;e[14]!==l?(U=l.filter(tg),e[14]=l,e[15]=U):U=e[15];const Z=U,ee=r.length+l.length,O=ee===0;let ae;e[16]!==n?(ae=()=>{n?n():A(!0)},e[16]=n,e[17]=ae):ae=e[17];const _=ae;let W;e[18]!==a||e[19]!==c?(W=st=>{c(st),a?.()},e[18]=a,e[19]=c,e[20]=W):W=e[20];const q=W;let L;e[21]!==r||e[22]!==d||e[23]!==i||e[24]!==w?(L=async st=>{const ft=r.find(Oe=>Oe.id===st);if(!ft)return;const jt=d[ft.spec];if(!jt||jt.kind!=="npm-ok"||!jt.hasUpdate||!jt.latestVersion)return;const Je=jt.latestVersion;(await w(st)).ok?F.success(i("settings.plugins.toast.updatedToLatest",{version:Je})):F.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=d,e[23]=i,e[24]=w,e[25]=L):L=e[25];const K=L;let z;e[26]!==g||e[27]!==i?(z=async()=>{F.info(i("settings.plugins.toast.refreshing"));try{await g({force:!0})}catch{F.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=g,e[27]=i,e[28]=z):z=e[28];const J=z;let oe;e[29]!==x||e[30]!==u||e[31]!==b||e[32]!==i?(oe=async()=>{if(!b)return;C(!0);const st=b.kind==="entry"?await x(b.id):await u(b.id);st.ok?F.success(st.message||i("settings.plugins.sidebar.toast.deleted",{name:b.label})):F.error(i("settings.plugins.sidebar.toast.deleteFailed")),k(null),C(!1)},e[29]=x,e[30]=u,e[31]=b,e[32]=i,e[33]=oe):oe=e[33];const re=oe;let pe;e[34]!==q||e[35]!==K||e[36]!==d||e[37]!==m||e[38]!==i?(pe=st=>{const ft=d[st.spec],jt=ft?.kind==="npm-ok"&&ft.hasUpdate&&!!ft.latestVersion,Je=[];return jt&&Je.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{K(st.id)}}),Je.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"entry",id:st.id,label:st.spec})}),s.jsx($r,{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:st.spec}),s.jsx($p,{spec:st.spec})]}),metadata:st.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:m===st.id,onSelect:()=>q(st.id),icon:s.jsx(B,{name:Hp(st),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Je},st.id)},e[34]=q,e[35]=K,e[36]=d,e[37]=m,e[38]=i,e[39]=pe):pe=e[39];const ve=pe;let be;e[40]!==q||e[41]!==m||e[42]!==i?(be=st=>s.jsx($r,{title:st.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:m===st.id,onSelect:()=>q(st.id),icon:s.jsx(B,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"file",id:st.id,label:st.fileName})}]},st.id),e[40]=q,e[41]=m,e[42]=i,e[43]=be):be=e[43];const te=be;let he;e[44]!==i?(he=(st,ft,jt)=>{const Je=jt===void 0?0:jt;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:[st,Je>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Je===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Je})})]}),ft]})},e[44]=i,e[45]=he):he=e[45];const ie=he;let ue;e[46]!==i?(ue=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=ue):ue=e[47];let de;e[48]!==ue?(de=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:Cn,children:ue})}),e[48]=ue,e[49]=de):de=e[49];let Pe;e[50]!==i||e[51]!==ee?(Pe=i("settings.plugins.sidebar.total",{count:ee}),e[50]=i,e[51]=ee,e[52]=Pe):Pe=e[52];let Ae;e[53]!==Pe?(Ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Pe}),e[53]=Pe,e[54]=Ae):Ae=e[54];let we;e[55]!==J?(we=()=>{J()},e[55]=J,e[56]=we):we=e[56];let Le;e[57]!==i?(Le=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=Le):Le=e[58];let _e;e[59]!==i?(_e=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=_e):_e=e[60];const Ve=j?"size-4 animate-spin":"size-4";let je;e[61]!==Ve?(je=s.jsx(B,{name:"refresh",className:Ve}),e[61]=Ve,e[62]=je):je=e[62];let ke;e[63]!==j||e[64]!==we||e[65]!==Le||e[66]!==_e||e[67]!==je?(ke=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:we,disabled:j,"aria-label":Le,title:_e,children:je}),e[63]=j,e[64]=we,e[65]=Le,e[66]=_e,e[67]=je,e[68]=ke):ke=e[68];let se;e[69]!==i?(se=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=se):se=e[70];let le;e[71]!==i?(le=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=le):le=e[72];let Ie;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx(B,{name:"add",className:"size-4"}),e[73]=Ie):Ie=e[73];let Ne;e[74]!==_||e[75]!==se||e[76]!==le?(Ne=s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:_,"aria-label":se,title:le,children:Ie}),e[74]=_,e[75]=se,e[76]=le,e[77]=Ne):Ne=e[77];let Re;e[78]!==ke||e[79]!==Ne?(Re=s.jsxs("div",{className:"flex items-center gap-1",children:[ke,Ne]}),e[78]=ke,e[79]=Ne,e[80]=Re):Re=e[80];let $e;e[81]!==Ae||e[82]!==Re?($e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ae,Re]}),e[81]=Ae,e[82]=Re,e[83]=$e):$e=e[83];let De;e[84]!==de||e[85]!==$e?(De=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[de,$e]}),e[84]=de,e[85]=$e,e[86]=De):De=e[86];let Ce;e[87]!==O||e[88]!==I||e[89]!==Z||e[90]!==ve||e[91]!==te||e[92]!==ie||e[93]!==i||e[94]!==P||e[95]!==V||e[96]!==H?(Ce=O?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:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.length>0&&ie(i("settings.plugins.sidebar.group.userEntries"),V.map(ve),P.userEntries),H.length>0&&ie(i("settings.plugins.sidebar.group.userFiles"),H.map(te)),I.length>0&&ie(i("settings.plugins.sidebar.group.projectEntries"),I.map(ve),P.projectEntries),Z.length>0&&ie(i("settings.plugins.sidebar.group.projectFiles"),Z.map(te))]}),e[87]=O,e[88]=I,e[89]=Z,e[90]=ve,e[91]=te,e[92]=ie,e[93]=i,e[94]=P,e[95]=V,e[96]=H,e[97]=Ce):Ce=e[97];let Ye;e[98]!==De||e[99]!==Ce?(Ye=s.jsx(Rc,{variant:"background",header:De,children:Ce}),e[98]=De,e[99]=Ce,e[100]=Ye):Ye=e[100];let xe;e[101]!==E?(xe=s.jsx(_p,{open:E,onOpenChange:A}),e[101]=E,e[102]=xe):xe=e[102];const Te=b!==null;let Ke;e[103]!==p?(Ke=st=>{!st&&!p&&k(null)},e[103]=p,e[104]=Ke):Ke=e[104];let tt;e[105]!==i?(tt=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=tt):tt=e[106];let Y;e[107]!==tt?(Y=s.jsx(Ht,{children:tt}),e[107]=tt,e[108]=Y):Y=e[108];const Se=b?.label??"";let Ee;e[109]!==i||e[110]!==Se?(Ee=i("settings.plugins.sidebar.deleteDialog.description",{name:Se}),e[109]=i,e[110]=Se,e[111]=Ee):Ee=e[111];let We;e[112]!==Ee?(We=s.jsx(qt,{children:Ee}),e[112]=Ee,e[113]=We):We=e[113];let lt;e[114]!==Y||e[115]!==We?(lt=s.jsxs(Vt,{children:[Y,We]}),e[114]=Y,e[115]=We,e[116]=lt):lt=e[116];let at;e[117]===Symbol.for("react.memo_cache_sentinel")?(at=()=>k(null),e[117]=at):at=e[117];let pt;e[118]!==i?(pt=i("settings.common.actions.cancel"),e[118]=i,e[119]=pt):pt=e[119];let bt;e[120]!==p||e[121]!==pt?(bt=s.jsx(G,{size:"sm",variant:"ghost",onClick:at,disabled:p,children:pt}),e[120]=p,e[121]=pt,e[122]=bt):bt=e[122];let Q;e[123]!==p||e[124]!==i?(Q=i(p?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=p,e[124]=i,e[125]=Q):Q=e[125];let qe;e[126]!==re||e[127]!==p||e[128]!==Q?(qe=s.jsx(G,{size:"sm",variant:"destructive",onClick:re,disabled:p,children:Q}),e[126]=re,e[127]=p,e[128]=Q,e[129]=qe):qe=e[129];let it;e[130]!==bt||e[131]!==qe?(it=s.jsxs(rs,{children:[bt,qe]}),e[130]=bt,e[131]=qe,e[132]=it):it=e[132];let ut;e[133]!==lt||e[134]!==it?(ut=s.jsxs($t,{className:"max-w-md",children:[lt,it]}),e[133]=lt,e[134]=it,e[135]=ut):ut=e[135];let gt;e[136]!==Te||e[137]!==Ke||e[138]!==ut?(gt=s.jsx(_t,{open:Te,onOpenChange:Ke,children:ut}),e[136]=Te,e[137]=Ke,e[138]=ut,e[139]=gt):gt=e[139];let Ot;return e[140]!==Ye||e[141]!==xe||e[142]!==gt?(Ot=s.jsxs(s.Fragment,{children:[Ye,xe,gt]}),e[140]=Ye,e[141]=xe,e[142]=gt,e[143]=Ot):Ot=e[143],Ot};function Gp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Wp(t){return t.registryInfo}function Jp(t){return t.isLoadingRegistry}function Qp(t){return t.loadRegistryInfo}function Yp(t){return t.updateToLatest}function Zp(t){return t.scope==="user"}function Xp(t){return t.scope==="project"}function eg(t){return t.scope==="user"}function tg(t){return t.scope==="project"}const sg=({entryId:t,spec:e})=>{const{t:a}=et(),n=js(v=>v.registryInfo[e]),i=js(v=>v.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const v=n.latestVersion,d=n.currentVersion??"",j=async()=>{l(!0);try{(await i(t)).ok?F.success(a("settings.plugins.toast.updatedToLatest",{version:v})):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:d,latest:v})})]}),s.jsx(G,{variant:"default",size:"sm",onClick:()=>{j()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:v})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(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 m=n.kind==="path-unreadable",c=m?"var(--status-warning)":"var(--status-error)",x=m?"alert":"error-warning",u=(()=>{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:x,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:u})]})]})};function ng(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 Fc(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function el(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Fc(t.options),fileName:"",content:""}}function tl(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const sl=t=>{const e=ct.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ye("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},ag=()=>{const{t}=et(),e=js(b=>b.selectedId),a=js(b=>b.entries),n=js(b=>b.files),i=js(b=>b.draft),r=js(b=>b.setDraft),l=js(b=>b.updateEntry),m=js(b=>b.updateFile),c=js(b=>b.readFile),x=o.useMemo(()=>e?a.find(b=>b.id===e)??null:null,[a,e]),u=o.useMemo(()=>e?n.find(b=>b.id===e)??null:null,[n,e]),[v,d]=o.useState(!1),[j,g]=o.useState(!1),w=o.useRef(new Map);if(o.useEffect(()=>{let b=!1;return x?(r(el(x)),()=>{b=!0}):u?(g(!0),(async()=>{const k=await c(u.id);if(b)return;g(!1);const p=k?.content??"";w.current.set(u.id,p),r(tl(u,p))})(),()=>{b=!0}):(r(null),()=>{b=!0})},[x,u,c,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(B,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(x&&i&&i.mode==="entry"){const b=ng(i.optionsJson),k=b.ok,p=i.spec!==x.spec||i.optionsJson!==Fc(x.options),C=()=>{r(el(x))},E=async()=>{if(!k)return;const A=i.spec.trim();if(!A){F.error(t("settings.plugins.validation.specRequired"));return}d(!0);try{const N=await l(x.id,{spec:A,options:b.value});N.ok?N.reloadFailed?F.warning(N.message||t("settings.plugins.toast.reloadFailed"),{description:N.warning}):N.restartDeferred?F.success(t("settings.view.pendingRestart.saved")):F.success(N.message||t("settings.plugins.toast.updated")):F.error(N.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsxs(is,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(sl,{scope:x.scope,label:x.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(ze,{divider:!1,children:s.jsx(sg,{entryId:x.id,spec:x.spec})}),s.jsx(ze,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Be,{value:i.spec,onChange:A=>r({...i,spec:A.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(ze,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ms,{value:i.optionsJson,onChange:A=>r({...i,optionsJson:A.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!k&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!k&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(G,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!p||!k||v,children:t("settings.plugins.page.action.save")}),s.jsx(G,{variant:"outline",size:"sm",onClick:C,disabled:!p||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(u&&i&&i.mode==="file"){const b=w.current.get(u.id)??"",k=i.content!==b||i.fileName!==u.fileName,p=()=>{(async()=>{g(!0);const A=(await c(u.id))?.content??"";g(!1),w.current.set(u.id,A),r(tl(u,A))})()},C=async()=>{d(!0);try{const E=await m(u.id,{content:i.content});E.ok?(w.current.set(u.id,i.content),E.reloadFailed?F.warning(E.message||t("settings.plugins.toast.reloadFailed"),{description:E.warning}):E.restartDeferred?F.success(t("settings.view.pendingRestart.saved")):F.success(E.message||t("settings.plugins.toast.updated"))):F.error(E.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsx(is,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(sl,{scope:u.scope,label:u.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:u.fileName})]}),showSaveStatus:!1,children:s.jsxs(ze,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ms,{value:i.content,onChange:E=>r({...i,content:E.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:j}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(G,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!k||v||j,children:t("settings.plugins.page.action.save")}),s.jsx(G,{variant:"outline",size:"sm",onClick:p,disabled:v||j,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(B,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},ig="<built-in>",ni=t=>t?.path===ig,Br=t=>!!t&&!ni(t)&&t.renamable===!0,rg=t=>{const e=ct.c(157),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,m]=o.useState(""),[c,x]=o.useState(null),[u,v]=o.useState(!1),[d,j]=o.useState(null),{selectedSkillName:g,setSelectedSkill:w,setSkillDraft:b,deleteSkill:k,renameSkill:p,getSkillDetail:C}=Xs(qs(og)),E=Ws();let A;e[0]!==E?(A=Oe=>Jr(Oe,E),e[0]=E,e[1]=A):A=e[1];const N=Xs(A),h=Xs(lg);let y,R;e[2]!==h||e[3]!==E?(y=()=>{h(E)},R=[h,E],e[2]=h,e[3]=E,e[4]=y,e[5]=R):(y=e[4],R=e[5]),o.useEffect(y,R);let T;e[6]!==a||e[7]!==w||e[8]!==b||e[9]!==N?(T=()=>{let Oe="new-skill",wt=1;for(;N.some(X=>X.name===Oe);)Oe=`new-skill-${wt}`,wt++;b({name:Oe,scope:"user",source:"opencode",description:""}),w(Oe),a?.()},e[6]=a,e[7]=w,e[8]=b,e[9]=N,e[10]=T):T=e[10];const P=T;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=async Oe=>{ni(Oe)||x(Oe)},e[11]=D):D=e[11];const V=D;let $;e[12]!==c||e[13]!==k||e[14]!==E||e[15]!==n?($=async()=>{if(!c)return;if(ni(c)){x(null);return}v(!0),await k(c.name,E)?(F.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),x(null)):F.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[12]=c,e[13]=k,e[14]=E,e[15]=n,e[16]=$):$=e[16];const I=$;let M;e[17]!==C||e[18]!==w||e[19]!==b||e[20]!==E||e[21]!==N||e[22]!==n?(M=async Oe=>{if(ni(Oe))return;const wt=Oe.name;let X=1,fe=`${wt}-copy`;for(;N.some(Me=>Me.name===fe);)X++,fe=`${wt}-copy-${X}`;const Fe=await C(Oe.name,E);if(!Fe){F.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:fe,scope:Oe.scope||"user",source:Oe.source||"opencode",description:(Fe.sources.md.fields.includes("description"),""),instructions:""}),w(fe)},e[17]=C,e[18]=w,e[19]=b,e[20]=E,e[21]=N,e[22]=n,e[23]=M):M=e[23];const H=M;let U;e[24]===Symbol.for("react.memo_cache_sentinel")?(U=Oe=>{Br(Oe)&&(m(Oe.name),r(Oe))},e[24]=U):U=e[24];const Z=U;let ee;e[25]!==i||e[26]!==l||e[27]!==p||e[28]!==w||e[29]!==E||e[30]!==N||e[31]!==n?(ee=async()=>{if(!i)return;if(!Br(i)){r(null);return}const Oe=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Oe){F.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Oe===i.name){r(null);return}if(N.some(X=>X.name===Oe)){F.error(n("settings.skills.page.toast.skillExists"));return}await p(i.name,Oe,E)?(F.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Oe})),w(Oe)):F.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=p,e[28]=w,e[29]=E,e[30]=N,e[31]=n,e[32]=ee):ee=e[32];const O=ee;let ae;e[33]!==N?(ae=N.filter(cg),e[33]=N,e[34]=ae):ae=e[34];const _=ae;let W;e[35]!==N?(W=N.filter(dg),e[35]=N,e[36]=W):W=e[36];const q=W;let L;e[37]===Symbol.for("react.memo_cache_sentinel")?(L=function(wt){const X={},fe=[];for(const Me of wt)Me.group?(X[Me.group]||(X[Me.group]=[]),X[Me.group].push(Me)):fe.push(Me);const Fe=Object.keys(X).sort(ug).map(Me=>({name:Me,skills:[...X[Me]].sort(mg)}));return fe.sort(pg),{sortedGroups:Fe,ungrouped:fe}},e[37]=L):L=e[37];const K=L;let z;e[38]!==_?(z=K(_),e[38]=_,e[39]=z):z=e[39];const J=z;let oe;e[40]!==q?(oe=K(q),e[40]=q,e[41]=oe):oe=e[41];const re=oe;let pe;e[42]===Symbol.for("react.memo_cache_sentinel")?(pe=ye("flex h-full flex-col","bg-background"),e[42]=pe):pe=e[42];let ve;e[43]!==n?(ve=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ve):ve=e[44];let be;e[45]!==ve?(be=s.jsx("h2",{className:`${Cn} mb-3`,children:ve}),e[45]=ve,e[46]=be):be=e[46];let te;e[47]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(ci,{className:"mb-3"}),e[47]=te):te=e[47];let he;e[48]!==N.length||e[49]!==n?(he=n("settings.skills.sidebar.total",{count:N.length}),e[48]=N.length,e[49]=n,e[50]=he):he=e[50];let ie;e[51]!==he?(ie=s.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[51]=he,e[52]=ie):ie=e[52];let ue;e[53]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[53]=ue):ue=e[53];let de;e[54]!==P?(de=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:P,children:ue}),e[54]=P,e[55]=de):de=e[55];let Pe;e[56]!==ie||e[57]!==de?(Pe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ie,de]}),e[56]=ie,e[57]=de,e[58]=Pe):Pe=e[58];let Ae;e[59]!==be||e[60]!==Pe?(Ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,te,Pe]}),e[59]=be,e[60]=Pe,e[61]=Ae):Ae=e[61];let we;e[62]!==J||e[63]!==re||e[64]!==H||e[65]!==a||e[66]!==d||e[67]!==_||e[68]!==g||e[69]!==w||e[70]!==N.length||e[71]!==n||e[72]!==q?(we=s.jsx(Ns,{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:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),J.sortedGroups.map(Oe=>{const{name:wt,skills:X}=Oe;return s.jsx(Kr,{label:wt,count:X.length,storageKey:"project-skills",children:X.map(fe=>s.jsx(Ai,{skill:fe,isSelected:g===fe.name,onSelect:()=>{w(fe.name),a?.()},onRename:()=>Z(fe),onDelete:()=>V(fe),onDuplicate:()=>H(fe),isMenuOpen:d===fe.name,onMenuOpenChange:Fe=>j(Fe?fe.name:null)},fe.name))},wt)}),J.ungrouped.map(Oe=>s.jsx(Ai,{skill:Oe,isSelected:g===Oe.name,onSelect:()=>{w(Oe.name),a?.()},onRename:()=>Z(Oe),onDelete:()=>V(Oe),onDuplicate:()=>H(Oe),isMenuOpen:d===Oe.name,onMenuOpenChange:wt=>j(wt?Oe.name:null)},Oe.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:n("settings.skills.sidebar.section.user")}),re.sortedGroups.map(Oe=>{const{name:wt,skills:X}=Oe;return s.jsx(Kr,{label:wt,count:X.length,storageKey:"user-skills",children:X.map(fe=>s.jsx(Ai,{skill:fe,isSelected:g===fe.name,onSelect:()=>{w(fe.name),a?.()},onRename:()=>Z(fe),onDelete:()=>V(fe),onDuplicate:()=>H(fe),isMenuOpen:d===fe.name,onMenuOpenChange:Fe=>j(Fe?fe.name:null)},fe.name))},wt)}),re.ungrouped.map(Oe=>s.jsx(Ai,{skill:Oe,isSelected:g===Oe.name,onSelect:()=>{w(Oe.name),a?.()},onRename:()=>Z(Oe),onDelete:()=>V(Oe),onDuplicate:()=>H(Oe),isMenuOpen:d===Oe.name,onMenuOpenChange:wt=>j(wt?Oe.name:null)},Oe.name))]})]})}),e[62]=J,e[63]=re,e[64]=H,e[65]=a,e[66]=d,e[67]=_,e[68]=g,e[69]=w,e[70]=N.length,e[71]=n,e[72]=q,e[73]=we):we=e[73];const Le=c!==null;let _e;e[74]!==u?(_e=Oe=>{!Oe&&!u&&x(null)},e[74]=u,e[75]=_e):_e=e[75];let Ve;e[76]!==n?(Ve=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ve):Ve=e[77];let je;e[78]!==Ve?(je=s.jsx(Ht,{children:Ve}),e[78]=Ve,e[79]=je):je=e[79];const ke=c?.name??"";let se;e[80]!==n||e[81]!==ke?(se=n("settings.skills.sidebar.deleteDialog.description",{name:ke}),e[80]=n,e[81]=ke,e[82]=se):se=e[82];let le;e[83]!==se?(le=s.jsx(qt,{children:se}),e[83]=se,e[84]=le):le=e[84];let Ie;e[85]!==je||e[86]!==le?(Ie=s.jsxs(Vt,{children:[je,le]}),e[85]=je,e[86]=le,e[87]=Ie):Ie=e[87];let Ne;e[88]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>x(null),e[88]=Ne):Ne=e[88];let Re;e[89]!==n?(Re=n("settings.common.actions.cancel"),e[89]=n,e[90]=Re):Re=e[90];let $e;e[91]!==u||e[92]!==Re?($e=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ne,disabled:u,children:Re}),e[91]=u,e[92]=Re,e[93]=$e):$e=e[93];let De;e[94]!==n?(De=n("settings.common.actions.delete"),e[94]=n,e[95]=De):De=e[95];let Ce;e[96]!==I||e[97]!==u||e[98]!==De?(Ce=s.jsx(G,{size:"sm",onClick:I,disabled:u,children:De}),e[96]=I,e[97]=u,e[98]=De,e[99]=Ce):Ce=e[99];let Ye;e[100]!==$e||e[101]!==Ce?(Ye=s.jsxs(rs,{children:[$e,Ce]}),e[100]=$e,e[101]=Ce,e[102]=Ye):Ye=e[102];let xe;e[103]!==Ie||e[104]!==Ye?(xe=s.jsxs($t,{className:"max-w-md",children:[Ie,Ye]}),e[103]=Ie,e[104]=Ye,e[105]=xe):xe=e[105];let Te;e[106]!==Le||e[107]!==_e||e[108]!==xe?(Te=s.jsx(_t,{open:Le,onOpenChange:_e,children:xe}),e[106]=Le,e[107]=_e,e[108]=xe,e[109]=Te):Te=e[109];const Ke=i!==null;let tt;e[110]===Symbol.for("react.memo_cache_sentinel")?(tt=Oe=>!Oe&&r(null),e[110]=tt):tt=e[110];let Y;e[111]!==n?(Y=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=Y):Y=e[112];let Se;e[113]!==Y?(Se=s.jsx(Ht,{children:Y}),e[113]=Y,e[114]=Se):Se=e[114];const Ee=i?.name??"";let We;e[115]!==n||e[116]!==Ee?(We=n("settings.skills.sidebar.renameDialog.description",{name:Ee}),e[115]=n,e[116]=Ee,e[117]=We):We=e[117];let lt;e[118]!==We?(lt=s.jsx(qt,{children:We}),e[118]=We,e[119]=lt):lt=e[119];let at;e[120]!==Se||e[121]!==lt?(at=s.jsxs(Vt,{children:[Se,lt]}),e[120]=Se,e[121]=lt,e[122]=at):at=e[122];let pt;e[123]===Symbol.for("react.memo_cache_sentinel")?(pt=Oe=>m(Oe.target.value),e[123]=pt):pt=e[123];let bt;e[124]!==n?(bt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=bt):bt=e[125];let Q;e[126]!==O?(Q=Oe=>{Oe.key==="Enter"&&O()},e[126]=O,e[127]=Q):Q=e[127];let qe;e[128]!==l||e[129]!==bt||e[130]!==Q?(qe=s.jsx(Be,{value:l,onChange:pt,placeholder:bt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Q}),e[128]=l,e[129]=bt,e[130]=Q,e[131]=qe):qe=e[131];let it;e[132]===Symbol.for("react.memo_cache_sentinel")?(it=()=>r(null),e[132]=it):it=e[132];let ut;e[133]!==n?(ut=n("settings.common.actions.cancel"),e[133]=n,e[134]=ut):ut=e[134];let gt;e[135]!==ut?(gt=s.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:it,children:ut}),e[135]=ut,e[136]=gt):gt=e[136];let Ot;e[137]!==n?(Ot=n("settings.common.actions.rename"),e[137]=n,e[138]=Ot):Ot=e[138];let st;e[139]!==O||e[140]!==Ot?(st=s.jsx(G,{size:"sm",onClick:O,children:Ot}),e[139]=O,e[140]=Ot,e[141]=st):st=e[141];let ft;e[142]!==gt||e[143]!==st?(ft=s.jsxs(rs,{children:[gt,st]}),e[142]=gt,e[143]=st,e[144]=ft):ft=e[144];let jt;e[145]!==at||e[146]!==qe||e[147]!==ft?(jt=s.jsxs($t,{children:[at,qe,ft]}),e[145]=at,e[146]=qe,e[147]=ft,e[148]=jt):jt=e[148];let Je;e[149]!==Ke||e[150]!==jt?(Je=s.jsx(_t,{open:Ke,onOpenChange:tt,children:jt}),e[149]=Ke,e[150]=jt,e[151]=Je):Je=e[151];let St;return e[152]!==Ae||e[153]!==we||e[154]!==Te||e[155]!==Je?(St=s.jsxs("div",{className:pe,children:[Ae,we,Te,Je]}),e[152]=Ae,e[153]=we,e[154]=Te,e[155]=Je,e[156]=St):St=e[156],St},Ai=t=>{const e=ct.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:m,isMenuOpen:c,onMenuOpenChange:x}=t,{t:u}=et();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=ii(),e[0]=v):v=e[0];const d=v;let j;e[1]!==a?(j=ni(a),e[1]=a,e[2]=j):j=e[2];const g=j;let w;e[3]!==a?(w=Br(a),e[3]=a,e[4]=w):w=e[4];const b=w,[k,p]=o.useState(!1);let C;e[5]!==b||e[6]!==r||e[7]!==m||e[8]!==l||e[9]!==u?(C=H=>s.jsxs(s.Fragment,{children:[b?s.jsxs(H,{onClick:U=>{U.stopPropagation(),l()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}):null,s.jsxs(H,{onClick:U=>{U.stopPropagation(),m()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),s.jsxs(H,{onClick:U=>{U.stopPropagation(),r()},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[5]=b,e[6]=r,e[7]=m,e[8]=l,e[9]=u,e[10]=C):C=e[10];const E=C,A=!g&&k,N=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==N?(h=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",N),e[11]=N,e[12]=h):h=e[12];let y;e[13]!==g?(y=!d&&!g?H=>{H.preventDefault(),p(!0)}:void 0,e[13]=g,e[14]=y):y=e[14];let R;e[15]!==h||e[16]!==y?(R=s.jsx("div",{className:h,onContextMenu:y}),e[15]=h,e[16]=y,e[17]=R):R=e[17];let T;e[18]!==a.name?(T=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]=T):T=e[19];let P;e[20]!==i||e[21]!==T?(P=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:T}),e[20]=i,e[21]=T,e[22]=P):P=e[22];let D;e[23]!==g||e[24]!==c||e[25]!==x||e[26]!==E?(D=g?null:s.jsxs(jn,{open:c,onOpenChange:H=>{H&&p(!1),x(H)},children:[s.jsx(vn,{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(yn,{align:"end",className:"w-fit min-w-20",children:E(wn)})]}),e[23]=g,e[24]=c,e[25]=x,e[26]=E,e[27]=D):D=e[27];let V;e[28]!==P||e[29]!==D?(V=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,D]}),e[28]=P,e[29]=D,e[30]=V):V=e[30];let $;e[31]!==V||e[32]!==R?($=s.jsx(ma,{render:R,children:V}),e[31]=V,e[32]=R,e[33]=$):$=e[33];let I;e[34]!==g||e[35]!==E?(I=g?null:s.jsx(da,{className:"w-fit min-w-20",children:E(ua)}),e[34]=g,e[35]=E,e[36]=I):I=e[36];let M;return e[37]!==$||e[38]!==I||e[39]!==A?(M=s.jsxs(pa,{open:A,onOpenChange:p,children:[$,I]}),e[37]=$,e[38]=I,e[39]=A,e[40]=M):M=e[40],M};function og(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function lg(t){return t.loadSkills}function cg(t){return t.scope==="project"}function dg(t){return t.scope==="user"}function ug(t,e){return t.localeCompare(e)}function mg(t,e){return t.name.localeCompare(e.name)}function pg(t,e){return t.name.localeCompare(e.name)}const gg=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,hg=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},fg=({open:t,onOpenChange:e})=>{const{t:a}=et(),n=Dn(I=>I.scanRepo),i=Dn(I=>I.loadCatalog),r=Dn(I=>I.loadSource),l=Dn(I=>I.setSelectedSource),m=Dn(I=>I.isScanning),c=sa(I=>I.defaultGitIdentityId),x=sa(I=>I.loadDefaultGitIdentityId),[u,v]=o.useState(""),[d,j]=o.useState(""),[g,w]=o.useState(""),[b,k]=o.useState(null),[p,C]=o.useState(null),[E,A]=o.useState(!1),[N,h]=o.useState([]),[y,R]=o.useState(null),T=o.useRef(0),P=o.useCallback(I=>{T.current+=1,A(!1),C(null),I?.clearIdentity&&(h([]),R(null))},[]);o.useEffect(()=>{t&&(T.current+=1,v(""),j(""),w(""),C(null),A(!1),h([]),R(null),x(),k(null),(async()=>{const I=await In();k(I?I.skillCatalogs??[]:null)})())},[t,x]);const D=o.useMemo(()=>{const I=d.trim(),M=g.trim();return(b??[]).some(H=>{const U=(H.source||"").trim(),Z=(H.subpath||"").trim();return U===I&&Z===M})},[b,d,g]),V=async()=>{const I=d.trim();if(!I){F.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}u.trim()||v(hg(I)),A(!1),C(null);const M=T.current+1;T.current=M;const H=await n({source:I,subpath:g.trim()||void 0,gitIdentityId:y||void 0});if(T.current!==M)return;if(!H.ok){if(H.error?.kind==="authRequired"){if(ds()){F.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Z=H.error.identities||[];if(h(Z),!y&&Z.length>0){const ee=c&&c!=="global"&&Z.some(O=>O.id===c)?c:Z[0].id;R(ee)}F.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}F.error(H.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const U=H.items?.length||0;if(C(U),U===0){F.error(a("settings.skills.catalog.add.toast.noSkillsFound")),A(!1);return}h([]),A(!0),F.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:U}))},$=async()=>{const I=u.trim(),M=d.trim(),H=g.trim();if(!I){F.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!M){F.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!E){F.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(D){F.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const U={id:gg(),label:I,source:M,...H?{subpath:H}:{},...y?{gitIdentityId:y}:{}};if(b===null){F.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const Z=[...b,U];try{if(!(await yt({skillCatalogs:Z})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(Z),F.success(a("settings.skills.catalog.add.toast.catalogAdded")),await i({refresh:!0}),await r(U.id,{refresh:!0}),l(U.id),e(!1)}catch(ee){F.error(ee instanceof Error?ee.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs($t,{className:"max-w-xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:a("settings.skills.catalog.add.title")}),s.jsxs(qt,{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(Be,{value:u,onChange:I=>v(I.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(Yt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(Be,{value:d,onChange:I=>{j(I.target.value),P({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(Be,{value:g,onChange:I=>{w(I.target.value),P({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),N.length>0&&!ds()?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(Yt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Tt,{value:y||"",onValueChange:I=>{R(I),P()},children:[s.jsx(Et,{className:"w-fit",children:s.jsx("span",{children:N.find(I=>I.id===y)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Dt,{align:"start",children:N.map(I=>s.jsx(dt,{value:I.id,children:I.name},I.id))})]})]}):null,p!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:p})}):null,D?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(rs,{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:()=>{V()},disabled:m||!d.trim(),children:[s.jsx(B,{name:"git-repository",className:"h-4 w-4"}),a(m?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(G,{size:"sm",onClick:()=>{$()},disabled:!E||D||b===null||!u.trim()||!d.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},xg=t=>{const e=ct.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=et();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={},e[0]=m):m=e[0];const[c,x]=o.useState(m);let u,v;e[1]!==i||e[2]!==a?(u=()=>{if(!a)return;const z={};for(const J of i)z[J.skillName]="skip";x(z)},v=[a,i],e[1]=i,e[2]=a,e[3]=u,e[4]=v):(u=e[3],v=e[4]),o.useEffect(u,v);let d;e[5]!==i?(d=z=>{const J={};for(const oe of i)J[oe.skillName]=z;x(J)},e[5]=i,e[6]=d):d=e[6];const j=d;let g;e[7]!==i||e[8]!==c?(g=i.length>0&&i.every(z=>c[z.skillName]),e[7]=i,e[8]=c,e[9]=g):g=e[9];const w=g;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(Ht,{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 C;e[16]!==p?(C=s.jsx(qt,{children:p}),e[16]=p,e[17]=C):C=e[17];let E;e[18]!==k||e[19]!==C?(E=s.jsxs(Vt,{children:[k,C]}),e[18]=k,e[19]=C,e[20]=E):E=e[20];let A;e[21]!==i.length||e[22]!==l?(A=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=A):A=e[23];let N;e[24]!==A?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=N):N=e[25];let h;e[26]!==j?(h=()=>j("skip"),e[26]=j,e[27]=h):h=e[27];let y;e[28]!==l?(y=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=y):y=e[29];let R;e[30]!==h||e[31]!==y?(R=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:y}),e[30]=h,e[31]=y,e[32]=R):R=e[32];let T;e[33]!==j?(T=()=>j("overwrite"),e[33]=j,e[34]=T):T=e[34];let P;e[35]!==l?(P=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=P):P=e[36];let D;e[37]!==T||e[38]!==P?(D=s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:P}),e[37]=T,e[38]=P,e[39]=D):D=e[39];let V;e[40]!==R||e[41]!==D?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[R,D]}),e[40]=R,e[41]=D,e[42]=V):V=e[42];let $;e[43]!==N||e[44]!==V?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,V]}),e[43]=N,e[44]=V,e[45]=$):$=e[45];let I;if(e[46]!==i||e[47]!==c||e[48]!==l){let z;e[50]!==c||e[51]!==l?(z=J=>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:J.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:J.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:J.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Tt,{value:c[J.skillName]||"skip",onValueChange:oe=>x(re=>({...re,[J.skillName]:oe})),children:[s.jsx(Et,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[J.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Dt,{align:"end",children:[s.jsx(dt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(dt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},J.skillName),e[50]=c,e[51]=l,e[52]=z):z=e[52],I=i.map(z),e[46]=i,e[47]=c,e[48]=l,e[49]=I}else I=e[49];let M;e[53]!==I?(M=s.jsx("div",{className:"space-y-2",children:I}),e[53]=I,e[54]=M):M=e[54];let H;e[55]!==$||e[56]!==M?(H=s.jsxs("div",{className:"space-y-3",children:[$,M]}),e[55]=$,e[56]=M,e[57]=H):H=e[57];let U;e[58]!==n?(U=()=>n(!1),e[58]=n,e[59]=U):U=e[59];let Z;e[60]!==l?(Z=l("settings.common.actions.cancel"),e[60]=l,e[61]=Z):Z=e[61];let ee;e[62]!==U||e[63]!==Z?(ee=s.jsx(G,{size:"sm",variant:"ghost",onClick:U,children:Z}),e[62]=U,e[63]=Z,e[64]=ee):ee=e[64];let O;e[65]!==c||e[66]!==r?(O=()=>r(c),e[65]=c,e[66]=r,e[67]=O):O=e[67];const ae=!w;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let W;e[70]!==O||e[71]!==ae||e[72]!==_?(W=s.jsx(G,{size:"sm",onClick:O,disabled:ae,children:_}),e[70]=O,e[71]=ae,e[72]=_,e[73]=W):W=e[73];let q;e[74]!==ee||e[75]!==W?(q=s.jsxs(rs,{children:[ee,W]}),e[74]=ee,e[75]=W,e[76]=q):q=e[76];let L;e[77]!==E||e[78]!==H||e[79]!==q?(L=s.jsxs($t,{className:"max-w-2xl",children:[E,H,q]}),e[77]=E,e[78]=H,e[79]=q,e[80]=L):L=e[80];let K;return e[81]!==n||e[82]!==a||e[83]!==L?(K=s.jsx(_t,{open:a,onOpenChange:n,children:L}),e[81]=n,e[82]=a,e[83]=L,e[84]=K):K=e[84],K},ro=[{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 ai(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 Oc(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=ro.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const bg=t=>{const e=ct.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=et(),l=Dn(vg),m=Dn(yg),[c,x]=o.useState("user"),[u,v]=o.useState("opencode"),d=en(jg),j=en(wg),[g,w]=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[C,E]=o.useState(p),[A,N]=o.useState(null);let h,y;e[1]!==j||e[2]!==a?(h=()=>{a&&(x("user"),v("opencode"),w(j),k(!1),E([]),N(null))},y=[a,j],e[1]=j,e[2]=a,e[3]=h,e[4]=y):(h=e[3],y=e[4]),o.useEffect(h,y);let R;e[5]!==r?(R=Ce=>{switch(Ce){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=R):R=e[6];const T=R;let P;e[7]!==r?(P=Ce=>{switch(Ce){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=P):P=e[8];const D=P;let V;e:{if(d.length===0){V=null;break e}if(g&&d.some(Ce=>Ce.id===g)){V=g;break e}if(j&&d.some(Ce=>Ce.id===j)){V=j;break e}V=d[0]?.id??null}const $=V;let I;e:{if(c!=="project"){I=null;break e}const Ce=$;if(!Ce){I=null;break e}let Ye;if(e[9]!==Ce||e[10]!==d){let Te;e[12]!==Ce?(Te=Ke=>Ke.id===Ce,e[12]=Ce,e[13]=Te):Te=e[13],Ye=d.find(Te),e[9]=Ce,e[10]=d,e[11]=Ye}else Ye=e[11];I=Ye?.path??null}const M=I;let H;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(H=async Ce=>{const Ye=await l({source:Ce.source,subpath:Ce.subpath,gitIdentityId:i?.gitIdentityId,scope:Ce.scope,targetSource:Ce.targetSource,selections:[{skillDir:Ce.skillDir}],conflictPolicy:"prompt",conflictDecisions:Ce.conflictDecisions},{directory:Ce.directoryOverride??null});if(Ye.ok){F.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ye.error?.kind==="conflicts"){N({source:Ce.source,subpath:Ce.subpath,scope:Ce.scope,targetSource:Ce.targetSource,skillDir:Ce.skillDir,directoryOverride:Ce.directoryOverride??null}),E(Ye.error.conflicts),k(!0);return}if(Ye.error?.kind==="authRequired"){F.error(Ye.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}F.error(Ye.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=H):H=e[18];const U=H;if(!i)return null;let Z;e[19]!==r?(Z=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=Z):Z=e[20];let ee;e[21]!==Z?(ee=s.jsx(Ht,{children:Z}),e[21]=Z,e[22]=ee):ee=e[22];let O;e[23]!==r?(O=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=O):O=e[24];let ae;e[25]!==i.skillName?(ae=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=ae):ae=e[26];let _;e[27]!==r?(_=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=_):_=e[28];let W;e[29]!==O||e[30]!==ae||e[31]!==_?(W=s.jsxs(qt,{children:[O," ",ae," ",_]}),e[29]=O,e[30]=ae,e[31]=_,e[32]=W):W=e[32];let q;e[33]!==ee||e[34]!==W?(q=s.jsxs(Vt,{children:[ee,W]}),e[33]=ee,e[34]=W,e[35]=q):q=e[35];let L;e[36]!==r?(L=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=L):L=e[37];let K;e[38]!==L?(K=s.jsx("span",{className:"typography-ui-label text-foreground",children:L}),e[38]=L,e[39]=K):K=e[39];let z;e[40]!==c||e[41]!==u?(z=ai(c,u),e[40]=c,e[41]=u,e[42]=z):z=e[42];let J;e[43]===Symbol.for("react.memo_cache_sentinel")?(J=Ce=>{const Ye=Oc(Ce);x(Ye.scope),v(Ye.source==="agents"?"agents":"opencode")},e[43]=J):J=e[43];let oe;e[44]!==c?(oe=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]=oe):oe=e[45];let re;e[46]!==u?(re=u==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=u,e[47]=re):re=e[47];let pe;e[48]!==T||e[49]!==c||e[50]!==u?(pe=T(ai(c,u)),e[48]=T,e[49]=c,e[50]=u,e[51]=pe):pe=e[51];let ve;e[52]!==pe?(ve=s.jsx("span",{children:pe}),e[52]=pe,e[53]=ve):ve=e[53];let be;e[54]!==oe||e[55]!==re||e[56]!==ve?(be=s.jsxs(Et,{className:"w-fit gap-1.5",children:[oe,re,ve]}),e[54]=oe,e[55]=re,e[56]=ve,e[57]=be):be=e[57];let te;e[58]!==D||e[59]!==T?(te=ro.map(Ce=>s.jsx(dt,{value:Ce.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:[Ce.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"}),Ce.source==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(Ce.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:D(Ce.value)})]})},Ce.value)),e[58]=D,e[59]=T,e[60]=te):te=e[60];let he;e[61]!==te?(he=s.jsx(Dt,{align:"start",children:te}),e[61]=te,e[62]=he):he=e[62];let ie;e[63]!==z||e[64]!==be||e[65]!==he?(ie=s.jsxs(Tt,{value:z,onValueChange:J,children:[be,he]}),e[63]=z,e[64]=be,e[65]=he,e[66]=ie):ie=e[66];let ue;e[67]!==K||e[68]!==ie?(ue=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[K,ie]}),e[67]=K,e[68]=ie,e[69]=ue):ue=e[69];let de;e[70]!==d||e[71]!==$||e[72]!==c||e[73]!==r?(de=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),d.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Tt,{value:$??"",onValueChange:Ce=>w(Ce),disabled:d.length===1,children:[s.jsx(Et,{className:"w-fit",children:s.jsx(Ut,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Dt,{align:"start",children:d.map(kg)})]})]}),e[70]=d,e[71]=$,e[72]=c,e[73]=r,e[74]=de):de=e[74];let Pe;e[75]!==i.warnings?(Pe=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Pe):Pe=e[76];let Ae;e[77]!==ue||e[78]!==de||e[79]!==Pe?(Ae=s.jsxs("div",{className:"mt-2 space-y-3",children:[ue,de,Pe]}),e[77]=ue,e[78]=de,e[79]=Pe,e[80]=Ae):Ae=e[80];let we;e[81]!==n?(we=()=>n(!1),e[81]=n,e[82]=we):we=e[82];let Le;e[83]!==r?(Le=r("settings.common.actions.cancel"),e[83]=r,e[84]=Le):Le=e[84];let _e;e[85]!==we||e[86]!==Le?(_e=s.jsx(G,{size:"sm",variant:"ghost",onClick:we,children:Le}),e[85]=we,e[86]=Le,e[87]=_e):_e=e[87];const Ve=m||!i.installable||c==="project"&&!M;let je;e[88]!==M||e[89]!==U||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==c||e[94]!==u?(je=()=>{U({source:i.repoSource,subpath:i.repoSubpath,scope:c,targetSource:u,skillDir:i.skillDir,directoryOverride:M})},e[88]=M,e[89]=U,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=c,e[94]=u,e[95]=je):je=e[95];let ke;e[96]!==m||e[97]!==r?(ke=r(m?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=m,e[97]=r,e[98]=ke):ke=e[98];let se;e[99]!==Ve||e[100]!==je||e[101]!==ke?(se=s.jsx(G,{size:"sm",disabled:Ve,onClick:je,children:ke}),e[99]=Ve,e[100]=je,e[101]=ke,e[102]=se):se=e[102];let le;e[103]!==_e||e[104]!==se?(le=s.jsxs(rs,{children:[_e,se]}),e[103]=_e,e[104]=se,e[105]=le):le=e[105];let Ie;e[106]!==q||e[107]!==Ae||e[108]!==le?(Ie=s.jsxs($t,{className:"max-w-md",children:[q,Ae,le]}),e[106]=q,e[107]=Ae,e[108]=le,e[109]=Ie):Ie=e[109];let Ne;e[110]!==n||e[111]!==a||e[112]!==Ie?(Ne=s.jsx(_t,{open:a,onOpenChange:n,children:Ie}),e[110]=n,e[111]=a,e[112]=Ie,e[113]=Ne):Ne=e[113];let Re;e[114]!==A||e[115]!==U?(Re=Ce=>{A&&(U({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:Ce,directoryOverride:A.directoryOverride??null}),k(!1))},e[114]=A,e[115]=U,e[116]=Re):Re=e[116];let $e;e[117]!==C||e[118]!==b||e[119]!==Re?($e=s.jsx(xg,{open:b,onOpenChange:k,conflicts:C,onConfirm:Re}),e[117]=C,e[118]=b,e[119]=Re,e[120]=$e):$e=e[120];let De;return e[121]!==Ne||e[122]!==$e?(De=s.jsxs(s.Fragment,{children:[Ne,$e]}),e[121]=Ne,e[122]=$e,e[123]=De):De=e[123],De};function vg(t){return t.installSkills}function yg(t){return t.isInstalling}function jg(t){return t.projects}function wg(t){return t.activeProjectId}function kg(t){return s.jsx(dt,{value:t.id,children:t.label||t.path},t.id)}const Ng=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,Sg=t=>{const e=t.trim();return Ng.test(e)?`https://github.com/${e}`:null},Cg=t=>{const e=Sg(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Ti=null;const Ig=t=>{const e=eo();return(!Ti||Ti.locale!==e)&&(Ti={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Ti.formatter.format(t)},Pg=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},Ag=t=>{const e=ct.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:m}=t,c=a.stars??null;let x,u,v,d,j,g,w,b,k,p;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==m){const N=a.repoUpdatedAt?Pg(a.repoUpdatedAt):null;b="button",k=l,p=n;const h=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==h?(u=ye("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",h),e[19]=h,e[20]=u):u=e[20],j="min-w-0 flex-1 block";let y;e[21]!==a.label?(y=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=y):y=e[22];let R;e[23]!==i||e[24]!==r||e[25]!==m?(R=i?s.jsx(B,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:m("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=m,e[26]=R):R=e[26],e[27]!==y||e[28]!==R?(g=s.jsxs("span",{className:"flex items-center gap-2",children:[y,R]}),e[27]=y,e[28]=R,e[29]=g):g=e[29],e[30]!==a.source?(w=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=w):w=e[31],x="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==m?(v=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:m("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(B,{name:"star",className:"h-3 w-3"}),Ig(c)]}),e[32]=c,e[33]=m,e[34]=v):v=e[34],d=N&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:N.key==="common.relative.justNow"?m(N.key):m("settings.skills.catalog.page.source.updated",{time:m(N.key,{count:N.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=m,e[9]=x,e[10]=u,e[11]=v,e[12]=d,e[13]=j,e[14]=g,e[15]=w,e[16]=b,e[17]=k,e[18]=p}else x=e[9],u=e[10],v=e[11],d=e[12],j=e[13],g=e[14],w=e[15],b=e[16],k=e[17],p=e[18];let C;e[35]!==x||e[36]!==v||e[37]!==d?(C=s.jsxs("span",{className:x,children:[v,d]}),e[35]=x,e[36]=v,e[37]=d,e[38]=C):C=e[38];let E;e[39]!==C||e[40]!==j||e[41]!==g||e[42]!==w?(E=s.jsxs("span",{className:j,children:[g,w,C]}),e[39]=C,e[40]=j,e[41]=g,e[42]=w,e[43]=E):E=e[43];let A;return e[44]!==u||e[45]!==E||e[46]!==b||e[47]!==k||e[48]!==p?(A=s.jsx("button",{type:b,onClick:k,"aria-pressed":p,className:u,children:E}),e[44]=u,e[45]=E,e[46]=b,e[47]=k,e[48]=p,e[49]=A):A=e[49],A},Tg=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=et(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:m,loadCatalog:c,loadSource:x,isLoadingCatalog:u,isLoadingSource:v,loadedSourceIds:d,lastCatalogError:j}=Dn(qs(U=>({sources:U.sources,itemsBySource:U.itemsBySource,selectedSourceId:U.selectedSourceId,setSelectedSource:U.setSelectedSource,loadCatalog:U.loadCatalog,loadSource:U.loadSource,isLoadingCatalog:U.isLoadingCatalog,isLoadingSource:U.isLoadingSource,loadedSourceIds:U.loadedSourceIds,lastCatalogError:U.lastCatalogError}))),[g,w]=o.useState(""),[b,k]=o.useState(!1),[p,C]=o.useState(!1),[E,A]=o.useState(null),[N,h]=o.useState(!1),[y,R]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const U=i.filter(O=>!d[O.id]);if(U.length===0)return;let Z=!1;return(async()=>{for(const O of U){if(Z)return;await x(O.id)}})(),()=>{Z=!0}},[i,d,x]),o.useEffect(()=>{!l||d[l]||x(l)},[l,d,x]),o.useEffect(()=>{const U=Z=>{(Z.metaKey||Z.ctrlKey)&&Z.key.toLowerCase()==="k"&&(Z.preventDefault(),T.current?.focus())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[]);const P=g.trim().length>0,D=o.useMemo(()=>P?$i(i.flatMap(U=>r[U.id]||[]),g,U=>[U.skillName,U.frontmatterName,U.description]):l?r[l]||[]:[],[i,r,l,g,P]),V=o.useMemo(()=>i.find(U=>U.id===l)||null,[i,l]),$=!!(l&&l.startsWith("custom:")),I=async()=>{if(!(!l||!$)){h(!0);try{const U=await In();if(!U)return;const ee=(U.skillCatalogs??[]).filter(O=>O.id!==l);await yt({skillCatalogs:ee}),await c({refresh:!0}),R(!1)}finally{h(!1)}}},M=P?n("settings.skills.catalog.page.list.searchTitle"):V?.label??"",H=!P&&l!==null&&!d[l]&&(v||u);return s.jsxs(s.Fragment,{children:[s.jsxs(is,{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(no,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:U=>e(U),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(Be,{ref:T,value:g,onChange:U=>w(U.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ye("h-8 pl-8 w-full",g&&"pr-8")}),g&&s.jsx("button",{type:"button",onClick:()=>{w(""),T.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(ze,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(U=>s.jsx(Ag,{source:U,isActive:U.id===l,isLoading:v&&!d[U.id],skillsCount:d[U.id]?(r[U.id]||[]).length:null,onSelect:()=>m(U.id),t:n},U.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")})]})]})]})}),j&&s.jsx(ze,{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:j.message})]})}),s.jsxs(ze,{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:D.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!P?x(l,{refresh:!0}):c({refresh:!0})},disabled:u||v,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(B,{name:"refresh",className:ye("h-3.5 w-3.5",(u||v)&&"animate-spin")})}),$&&!P&&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:()=>R(!0),disabled:N,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),H||v&&D.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")})]}):D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:D.map(U=>{const Z=U.installed?.isInstalled,ee=U.installed?.scope,O=Cg(U);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:U.skillName}),Z&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:ee||n("settings.skills.catalog.page.badge.unknown")})}),!U.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")})]}),U.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:U.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:[O?s.jsxs("a",{href:O,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"}),U.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:U.repoSource}),U.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:U.skillDir})]})]}),U.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:U.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[O&&s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(O,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"})}),Z?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:ee||""}),children:s.jsx(B,{name:"check",className:"h-4 w-4"})}):s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",disabled:!U.installable,onClick:()=>{A(U),C(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${U.sourceId}:${U.skillDir}`)})})]})]}),s.jsx(fg,{open:b,onOpenChange:k}),s.jsx(bg,{open:p,onOpenChange:C,item:E}),s.jsx(_t,{open:y,onOpenChange:U=>{N||R(U)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(qt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(rs,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>R(!1),disabled:N,children:n("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{I()},disabled:N,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Eg=()=>{const t=ct.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Tg,{mode:"external",onModeChange:Lg,showModeTabs:!1}),t[0]=e):e=t[0],e},Dg="SKILL.md",Mg="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",zi=(t,e)=>{const a=nm({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},Rg=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Lc=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=am(e[1]);if(Rg(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Fg=(t,e)=>{const a=Lc(t);return zi(e,a.instructions)},Og=()=>{const{t}=et(),{currentTheme:e}=Ua(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:m,setSkillDraft:c,setSelectedSkill:x}=Xs(qs(xe=>({selectedSkillName:xe.selectedSkillName,getSkillByName:xe.getSkillByName,getSkillDetail:xe.getSkillDetail,createSkill:xe.createSkill,updateSkill:xe.updateSkill,skillDraft:xe.skillDraft,setSkillDraft:xe.setSkillDraft,setSelectedSkill:xe.setSelectedSkill}))),u=Ws(),v=Xs(xe=>Jr(xe,u)),d=a?n(a,u):null,j=!!(m&&m.name===a&&!d),g=!!(a&&!d&&!m),w=d?.path==="<built-in>";o.useEffect(()=>{g&&x(null)},[g,x]);const[b,k]=o.useState(""),[p,C]=o.useState("user"),[E,A]=o.useState("opencode"),[N,h]=o.useState(""),[y,R]=o.useState(""),[T,P]=o.useState(()=>zi("","")),[D,V]=o.useState("edit"),[$,I]=o.useState([]),[M,H]=o.useState([]),[U,Z]=o.useState(!1),[ee,O]=o.useState(!1),[ae,_]=o.useState(""),[W,q]=o.useState(""),[L,K]=o.useState(!1),[z,J]=o.useState(""),[oe,re]=o.useState(""),[pe,ve]=o.useState(null),[be,te]=o.useState(!1),[he,ie]=o.useState(""),[ue,de]=o.useState(null),[Pe,Ae]=o.useState(!1),we=j?b.trim()!==""||N.trim()!==""||y.trim()!==""||M.length>0:N!==ae||y!==W,Le=pe?oe!==he:z.trim()!=="",_e=o.useCallback(xe=>{switch(xe){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]),Ve=o.useCallback(xe=>{switch(xe){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(j&&m){const Te=m.description||"",Ke=m.instructions||"";k(m.name||""),C(m.scope||"user"),A(m.source==="agents"?"agents":"opencode"),h(Te),R(Ke),P(zi(Te,Ke)),_(""),q(""),I([]),H(m.pendingFiles||[])}else if(a&&d){O(!0);try{const Te=await i(a,u);if(Te){const Ke=Te.sources.md,tt=Ke.description||"",Y=Ke.instructions||"";h(tt),R(Y),P(zi(tt,Y)),_(tt),q(Y),I(Ke.supportingFiles||[])}}catch(Te){console.error("Failed to load skill details:",Te)}finally{O(!1)}}})()},[d,j,a,u,v,m,i]);const je=ce(xe=>xe.editorFontSize),ke=o.useMemo(()=>{const xe=[zo(e,{fontSize:je})],Te=vo(Dg);return Te&&xe.push(Te),xe.push(_o.lineWrapping),xe},[e,je]),se=o.useMemo(()=>{const xe=z.trim()||"supporting-file.md",Te=jd(xe),Ke=!!Te&&Te!=="markdown",tt=[zo(e,Ke?{syntaxColors:!1,fontSize:je}:{fontSize:je})],Y=vo(xe);return Y&&tt.push(Y),Ke&&Te&&tt.push(im({language:Te,themeName:e.metadata.id,theme:om(e)})),tt.push(_o.lineWrapping),tt},[e,z,je]),le=o.useCallback(xe=>{h(xe),P(Te=>Fg(Te,xe))},[]),Ie=o.useCallback(xe=>{P(xe);const Te=Lc(xe);h(Te.description??""),R(Te.instructions)},[]),Ne=async()=>{const xe=j?b.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!xe){F.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(xe)||xe.length>64){F.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!N.trim()){F.error(t("settings.skills.page.toast.descriptionRequired"));return}if(j&&v.some(Te=>Te.name===xe)){F.error(t("settings.skills.page.toast.skillExists"));return}Z(!0);try{const Te={name:xe,description:N.trim(),instructions:y.trim()||void 0,scope:j?p:void 0,source:j?E:void 0,targetPath:j?void 0:d?.path,supportingFiles:j&&M.length>0?M:void 0};let Ke;if(j?(Ke=await r(Te,u),Ke&&(c(null),H([]),x(xe))):(Ke=await l(xe,Te,u),Ke&&(_(N.trim()),q(y.trim()))),Ke){const tt=ia.getState().changes.some(Y=>Y.scope==="skills"&&Y.id.startsWith(`skills:${xe}:`));F.success(t(tt?"settings.view.pendingRestart.saved":j?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else F.error(t(j?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Te){console.error("Error saving skill:",Te),F.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{Z(!1)}},Re=()=>{ve(null),J(""),re(""),ie(""),K(!0)},$e=async xe=>{if(ve(xe),J(xe),j){const Ke=M.find(tt=>tt.path===xe)?.content||"";re(Ke),ie(Ke),K(!0);return}if(a){te(!0),K(!0);try{const{readSupportingFile:Te}=Xs.getState(),Ke=await Te(a,xe,u);re(Ke||""),ie(Ke||"")}catch{F.error(t("settings.skills.page.toast.loadFileContentFailed")),re(""),ie("")}finally{te(!1)}}},De=async()=>{if(!z.trim()){F.error(t("settings.skills.page.toast.fileNameRequired"));return}const xe=z.trim(),Te=pe!==null;if(j){if(Te)H(Y=>Y.map(Se=>Se.path===pe?{path:xe,content:oe}:Se)),F.success(t("settings.skills.page.toast.fileUpdated",{path:xe}));else{if(M.some(Y=>Y.path===xe)){F.error(t("settings.skills.page.toast.fileExists"));return}H(Y=>[...Y,{path:xe,content:oe}]),F.success(t("settings.skills.page.toast.fileAdded",{path:xe}))}K(!1),ve(null);return}if(!a){F.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Ke}=Xs.getState();if(await Ke(a,xe,oe,u)){F.success(Te?t("settings.skills.page.toast.fileUpdated",{path:xe}):t("settings.skills.page.toast.fileCreated",{path:xe})),K(!1),ve(null);const Y=await i(a,u);Y&&I(Y.sources.md.supportingFiles||[])}else F.error(t(Te?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ce=xe=>{if(j){H(Te=>Te.filter(Ke=>Ke.path!==xe)),F.success(t("settings.skills.page.toast.fileRemoved",{path:xe}));return}a&&de(xe)},Ye=async()=>{if(!ue||!a)return;Ae(!0);const{deleteSupportingFile:xe}=Xs.getState();if(await xe(a,ue,u)){F.success(t("settings.skills.page.toast.fileDeleted",{path:ue}));const Ke=await i(a,u);Ke&&I(Ke.sources.md.supportingFiles||[]),de(null)}else F.error(t("settings.skills.page.toast.deleteFileFailed"));Ae(!1)};return!a&&!m||g?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")})]})}):ee?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(is,{title:j?t("settings.skills.page.title.newSkill"):a,description:d?t("settings.skills.page.subtitle.skillLocation",{location:_e(ai(d.scope,d.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[j&&s.jsxs(Ft,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Be,{value:b,onChange:xe=>k(xe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Tt,{value:ai(p,E),onValueChange:xe=>{const Te=Oc(xe);C(Te.scope),A(Te.source==="agents"?"agents":"opencode")},children:[s.jsxs(Et,{size:Bt,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"}),E==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:_e(ai(p,E))})]}),s.jsx(Dt,{align:"start",children:ro.map(xe=>s.jsx(dt,{value:xe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[xe.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"}),xe.source==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:_e(xe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ve(xe.value)})]})},xe.value))})]})]}),s.jsx(At,{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(Ms,{value:N,onChange:xe=>le(xe.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:w})})]}),s.jsx(ze,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(rm,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>V(xe=>xe==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Mg),children:D==="preview"?s.jsx(Ns,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(wd,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Uo,{value:T,onChange:Ie,readOnly:w,extensions:ke,className:"h-full",enableSearch:!0})})}),s.jsx(ze,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Re,disabled:w,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 xe=j?M:$;return xe.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:xe.map(Te=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>$e(Te.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:Te.path}),j&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!w&&s.jsx(G,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ke=>{Ke.stopPropagation(),Ce(Te.path)},children:s.jsx(B,{name:"delete-bin",className:"h-3 w-3"})})]},Te.path))})})()}),s.jsx(ze,{children:s.jsx(G,{onClick:Ne,disabled:w||U||!we,size:"xs",className:"!font-normal",children:t(U?"settings.common.actions.saving":j?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(_t,{open:ue!==null,onOpenChange:xe=>{!xe&&!Pe&&de(null)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(qt,{children:t("settings.skills.page.deleteFileDialog.description",{path:ue??""})})]}),s.jsxs(rs,{children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>de(null),disabled:Pe,children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:Ye,disabled:Pe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(_t,{open:L,onOpenChange:xe=>{K(xe),xe||ve(null)},children:s.jsxs($t,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Vt,{className:"flex-shrink-0",children:[s.jsx(Ht,{children:t(pe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(qt,{children:t(pe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),be?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:Kt,children:t("settings.skills.page.fileDialog.field.filePath")}),!pe&&s.jsx(Yt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Be,{value:z,onChange:xe=>J(xe.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:`${Kt} 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(Uo,{value:oe,onChange:re,extensions:se,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(rs,{className:"mt-4",children:[s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{K(!1),ve(null)},children:t("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",onClick:De,disabled:be||!Le,children:t(pe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},nl=t=>{const e=ct.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(Eg,{}):s.jsx(Og,{}),e[0]=n,e[1]=i):i=e[1],i};function Lg(){}const Kg=t=>{const e=ct.c(38),{onItemSelect:a}=t,{t:n}=et(),i=en(zg),r=ce(Ug),l=ce(_g),{currentTheme:m}=Ua();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ds(),e[0]=c):c=e[0];const x=c,u=$g;let v,d;e[1]!==i||e[2]!==r||e[3]!==l?(v=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(h=>h.id===r)||l(i[0].id)},d=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=d):(v=e[4],d=e[5]),o.useEffect(v,d);let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j=ye("border-b px-3","pt-4 pb-3"),e[6]=j):j=e[6];let g;e[7]!==n?(g=n("settings.page.projects.title"),e[7]=n,e[8]=g):g=e[8];let w;e[9]!==g?(w=s.jsx("h2",{className:`${Cn} mb-3`,children:g}),e[9]=g,e[10]=w):w=e[10];let b;e[11]!==i.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.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=!x&&s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:u,"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 C;e[18]!==k||e[19]!==p?(C=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,p]}),e[18]=k,e[19]=p,e[20]=C):C=e[20];let E;e[21]!==C||e[22]!==w?(E=s.jsxs("div",{className:j,children:[w,C]}),e[21]=C,e[22]=w,e[23]=E):E=e[23];let A;if(e[24]!==m||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let h;e[30]!==m||e[31]!==a||e[32]!==r||e[33]!==l?(h=y=>{const R=y.id===r,T=y.icon?Nd[y.icon]:null,P=y.color?Sd[y.color]??null:null,D=T?s.jsx(B,{name:T,className:ye("h-4 w-4",R?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}):s.jsx(B,{name:"folder",className:ye("h-4 w-4",R?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}),V=y.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:y.iconBackground?{backgroundColor:y.iconBackground}:void 0,children:s.jsx(Cd,{project:y,options:{themeVariant:m.metadata.variant,iconColor:m.colors.surface.foreground},className:"h-full w-full object-contain",fallback:D})}):D;return s.jsx($r,{title:y.label||y.path,icon:V,selected:R,onSelect:()=>{l(y.id),a?.()}},y.id)},e[30]=m,e[31]=a,e[32]=r,e[33]=l,e[34]=h):h=e[34],A=i.map(h),e[24]=m,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=A}else A=e[29];let N;return e[35]!==E||e[36]!==A?(N=s.jsx(Rc,{variant:"background",header:E,children:A}),e[35]=E,e[36]=A,e[37]=N):N=e[37],N};function zg(t){return t.projects}function Ug(t){return t.settingsProjectsSelectedId}function _g(t){return t.setSettingsProjectsSelectedId}function $g(){kd.requestDirectoryDialog()}const Bg=()=>{const t=ct.c(30),{t:e}=et(),a=en(Vg),n=en(Hg),i=ce(qg),r=ce(Gg);let l;e:{if(!i){l=null;break e}let b;t[0]!==a||t[1]!==i?(b=a.find(k=>k.id===i)??null,t[0]=a,t[1]=i,t[2]=b):b=t[2],l=b}const m=l;let c,x;t[3]!==a||t[4]!==i||t[5]!==r?(c=()=>{if(a.length===0){r(null);return}i&&a.some(b=>b.id===i)||r(a[0].id)},x=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=c,t[7]=x):(c=t[6],x=t[7]),o.useEffect(c,x);let u;t[8]!==m||t[9]!==n?(u=async b=>{m&&n(m.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]=m,t[9]=n,t[10]=u):u=t[10];const v=u;if(!m){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 C;return t[17]!==b||t[18]!==p?(C=s.jsx(is,{title:b,showSaveStatus:!0,children:p}),t[17]=b,t[18]=p,t[19]=C):C=t[19],C}let d;t[20]!==m.label||t[21]!==e?(d=m.label??e("settings.projects.page.title.default"),t[20]=m.label,t[21]=e,t[22]=d):d=t[22];const j=d;let g;t[23]!==v||t[24]!==m?(g=s.jsx(Qu,{project:m,onIdentitySave:v}),t[23]=v,t[24]=m,t[25]=g):g=t[25];let w;return t[26]!==j||t[27]!==m.path||t[28]!==g?(w=s.jsx(is,{title:j,description:m.path,showSaveStatus:!0,outerClassName:"bg-background",children:g}),t[26]=j,t[27]=m.path,t[28]=g,t[29]=w):w=t[29],w};function Vg(t){return t.projects}function Hg(t){return t.updateProjectMeta}function qg(t){return t.settingsProjectsSelectedId}function Gg(t){return t.setSettingsProjectsSelectedId}const Ui=()=>Math.floor(2e4+Math.random()*3e4),Wg=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")},Jg=()=>{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"},al=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"}},Qg=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),oo=t=>!!(t&&Qg.has(t)),rl=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||oo(t)?"connecting":"idle",ol=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Yg=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},ll={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Zg=t=>t==="noRuntime"?ll.noRuntime:t==="noOpencode"?ll.noOpencode:null,cl=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||oo(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Xg=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}`,eh=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Ui(),remoteHost:"127.0.0.1",remotePort:80}),th=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Qs=t=>{const e=ct.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Yt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Kt}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},sh=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}`},nh=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},ah=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},Vr=(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}),ih=t=>t.trim().toLowerCase()==="authorization",wr=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!ih(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},rh=t=>Object.entries(t||{}).map(([e,a])=>Vr(e,a)),Kc=()=>{if(typeof window>"u")return null;const e=ri()||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}},ul=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},oh=async()=>{const t=Ta(ri())||window.location.origin;if(!cs()||!oi()||(await In())?.desktopLanAccessActive!==!0)return t;const a=await yc(),n=Kc();return!a||!n?t:`http://${a}:${n}`},Ei=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},lh=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},ch=()=>{const{t}=et(),e=ce(S=>S.timeFormatPreference),{clientAuth:a}=to(),n=cs(),i=Rs(S=>S.instances),r=Rs(S=>S.statusesById),l=Rs(S=>S.importCandidates),m=Rs(S=>S.isLoading),c=Rs(S=>S.isImportsLoading),x=Rs(S=>S.isSaving),u=Rs(S=>S.error),v=Rs(S=>S.load),d=Rs(S=>S.loadImports),j=Rs(S=>S.refreshStatuses),g=Rs(S=>S.upsertInstance),w=Rs(S=>S.createFromCommand),b=Rs(S=>S.removeInstance),k=Rs(S=>S.connect),p=Rs(S=>S.disconnect),C=Rs(S=>S.retry),E=ce(S=>S.settingsRemoteInstancesSelectedId),A=ce(S=>S.setSettingsRemoteInstancesSelectedId),N=o.useMemo(()=>E&&i.find(S=>S.id===E)||null,[i,E]),[h,y]=o.useState(null),[R,T]=o.useState(!1),[P,D]=o.useState(!1),[V,$]=o.useState(null),[I,M]=o.useState([]),[H,U]=o.useState(null),[Z,ee]=o.useState(""),[O,ae]=o.useState(!1),[_,W]=o.useState({}),[q,L]=o.useState(!1),[K,z]=o.useState(!1),[J,oe]=o.useState(()=>Date.now()),[re,pe]=o.useState([]),[ve,be]=o.useState({}),[te,he]=o.useState("local"),[ie,ue]=o.useState(!1),[de,Pe]=o.useState(!1),[Ae,we]=o.useState(""),[Le,_e]=o.useState(""),[Ve,je]=o.useState(""),[ke,se]=o.useState([]),[le,Ie]=o.useState(""),[Ne,Re]=o.useState(null),[$e,De]=o.useState(!1),[Ce,Ye]=o.useState(!1),[xe,Te]=o.useState(null),[Ke,tt]=o.useState(""),[Y,Se]=o.useState(""),[Ee,We]=o.useState(""),[lt,at]=o.useState([]),[pt,bt]=o.useState([]),[Q,qe]=o.useState([]),[it,ut]=o.useState(!1),[gt,Ot]=o.useState(""),[st,ft]=o.useState(null),[jt,Je]=o.useState(null),[St,Oe]=o.useState(null),[wt,X]=o.useState(null),[fe,Fe]=o.useState(!1),[Me,rt]=o.useState(!1),[ot,Ge]=o.useState("configure"),[Nt,ns]=o.useState(!1),[Zt,Qe]=o.useState("relay"),[He,Ct]=o.useState(!0),[Pt,es]=o.useState(null),ts=o.useMemo(()=>pt.filter(S=>!!S.revokedAt).length,[pt]),[os,xs]=o.useState(!1),[Fs,me]=o.useState("saved"),[ht,kt]=o.useState(""),[Xt,ss]=o.useState(""),[Jt,ps]=o.useState(""),[Ss,us]=o.useState(!1);o.useEffect(()=>{v(),d()},[v,d]);const It=o.useCallback(async()=>{ue(!0),Re(null);try{const S=await Ao();pe(S.hosts||[]),he(S.defaultHostId||"local")}catch(S){Re(S instanceof Error?S.message:String(S))}finally{ue(!1)}},[]);o.useEffect(()=>{It()},[It]);const Lt=o.useCallback(async(S,ne=te)=>{Pe(!0),Re(null);try{await To({hosts:S,defaultHostId:ne,initialHostChoiceCompleted:!0}),pe(S),he(ne)}catch(Ue){Re(Ue instanceof Error?Ue.message:String(Ue))}finally{Pe(!1)}},[te]),Wt=o.useCallback(async()=>{const S=Eo(Le);if(!S){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=S.persistedUrl,nt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ae.trim()||qa(ne),url:ne,apiUrl:ne,...Ve.trim()?{clientToken:Ve.trim()}:{},...wr(ke)?{requestHeaders:wr(ke)}:{}};await Lt([nt,...re],te),we(""),_e(""),je(""),se([]),De(!1),S.redeemUrl&&Ei(S.redeemUrl)},[te,ke,re,Ae,Ve,Le,Lt,t]),Gt=o.useCallback(async()=>{const S=bu(le);if(!S){Re(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ne=await vu().catch(()=>""),Ue=JSON.stringify({pairingId:S.pairingId,secret:S.secret,clientLabel:S.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Jg(),...ne?{dedupeKey:`desktop:${ne}`}:{}}),nt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Ue},zt=async Rt=>{if(!Rt.ok)return null;const Ls=await Rt.json().catch(()=>null);return(typeof Ls?.clientToken=="string"?Ls.clientToken.trim():"")||null},Is=[...S.candidates].sort((Rt,Ls)=>(Rt.type==="relay"?1:0)-(Ls.type==="relay"?1:0));let bs=null;for(const Rt of Is){if(Rt.type==="relay"){const Jn=yu({relayUrl:Rt.relayUrl,serverId:Rt.serverId,hostEncPubJwk:Rt.hostEncPubJwk,...Rt.grant?{grant:Rt.grant}:{}});try{const Na=await Jn.fetch("/api/client-auth/pairing/redeem",nt),ji=await zt(Na);if(ji){bs={kind:"relay",relay:{relayUrl:Rt.relayUrl,serverId:Rt.serverId,hostEncPubJwk:Rt.hostEncPubJwk},token:ji};break}}catch{}finally{Jn.close()}continue}const Ls=Ta(Rt.url);if(Ls)try{const Jn=await fetch(`${Ls}/api/client-auth/pairing/redeem`,nt),Na=await zt(Jn);if(Na){bs={kind:"direct",url:Ls,token:Na};break}}catch{}}if(!bs){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const Js=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Ps=S.candidates.find(Rt=>Rt.type==="relay"),sn=bs.kind==="relay"?bs.relay:Ps?{relayUrl:Ps.relayUrl,serverId:Ps.serverId,hostEncPubJwk:Ps.hostEncPubJwk}:void 0,Va=S.candidates.filter(Rt=>Rt.type!=="relay").map(Rt=>Ta(Rt.url)).find(Rt=>!!Rt),Wn=bs.kind==="direct"?bs.url:Va,{token:Ha}=bs,Mt=Wn||(sn?ju(sn.serverId):null);if(!Mt){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const Qt={url:Mt,apiUrl:Wn||void 0,clientToken:Ha,...sn?{relay:sn}:{}},gn=re.find(Rt=>sn?Rt.relay?.serverId===sn.serverId:!Rt.relay&&Ta(Rt.apiUrl||Rt.url)===Mt);if(gn){const Rt=re.map(Ls=>Ls.id===gn.id?{...Ls,label:S.label||Ls.label,...Qt}:Ls);await Lt(Rt,te)}else await Lt([{id:Js(),label:S.label||qa(Mt),...Qt},...re],te);Ie(""),Re(null),Ye(!1)},[le,te,re,Lt,t]),ms=o.useCallback(async S=>{const ne=re.filter(nt=>nt.id!==S);await Lt(ne,te===S?"local":te),xe===S&&Te(null)},[te,xe,re,Lt]),Os=o.useCallback(S=>{Te(S.id),tt(S.label),Se(S.apiUrl||S.url),We(S.clientToken||""),at(rh(S.requestHeaders)),Re(null)},[]),Qi=o.useCallback(async()=>{if(!xe)return;const S=Eo(Y);if(!S){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=S.persistedUrl,Ue=re.map(nt=>nt.id===xe?{...nt,label:Ke.trim()||qa(ne),url:ne,apiUrl:ne,clientToken:Ee.trim()||void 0,requestHeaders:wr(lt)}:nt);await Lt(Ue,te),Te(null),S.redeemUrl&&Ei(S.redeemUrl)},[te,lt,Ke,Ee,Y,xe,re,Lt,t]),Yi=o.useCallback(async()=>{const S=Xt.trim();if(!S){F.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ne=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await w(ne,S,Jt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),A(ne),xs(!1),ss(""),ps(""),F.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Ue){F.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ue instanceof Error?Ue.message:String(Ue)})}},[w,A,Xt,Jt,t]),di=o.useCallback(()=>{kt(""),me(l.length>0?"saved":"manual"),xs(!0)},[l.length]),Zi=o.useCallback(async S=>{await Lt(re,S)},[re,Lt]);o.useEffect(()=>{if(!n||re.length===0)return;let S=!1;return Promise.all(re.map(async ne=>{const Ue=()=>Iu(ne.relay,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ne.relay&&!ne.apiUrl)return[ne.id,await Ue()];const nt=Ta(wu(ne));if(!nt)return[ne.id,ne.relay?await Ue():{status:"unreachable",latencyMs:0}];const zt=await ku(nt,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(zt.status==="unreachable"&&ne.relay){const Is=await Ue();if(Is.status==="ok")return[ne.id,Is]}return[ne.id,zt]})).then(ne=>{S||be(Object.fromEntries(ne))}),()=>{S=!0}},[re,n]);const $s=o.useCallback(async S=>{if(a){S?.silent||ut(!0),S?.silent||ft(null);try{const[ne,Ue]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);bt(ne),Ue&&qe(Ue)}catch(ne){S?.silent||ft(ne instanceof Error?ne.message:String(ne))}finally{S?.silent||ut(!1)}}},[a]),_a=o.useRef(!1);o.useEffect(()=>{if(!(!Me||ot!=="result"||!St)){if(Q.some(S=>S.id===St)){_a.current=!0;return}_a.current&&(Oe(null),rt(!1),pt.some(S=>S.pairingId===St)&&F.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Me,ot,St,Q,pt,t]);const Xi=o.useCallback(async S=>{if(a)try{await a.cancelPairing(S),qe(ne=>ne.filter(Ue=>Ue.id!==S)),await $s({silent:!0})}catch(ne){ft(ne instanceof Error?ne.message:String(ne))}},[a,$s]);o.useEffect(()=>{if(!a)return;$s();const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||$s({silent:!0})},5e3);return()=>window.clearInterval(S)},[a,$s]);const ui=o.useCallback(async()=>{if(a?.getPairingTransports)try{const nt=await a.getPairingTransports();return{localUrl:nt.local,lanUrl:nt.lan,relayAvailable:nt.relayAvailable}}catch{}const S=Kc(),ne=S?`http://127.0.0.1:${S}`:ul(window.location.origin)?window.location.origin:null;let Ue=null;try{const nt=Ta(await oh());Ue=nt&&!ul(nt)?nt:null}catch{}return{localUrl:ne,lanUrl:Ue,relayAvailable:!0}},[a]),mi=o.useCallback(async()=>{ft(null),Je(null),X(null),Fe(!1),Oe(null),Ge("configure"),Ct(!0),rt(!0);const S=await ui();es(S),Qe(S.relayAvailable?"relay":S.lanUrl?"lan":"local")},[ui]),er=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Pt)){ft(null),ns(!0);try{const S=gt.trim()||void 0;let ne,Ue,nt=!0;Zt==="local"?(ne=Pt.localUrl??void 0,Ue=!1):Zt==="lan"?(ne=Pt.lanUrl??void 0,Ue=He):He&&Pt.lanUrl?(ne=Pt.lanUrl,Ue=!0):(nt=!1,Ue=!0);const{pairing:zt,server:Is}=await a.createPairingSession({label:S,allowedClientKinds:["mobile","desktop"],serverUrl:ne,includeRelay:Ue,includeDirect:nt}),bs=Nu({pairingId:zt.id,secret:zt.secret,label:Is.label,fingerprint:zt.fingerprint??void 0,expiresAt:zt.expiresAt,candidates:Is.candidates}),Js=Su(bs);Je(Js),X(await Pc.toDataURL(Js,{width:1024,margin:2,errorCorrectionLevel:"L"})),Fe(!1),_a.current=!1,Oe(zt.id),Ge("result"),await $s({silent:!0})}catch(S){ft(S instanceof Error?S.message:String(S))}finally{ns(!1)}}},[a,Pt,Zt,He,gt,$s]),tr=o.useCallback(()=>{jt&&Ra(jt).then(S=>{S.ok&&(Fe(!0),window.setTimeout(()=>Fe(!1),2e3))})},[jt]),sr=o.useCallback(async S=>{if(!a)return;const ne=S.clientKind==="desktop-local";ft(null);try{if(await a.revokeClient(S.id),ne&&cs()){const Ue=await Ao();await To({hosts:Ue.hosts,defaultHostId:Ue.defaultHostId,initialHostChoiceCompleted:Ue.initialHostChoiceCompleted,localClientToken:null}),bt(nt=>nt.map(zt=>zt.id===S.id?{...zt,revokedAt:new Date().toISOString()}:zt)),Cu({apiBaseUrl:ri(),clientToken:null,runtimeKey:"local"});return}await $s()}catch(Ue){ft(Ue instanceof Error?Ue.message:String(Ue))}},[a,$s]),pi=o.useCallback(async()=>{if(a){ft(null);try{await a.purgeRevokedClients(),await $s()}catch(S){ft(S instanceof Error?S.message:String(S))}}},[a,$s]);o.useEffect(()=>{y(N)},[N]),o.useEffect(()=>{us(!1)},[E]),o.useEffect(()=>{if(!E)return;const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||j()},2e3);return()=>{window.clearInterval(S)}},[j,E]),o.useEffect(()=>{let S=null,ne=Date.now();const Ue=()=>{const zt=Date.now();zt-ne>=1e3&&(oe(zt),ne=zt),S=requestAnimationFrame(Ue)};(typeof document>"u"||document.visibilityState==="visible")&&(S=requestAnimationFrame(Ue));const nt=()=>{document.visibilityState==="visible"&&S===null?S=requestAnimationFrame(Ue):document.visibilityState!=="visible"&&S!==null&&(cancelAnimationFrame(S),S=null)};return document.addEventListener("visibilitychange",nt),()=>{document.removeEventListener("visibilitychange",nt),S!==null&&cancelAnimationFrame(S)}},[]);const Cs=E?r[E]:null,tn=Cs?.phase,fa=tn==="ready",Pn=tn==="degraded",Fn=oo(tn),mn=fa||(Fn||Pn),nr=Cs?Math.max(0,J-Cs.updatedAtMs):0,Hn=Pn&&nr>12e3,xa=rl(tn),qn=xa==="error"?Yg(Cs?.detail):null,$a=Zg(qn),ar=o.useMemo(()=>!h||!N?!1:JSON.stringify(h)!==JSON.stringify(N),[h,N]),gs=o.useCallback(S=>{y(ne=>ne&&S(ne))},[]),ir=o.useCallback(async()=>{if(!h)return;const S=lh(h);if(!S.sshCommand.trim()){F.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(S.remoteOpenchamber.mode==="external"&&!S.remoteOpenchamber.preferredPort){F.error(t("settings.remoteInstances.page.validation.externalPortRequired")),us(!0);return}if(S.remoteOpenchamber.mode==="managed"&&S.remoteOpenchamber.bindHost==="0.0.0.0"&&!S.auth.openchamberPassword?.value?.trim()){F.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),us(!0),window.setTimeout(()=>An.current?.focus(),0);return}if(!(S.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(S.auth.sshPassword?.enabled&&S.auth.sshPassword.value?.trim()&&S.auth.sshPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));S.auth.sshPassword.store=ne?"settings":"never",ne||(S.auth.sshPassword.value=void 0)}if(S.auth.openchamberPassword?.enabled&&S.auth.openchamberPassword.value?.trim()&&S.auth.openchamberPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));S.auth.openchamberPassword.store=ne?"settings":"never",ne||(S.auth.openchamberPassword.value=void 0)}try{await g(S),F.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ne){F.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ne instanceof Error?ne.message:String(ne)})}}},[h,t,g]),ba=o.useCallback(async(S,ne)=>{const Ue=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await w(Ue,`ssh ${ne}`,S),A(Ue),F.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(nt){return F.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:nt instanceof Error?nt.message:String(nt)}),!1}},[w,A,t]),va=o.useCallback(()=>{O||(U(null),ee(""))},[O]),rr=o.useCallback((S,ne)=>{if(xs(!1),ne){U(S),ee(th(S));return}ba(S,S)},[ba]),gi=o.useMemo(()=>$i(l,ht,S=>[S.host,S.sshCommand]),[l,ht]),or=o.useCallback(S=>{const ne=(S||"").trim();if(!ne){F.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ei(ne)},[t]),hi=o.useCallback(async()=>{const S=H,ne=Z.trim();if(S){if(!ne){F.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}ae(!0);try{await ba(S,ne)&&(U(null),ee(""))}finally{ae(!1)}}},[ba,Z,H,t]),ya=o.useCallback(async()=>{if(N)try{await k(N.id);return}catch(S){if(!Wg(S)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw S;const Ue={...N,localForward:{...N.localForward,preferredLocalPort:Ui()}};await g(Ue),await k(Ue.id),F.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[k,N,t,g]),An=o.useRef(null),Gn=o.useRef(null),Ba=o.useCallback(async S=>{if(N){if(S==="localPort"){const ne={...N,localForward:{...N.localForward,preferredLocalPort:Ui()}};try{await g(ne),await k(ne.id),F.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Ue){F.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Ue instanceof Error?Ue.message:String(Ue)})}return}us(!0),window.setTimeout(()=>{if(S==="uiPassword"){An.current?.focus();return}Gn.current?.scrollIntoView({block:"center"})},0)}},[k,N,t,g]),On=o.useCallback(async S=>(await Id(S,600)).map(Ue=>ah(Ue)),[]),ja=o.useCallback(async()=>{if(h){T(!0),D(!0),$(null);try{const S=await On(h.id);M(S)}catch(S){M([]),$(S instanceof Error?S.message:String(S))}finally{D(!1)}}},[h,On]);o.useEffect(()=>{if(!R||!h)return;let S=!1;const ne=async()=>{try{const nt=await On(h.id);S||(M(nt),$(null))}catch(nt){S||$(nt instanceof Error?nt.message:String(nt))}};ne();const Ue=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ne()},1e3);return()=>{S=!0,window.clearInterval(Ue)}},[h,R,On]);const ge=o.useMemo(()=>I.join(`
27
- `),[I]),hs=o.useCallback(()=>{if(!ge.trim()){F.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ra(ge).then(S=>{S.ok&&F.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ge,t]),wa=o.useCallback(async()=>{if(h)try{await Pd(h.id),M([]),F.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(S){F.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:S instanceof Error?S.message:String(S)})}},[h,t]),fi=o.useCallback(async()=>{if(!Cs?.localUrl){F.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const S=Cs.localUrl.trim();if(!S){F.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ei(S)},[Cs?.localUrl,t]),xi=o.useCallback(()=>{if(!h)return;if(!mn&&h.remoteOpenchamber.mode==="external"&&!h.remoteOpenchamber.preferredPort){F.error(t("settings.remoteInstances.page.validation.externalPortRequired")),us(!0);return}if(!mn&&h.remoteOpenchamber.mode==="managed"&&h.remoteOpenchamber.bindHost==="0.0.0.0"&&!h.auth.openchamberPassword?.value?.trim()){F.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),us(!0),window.setTimeout(()=>An.current?.focus(),0);return}L(!0),(mn?p(h.id):ya()).catch(ne=>{const Ue=mn?fa?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";F.error(t(Ue),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{L(!1)})},[mn,ya,p,h,fa,t]),bi=o.useCallback(()=>{if(!h||Fn)return;z(!0),(Pn?p(h.id).then(()=>ya()):C(h.id)).catch(ne=>{F.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{z(!1)})},[ya,p,h,Fn,Pn,C,t]),vi=t(Fn?"settings.remoteInstances.page.actions.connecting":Pn?Hn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),yi=!q&&!K&&(tn==="error"||tn==="idle"||!tn||Pn&&Hn)&&!Fn,lr=t(fa?"settings.remoteInstances.sidebar.actions.disconnect":mn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!h)return s.jsxs(is,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(ze,{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:()=>{mi()},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:[ts>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{pi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,it&&pt.length===0&&Q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):pt.length===0&&Q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[Q.map(S=>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:S.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),S.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:()=>{Xi(S.id)},children:t("settings.common.actions.cancel")})]},`pending-${S.id}`)),pt.map(S=>{const ne=S.clientKind==="desktop-local",Ue=S.lastUsedAt?Date.parse(S.lastUsedAt):Number.NaN,nt=!S.revokedAt&&(ne||Number.isFinite(Ue)&&Date.now()-Ue<9e4),zt=S.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):nt?S.lastTransport==="relay"&&!ne?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Ue)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Ad(Ue,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",S.revokedAt?"bg-muted-foreground/20":nt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:S.label}),al(S.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:al(S.devicePlatform)}):null,ne?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:ye("typography-micro truncate",nt&&!S.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:zt})]})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{sr(S)},disabled:!!S.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},S.id)})]})]}),st?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:st}):null]}):null,n?s.jsxs(ze,{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:()=>Ye(!0),disabled:de,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>De(!0),disabled:de,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:ie?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(S=>{const ne=ve[S.id],Ue=ne?ne.status==="ok"?"desktopHostSwitcher.status.connected":ne.status==="auth"?"desktopHostSwitcher.status.authRequired":ne.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ne.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ne.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",nt=ne?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",ne?nt?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:qa(S.label)}),te===S.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ye("typography-micro shrink-0",nt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Ue),nt&&typeof ne?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ne.latencyMs))}):""]})]}),s.jsx("p",{className:ye("typography-micro text-muted-foreground truncate",S.apiUrl&&"font-mono"),children:S.relay&&!S.apiUrl?t("mobile.connect.relay.badge"):qa(S.apiUrl||S.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:()=>{Zi(S.id)},disabled:de||te===S.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:te===S.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"})}),S.relay&&!S.apiUrl?null:s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Os(S),disabled:de,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:()=>{ms(S.id)},disabled:de,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},S.id)})}),Ne?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ne}):null]}):null,n?s.jsx(_t,{open:$e,onOpenChange:De,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Wt()},children:[s.jsx(Be,{className:"h-8",value:Ae,onChange:S=>we(S.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:de}),s.jsx(Be,{className:"h-8",value:Le,onChange:S=>_e(S.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:de,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Be,{className:"h-8",value:Ve,onChange:S=>je(S.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:de}),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(dn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ke.map(S=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Be,{className:"h-8 font-mono text-xs",value:S.name,onChange:ne=>se(Ue=>Ue.map(nt=>nt.id===S.id?{...nt,name:ne.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:de}),s.jsx(Be,{className:"h-8 font-mono text-xs",value:S.value,onChange:ne=>se(Ue=>Ue.map(nt=>nt.id===S.id?{...nt,value:ne.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:de}),s.jsx("button",{type:"button",onClick:()=>se(ne=>ne.filter(Ue=>Ue.id!==S.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:de,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},S.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(S=>[...S,Vr()]),disabled:de,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:()=>De(!1),disabled:de,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:de||!Le.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(_t,{open:!!xe,onOpenChange:S=>{S||Te(null)},children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Qi()},children:[s.jsx(Be,{className:"h-8",value:Ke,onChange:S=>tt(S.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:de}),s.jsx(Be,{className:"h-8",value:Y,onChange:S=>Se(S.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:de,autoFocus:!0}),s.jsx(Be,{className:"h-8",value:Ee,onChange:S=>We(S.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:de}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(dn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),lt.map(S=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Be,{className:"h-8 font-mono text-xs",value:S.name,onChange:ne=>at(Ue=>Ue.map(nt=>nt.id===S.id?{...nt,name:ne.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:de}),s.jsx(Be,{className:"h-8 font-mono text-xs",value:S.value,onChange:ne=>at(Ue=>Ue.map(nt=>nt.id===S.id?{...nt,value:ne.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:de}),s.jsx("button",{type:"button",onClick:()=>at(ne=>ne.filter(Ue=>Ue.id!==S.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:de,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},S.id)),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>at(S=>[...S,Vr()]),disabled:de,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:()=>Te(null),disabled:de,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:de,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(_t,{open:Ce,onOpenChange:Ye,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Gt()},children:[s.jsx(Be,{className:"h-8",value:le,onChange:S=>Ie(S.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:de,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:()=>Ye(!1),disabled:de,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:de||!le.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(_t,{open:Me,onOpenChange:rt,children:s.jsxs($t,{className:ot==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t(ot==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(qt,{children:t(ot==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),ot==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:S=>{S.preventDefault(),er()},children:[s.jsx(Be,{className:"h-8",value:gt,onChange:S=>Ot(S.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Pt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Pt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Pt?.localUrl}].map(S=>{const ne=Zt===S.key;return s.jsxs("div",{className:ye("flex items-start gap-2 py-0.5",S.available?"cursor-pointer":"opacity-45"),onClick:()=>{S.available&&Qe(S.key)},role:"presentation",children:[s.jsx(Yr,{checked:ne,disabled:!S.available,onChange:()=>Qe(S.key),ariaLabel:S.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ye("typography-ui-label font-normal",ne?"text-foreground":"text-foreground/70"),children:S.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:S.hint})]})]},S.key)})}),Zt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Rr,{checked:He,onChange:Ct,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,Zt==="relay"&&Pt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Rr,{checked:He,onChange:Ct,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]}),st?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:st}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rt(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!Pt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,jt?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:jt}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:tr,children:[s.jsx(B,{name:fe?"check":"file-copy",className:ye("h-3.5 w-3.5",fe&&"text-[var(--status-success)]")}),t(fe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(ze,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(G,{type:"button",size:"xs",className:"!font-normal",onClick:di,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:m?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(S=>{const ne=r[S.id],Ue=S.nickname?.trim()||S.sshParsed?.destination||S.id,nt=ne?.phase,zt=nt==="ready",Is=rl(nt),bs=Is==="error"?ne?.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 ${cl(nt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ue})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(ol(Is)),Is==="connecting"?` · ${t(il(nt))}`:"",zt&&ne?.localUrl?` · ${ne.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[zt?s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>or(ne?.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:()=>{(zt?p(S.id):k(S.id)).catch(Ps=>F.error(t(zt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Ps instanceof Error?Ps.message:String(Ps)}))},children:[zt?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(zt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(S.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(S.id).catch(Ps=>F.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Ps instanceof Error?Ps.message:String(Ps)}))},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),bs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:bs}):null]},S.id)})}):null,n?s.jsx(_t,{open:os,onOpenChange:xs,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(qt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(cn,{value:Fs,onChange:me,"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")}]}),Fs==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Be,{className:"h-8",value:ht,onChange:S=>kt(S.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")}):gi.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:gi.map(S=>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:[S.host,S.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:S.sshCommand})]}),s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(S.host,S.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${S.source}:${S.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Yi()},children:[s.jsx(Be,{className:"h-8",value:Jt,onChange:S=>ps(S.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:x}),s.jsx(Be,{className:"h-8",value:Xt,onChange:S=>ss(S.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:x,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>xs(!1),disabled:x,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:x||!Xt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(_t,{open:!!H,onOpenChange:S=>{S||va()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:H?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:H}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),hi()},children:[s.jsx(Be,{value:Z,onChange:S=>ee(S.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:va,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const pn=h.remoteOpenchamber.mode==="managed",Ln=pn&&h.remoteOpenchamber.bindHost==="0.0.0.0",ka=Ln&&!h.auth.openchamberPassword?.value?.trim(),cr=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(_t,{open:!!h,onOpenChange:S=>{S||A(null)},children:s.jsxs($t,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Mr} truncate`,children:cr}),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 ${cl(tn)}`}),s.jsx("span",{className:"text-foreground",children:t(ol(xa))}),xa==="connecting"?s.jsx("span",{children:t(il(tn))}):null,Cs?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Cs.localUrl}):null,Hn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(ze,{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:mn?"outline":"default",size:"xs",className:"!font-normal",onClick:xi,disabled:q||K,children:[mn?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"}),lr]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:bi,disabled:!yi,children:[s.jsx(B,{name:"refresh",className:`h-3.5 w-3.5 ${Fn||Pn&&!Hn?"animate-spin":""}`}),vi]}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ja()},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(h.id).then(()=>{A(null),F.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ne=>{F.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ne instanceof Error?ne.message:String(ne)})})},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),xa==="error"&&Cs?.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:Cs.detail}),$a?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t($a)}):null,qn&&!$a?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ba(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,Cs?.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:Cs.localUrl})]}):null]}),s.jsxs(ze,{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(Be,{className:"h-7 md:max-w-xl",value:h.sshCommand,onChange:S=>gs(ne=>({...ne,sshCommand:S.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(Be,{className:"h-7 md:max-w-sm",value:h.nickname||"",onChange:S=>gs(ne=>({...ne,nickname:S.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(Qs,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Tt,{value:h.remoteOpenchamber.mode,onValueChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,mode:S==="external"?"external":"managed"}})),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[140px]",children:s.jsx(Ut,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(dt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(kn,{open:Ss,onOpenChange:us,children:[s.jsxs(Nn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:ic,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(B,{name:Ss?"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(ks,{containerClassName:"w-fit",min:5,max:240,step:1,className:ye(Ds,"tabular-nums"),value:h.connectionTimeoutSec,onValueChange:S=>{gs(ne=>({...ne,connectionTimeoutSec:Number.isFinite(S)?S:ne.connectionTimeoutSec}))}})]}),s.jsxs(ze,{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:Gn,children:s.jsx(Qs,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Ds,"tabular-nums"),value:h.remoteOpenchamber.preferredPort,onValueChange:S=>{gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,preferredPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{gs(S=>({...S,remoteOpenchamber:{...S.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),pn?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(Qs,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Tt,{value:h.remoteOpenchamber.installMethod,onValueChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,installMethod:S==="npm"||S==="bun"?S:"auto"}})),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[140px]",children:s.jsx(Ut,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(dt,{value:"bun",children:"bun"}),s.jsx(dt,{value:"npm",children:"npm"})]})]})]}):null,pn?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(Qs,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(si,{checked:Ln,onCheckedChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,bindHost:S?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),Ln?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,pn?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(Qs,{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(si,{checked:h.remoteOpenchamber.keepRunning,onCheckedChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,keepRunning:S}}))})})]}):null]}),s.jsxs(ze,{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(Qs,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Tt,{value:h.localForward.bindHost,onValueChange:S=>{S==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||gs(ne=>({...ne,localForward:{...ne.localForward,bindHost:S==="localhost"||S==="0.0.0.0"?S:"127.0.0.1"}}))},children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[240px]",children:s.jsx(Ut,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(dt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(dt,{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(Qs,{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(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Ds,"tabular-nums"),value:h.localForward.preferredLocalPort,onValueChange:S=>{gs(ne=>({...ne,localForward:{...ne.localForward,preferredLocalPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{gs(S=>({...S,localForward:{...S.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:()=>gs(S=>({...S,localForward:{...S.localForward,preferredLocalPort:Ui()}})),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:`${h.localForward.bindHost}:${h.localForward.preferredLocalPort||"auto"} → ${h.sshParsed?.destination||h.nickname||"remote"}:${h.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(ze,{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(Qs,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Be,{className:"h-7 md:max-w-sm",type:"password",value:h.auth.sshPassword?.value||"",onChange:S=>gs(ne=>({...ne,auth:{...ne.auth,sshPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:ne.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(Qs,{label:t(Ln?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(pn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Be,{className:ye("h-7 md:max-w-sm",ka&&"border-[var(--status-error)]"),type:"password",ref:An,"aria-invalid":ka,value:h.auth.openchamberPassword?.value||"",onChange:S=>gs(ne=>({...ne,auth:{...ne.auth,openchamberPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:ne.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ka?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[h.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,h.portForwards.map((S,ne)=>{const Ue=Mt=>{gs(Qt=>({...Qt,portForwards:Qt.portForwards.map((gn,Rt)=>Rt===ne?Mt(gn):gn)}))},nt=S.type==="remote"?"Local target":"Local listen",zt=S.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.",Is=S.type==="remote"?"Remote listen":"Remote target",bs=S.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Js=dl(S.localHost||"localhost",S.localPort),Ps=dl(S.remoteHost||"localhost",S.remotePort),sn=S.type==="local"&&typeof S.localPort=="number"&&S.localPort>0,Va=sn?`http://${nh(S.localHost)}:${S.localPort}`:"",Wn=!!_[S.id],Ha=S.type==="local"?t("settings.remoteInstances.page.forwardType.local"):S.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(kn,{open:Wn,onOpenChange:Mt=>{W(Qt=>({...Qt,[S.id]:Mt}))},className:`${ne>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 ${Wn?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Xg(S)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ha})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(si,{checked:S.enabled,onCheckedChange:Mt=>Ue(Qt=>({...Qt,enabled:Mt})),"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:()=>gs(Mt=>({...Mt,portForwards:Mt.portForwards.filter(Qt=>Qt.id!==S.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(Qs,{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(sh(S.type))})]})})}),s.jsxs(Tt,{value:S.type,onValueChange:Mt=>Ue(Qt=>({...Qt,type:Mt==="dynamic"||Mt==="remote"?Mt:"local"})),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[140px]",children:s.jsx(Ut,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(dt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(dt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Qs,{label:nt,hint:zt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Be,{className:"h-7 w-32",value:S.localHost||"127.0.0.1",onChange:Mt=>Ue(Qt=>({...Qt,localHost:Mt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Ds,"tabular-nums"),value:S.localPort,onValueChange:Mt=>{Ue(Qt=>({...Qt,localPort:Number.isFinite(Mt)&&Mt>0?Mt:void 0}))},onClear:()=>{Ue(Mt=>({...Mt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),S.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(Qs,{label:Is,hint:bs})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Be,{className:"h-7 w-32",value:S.remoteHost||"",onChange:Mt=>Ue(Qt=>({...Qt,remoteHost:Mt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Ds,"tabular-nums"),value:S.remotePort,onValueChange:Mt=>{Ue(Qt=>({...Qt,remotePort:Number.isFinite(Mt)&&Mt>0?Mt:void 0}))},onClear:()=>{Ue(Mt=>({...Mt,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:S.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:Js}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):S.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:Ps}),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:Js}),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:Js}),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:Ps}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),sn?s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{bn(Va).then(Mt=>{Mt||F.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]})]})})]},S.id)}),s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const S=eh();gs(ne=>({...ne,portForwards:[...ne.portForwards,S]})),W(ne=>({...ne,[S.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:()=>{ir()},disabled:!ar||x,children:t("settings.common.actions.saveChanges")}),Cs?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ra(Cs.localUrl||"").then(S=>{S.ok&&F.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:()=>{fi()},children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,u?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:u}):null]})}),s.jsx(_t,{open:R,onOpenChange:T,children:s.jsxs($t,{className:"sm:max-w-2xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(qt,{children:h?.nickname?.trim()||h?.sshParsed?.destination||h?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:hs,disabled:P||!ge.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:()=>{wa()},disabled:P,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),P?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):V?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:V}):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:I.length>0?I.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(_t,{open:!!H,onOpenChange:S=>{S||va()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:H?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:H}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),hi()},children:[s.jsx(Be,{value:Z,onChange:S=>ee(S.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:va,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.common.actions.create")})]})]})]})})]})})},dh="__add_provider__",uh=()=>{const t=Mn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},mh=({onItemSelect:t})=>{const{t:e}=et(),a=Ws(),n=Xe(g=>rc(g,a)),i=Xe(g=>g.selectedProviderId),r=Xe(g=>g.setSelectedProvider),l=en(g=>g.activeProjectId),[m,c]=o.useState({}),x=o.useMemo(()=>a||uh(),[l,a]),u=Xe(g=>g.loadProviders);o.useEffect(()=>{a&&u({directory:a,source:"settings:providers"})},[u,a]),o.useEffect(()=>{if(n.length===0){c({});return}let g=!1;return(async()=>{const b=n.map(async k=>{try{const p=x?`?directory=${encodeURIComponent(x)}`:"",C=await xt(`/api/provider/${encodeURIComponent(k.id)}/source${p}`,{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const E=await C.json().catch(()=>null),A=E?.sources??E?.data?.sources;if(!A||g)return;c(N=>({...N,[k.id]:A}))}catch{}});await Promise.all(b)})(),()=>{g=!0}},[x,n]);const v="bg-background",d=o.useMemo(()=>n.filter(g=>!!m[g.id]?.project?.exists),[n,m]),j=o.useMemo(()=>n.filter(g=>!m[g.id]?.project?.exists),[n,m]);return s.jsxs("div",{className:ye("flex h-full flex-col",v),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Cn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(ci,{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:()=>{r(dh),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(Ns,{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:[j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),j.map(g=>s.jsx(ml,{provider:g,selectedProviderId:i,onSelect:()=>{r(g.id),t?.()}},g.id))]}),d.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",j.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),d.map(g=>s.jsx(ml,{provider:g,selectedProviderId:i,onSelect:()=>{r(g.id),t?.()}},g.id))]})]})})]})},ml=t=>{const e=ct.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,m=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==c?(x=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=x):x=e[1];let u;e[2]!==a.id?(u=s.jsx(Zn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=u):u=e[3];const v=a.name||a.id;let d;e[4]!==v?(d=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=d):d=e[5];let j;e[6]!==r?(j=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=j):j=e[7];let g;e[8]!==i||e[9]!==u||e[10]!==d||e[11]!==j?(g=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[u,d,j]}),e[8]=i,e[9]=u,e[10]=d,e[11]=j,e[12]=g):g=e[12];let w;return e[13]!==a.id||e[14]!==x||e[15]!==g?(w=s.jsx("div",{className:x,children:g},m),e[13]=a.id,e[14]=x,e[15]=g,e[16]=w):w=e[16],w},ph=t=>t,gh=(t,e,a)=>t&&!e&&!a,pl=t=>typeof t=="object"&&t!==null,zc=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},hh=t=>{if(!pl(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>pl(i)));return e},gl=t=>t.length===0?!0:t.some(e=>zc(e)==="api"),hl=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>zc(e)==="oauth"),fh=t=>t!=="claude-code",fl=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,xh=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),bh=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,lo={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Yn="__custom_provider__",vh=/^[a-z0-9][a-z0-9-_]*$/,Uc=/^https?:\/\//,yh=/^\{env:([^}]+)\}$/;let jh=0;const Hi=()=>`row-${jh++}`,co=()=>({row:Hi(),id:"",name:""}),uo=()=>({row:Hi(),key:"",value:""}),wh=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[co()],headers:[uo()]});function kh(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Nh(t){const e=t.trim();if(!e)return{};const n=e.match(yh)?.[1]?.trim();return n?{env:n}:{key:e}}function Sh(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Uc.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(lo)).has(r.npm)})}function xl(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&Sh(t):!1}function bl(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function Ch(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(x=>typeof x[0]=="string"&&typeof x[1]=="string").map(([x,u])=>({row:Hi(),key:x,value:u})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([x,u])=>({id:x,name:u&&typeof u=="object"&&"name"in u&&typeof u.name=="string"?u.name:x})):[],l=r.length>0?r.map(x=>({row:Hi(),id:typeof x?.id=="string"?x.id:"",name:typeof x?.name=="string"?x.name:typeof x?.id=="string"?x.id:""})):[co()],m=Array.isArray(t.env)?t.env.find(x=>typeof x=="string"&&x.trim().length>0)?.trim():void 0,c=r.find(x=>"api"in x);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:kh(c?.api?.npm),baseURL:a,apiKey:m?`{env:${m}}`:"",models:l,headers:i.length>0?i:[uo()]}}function Ih(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=Nh(t.form.apiKey),l=t.disabledProviders??[],m=t.editingProviderID?.trim(),c=e?vh.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),x=a?void 0:t.t("settings.providers.page.custom.error.name.required"),u=n?Uc.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),d=!!(i||r||m&&t.allowExistingAuth&&m===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),j=l.includes(e),w=c||!!(m&&m===e)?void 0:t.existingProviderIDs.has(e)&&!j?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(T=>{const P=T.id.trim(),D=P?b.has(P)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(P):t.t("settings.providers.page.custom.error.required"),V=T.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:D,name:V}}),p=k.every(T=>!T.id&&!T.name),C=Object.fromEntries(t.form.models.map(T=>[T.id.trim(),{name:T.name.trim()}])),E=new Set,A=t.form.headers.map(T=>{const P=T.key.trim(),D=T.value.trim();if(!P&&!D)return{};const V=P?E.has(P.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void E.add(P.toLowerCase()):t.t("settings.providers.page.custom.error.required"),$=D?void 0:t.t("settings.providers.page.custom.error.required");return{key:V,value:$}}),N=A.every(T=>!T.key&&!T.value),h=Object.fromEntries(t.form.headers.map(T=>({key:T.key.trim(),value:T.value.trim()})).filter(T=>T.key&&T.value).map(T=>[T.key,T.value])),y={providerID:c??w,name:x,baseURL:u,apiKey:d};return!c&&!w&&!x&&!u&&!d&&p&&N?{err:y,models:k,headers:A,result:{providerID:e,name:a,apiKey:r,config:{npm:lo[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(h).length>0?{headers:h}:{}},models:C}}}:{err:y,models:k,headers:A}}function Ph(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function Ah(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const vl=t=>{const e=ct.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:m,authFailureHint:c,onSubmit:x,onCancel:u,onDisconnect:v}=t;let d;e[0]!==n?(d=n===void 0?[]:n,e[0]=n,e[1]=d):d=e[1];const j=d,g=i===void 0?!1:i,w=r===void 0?"create":r,b=m===void 0?!1:m,k=c===void 0?null:c,{t:p}=et(),C=w==="edit";let E;e[2]!==l?(E=()=>l??wh(),e[2]=l,e[3]=E):E=e[3];const[A,N]=o.useState(E);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[y,R]=o.useState(h);let T;e[5]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[5]=T):T=e[5];const[P,D]=o.useState(T);let V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=[],e[6]=V):V=e[6];const[$,I]=o.useState(V),M=o.useRef(null);let H,U;e[7]!==l||e[8]!==C?(H=()=>{l&&(C&&M.current===l.providerID||(M.current=C?l.providerID:null,N(l),R({}),D([]),I([])))},U=[l,C],e[7]=l,e[8]=C,e[9]=H,e[10]=U):(H=e[9],U=e[10]),o.useEffect(H,U);let Z;e[11]===Symbol.for("react.memo_cache_sentinel")?(Z=(It,Lt)=>{N(Wt=>({...Wt,[It]:Lt})),R(Wt=>({...Wt,[It]:void 0}))},e[11]=Z):Z=e[11];const ee=Z;let O;e[12]===Symbol.for("react.memo_cache_sentinel")?(O=(It,Lt,Wt)=>{N(Gt=>({...Gt,models:Gt.models.map((ms,Os)=>Os===It?{...ms,[Lt]:Wt}:ms)})),D(Gt=>{const ms=[...Gt];return ms[It]={...ms[It]??{},[Lt]:void 0},ms})},e[12]=O):O=e[12];const ae=O;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(It,Lt,Wt)=>{N(Gt=>({...Gt,headers:Gt.headers.map((ms,Os)=>Os===It?{...ms,[Lt]:Wt}:ms)})),I(Gt=>{const ms=[...Gt];return ms[It]={...ms[It]??{},[Lt]:void 0},ms})},e[13]=_):_=e[13];const W=_;let q;e[14]!==b||e[15]!==g||e[16]!==j||e[17]!==a||e[18]!==A||e[19]!==C||e[20]!==x||e[21]!==p?(q=async It=>{if(It.preventDefault(),g)return;const Lt=Ih({form:A,t:((Wt,Gt)=>p(Wt,Gt)),existingProviderIDs:a,disabledProviders:j,editingProviderID:C?A.providerID:void 0,allowExistingAuth:C&&b});R(Lt.err),D(Lt.models),I(Lt.headers),Lt.result&&await x(Lt.result)},e[14]=b,e[15]=g,e[16]=j,e[17]=a,e[18]=A,e[19]=C,e[20]=x,e[21]=p,e[22]=q):q=e[22];const L=q;let K;e[23]!==C||e[24]!==p?(K=p(C?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=C,e[24]=p,e[25]=K):K=e[25];let z;e[26]!==p?(z=p("settings.providers.page.custom.description"),e[26]=p,e[27]=z):z=e[27];let J;e[28]!==z?(J=s.jsx("p",{className:rn,children:z}),e[28]=z,e[29]=J):J=e[29];let oe;e[30]!==k?(oe=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=oe):oe=e[31];let re;e[32]!==p?(re=p("settings.providers.page.custom.field.providerID.label"),e[32]=p,e[33]=re):re=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 ve=A.providerID;let be;e[36]===Symbol.for("react.memo_cache_sentinel")?(be=It=>ee("providerID",It.target.value),e[36]=be):be=e[36];let te;e[37]!==p?(te=p("settings.providers.page.custom.field.providerID.placeholder"),e[37]=p,e[38]=te):te=e[38];const he=!C,ie=C||g,ue=!!y.providerID;let de;e[39]!==p?(de=p("settings.providers.page.custom.field.providerID.label"),e[39]=p,e[40]=de):de=e[40];let Pe;e[41]!==A.providerID||e[42]!==te||e[43]!==he||e[44]!==ie||e[45]!==ue||e[46]!==de?(Pe=s.jsx(Be,{value:ve,onChange:be,placeholder:te,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:he,disabled:ie,"aria-invalid":ue,"aria-label":de}),e[41]=A.providerID,e[42]=te,e[43]=he,e[44]=ie,e[45]=ue,e[46]=de,e[47]=Pe):Pe=e[47];let Ae;e[48]!==y.providerID?(Ae=y.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.providerID}):null,e[48]=y.providerID,e[49]=Ae):Ae=e[49];let we;e[50]!==re||e[51]!==pe||e[52]!==Pe||e[53]!==Ae?(we=s.jsxs(At,{label:re,info:pe,children:[Pe,Ae]}),e[50]=re,e[51]=pe,e[52]=Pe,e[53]=Ae,e[54]=we):we=e[54];let Le;e[55]!==p?(Le=p("settings.providers.page.custom.field.protocol.label"),e[55]=p,e[56]=Le):Le=e[56];let _e;e[57]!==p?(_e=p("settings.providers.page.custom.field.protocol.info"),e[57]=p,e[58]=_e):_e=e[58];const Ve=A.protocol;let je;e[59]===Symbol.for("react.memo_cache_sentinel")?(je=It=>{It in lo&&N(Lt=>({...Lt,protocol:It}))},e[59]=je):je=e[59];let ke;e[60]!==p?(ke=p("settings.providers.page.custom.field.protocol.label"),e[60]=p,e[61]=ke):ke=e[61];let se;e[62]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Ut,{}),e[62]=se):se=e[62];let le;e[63]!==ke?(le=s.jsx(Et,{"aria-label":ke,className:"w-full",children:se}),e[63]=ke,e[64]=le):le=e[64];let Ie;e[65]!==p?(Ie=p("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=p,e[66]=Ie):Ie=e[66];let Ne;e[67]!==Ie?(Ne=s.jsx(dt,{value:"openai-chat",children:Ie}),e[67]=Ie,e[68]=Ne):Ne=e[68];let Re;e[69]!==p?(Re=p("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=p,e[70]=Re):Re=e[70];let $e;e[71]!==Re?($e=s.jsx(dt,{value:"openai-responses",children:Re}),e[71]=Re,e[72]=$e):$e=e[72];let De;e[73]!==p?(De=p("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=p,e[74]=De):De=e[74];let Ce;e[75]!==De?(Ce=s.jsx(dt,{value:"anthropic-messages",children:De}),e[75]=De,e[76]=Ce):Ce=e[76];let Ye;e[77]!==Ne||e[78]!==$e||e[79]!==Ce?(Ye=s.jsxs(Dt,{children:[Ne,$e,Ce]}),e[77]=Ne,e[78]=$e,e[79]=Ce,e[80]=Ye):Ye=e[80];let xe;e[81]!==g||e[82]!==A.protocol||e[83]!==le||e[84]!==Ye?(xe=s.jsxs(Tt,{value:Ve,onValueChange:je,disabled:g,children:[le,Ye]}),e[81]=g,e[82]=A.protocol,e[83]=le,e[84]=Ye,e[85]=xe):xe=e[85];let Te;e[86]!==Le||e[87]!==_e||e[88]!==xe?(Te=s.jsx(At,{label:Le,info:_e,children:xe}),e[86]=Le,e[87]=_e,e[88]=xe,e[89]=Te):Te=e[89];let Ke;e[90]!==p?(Ke=p("settings.providers.page.custom.field.name.label"),e[90]=p,e[91]=Ke):Ke=e[91];let tt;e[92]!==p?(tt=p("settings.providers.page.custom.field.name.info"),e[92]=p,e[93]=tt):tt=e[93];const Y=A.name;let Se;e[94]===Symbol.for("react.memo_cache_sentinel")?(Se=It=>ee("name",It.target.value),e[94]=Se):Se=e[94];let Ee;e[95]!==p?(Ee=p("settings.providers.page.custom.field.name.placeholder"),e[95]=p,e[96]=Ee):Ee=e[96];const We=!!y.name;let lt;e[97]!==p?(lt=p("settings.providers.page.custom.field.name.label"),e[97]=p,e[98]=lt):lt=e[98];let at;e[99]!==A.name||e[100]!==Ee||e[101]!==We||e[102]!==lt?(at=s.jsx(Be,{value:Y,onChange:Se,placeholder:Ee,className:"h-8 rounded-md px-3","aria-invalid":We,"aria-label":lt}),e[99]=A.name,e[100]=Ee,e[101]=We,e[102]=lt,e[103]=at):at=e[103];let pt;e[104]!==y.name?(pt=y.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.name}):null,e[104]=y.name,e[105]=pt):pt=e[105];let bt;e[106]!==Ke||e[107]!==tt||e[108]!==at||e[109]!==pt?(bt=s.jsxs(At,{label:Ke,info:tt,children:[at,pt]}),e[106]=Ke,e[107]=tt,e[108]=at,e[109]=pt,e[110]=bt):bt=e[110];let Q;e[111]!==p?(Q=p("settings.providers.page.custom.field.baseURL.label"),e[111]=p,e[112]=Q):Q=e[112];let qe;e[113]!==p?(qe=p("settings.providers.page.custom.field.baseURL.info"),e[113]=p,e[114]=qe):qe=e[114];const it=A.baseURL;let ut;e[115]===Symbol.for("react.memo_cache_sentinel")?(ut=It=>ee("baseURL",It.target.value),e[115]=ut):ut=e[115];let gt;e[116]!==p?(gt=p("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=p,e[117]=gt):gt=e[117];const Ot=!!y.baseURL;let st;e[118]!==p?(st=p("settings.providers.page.custom.field.baseURL.label"),e[118]=p,e[119]=st):st=e[119];let ft;e[120]!==A.baseURL||e[121]!==gt||e[122]!==Ot||e[123]!==st?(ft=s.jsx(Be,{value:it,onChange:ut,placeholder:gt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ot,"aria-label":st}),e[120]=A.baseURL,e[121]=gt,e[122]=Ot,e[123]=st,e[124]=ft):ft=e[124];let jt;e[125]!==y.baseURL?(jt=y.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.baseURL}):null,e[125]=y.baseURL,e[126]=jt):jt=e[126];let Je;e[127]!==Q||e[128]!==qe||e[129]!==ft||e[130]!==jt?(Je=s.jsxs(At,{label:Q,info:qe,children:[ft,jt]}),e[127]=Q,e[128]=qe,e[129]=ft,e[130]=jt,e[131]=Je):Je=e[131];let St;e[132]!==p?(St=p("settings.providers.page.custom.field.apiKey.label"),e[132]=p,e[133]=St):St=e[133];let Oe;e[134]!==b||e[135]!==C||e[136]!==p?(Oe=p(C&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=C,e[136]=p,e[137]=Oe):Oe=e[137];const wt=A.apiKey;let X;e[138]===Symbol.for("react.memo_cache_sentinel")?(X=It=>ee("apiKey",It.target.value),e[138]=X):X=e[138];let fe;e[139]!==b||e[140]!==C||e[141]!==p?(fe=p(C&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=C,e[141]=p,e[142]=fe):fe=e[142];const Fe=!!y.apiKey;let Me;e[143]!==p?(Me=p("settings.providers.page.custom.field.apiKey.label"),e[143]=p,e[144]=Me):Me=e[144];let rt;e[145]!==A.apiKey||e[146]!==fe||e[147]!==Fe||e[148]!==Me?(rt=s.jsx(Be,{type:"password",value:wt,onChange:X,placeholder:fe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Fe,"aria-label":Me}),e[145]=A.apiKey,e[146]=fe,e[147]=Fe,e[148]=Me,e[149]=rt):rt=e[149];let ot;e[150]!==y.apiKey?(ot=y.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.apiKey}):null,e[150]=y.apiKey,e[151]=ot):ot=e[151];let Ge;e[152]!==St||e[153]!==Oe||e[154]!==rt||e[155]!==ot?(Ge=s.jsxs(At,{label:St,info:Oe,children:[rt,ot]}),e[152]=St,e[153]=Oe,e[154]=rt,e[155]=ot,e[156]=Ge):Ge=e[156];let Nt;e[157]!==K||e[158]!==J||e[159]!==oe||e[160]!==we||e[161]!==Te||e[162]!==bt||e[163]!==Je||e[164]!==Ge?(Nt=s.jsxs(ze,{title:K,divider:!1,settingsItem:"providers.custom",contentClassName:_s,children:[J,oe,we,Te,bt,Je,Ge]}),e[157]=K,e[158]=J,e[159]=oe,e[160]=we,e[161]=Te,e[162]=bt,e[163]=Je,e[164]=Ge,e[165]=Nt):Nt=e[165];let ns;e[166]!==p?(ns=p("settings.providers.page.custom.models.title"),e[166]=p,e[167]=ns):ns=e[167];let Zt;if(e[168]!==A.models||e[169]!==P||e[170]!==p){let It;e[172]!==A.models.length||e[173]!==P||e[174]!==p?(It=(Lt,Wt)=>s.jsx("div",{className:`${Hs} 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:Kt,children:p("settings.providers.page.custom.models.idLabel")}),s.jsx(Be,{value:Lt.id,onChange:Gt=>ae(Wt,"id",Gt.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")}),P[Wt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Wt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Kt,children:p("settings.providers.page.custom.models.nameLabel")}),s.jsx(Be,{value:Lt.name,onChange:Gt=>ae(Wt,"name",Gt.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")}),P[Wt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Wt]?.name}):null]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:ws,disabled:A.models.length<=1,onClick:()=>{A.models.length<=1||(N(Gt=>({...Gt,models:Gt.models.filter((ms,Os)=>Os!==Wt)})),D(Gt=>Gt.filter((ms,Os)=>Os!==Wt)))},"aria-label":p("settings.providers.page.custom.models.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},Lt.row),e[172]=A.models.length,e[173]=P,e[174]=p,e[175]=It):It=e[175],Zt=A.models.map(It),e[168]=A.models,e[169]=P,e[170]=p,e[171]=Zt}else Zt=e[171];let Qe;e[176]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>{N(Th),D(Eh)},e[176]=Qe):Qe=e[176];let He;e[177]!==p?(He=p("settings.providers.page.custom.models.add"),e[177]=p,e[178]=He):He=e[178];let Ct;e[179]!==He?(Ct=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Qe,children:He}),e[179]=He,e[180]=Ct):Ct=e[180];let Pt;e[181]!==ns||e[182]!==Zt||e[183]!==Ct?(Pt=s.jsxs(ze,{title:ns,contentClassName:_s,children:[Zt,Ct]}),e[181]=ns,e[182]=Zt,e[183]=Ct,e[184]=Pt):Pt=e[184];let es;e[185]!==p?(es=p("settings.providers.page.custom.headers.title"),e[185]=p,e[186]=es):es=e[186];let ts;e[187]!==p?(ts=p("settings.providers.page.custom.headers.description"),e[187]=p,e[188]=ts):ts=e[188];let os;e[189]!==ts?(os=s.jsx("p",{className:rn,children:ts}),e[189]=ts,e[190]=os):os=e[190];let xs;if(e[191]!==A.headers||e[192]!==$||e[193]!==p){let It;e[195]!==A.headers.length||e[196]!==$||e[197]!==p?(It=(Lt,Wt)=>s.jsx("div",{className:`${Hs} 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:Kt,children:p("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Be,{value:Lt.key,onChange:Gt=>W(Wt,"key",Gt.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")}),$[Wt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Wt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Kt,children:p("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Be,{value:Lt.value,onChange:Gt=>W(Wt,"value",Gt.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")}),$[Wt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Wt]?.value}):null]})]}),s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:ws,disabled:A.headers.length<=1,onClick:()=>{A.headers.length<=1||(N(Gt=>({...Gt,headers:Gt.headers.filter((ms,Os)=>Os!==Wt)})),I(Gt=>Gt.filter((ms,Os)=>Os!==Wt)))},"aria-label":p("settings.providers.page.custom.headers.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},Lt.row),e[195]=A.headers.length,e[196]=$,e[197]=p,e[198]=It):It=e[198],xs=A.headers.map(It),e[191]=A.headers,e[192]=$,e[193]=p,e[194]=xs}else xs=e[194];let Fs;e[199]===Symbol.for("react.memo_cache_sentinel")?(Fs=()=>{N(Dh),I(Mh)},e[199]=Fs):Fs=e[199];let me;e[200]!==p?(me=p("settings.providers.page.custom.headers.add"),e[200]=p,e[201]=me):me=e[201];let ht;e[202]!==me?(ht=s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Fs,children:me}),e[202]=me,e[203]=ht):ht=e[203];let kt;e[204]!==es||e[205]!==os||e[206]!==xs||e[207]!==ht?(kt=s.jsxs(ze,{title:es,contentClassName:_s,children:[os,xs,ht]}),e[204]=es,e[205]=os,e[206]=xs,e[207]=ht,e[208]=kt):kt=e[208];let Xt;e[209]!==g||e[210]!==u||e[211]!==p?(Xt=u?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:u,disabled:g,children:p("settings.providers.page.custom.actions.back")}):null,e[209]=g,e[210]=u,e[211]=p,e[212]=Xt):Xt=e[212];let ss;e[213]!==g||e[214]!==v||e[215]!==p?(ss=v?s.jsx(G,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:g,children:p("settings.providers.page.actions.disconnect")}):null,e[213]=g,e[214]=v,e[215]=p,e[216]=ss):ss=e[216];let Jt;e[217]!==g||e[218]!==C||e[219]!==p?(Jt=p(g?"settings.providers.page.actions.saving":C?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=g,e[218]=C,e[219]=p,e[220]=Jt):Jt=e[220];let ps;e[221]!==g||e[222]!==Jt?(ps=s.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:g,children:Jt}),e[221]=g,e[222]=Jt,e[223]=ps):ps=e[223];let Ss;e[224]!==Xt||e[225]!==ss||e[226]!==ps?(Ss=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Xt,ss,ps]}),e[224]=Xt,e[225]=ss,e[226]=ps,e[227]=Ss):Ss=e[227];let us;return e[228]!==L||e[229]!==Nt||e[230]!==Pt||e[231]!==kt||e[232]!==Ss?(us=s.jsxs("form",{onSubmit:L,className:"space-y-0",children:[Nt,Pt,kt,Ss]}),e[228]=L,e[229]=Nt,e[230]=Pt,e[231]=kt,e[232]=Ss,e[233]=us):us=e[233],us};function Th(t){return{...t,models:[...t.models,co()]}}function Eh(t){return[...t,{}]}function Dh(t){return{...t,headers:[...t.headers,uo()]}}function Mh(t){return[...t,{}]}const Rh=(t,e)=>!!e&&t!=="claude-code",Fh=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,ga=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Es=t=>typeof t=="string"&&t.length>0?t:void 0,Oh=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ga(a))continue;const n=Es(a.value);n!==void 0&&e.push({value:n,label:Es(a.label)??n,...Es(a.hint)?{hint:Es(a.hint)}:{}})}return e},Lh=t=>{if(!ga(t))return;const e=Es(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},Kh=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ga(a))continue;const n=Es(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?Oh(a.options):[];if(i==="select"&&r.length===0)continue;const l=Lh(a.when);e.push({type:i,key:n,message:Es(a.message)??n,options:r,...Es(a.placeholder)?{placeholder:Es(a.placeholder)}:{},...l?{when:l}:{}})}return e},zh=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},mo=(t,e)=>t.filter(a=>zh(a,e)),Uh=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},_h=(t,e)=>mo(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,$h=(t,e)=>{const a={};for(const n of mo(t,e))a[n.key]=(e[n.key]??"").trim();return a},Bh=t=>{const e=ga(t)?t:{},a=ga(e.data)?e.data:e,n=Es(a.url)??Es(a.verification_uri_complete)??Es(a.verification_uri),i=Es(a.instructions)??Es(a.message);if(!n&&!i)return null;const r=Es(a.user_code)??Es(a.userCode)??(i?Fh.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},yl=(t,e,a)=>{const n=ga(t)?t:{},i=ga(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return Es(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},kr={phase:"idle"},jl=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=et(),[r,l]=o.useState(kr),[m,c]=o.useState({}),[x,u]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const d=r.phase==="idle"?null:r.methodIndex,j=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,g=async(h,y,R)=>{const T=await Ra(h);if(T.ok){F.success(i(y));return}console.error("Failed to copy OAuth value:",T.error),F.error(i(R))},w=async(h,y)=>{const R=new AbortController;v.current?.abort(),v.current=R;try{const T=await Mn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...y?{code:y}:{}},{signal:R.signal});if(R.signal.aborted)return;if(T.error)throw T.error;l(kr),F.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(T){if(R.signal.aborted)return;console.error("Failed to complete OAuth flow:",T),l({phase:"failed",methodIndex:h,message:yl(T,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===R&&(v.current=null)}},b=async(h,y)=>{l({phase:"authorizing",methodIndex:h});let R;try{const T=await Mn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(y).length>0?{inputs:y}:{}});if(T.error)throw T.error;const P=Bh(T.data);if(!P){l({phase:"failed",methodIndex:h,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}R=P}catch(T){console.error("Failed to start OAuth flow:",T),l({phase:"failed",methodIndex:h,message:yl(T,i,"settings.providers.page.toast.oauthStartFailed")});return}if(R.url&&Rh(t,R.url)&&bn(R.url),R.method==="code"){u(""),l({phase:"awaitingCode",methodIndex:h,authorization:R,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:R}),await w(h)},k=h=>{const y=Kh(h.prompts);if(y.length===0){b(h.index,{});return}c(Uh(y)),l({phase:"prompting",methodIndex:h.index,prompts:y,error:null})},p=()=>{if(r.phase!=="prompting")return;const h=_h(r.prompts,m);if(h){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:h.message})});return}b(r.methodIndex,$h(r.prompts,m))},C=()=>{if(r.phase!=="awaitingCode")return;const h=x.trim();h&&(l({...r,submitting:!0}),w(r.methodIndex,h))},E=()=>{v.current?.abort(),v.current=null,l(kr)},A=h=>{const y=m[h.key]??"",R=T=>c(P=>({...P,[h.key]:T}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:h.message}),h.type==="select"?s.jsxs(Tt,{value:y,onValueChange:R,children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{children:T=>h.options.find(P=>P.value===T)?.label??null})}),s.jsx(Dt,{children:h.options.map(T=>s.jsx(dt,{value:T.value,children:T.hint?`${T.label} · ${T.hint}`:T.label},T.value))})]}):s.jsx(Be,{value:y,onChange:T=>R(T.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},N=h=>s.jsxs(s.Fragment,{children:[h.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:h.instructions}),h.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:h.userCode,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:()=>{g(h.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),h.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:h.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{bn(h.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{g(h.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ye("space-y-4",n),children:e.map(h=>{const y=d===h.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:h.label}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>k(h),disabled:j,children:i("settings.providers.page.actions.connect")})]}),y&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[mo(r.prompts,m).map(A),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{size:"xs",className:"!font-normal",onClick:p,children:i("settings.providers.page.actions.continue")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:E,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="authorizing"&&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")]}),y&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[N(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(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:E,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),y&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[N(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:x,onChange:R=>u(R.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:C,disabled:r.submitting||x.trim().length===0,children:r.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:E,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(h),children:i("settings.providers.page.actions.tryAgain")})]})]},h.index)})})},wl=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Vh=t=>new Intl.NumberFormat(eo(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),kl=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Vh(t);return e.endsWith(".0")?e.slice(0,-2):e},Qa="__add_provider__",_c=t=>typeof t=="object"&&t!==null,Nl=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Hh=t=>{if(typeof t=="string")return{id:t};if(!_c(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}},qh=t=>{let e=[];Array.isArray(t)?e=t:_c(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>Hh(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Gh=()=>{const{t}=et(),e=Ws(),a=Xe(Y=>rc(Y,e)),n=Xe(Y=>Y.selectedProviderId),i=Xe(Y=>Y.setSelectedProvider),r=Xe(Y=>Y.getModelMetadata),l=ce(Y=>Y.hiddenModels),m=ce(Y=>Y.toggleHiddenModel),c=ce(Y=>Y.hideAllModels),x=ce(Y=>Y.showAllModels),[u,v]=o.useState({}),[d,j]=o.useState(!1),[g,w]=o.useState({}),[b,k]=o.useState(null),[p,C]=o.useState(""),[E,A]=o.useState([]),[N,h]=o.useState(!1),[y,R]=o.useState(null),[T,P]=o.useState(""),[D,V]=o.useState(""),[$,I]=o.useState(!1),[M,H]=o.useState({}),[U,Z]=o.useState(0),[ee,O]=o.useState(!1),[ae,_]=o.useState(null),[W,q]=o.useState(null),[L,K]=o.useState(null),[z,J]=o.useState(null),[oe,re]=o.useState(null),[pe,ve]=o.useState(null),be=n===Qa,te=be&&T===Yn,he=!!(W&&n&&W===n&&!be);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let Y=!0;return(async()=>{j(!0);try{const Ee=await Mn.getSdkClient().provider.auth();if(Ee.error)throw new Error(`provider.auth failed: ${String(Ee.error)}`);if(!Y)return;v(hh(Ee.data))}catch(Ee){if(!Y)return;console.error("Failed to load provider auth methods:",Ee),F.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Y&&j(!1)}})(),()=>{Y=!1}},[n,t]),o.useEffect(()=>{if(!ph(be))return;let Y=!0;return(async()=>{h(!0),R(null);try{const Ee=await Mn.getSdkClient().provider.list();if(Ee.error)throw new Error(`provider.list failed: ${String(Ee.error)}`);if(!Y)return;A(qh(Ee.data))}catch(Ee){if(!Y)return;console.error("Failed to load available providers:",Ee),R(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Y&&h(!1)}})(),()=>{Y=!1}},[be,t]);const ie=o.useMemo(()=>new Set(a.map(Y=>Y.id)),[a]),ue=o.useMemo(()=>E.filter(Y=>!ie.has(Y.id)).sort((Y,Se)=>{const Ee=(Y.name||Y.id).toLowerCase(),We=(Se.name||Se.id).toLowerCase();return Ee.localeCompare(We)}),[E,ie]);o.useEffect(()=>{n===Qa&&T&&T!==Yn&&!ue.some(Y=>Y.id===T)&&P("")},[n,T,ue]),o.useEffect(()=>{if(n===Qa){O(!0),_(null),q(null),K(null),J(null),re(null);return}O(!1),_(null),W&&W!==n&&(q(null),K(null),J(null),re(null))},[n,W]),o.useEffect(()=>{if(!n||n===Qa)return;const Y=M[n];if(!Y)return;const Se=a.find(lt=>lt.id===n),Ee=fl({key:Se?.key,authSourceExists:Y.auth.exists,optionsApiKey:Se?.options?.apiKey??null,envDeclared:wl(Se)}),We=!!(Se&&xl(Se,Y));bh({hasCredentials:Ee,userDismissed:ae===n,isEditableCustomProvider:We})&&O(!0)},[n,M,a,ae]),o.useEffect(()=>{if(!n||n===Qa)return;let Y=!1;return(async()=>{try{const Ee=e?`?directory=${encodeURIComponent(e)}`:"",We=await xt(`/api/provider/${encodeURIComponent(n)}/source${Ee}`,{method:"GET",headers:{Accept:"application/json"}}),lt=await We.json().catch(()=>null);if(!We.ok)throw new Error(lt?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const at=lt?.sources??lt?.data?.sources;!Y&&at&&H(pt=>({...pt,[n]:at}))}catch(Ee){Y||console.error("Failed to load provider sources:",Ee)}})(),()=>{Y=!0}},[n,U,e,t]);const de=o.useCallback(()=>{Z(Y=>Y+1)},[]),Pe=o.useCallback(Y=>{H(Se=>{const Ee=Se[Y];return{...Se,[Y]:{auth:{exists:!0,path:Ee?.auth.path??null},user:Ee?.user??{exists:!1,path:null},project:Ee?.project??{exists:!1,path:null},...Ee?.custom?{custom:Ee.custom}:{}}}}),_(null),O(!1),i(Y),de()},[de,i]),Ae=o.useCallback(async(Y,Se)=>{try{return await oc({scopes:[Y],mode:"active"}),"reloaded"}catch(Ee){if(Ee?.requiresManualRestart===!0)return Se&&aa(Y,{id:Se}),"manual-restart";throw Ee}},[]),we=a.find(Y=>Y.id===n),Le=n?M[n]:void 0,_e=async Y=>{const Se=g[Y]?.trim()??"";if(!Se){F.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ee=`api:${Y}`;k(Ee);try{if((await Mn.getSdkClient().auth.set({providerID:Y,auth:{type:"api",key:Se}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));F.success(t("settings.providers.page.toast.apiKeySaved")),w(lt=>({...lt,[Y]:""})),await Ae("providers",Y),Pe(Y)}catch(We){console.error("Failed to save API key:",We),F.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},Ve=async Y=>{const Se=`custom:${Y.providerID}`;k(Se),ve(Y.providerID),re(null);try{const Ee=Ph(Y);if(Ee&&(await Mn.getSdkClient().auth.set(Ee)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const We=Ah(Y,{scope:W?z??bl(M[W]):"user"}),lt=await xt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(We)}),at=await lt.json().catch(()=>null);if(!lt.ok)throw Ee&&re(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(at?.error||t("settings.providers.page.toast.customProviderSaveFailed"));F.success(t("settings.providers.page.toast.customProviderSaved",{provider:Y.name})),P(""),q(null),K(null),J(null),re(null),ve(null),await Ae("providers",Y.providerID),Pe(Y.providerID)}catch(Ee){console.error("Failed to save custom provider:",Ee),F.error(Ee instanceof Error&&Ee.message?Ee.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},je=Y=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(Y+1)}),ke=Y=>{O(!1),fh(Y)&&aa("providers",{id:Y}),Pe(Y)},se=async Y=>{const Se=`disconnect:${Y}`;k(Se);try{const Ee=await xt(`/api/provider/${encodeURIComponent(Y)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),We=await Ee.json().catch(()=>null);if(!Ee.ok)throw new Error(We?.error||t("settings.providers.page.toast.providerDisconnectFailed"));F.success(t("settings.providers.page.toast.providerDisconnected")),await Ae("providers",Y),_(null),de()}catch(Ee){console.error("Failed to disconnect provider:",Ee),F.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},le=async Y=>{Y&&(await se(Y),q(null),K(null),J(null),re(null),ve(null),P(""))};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(is,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(ze,{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")}),N?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):y?s.jsx("p",{className:"typography-meta text-muted-foreground",children:y}):s.jsxs(jn,{open:$,onOpenChange:Y=>{I(Y),Y||V("")},children:[s.jsx(vn,{asChild:!0,children:s.jsxs("button",{type:"button",className:on,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T&&T!==Yn?s.jsx(Zn,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T===Yn?t("settings.providers.page.custom.optionLabel"):T?ue.find(Y=>Y.id===T)?.name||T: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(yn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Y=>Y.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Y=>Y.stopPropagation(),children:[s.jsx(B,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:D,onChange:Y=>V(Y.target.value),onKeyDown:Y=>Y.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(Ns,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Y=t("settings.providers.page.custom.optionLabel"),Se=Td([Y,"other","custom"],D),Ee=$i(ue,D,We=>[We.name||We.id,We.id]);return Ee.length===0&&!Se?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:[Ee.map(We=>s.jsxs(wn,{onSelect:()=>{P(We.id),I(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Zn,{providerId:We.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:We.name||We.id})]}),T===We.id&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},We.id)),Se?s.jsxs(wn,{onSelect:()=>{P(Yn),I(!1),V("")},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:Y})]}),T===Yn&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Yn):null]})})()})]})]})]})}),te?s.jsx(vl,{mode:"create",existingProviderIDs:ie,busy:b?.startsWith("custom:")??!1,authFailureHint:oe,onCancel:()=>{P(""),re(null),ve(null)},onDisconnect:oe&&pe?()=>{le(pe)}:void 0,onSubmit:Ve}):T?s.jsx(ze,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const Y=u[T]??[],Se=Nl(hl(Y),je),Ee=gl(Y);return s.jsxs(s.Fragment,{children:[Ee?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Be,{type:"password",value:g[T]??"",onChange:We=>w(lt=>({...lt,[T]:We.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:()=>_e(T),disabled:b===`api:${T}`,children:b===`api:${T}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Se.length>0?s.jsx(jl,{providerId:T,methods:Se,onConnected:()=>ke(T),className:ye(Ee&&"border-t border-[var(--surface-subtle)] pt-2")},T):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 Ie=Array.isArray(we.models)?we.models:[],Ne=u[we.id]??[],Re=Nl(hl(Ne),je),$e=gl(Ne),De=!!Le,Ce=De&&xl(we,Le),Ye=fl({key:we.key,authSourceExists:Le?.auth.exists,optionsApiKey:we.options?.apiKey??null,envDeclared:wl(we)}),xe=gh(De,Ye,Ce),Te=xh({modelCount:Ie.length,sourcesLoaded:De,hasCredentials:Ye,isEditableCustomProvider:Ce}),Ke=!$e&&Re.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),tt=$i(Ie,p,Y=>[typeof Y?.name=="string"?Y.name:"",typeof Y?.id=="string"?Y.id:""]);return he&&Ce&&L?s.jsx(is,{title:we.name||we.id,titleLeading:s.jsx(Zn,{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(vl,{mode:"edit",existingProviderIDs:ie,initialValues:L,allowExistingAuth:Ye||!De,busy:b?.startsWith("custom:")??!1,authFailureHint:oe,onCancel:()=>{q(null),K(null),J(null),re(null),ve(null)},onDisconnect:()=>{le(we.id)},onSubmit:Ve})}):s.jsxs(is,{title:we.name||we.id,titleLeading:s.jsx(Zn,{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(ze,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[Ce?s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{re(null),K(Ch(we)),J(bl(Le)),q(we.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Y=!ee;O(Y),_(Y?null:we.id)},children:t(ee?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ee?d?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(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Be,{type:"password",value:g[we.id]??"",onChange:Y=>w(Se=>({...Se,[we.id]:Y.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:()=>_e(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,Re.length>0&&s.jsx(jl,{providerId:we.id,methods:Re,onConnected:()=>ke(we.id),className:ye($e&&"border-t border-[var(--surface-subtle)] pt-2")},we.id)]}):xe?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(Yt,{children:Ke})]}):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(Yt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(ze,{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:Le&&(Le.auth.exists||Le.user.exists||Le.project.exists||Le.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[Le.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,Le.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,Le.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,Le.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:()=>se(we.id),disabled:b===`disconnect:${we.id}`,children:b===`disconnect:${we.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Te?s.jsxs(ze,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",Ie.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Y=Ie.map(Se=>typeof Se?.id=="string"?Se.id:"").filter(Se=>Se.length>0);c(we.id,Y)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(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(Be,{value:p,onChange:Y=>C(Y.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),tt.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:tt.map(Y=>{const Se=typeof Y?.id=="string"?Y.id:"",Ee=typeof Y?.name=="string"?Y.name:Se,We=Se?r(we.id,Se):void 0,lt=l.some(Q=>Q.providerID===we.id&&Q.modelID===Se),at=kl(We?.limit?.context),pt=kl(We?.limit?.output),bt=[];return We?.tool_call&&bt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),We?.reasoning&&bt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),We?.attachment&&bt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",lt&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ee}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(at||pt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[at?`${at} ${t("settings.providers.page.models.tokenBadge.context")}`:"",at&&pt?" · ":"",pt?`${pt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),bt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:bt.map(({key:Q,icon:qe,label:it})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:it,"aria-label":it,children:s.jsx(B,{name:qe,className:"h-3 w-3"})},Q))}),s.jsx("button",{type:"button",onClick:()=>m(we.id,Se),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(lt?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(lt?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:lt?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"})})]})]})},Se)})})]}):null]})},Wh=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)},Jh=t=>{const e=ct.c(75),{onItemSelect:a}=t,{t:n}=et(),i=ls(Qh),r=ls(Yh),l=ls(Zh),m=ls(Xh),c=ls(ef),x=ls(tf),u=ls(sf),v=ls(nf);let d,j;e[0]!==v?(d=()=>{v()},j=[v],e[0]=v,e[1]=d,e[2]=j):(d=e[1],j=e[2]),o.useEffect(d,j);const g=af;let w;e[3]!==u?(w=J=>{J!=="usage"&&J!=="remaining"||(u(J),g({usageDisplayMode:J}))},e[3]=u,e[4]=w):w=e[4];const b=w;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=ye("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 C;e[8]!==p?(C=s.jsx("h2",{className:`${Cn} mb-3`,children:p}),e[8]=p,e[9]=C):C=e[9];let E;e[10]!==n?(E=n("settings.usage.sidebar.total",{count:Bi.length}),e[10]=n,e[11]=E):E=e[11];let A;e[12]!==E?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:E}),e[12]=E,e[13]=A):A=e[13];let N;e[14]!==m?(N=()=>m(),e[14]=m,e[15]=N):N=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let y;e[18]!==n?(y=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=y):y=e[19];const R=c&&"animate-spin";let T;e[20]!==R?(T=ye("h-3.5 w-3.5",R),e[20]=R,e[21]=T):T=e[21];let P;e[22]!==T?(P=s.jsx(B,{name:"refresh",className:T}),e[22]=T,e[23]=P):P=e[23];let D;e[24]!==c||e[25]!==h||e[26]!==y||e[27]!==P||e[28]!==N?(D=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:N,"aria-label":h,title:y,disabled:c,children:P})}),e[24]=c,e[25]=h,e[26]=y,e[27]=P,e[28]=N,e[29]=D):D=e[29];let V;e[30]!==D||e[31]!==A?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,D]}),e[30]=D,e[31]=A,e[32]=V):V=e[32];let $;e[33]!==n?($=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=$):$=e[34];let I;e[35]!==$?(I=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[35]=$,e[36]=I):I=e[36];let M;e[37]!==n?(M=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=M):M=e[38];let H;e[39]!==M?(H=s.jsx(Et,{className:"w-fit",children:s.jsx(Ut,{placeholder:M})}),e[39]=M,e[40]=H):H=e[40];let U;e[41]!==n?(U=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=U):U=e[42];let Z;e[43]!==U?(Z=s.jsx(dt,{value:"usage",children:U}),e[43]=U,e[44]=Z):Z=e[44];let ee;e[45]!==n?(ee=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ee):ee=e[46];let O;e[47]!==ee?(O=s.jsx(dt,{value:"remaining",children:ee}),e[47]=ee,e[48]=O):O=e[48];let ae;e[49]!==Z||e[50]!==O?(ae=s.jsxs(Dt,{children:[Z,O]}),e[49]=Z,e[50]=O,e[51]=ae):ae=e[51];let _;e[52]!==b||e[53]!==H||e[54]!==ae||e[55]!==x?(_=s.jsxs(Tt,{value:x,onValueChange:b,children:[H,ae]}),e[52]=b,e[53]=H,e[54]=ae,e[55]=x,e[56]=_):_=e[56];let W;e[57]!==I||e[58]!==_?(W=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[I,_]}),e[57]=I,e[58]=_,e[59]=W):W=e[59];let q;e[60]!==V||e[61]!==W||e[62]!==C?(q=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,V,W]}),e[60]=V,e[61]=W,e[62]=C,e[63]=q):q=e[63];let L;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(L=Bi.map(J=>{const oe=i.find(he=>he.providerId===J.id),re=Wh(oe?.usage),pe=lc(re),ve=J.id===r,be=oe?.configured,te=be?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:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ve?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(J.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:te}),s.jsx(Zn,{providerId:J.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:J.name}),be===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},J.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=L):L=e[69];let K;e[70]!==L?(K=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:L}),e[70]=L,e[71]=K):K=e[71];let z;return e[72]!==q||e[73]!==K?(z=s.jsxs("div",{className:k,children:[q,K]}),e[72]=q,e[73]=K,e[74]=z):z=e[74],z};function Qh(t){return t.results}function Yh(t){return t.selectedProviderId}function Zh(t){return t.setSelectedProvider}function Xh(t){return t.fetchAllQuotas}function ef(t){return t.isLoading}function tf(t){return t.displayMode}function sf(t){return t.setDisplayMode}function nf(t){return t.loadSettings}async function af(t){try{await yt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const rf=t=>{const e=ct.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Ed(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,m=n??a;let c;e[2]!==m?(c=lc(m),e[2]=m,e[3]=c):c=e[3];const x=c;let u;e[4]!==x?(u=x==="critical"?{backgroundColor:"var(--status-error)"}:x==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=x,e[5]=u):u=e[5];const v=u;let d;e[6]!==i?(d=ye("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=d):d=e[7];const j=`${l}%`;let g;e[8]!==v||e[9]!==j?(g={...v,width:j},e[8]=v,e[9]=j,e[10]=g):g=e[10];let w;e[11]!==l||e[12]!==g?(w=s.jsx("div",{className:"h-full transition-all duration-300",style:g,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=g,e[13]=w):w=e[13];let b;return e[14]!==d||e[15]!==w?(b=s.jsx("div",{className:d,children:w}),e[14]=d,e[15]=w,e[16]=b):b=e[16],b},Nr=t=>{const e=ct.c(37),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:m}=t,c=r===void 0?!1:r,x=l===void 0?!1:l,u=ls(of),v=ce(lf),d=u==="remaining"?n.remainingPercent:n.usedPercent,j=d!==null,g=u==="remaining"?"remaining":"used";let w;e[0]!==d||e[1]!==n.valueLabel?(w=Dd(n.valueLabel,d),e[0]=d,e[1]=n.valueLabel,e[2]=w):w=e[2];const b=w,k=n.resetAfterFormatted??n.resetAtFormatted;let p;e[3]!==k||e[4]!==v||e[5]!==n.resetAt?(p=Md(n.resetAt,k,v),e[3]=k,e[4]=v,e[5]=n.resetAt,e[6]=p):p=e[6];const C=p,E=C?`Resets ${C}`:"";let A;e[7]!==a?(A=Rd(a),e[7]=a,e[8]=A):A=e[8];const N=A;let h;e[9]!==m||e[10]!==c||e[11]!==x?(h=c&&s.jsx(Rr,{checked:x,onChange:H=>m?.(H),ariaLabel:"Show in dropdown"}),e[9]=m,e[10]=c,e[11]=x,e[12]=h):h=e[12];let y;e[13]!==N?(y=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N}),e[13]=N,e[14]=y):y=e[14];let R;e[15]!==i?(R=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=R):R=e[16];let T;e[17]!==y||e[18]!==R?(T=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[y,R]}),e[17]=y,e[18]=R,e[19]=T):T=e[19];let P;e[20]!==T||e[21]!==h?(P=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[h,T]}),e[20]=T,e[21]=h,e[22]=P):P=e[22];const D=b==="-"?"":b;let V;e[23]!==D?(V=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[23]=D,e[24]=V):V=e[24];let $;e[25]!==P||e[26]!==V?($=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[P,V]}),e[25]=P,e[26]=V,e[27]=$):$=e[27];let I;e[28]!==g||e[29]!==d||e[30]!==j||e[31]!==E||e[32]!==n.usedPercent?(I=j?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(rf,{percent:d,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:E}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:g})]})]}):E?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:E}):null,e[28]=g,e[29]=d,e[30]=j,e[31]=E,e[32]=n.usedPercent,e[33]=I):I=e[33];let M;return e[34]!==$||e[35]!==I?(M=s.jsxs("div",{className:"py-3",children:[$,I]}),e[34]=$,e[35]=I,e[36]=M):M=e[36],M};function of(t){return t.displayMode}function lf(t){return t.timeFormatPreference}const cf=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,df=({providerId:t,providerName:e})=>{const{t:a}=et(),[n,i]=o.useState(null),[r,l]=o.useState({}),[m,c]=o.useState(!1),x=`/api/quota/credentials/${t}`;o.useEffect(()=>{xt(x).then(async d=>{if(!d.ok)throw new Error;const j=await d.json();i(j),l({})}).catch(()=>i({configured:!1}))},[x]);const u=async(d,j,g)=>{c(!0);try{const w=await xt(d,{method:j,headers:g?{"Content-Type":"application/json"}:void 0,body:g?JSON.stringify(g):void 0}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error(b?.error);b?.configured!==void 0&&i(b),l({}),F.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(w){F.error(w instanceof Error&&w.message?w.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},v=(d,j,g)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[j,s.jsx(Be,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[d]??"",onChange:w=>l(b=>({...b,[d]:w.target.value})),placeholder:n?.secretMasked??g})]});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:cf})]}),t==="ollama-cloud"&&v("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&v("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(G,{size:"xs",disabled:m,onClick:()=>u(x,"PUT",r),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:m,onClick:()=>u(`${x}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(G,{variant:"outline",size:"xs",disabled:m,onClick:()=>u(`${x}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(G,{variant:"destructive",size:"xs",disabled:m,onClick:()=>u(x,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Sl=(t,e)=>{if(!t)return"-";try{return cc(t,e,{fallback:"-"})}catch{return"-"}},uf=()=>{const{t}=et(),e=ce(M=>M.timeFormatPreference),a=ls(M=>M.results),n=ls(M=>M.selectedProviderId),i=ls(M=>M.setSelectedProvider),r=ls(M=>M.loadSettings),l=ls(M=>M.fetchAllQuotas),m=ls(M=>M.isLoading),c=ls(M=>M.lastUpdated),x=ls(M=>M.refreshErrors),u=ls(M=>M.dropdownProviderIds),v=ls(M=>M.setDropdownProviderIds),d=ls(M=>M.selectedModels),j=ls(M=>M.toggleModelSelected),g=ls(M=>M.applyDefaultSelections);Fd(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const M=a.find(H=>H.configured)?.providerId;i(M??Bi[0]?.id??null)},[a,n,i]);const w=a.find(M=>M.providerId===n)??null,k=Bi.find(M=>M.id===n)?.name??n??t("settings.usage.sidebar.title"),p=w?.usage,C=n?x[n]:void 0,E=C?p?t("header.services.usageRefreshFailedStale",{error:C}):C:w?.configured&&!w.ok?w.error:null,A=n?u.includes(n):!1,N=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",h=o.useCallback(M=>{if(!n)return;const H=M?Array.from(new Set([...u,n])):u.filter(U=>U!==n);v(H),yt({usageDropdownProviders:H})},[u,n,v]),y=o.useMemo(()=>p?.models?Object.entries(p.models).map(([M,H])=>({name:M,windows:H})).filter(M=>Object.keys(M.windows.windows).length>0):[],[p?.models]);o.useEffect(()=>{n&&y.length>0&&g(n,y.map(M=>M.name))},[n,y,g]);const R=o.useMemo(()=>!n||y.length===0?new Map:Od(y,M=>M.name,n),[y,n]),T=o.useMemo(()=>{if(!n)return[];const M=Kd(n);return Ld(M)},[n]),[P,D]=o.useState(()=>({})),V=o.useCallback(M=>{D(H=>({...H,[M]:!H[M]}))},[]),$=o.useCallback(M=>{if(!n)return;j(n,M);const H=d[n]??[],Z=H.includes(M)?H.filter(O=>O!==M):[...H,M],ee={...d,[n]:Z};yt({usageSelectedModels:ee})},[n,d,j]),I=n?d[n]??[]:[];return n?s.jsxs(is,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(Zn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:m?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):w?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:w.planLabel,time:Sl(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Sl(c,e)}),showSaveStatus:!0,children:[s.jsx(ze,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(mt,{checked:A,onChange:h,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!w&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),E&&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:E})]}),w&&!w.configured&&!N&&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(df,{providerId:n,providerName:k}),p?.windows&&Object.keys(p.windows).length>0&&s.jsx(ze,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(p.windows).map(([M,H])=>s.jsx(Nr,{title:M,window:H},M))})}),y.length>0&&s.jsxs(ze,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[T.map(M=>{const H=R.get(M.id)??[];if(H.length===0)return null;const U=P[M.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!U,onOpenChange:()=>V(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:["(",H.length,")"]})]}),U?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:H.map(Z=>{const ee=Object.entries(Z.windows.windows);if(ee.length===0)return null;const[O,ae]=ee[0],_=I.includes(Z.name);return s.jsx(Nr,{title:O,subtitle:yo(Z.name),window:ae,showToggle:!0,toggleEnabled:_,onToggle:()=>$(Z.name)},Z.name)})})})]})},M.id)}),(()=>{const M=R.get(null)??[];if(M.length===0)return null;const H=P.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(kn,{open:!H,onOpenChange:()=>V("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,")"]})]}),H?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(U=>{const Z=Object.entries(U.windows.windows);if(Z.length===0)return null;const[ee,O]=Z[0],ae=I.includes(U.name);return s.jsx(Nr,{title:ee,subtitle:yo(U.name),window:O,showToggle:!0,toggleEnabled:ae,onToggle:()=>$(U.name)},U.name)})})})]})})})()]}),w?.configured&&p&&Object.keys(p.windows??{}).length===0&&y.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")})})},mf="git.commit.generate",Hr=Ic(t=>({selectedPromptId:mf,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),pf=t=>{const e=ct.c(24),{onItemSelect:a}=t,{t:n}=et(),i=Hr(gf),r=Hr(hf);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=m):m=e[1];let 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 x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=x):x=e[3];let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=[l,m,c,x,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=u):u=e[4];const v=u;let d;e[5]!==n?(d=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=d):d=e[6];let j;e[7]!==d?(j=s.jsx("h2",{className:Cn,children:d}),e[7]=d,e[8]=j):j=e[8];let g;e[9]!==n?(g=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=g):g=e[10];let w;e[11]!==g?(w=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:g}),e[11]=g,e[12]=w):w=e[12];let b;e[13]!==j||e[14]!==w?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[j,w]}),e[13]=j,e[14]=w,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(k=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:v.map(C=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(C.groupKey)}),C.items.map(E=>{const A=i===E.id;return s.jsx("button",{type:"button",onClick:()=>{r(E.id),a?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",A?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(E.titleKey)})},E.id)})]},C.groupKey))}),e[16]=a,e[17]=i,e[18]=r,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 gf(t){return t.selectedPromptId}function hf(t){return t.setSelectedPromptId}const Cl={"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"}]}},Il=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Sr=t=>t.endsWith(".visible"),ff=()=>{const{t}=et(),e=o.useCallback(N=>t(N),[t]),a=Hr(N=>N.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[m,c]=o.useState({}),[x,u]=o.useState({}),[v,d]=o.useState({}),[j,g]=o.useState(!1);o.useEffect(()=>{let N=!0;return(async()=>{i(!0);try{const y=await $d();if(!N)return;l(y)}catch(y){console.warn("Failed to load magic prompts:",y),F.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{N&&i(!1)}})(),()=>{N=!1}},[t]);const w=Cl[a]??Cl["git.commit.generate"],b=o.useCallback(N=>Il(r,N)?r[N]:mr(N),[r]),k=o.useCallback(N=>m[N]??b(N),[m,b]),p=o.useCallback((N,h)=>{c(y=>y[N]===h?y:{...y,[N]:h})},[]),C=o.useCallback(async N=>{const h=k(N);if(Sr(N)&&h.trim().length===0){F.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}u(y=>({...y,[N]:!0}));try{const y=h===mr(N)?await jo(N):await zd(N,h);l(y.overrides),F.success(t("settings.magicPrompts.page.toast.saved"))}catch(y){const R=y instanceof Error?y.message:String(y);F.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:R})}finally{u(y=>({...y,[N]:!1}))}},[k,t]),E=o.useCallback(async N=>{d(h=>({...h,[N]:!0}));try{const h=await jo(N);l(h.overrides),c(y=>({...y,[N]:mr(N)})),F.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const y=h instanceof Error?h.message:String(h);F.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:y})}finally{d(h=>({...h,[N]:!1}))}},[t]),A=o.useCallback(async()=>{g(!0);try{const N=await Ud();l(N.overrides),c({}),F.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(N){const h=N instanceof Error?N.message:String(N);F.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:h})}finally{g(!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(is,{title:e(w.titleKey),titleAccessory:s.jsx(Yt,{contentClassName:"max-w-xs",children:e(w.descriptionKey)}),headerEnd:s.jsx(G,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{A()},disabled:j||Object.keys(r).length===0,children:t(j?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:w.blocks.map((N,h)=>{const y=_d(N.id),R=b(N.id),T=k(N.id),P=Il(r,N.id),D=T!==R,V=Sr(N.id)&&T.trim().length===0,$=x[N.id]===!0,I=v[N.id]===!0;return s.jsxs(ze,{title:e(N.titleKey),info:y.description,description:y.placeholders&&y.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${y.placeholders.map(M=>`{{${M.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:Sr(N.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ms,{value:T,onChange:M=>p(N.id,M.target.value),className:"min-h-[220px] font-mono text-sm"}),V&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(D?"settings.magicPrompts.page.status.unsavedChanges":P?"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:()=>{E(N.id)},disabled:!P||$||I,children:t(I?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(G,{size:"sm",onClick:()=>{C(N.id)},disabled:!D||$||I||V,children:t($?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},N.id)})})},xf=t=>{const e=ct.c(89),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,m]=o.useState(null),[c,x]=o.useState(null),{selectedSnippetName:u,snippets:v,setSelectedSnippet:d,setSnippetDraft:j,deleteSnippet:g,loadSnippets:w}=Vi(qs(bf));let b,k;e[0]!==w?(b=()=>{w()},k=[w],e[0]=w,e[1]=b,e[2]=k):(b=e[1],k=e[2]),o.useEffect(b,k);let p;e[3]!==a||e[4]!==d||e[5]!==j||e[6]!==v?(p=async()=>{const ie=new Set(v.map(vf));let ue="new-snippet",de=1;for(;ie.has(ue);)ue=`new-snippet-${de++}`;j({name:ue,scope:"global"}),d(ue),a?.()},e[3]=a,e[4]=d,e[5]=j,e[6]=v,e[7]=p):p=e[7];const C=p;let E;e[8]!==i||e[9]!==g||e[10]!==n?(E=async()=>{if(!i)return;await g(i.name)?(F.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):F.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=g,e[10]=n,e[11]=E):E=e[11];const A=E;let N;e[12]!==v?(N=[...v].sort(yf),e[12]=v,e[13]=N):N=e[13];const h=N;let y;e[14]===Symbol.for("react.memo_cache_sentinel")?(y=ye("flex h-full flex-col","bg-background"),e[14]=y):y=e[14];let R;e[15]!==n?(R=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=R):R=e[16];let T;e[17]!==R?(T=s.jsx("h2",{className:`${Cn} mb-3`,children:R}),e[17]=R,e[18]=T):T=e[18];let P;e[19]!==v.length||e[20]!==n?(P=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=P):P=e[21];let D;e[22]!==P?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[22]=P,e[23]=D):D=e[23];let V;e[24]!==n?(V=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=V):V=e[25];let $;e[26]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[26]=$):$=e[26];let I;e[27]!==C||e[28]!==V?(I=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:C,"aria-label":V,children:$}),e[27]=C,e[28]=V,e[29]=I):I=e[29];let M;e[30]!==D||e[31]!==I?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,I]}),e[30]=D,e[31]=I,e[32]=M):M=e[32];let H;e[33]!==M||e[34]!==T?(H=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,M]}),e[33]=M,e[34]=T,e[35]=H):H=e[35];let U;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==u||e[40]!==d||e[41]!==h||e[42]!==n){let ie;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==u||e[48]!==d||e[49]!==n?(ie=ue=>s.jsxs(pa,{open:c===ue.name,onOpenChange:de=>x(de?ue.name:null),children:[s.jsxs(ma,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u===ue.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:de=>{de.preventDefault(),x(ue.name)}}),children:[s.jsxs("button",{onClick:()=>{d(ue.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:["#",ue.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.${ue.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ue.description||ue.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(jn,{open:l===ue.name,onOpenChange:de=>{de&&x(null),m(de?ue.name:null)},children:[s.jsx(vn,{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:ue.name}),children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(yn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(wn,{onClick:de=>{de.stopPropagation(),r(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")]})})]})]}),s.jsx(da,{className:"w-fit min-w-20",children:s.jsxs(ua,{onClick:de=>{de.stopPropagation(),r(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")]})})]},`${ue.source}:${ue.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=u,e[48]=d,e[49]=n,e[50]=ie):ie=e[50],U=h.map(ie),e[36]=a,e[37]=l,e[38]=c,e[39]=u,e[40]=d,e[41]=h,e[42]=n,e[43]=U}else U=e[43];let Z;e[51]!==U?(Z=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:U}),e[51]=U,e[52]=Z):Z=e[52];const ee=i!==null;let O;e[53]===Symbol.for("react.memo_cache_sentinel")?(O=ie=>{ie||r(null)},e[53]=O):O=e[53];let ae;e[54]!==n?(ae=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=ae):ae=e[55];let _;e[56]!==ae?(_=s.jsx(Ht,{children:ae}),e[56]=ae,e[57]=_):_=e[57];const W=i?.name??"";let q;e[58]!==n||e[59]!==W?(q=n("settings.snippets.sidebar.dialog.deleteDescription",{name:W}),e[58]=n,e[59]=W,e[60]=q):q=e[60];let L;e[61]!==q?(L=s.jsx(qt,{children:q}),e[61]=q,e[62]=L):L=e[62];let K;e[63]!==_||e[64]!==L?(K=s.jsxs(Vt,{children:[_,L]}),e[63]=_,e[64]=L,e[65]=K):K=e[65];let z;e[66]===Symbol.for("react.memo_cache_sentinel")?(z=()=>r(null),e[66]=z):z=e[66];let J;e[67]!==n?(J=n("settings.common.actions.cancel"),e[67]=n,e[68]=J):J=e[68];let oe;e[69]!==J?(oe=s.jsx(G,{size:"sm",variant:"ghost",onClick:z,children:J}),e[69]=J,e[70]=oe):oe=e[70];let re;e[71]!==n?(re=n("settings.common.actions.delete"),e[71]=n,e[72]=re):re=e[72];let pe;e[73]!==A||e[74]!==re?(pe=s.jsx(G,{size:"sm",onClick:A,children:re}),e[73]=A,e[74]=re,e[75]=pe):pe=e[75];let ve;e[76]!==oe||e[77]!==pe?(ve=s.jsxs(rs,{children:[oe,pe]}),e[76]=oe,e[77]=pe,e[78]=ve):ve=e[78];let be;e[79]!==K||e[80]!==ve?(be=s.jsxs($t,{className:"max-w-md",children:[K,ve]}),e[79]=K,e[80]=ve,e[81]=be):be=e[81];let te;e[82]!==ee||e[83]!==be?(te=s.jsx(_t,{open:ee,onOpenChange:O,children:be}),e[82]=ee,e[83]=be,e[84]=te):te=e[84];let he;return e[85]!==H||e[86]!==Z||e[87]!==te?(he=s.jsxs("div",{className:y,children:[H,Z,te]}),e[85]=H,e[86]=Z,e[87]=te,e[88]=he):he=e[88],he};function bf(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function vf(t){return t.name}function yf(t,e){return t.name.localeCompare(e.name)}const jf=()=>{const{t}=et(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=Vi(qs(y=>({selectedSnippetName:y.selectedSnippetName,snippets:y.snippets,snippetDraft:y.snippetDraft,setSnippetDraft:y.setSnippetDraft,updateSnippet:y.updateSnippet,createSnippet:y.createSnippet}))),m=o.useMemo(()=>e?a.find(y=>y.name===e||y.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!m),[x,u]=o.useState(""),[v,d]=o.useState("global"),[j,g]=o.useState(""),[w,b]=o.useState(""),[k,p]=o.useState(""),[C,E]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{if(c&&n){const y={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};u(y.draftName),d(y.draftScope),g(y.description),b(y.aliases),p(y.content),A.current=y}else if(m){const y={draftName:"",draftScope:"global",description:m.description??"",aliases:m.aliases.join(", "),content:m.content};g(y.description),b(y.aliases),p(y.content),A.current=y}},[m,c,e,n]);const N=o.useMemo(()=>{const y=A.current;return y?c&&x!==y.draftName||c&&v!==y.draftScope?!0:j!==y.description||w!==y.aliases||k!==y.content:!1},[w,k,j,x,v,c]),h=async()=>{const y=c?x.trim().replace(/\s+/g,"-"):e?.trim();if(!y){F.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){F.error(t("settings.snippets.page.toast.contentRequired"));return}const R=w.split(",").map(T=>T.trim()).filter(Boolean);E(!0);try{if(!(c?await l(y,k,{aliases:R,description:j,scope:v}):await r(y,{content:k,aliases:R,description:j}))){F.error(t("settings.snippets.page.toast.saveFailed"));return}F.success(t("settings.snippets.page.toast.saved")),c&&i(null)}finally{E(!1)}};return e?s.jsxs(is,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:m?m.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(ze,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Ft,{label:"#",children:[s.jsx(Be,{value:x,onChange:y=>u(y.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Tt,{value:v,onValueChange:y=>d(y),children:[s.jsx(Et,{size:Bt,className:"w-fit min-w-[100px]",children:s.jsx(Ut,{})}),s.jsxs(Dt,{align:"end",children:[s.jsx(dt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(dt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(At,{label:t("settings.common.field.description"),children:s.jsx(Be,{value:j,onChange:y=>g(y.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(At,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Be,{value:w,onChange:y=>b(y.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(ze,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Yt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ms,{value:k,onChange:y=>p(y.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:h,disabled:C||!N,size:"xs",className:"!font-normal",children:t(C?"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")})]})})},$c=()=>{const{t}=et(),e=Xe(v=>v.settingsGitmojiEnabled),a=Xe(v=>v.setSettingsGitmojiEnabled),n=Pu(),i=ce(v=>v.gitChangesViewMode),r=ce(v=>v.setGitChangesViewMode),[l,m]=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 d=await In();d&&(d.gitmojiEnabled!==void 0&&a(d.gitmojiEnabled),d.gitChangesViewMode!==void 0&&r(d.gitChangesViewMode))}catch(d){console.warn("Failed to load git settings:",d)}finally{m(!1)}})()},[r,a]);const x=o.useCallback(async v=>{a(v);try{await yt({gitmojiEnabled:v})}catch(d){console.warn("Failed to save gitmoji setting:",d)}},[a]),u=o.useCallback(v=>{v!==i&&(r(v),yt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx(ze,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(As,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(an,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(v=>s.jsx(Ys,{selected:i===v.id,onSelect:()=>{u(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(mt,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{x(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(mt,{settingsItem:"git.gitignored-files",checked:n,onChange:Au,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Pl=[{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)"}],wf=[{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"}],kf=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=et(),r=sa(L=>L.getProfileById),l=sa(L=>L.createProfile),m=sa(L=>L.updateProfile),c=sa(L=>L.deleteProfile),x=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),u=a==="new"||n!=null,v=a==="global",[d,j]=o.useState(""),[g,w]=o.useState(""),[b,k]=o.useState(""),[p,C]=o.useState("ssh"),[E,A]=o.useState(""),[N,h]=o.useState(!1),[y,R]=o.useState(""),[T,P]=o.useState(""),[D,V]=o.useState("keyword"),[$,I]=o.useState("branch"),[M,H]=o.useState(!1),[U,Z]=o.useState(!1),[ee,O]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const L=n.host.split("/"),K=L.length>=3?L[L.length-1]:n.host;j(K),w(n.username),k(""),C("token"),A(""),h(!1),R(""),P(n.host),V("string"),I("code")}else if(u)j(""),w(""),k(""),C("ssh"),A(""),h(!1),R(""),P(""),V("keyword"),I("branch");else if(x)j(x.name),w(x.userName),k(x.userEmail),C(x.authType||"ssh"),A(x.sshKey||""),h(x.signCommits===!0),R(x.signingKey||""),P(x.host||""),V(x.color||"keyword"),I(x.icon||"branch");else if(v){const L=r("global");L&&(j(L.name),w(L.userName),k(L.userEmail),C(L.authType||"ssh"),A(L.sshKey||""),h(!1),R(""),P(L.host||""),V(L.color||"keyword"),I(L.icon||"branch"))}}},[t,a,x,u,n,v,r]);const ae=async()=>{if(!g.trim()||!b.trim()){F.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(p==="token"&&!T.trim()){F.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(N&&!y.trim()){F.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}H(!0);try{const L={name:d.trim()||g.trim(),userName:g.trim(),userEmail:b.trim(),authType:p,sshKey:p==="ssh"&&E.trim()||null,signCommits:N,signingKey:y.trim()||null,host:p==="token"&&T.trim()||null,color:D,icon:$};let K;if(u)K=await l(L);else if(a)K=await m(a,L);else return;K?(F.success(i(u?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):F.error(i(u?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(L){console.error("Error saving profile:",L),F.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{H(!1)}},_=async()=>{if(!(!a||u)){O(!0);try{await c(a)?(F.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Z(!1),e(!1)):F.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(L){console.error("Error deleting profile:",L),F.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{O(!1)}}},W=o.useMemo(()=>Pl.find(K=>K.key===D)?.cssVar||"var(--syntax-keyword)",[D]),q=n?i("settings.gitIdentities.editor.title.importCredential"):u?i("settings.gitIdentities.editor.title.newIdentity"):v?i("settings.gitIdentities.editor.title.globalIdentity"):x?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs($t,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:q}),s.jsx(qt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":u?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!v&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Kt} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Be,{value:d,onChange:L=>j(L.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Pl.map(L=>s.jsx("button",{type:"button",onClick:()=>V(L.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===L.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:L.cssVar},title:L.label},L.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:wf.map(L=>{const K=L.Icon;return s.jsx("button",{type:"button",onClick:()=>I(L.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",$===L.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:L.label,children:s.jsx(B,{name:K,className:"w-3.5 h-3.5",style:{color:$===L.key?W:"var(--surface-muted-foreground)"}})},L.key)})})]})]}),!v&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Kt,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Be,{value:g,onChange:L=>w(L.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Kt,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Be,{type:"email",value:b,onChange:L=>k(L.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]})]}),!v&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":p==="ssh",onClick:()=>C("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:()=>C("token"),children:[s.jsx(B,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("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:Kt,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Be,{value:E,onChange:L=>A(L.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(mt,{checked:N,onChange:h,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Kt,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Be,{value:y,onChange:L=>R(L.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!N,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:Kt,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Be,{value:T,onChange:L=>P(L.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(rs,{className:"gap-2",children:[!v&&!u&&s.jsxs(G,{variant:"outline",size:"sm",onClick:()=>Z(!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"})," ",i("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:i(v?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!v&&s.jsx(G,{size:"sm",onClick:ae,disabled:M,children:i(M?"settings.common.actions.saving":u?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(_t,{open:U,onOpenChange:L=>{ee||Z(L)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(qt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||d})})]}),s.jsxs(rs,{children:[s.jsx(G,{variant:"ghost",onClick:()=>Z(!1),disabled:ee,children:i("settings.common.actions.cancel")}),s.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:ee,children:i("settings.common.actions.delete")})]})]})})]})},Nf={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Sf={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Cf=()=>{const t=ct.c(112),{t:e}=et(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:m,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:u,getUnimportedCredentials:v}=sa(qs(Pf)),[d,j]=o.useState(!1),[g,w]=o.useState(null),[b,k]=o.useState(null),[p,C]=o.useState(null),[E,A]=o.useState(!1);let N,h;t[0]!==x||t[1]!==c||t[2]!==m||t[3]!==l?(N=()=>{l(),m(),c(),x()},h=[l,m,c,x],t[0]=x,t[1]=c,t[2]=m,t[3]=l,t[4]=N,t[5]=h):(N=t[4],h=t[5]),o.useEffect(N,h);let y,R,T,P,D,V,$,I,M,H,U,Z,ee,O;if(t[6]!==i||t[7]!==p||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==u||t[13]!==e){const Ve=v();let je;t[28]===Symbol.for("react.memo_cache_sentinel")?(je=(De,Ce)=>{w(De),k(Ce??null),j(!0)},t[28]=je):je=t[28];const ke=je;let se;t[29]!==i||t[30]!==u||t[31]!==e?(se=async De=>{const Ce=i===De?null:De;if(!await u(Ce)){F.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}F.success(e(Ce?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=u,t[31]=e,t[32]=se):se=t[32];const le=se;let Ie;t[33]!==p||t[34]!==r||t[35]!==e?(Ie=async()=>{if(!p)return;A(!0),await r(p.id)?(F.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:p.name})),C(null)):F.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[33]=p,t[34]=r,t[35]=e,t[36]=Ie):Ie=t[36],T=Ie,R=is,t[37]!==e?(D=e("settings.page.git.title"),t[37]=e,t[38]=D):D=t[38],V=!0,y=ze,t[39]!==e?(Z=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=Z):Z=t[40],ee=!1;let Ne,Re;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>ke("new"),Re=s.jsx(B,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ne,t[42]=Re):(Ne=t[41],Re=t[42]);let $e;t[43]!==e?($e=e("settings.common.badge.new"),t[43]=e,t[44]=$e):$e=t[44],t[45]!==$e?(O=s.jsxs(G,{size:"sm",variant:"outline",onClick:Ne,children:[Re," ",$e]}),t[45]=$e,t[46]=O):O=t[46],P="git.identities",$="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",I=n&&s.jsx(Al,{profile:n,isDefault:i==="global",onEdit:()=>ke("global"),onToggleDefault:()=>le("global"),isReadOnly:!0,hasBorder:a.length>0||Ve.length>0}),M=a.map((De,Ce)=>s.jsx(Al,{profile:De,isDefault:i===De.id,onEdit:()=>ke(De.id),onToggleDefault:()=>le(De.id),onDelete:()=>C(De),hasBorder:Ce<a.length-1||Ve.length>0},De.id)),H=!n&&a.length===0&&Ve.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")})]}),U=Ve.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")})}),Ve.map((De,Ce)=>s.jsx(If,{credential:De,onImport:()=>ke("new",{host:De.host,username:De.username}),hasBorder:Ce<Ve.length-1},`${De.host}-${De.username}`))]}),t[6]=i,t[7]=p,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=u,t[13]=e,t[14]=y,t[15]=R,t[16]=T,t[17]=P,t[18]=D,t[19]=V,t[20]=$,t[21]=I,t[22]=M,t[23]=H,t[24]=U,t[25]=Z,t[26]=ee,t[27]=O}else y=t[14],R=t[15],T=t[16],P=t[17],D=t[18],V=t[19],$=t[20],I=t[21],M=t[22],H=t[23],U=t[24],Z=t[25],ee=t[26],O=t[27];let ae;t[47]!==$||t[48]!==I||t[49]!==M||t[50]!==H||t[51]!==U?(ae=s.jsxs("div",{className:$,children:[I,M,H,U]}),t[47]=$,t[48]=I,t[49]=M,t[50]=H,t[51]=U,t[52]=ae):ae=t[52];let _;t[53]!==y||t[54]!==P||t[55]!==ae||t[56]!==Z||t[57]!==ee||t[58]!==O?(_=s.jsx(y,{title:Z,divider:ee,headerAction:O,settingsItem:P,children:ae}),t[53]=y,t[54]=P,t[55]=ae,t[56]=Z,t[57]=ee,t[58]=O,t[59]=_):_=t[59];let W;t[60]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx($c,{}),t[60]=W):W=t[60];let q;t[61]!==R||t[62]!==D||t[63]!==V||t[64]!==_?(q=s.jsxs(R,{title:D,showSaveStatus:V,children:[_,W]}),t[61]=R,t[62]=D,t[63]=V,t[64]=_,t[65]=q):q=t[65];let L;t[66]!==b||t[67]!==d||t[68]!==g?(L=s.jsx(kf,{open:d,onOpenChange:j,profileId:g,importData:b}),t[66]=b,t[67]=d,t[68]=g,t[69]=L):L=t[69];const K=p!==null;let z;t[70]!==E?(z=Ve=>{E||Ve||C(null)},t[70]=E,t[71]=z):z=t[71];let J;t[72]!==e?(J=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=J):J=t[73];let oe;t[74]!==J?(oe=s.jsx(Ht,{children:J}),t[74]=J,t[75]=oe):oe=t[75];const re=p?.name??"";let pe;t[76]!==e||t[77]!==re?(pe=e("settings.gitIdentities.page.deleteDialog.description",{name:re}),t[76]=e,t[77]=re,t[78]=pe):pe=t[78];let ve;t[79]!==pe?(ve=s.jsx(qt,{children:pe}),t[79]=pe,t[80]=ve):ve=t[80];let be;t[81]!==oe||t[82]!==ve?(be=s.jsxs(Vt,{children:[oe,ve]}),t[81]=oe,t[82]=ve,t[83]=be):be=t[83];let te;t[84]===Symbol.for("react.memo_cache_sentinel")?(te=()=>C(null),t[84]=te):te=t[84];let he;t[85]!==e?(he=e("settings.common.actions.cancel"),t[85]=e,t[86]=he):he=t[86];let ie;t[87]!==E||t[88]!==he?(ie=s.jsx(G,{variant:"ghost",onClick:te,disabled:E,children:he}),t[87]=E,t[88]=he,t[89]=ie):ie=t[89];let ue;t[90]!==T?(ue=()=>{T()},t[90]=T,t[91]=ue):ue=t[91];let de;t[92]!==e?(de=e("settings.common.actions.delete"),t[92]=e,t[93]=de):de=t[93];let Pe;t[94]!==E||t[95]!==ue||t[96]!==de?(Pe=s.jsx(G,{size:"sm",variant:"destructive",onClick:ue,disabled:E,children:de}),t[94]=E,t[95]=ue,t[96]=de,t[97]=Pe):Pe=t[97];let Ae;t[98]!==ie||t[99]!==Pe?(Ae=s.jsxs(rs,{children:[ie,Pe]}),t[98]=ie,t[99]=Pe,t[100]=Ae):Ae=t[100];let we;t[101]!==be||t[102]!==Ae?(we=s.jsxs($t,{className:"max-w-md",children:[be,Ae]}),t[101]=be,t[102]=Ae,t[103]=we):we=t[103];let Le;t[104]!==K||t[105]!==z||t[106]!==we?(Le=s.jsx(_t,{open:K,onOpenChange:z,children:we}),t[104]=K,t[105]=z,t[106]=we,t[107]=Le):Le=t[107];let _e;return t[108]!==q||t[109]!==L||t[110]!==Le?(_e=s.jsxs(s.Fragment,{children:[q,L,Le]}),t[108]=q,t[109]=L,t[110]=Le,t[111]=_e):_e=t[111],_e},Al=t=>{const e=ct.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:m,hasBorder:c}=t,{t:x}=et(),[u,v]=o.useState(!1),d=Nf[a.icon||"branch"]||"git-branch",j=Sf[a.color||""],g=a.authType||"ssh";let w;e[0]!==i?(w=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),i()))},e[0]=i,e[1]=w):w=e[1];const b=w;let k;e[2]!==n||e[3]!==m||e[4]!==l||e[5]!==r||e[6]!==x?(k=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:W=>{W.stopPropagation(),r()},children:x(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!m&&l&&s.jsxs(_,{onClick:W=>{W.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=n,e[3]=m,e[4]=l,e[5]=r,e[6]=x,e[7]=k):k=e[7];const p=k,C=c&&"border-b border-[var(--surface-subtle)]";let E;e[8]!==C?(E=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",C),e[8]=C,e[9]=E):E=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=_=>{_.preventDefault(),v(!0)},e[10]=A):A=e[10];let N;e[11]!==b||e[12]!==i||e[13]!==E?(N=s.jsx("div",{className:E,onClick:i,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:A}),e[11]=b,e[12]=i,e[13]=E,e[14]=N):N=e[14];let h;e[15]!==j?(h={color:j},e[15]=j,e[16]=h):h=e[16];let y;e[17]!==d||e[18]!==h?(y=s.jsx(B,{name:d,className:"w-4 h-4 shrink-0",style:h}),e[17]=d,e[18]=h,e[19]=y):y=e[19];let R;e[20]!==a.name?(R=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=R):R=e[21];let T;e[22]!==g?(T=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:g}),e[22]=g,e[23]=T):T=e[23];let P;e[24]!==n||e[25]!==x?(P=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:x("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=x,e[26]=P):P=e[26];let D;e[27]!==m||e[28]!==x?(D=m&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:x("settings.agents.sidebar.badge.system")}),e[27]=m,e[28]=x,e[29]=D):D=e[29];let V;e[30]!==T||e[31]!==P||e[32]!==D||e[33]!==R?(V=s.jsxs("div",{className:"flex items-center gap-1.5",children:[R,T,P,D]}),e[30]=T,e[31]=P,e[32]=D,e[33]=R,e[34]=V):V=e[34];const $=g==="token"&&a.host?a.host:a.userEmail;let I;e[35]!==$?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:$}),e[35]=$,e[36]=I):I=e[36];let M;e[37]!==V||e[38]!==I?(M=s.jsxs("div",{className:"min-w-0",children:[V,I]}),e[37]=V,e[38]=I,e[39]=M):M=e[39];let H;e[40]!==M||e[41]!==y?(H=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[y,M]}),e[40]=M,e[41]=y,e[42]=H):H=e[42];let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(vn,{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:Af,children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=U):U=e[43];let Z;e[44]!==p?(Z=s.jsxs(jn,{children:[U,s.jsx(yn,{align:"end",className:"w-fit min-w-28",children:p(wn)})]}),e[44]=p,e[45]=Z):Z=e[45];let ee;e[46]!==H||e[47]!==Z||e[48]!==N?(ee=s.jsxs(ma,{render:N,children:[H,Z]}),e[46]=H,e[47]=Z,e[48]=N,e[49]=ee):ee=e[49];let O;e[50]!==p?(O=s.jsx(da,{className:"w-fit min-w-28",children:p(ua)}),e[50]=p,e[51]=O):O=e[51];let ae;return e[52]!==u||e[53]!==ee||e[54]!==O?(ae=s.jsxs(pa,{open:u,onOpenChange:v,children:[ee,O]}),e[52]=u,e[53]=ee,e[54]=O,e[55]=ae):ae=e[55],ae},If=t=>{const e=ct.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=et();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const m=l,c=m.length>=3?m[m.length-1]:a.host,x=a.host.includes("/"),u=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==u?(v=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",u),e[2]=u,e[3]=v):v=e[3];let d;e[4]!==c?(d=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=d):d=e[5];const j=x?a.host:a.username;let g;e[6]!==j?(g=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:j}),e[6]=j,e[7]=g):g=e[7];let w;e[8]!==d||e[9]!==g?(w=s.jsxs("div",{className:"min-w-0",children:[d,g]}),e[8]=d,e[9]=g,e[10]=w):w=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]!==r?(k=r("settings.gitIdentities.page.actions.import"),e[12]=r,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 C;return e[17]!==p||e[18]!==v||e[19]!==w?(C=s.jsxs("div",{className:v,children:[w,p]}),e[17]=p,e[18]=v,e[19]=w,e[20]=C):C=e[20],C};function Pf(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 Af(t){return t.stopPropagation()}const Bc=({guest:t})=>{const{t:e}=et(),a=t.integration,n=fr(z=>z.byId[t.id]),i=fr(z=>z.setStatus),r=o.useMemo(()=>dc(t.id,t.icon,jc().authenticatedAsset),[t.id,t.icon]),l=fr(z=>z.refresh),[m,c]=o.useState(!1),[x,u]=o.useState(!1),[v,d]=o.useState(!1),[j,g]=o.useState(""),[w,b]=o.useState(""),[k,p]=o.useState(""),[C,E]=o.useState(""),[A,N]=o.useState({}),[h,y]=o.useState(!1),R=o.useRef(null),[T]=o.useState(Rn),P=o.useRef(!0),D=()=>P.current&&Rn()===T,V=o.useCallback(()=>{R.current!=null&&(window.clearInterval(R.current),R.current=null),d(!1)},[]);if(o.useEffect(()=>(P.current=!0,l(t.id),()=>{P.current=!1,V()}),[t.id,l,V]),o.useEffect(()=>{n&&N(n.settings)},[n]),!a)return null;const $=a.auth,I=$==="token"&&a.token?.scheme==="basic",M=!!n?.connection.connected,H=n?.connection.account.trim()||"",U=v?e("settings.integrations.guests.status.waiting"):M?H||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),Z=v?"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",ee=v||m,O=a.name,ae=async()=>{if(!D())return!1;const z=j.trim();if(!z)return n?.hasClient?!0:(F.error(e("settings.integrations.guests.toast.clientRequired")),!1);ys("saving");const J=await hm(t.id,z,w.trim()||void 0);return D()?J?(i(t.id,J),b(""),ys("saved"),!0):(ys("error"),F.error(e("settings.integrations.guests.toast.saveFailed",{name:O})),!1):!1},_=async(z=A)=>{if(!D())return!1;const J=n?.settings??{};if((a.settings??[]).every(ve=>(z[ve.id]??"").trim()===(J[ve.id]??"")))return!0;ys("saving");const pe=await lm(t.id,z);return D()?pe?(i(t.id,pe),ys("saved"),!0):(ys("error"),F.error(e("settings.integrations.guests.toast.saveFailed",{name:O})),!1):!1},W=async()=>{if(!D())return!1;const z=k.trim();if(!z)return M?!0:(F.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const J=C.trim();if(I&&!J)return F.error(e("settings.integrations.guests.toast.usernameRequired")),!1;ys("saving");const oe=await gm(t.id,z,I?J:void 0);return D()?oe?(i(t.id,oe),p(""),E(""),ys("saved"),!0):(ys("error"),F.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},q=async()=>{if(!D())return;V(),u(!0);const z=n?.connection??{connected:!1,account:""};try{if($==="token"){if(await W()){if((a.settings??[]).length>0&&!await _()||!D())return;F.success(e("settings.integrations.guests.toast.connected",{name:O}))}return}if($==="oauth"&&!n?.hasClient&&!await ae())return;const J=await dm(t.id);if(!D())return;if(!J){F.error(e("settings.integrations.guests.toast.startFailed",{name:O}));return}d(!0),c(!0),bn(J);const oe=Date.now()+um;R.current=window.setInterval(()=>{(async()=>{if(!D()){V();return}if(Date.now()>oe){V(),F.error(e("settings.integrations.guests.toast.authorizationFailed",{name:O}));return}const re=await l(t.id);D()&&re&&mm(z,re.connection)&&(V(),F.success(e("settings.integrations.guests.toast.connected",{name:O})),cs()&&wc())})()},pm)}catch(J){if(!D())return;console.error("Failed to start guest connect:",J),F.error(e("settings.integrations.guests.toast.startFailed",{name:O})),V()}finally{D()&&u(!1)}},L=async()=>{if(D()){u(!0);try{V();const z=await cm(t.id);if(!D())return;if(!z){F.error(e("settings.integrations.guests.toast.disconnectFailed",{name:O}));return}i(t.id,z),F.success(e("settings.integrations.guests.toast.disconnected",{name:O}))}catch(z){if(!D())return;console.error("Failed to disconnect guest:",z),F.error(e("settings.integrations.guests.toast.disconnectFailed",{name:O}))}finally{D()&&u(!1)}}},K=async()=>{const z=n?.redirectUri??"";!z||!(await Ra(z)).ok||(y(!0),window.setTimeout(()=>y(!1),1500))};return s.jsx(kn,{open:ee,onOpenChange:z=>{if(v){c(!0);return}c(z)},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(uc,{icon:mc(t.icon),iconSrc:r,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:O}),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:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",Z),children:U}),s.jsx(B,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ee&&"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:[$==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(At,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:j,onChange:z=>g(z.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:x})}),s.jsx(At,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{type:"password",value:w,onChange:z=>b(z.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:x})})]}):null,I?s.jsx(At,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:C,onChange:z=>E(z.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:x})}):null,$==="token"?s.jsx(At,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{type:"password",value:k,onChange:z=>p(z.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:x})}):null,(a.settings??[]).map(z=>s.jsx(At,{label:z.label,controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:A[z.id]??"",onChange:J=>{N(oe=>({...oe,[z.id]:J.target.value}))},onBlur:()=>{_()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:x})},z.id)),$==="oauth"?s.jsxs(At,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(Be,{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:()=>{K()},children:e(h?"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:x,onClick:()=>{L()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(G,{type:"button",size:"sm",disabled:x||v,onClick:()=>{q()},children:[x?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},Tf=t=>{const e=ct.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:i}=et(),r=Zs(Ef),l=Zs(Df);let m;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0],o.useEffect(Mf,m),ds()||kc())return null;let c,x,u,v,d,j,g,w;if(e[1]!==n||e[2]!==r||e[3]!==l||e[4]!==i){w=Symbol.for("react.early_return_sentinel");e:{const k=r.filter(Rf);if(k.length===0){w=null;break e}c=ze,e[13]!==i?(x=i("settings.integrations.guests.title"),e[13]=i,e[14]=x):x=e[14],e[15]!==i?(u=i("settings.integrations.guests.info"),e[15]=i,e[16]=u):u=e[16],v=n,d="integrations.guests",j="space-y-3";let p;e[17]!==l?(p=C=>s.jsx(Bc,{guest:C},`${l}:${C.id}`),e[17]=l,e[18]=p):p=e[18],g=k.map(p)}e[1]=n,e[2]=r,e[3]=l,e[4]=i,e[5]=c,e[6]=x,e[7]=u,e[8]=v,e[9]=d,e[10]=j,e[11]=g,e[12]=w}else c=e[5],x=e[6],u=e[7],v=e[8],d=e[9],j=e[10],g=e[11],w=e[12];if(w!==Symbol.for("react.early_return_sentinel"))return w;let b;return e[19]!==c||e[20]!==x||e[21]!==u||e[22]!==v||e[23]!==d||e[24]!==j||e[25]!==g?(b=s.jsx(c,{title:x,info:u,divider:v,settingsItem:d,contentClassName:j,children:g}),e[19]=c,e[20]=x,e[21]=u,e[22]=v,e[23]=d,e[24]=j,e[25]=g,e[26]=b):b=e[26],b};function Ef(t){return t.guests}function Df(t){return t.runtimeKey}function Mf(){Bn()}function Rf(t){return t.source!=="bundled"&&t.integration&&pc(t)}const Ff=({embedded:t=!1})=>{const{t:e}=et(),{isMobile:a}=ha(),n=Fa()?.github,i=Vn(I=>I.status),r=Vn(I=>I.isLoading),l=Vn(I=>I.hasChecked),m=Vn(I=>I.refreshStatus),c=Vn(I=>I.setStatus),x=o.useCallback(async I=>{await bn(I)},[]),[u,v]=o.useState(!1),[d,j]=o.useState(null),[g,w]=o.useState(null),b=o.useRef(null),k=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),w(null)},[]);o.useEffect(()=>((async()=>{try{l||await m(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{k()}),[l,m,n,k]);const p=o.useCallback(async()=>{v(!0);try{const I=n?await n.authStart():await(async()=>{const H=await xt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),U=await H.json().catch(()=>null);if(!H.ok||!U||!("deviceCode"in U))throw new Error(U?.error||H.statusText);return U})();j(I),w(Math.max(1,I.interval)*1e3);const M=I.verificationUriComplete||I.verificationUri;x(M)}catch(I){console.error("Failed to start GitHub connect:",I),F.error(e("settings.github.page.toast.startConnectFailed"))}finally{v(!1)}},[x,n,e]),C=o.useCallback(async I=>{if(n)return n.authComplete(I);const M=await xt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),H=await M.json().catch(()=>null);if(!M.ok||!H)throw new Error(H?.error||M.statusText);return H},[n]);o.useEffect(()=>{if(!(!d?.deviceCode||!g)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const I=await C(d.deviceCode);if(I.connected){F.success(e("settings.github.page.toast.connected")),j(null),k(),await m(n,{force:!0});return}I.status==="slow_down"&&w(M=>M?M+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(F.error(I.error||e("settings.github.page.toast.authorizationFailed")),j(null),k())}catch(I){console.warn("GitHub polling failed:",I)}})()},g),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[d,g,C,m,n,k,e]);const E=o.useCallback(async I=>{v(!0);try{if(n)await n.authSetGhCliDisabled(I);else{const M=await xt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:I})}),H=await M.json().catch(()=>null);if(!M.ok)throw new Error(H?.error||M.statusText)}F.success(e(I?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await m(n,{force:!0})}catch(M){console.error("Failed to update gh CLI setting:",M),F.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{v(!1)}},[m,n,e]),A=o.useCallback(async()=>{v(!0);try{if(k(),j(null),n)await n.authDisconnect();else{const I=await xt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}F.success(e("settings.github.page.toast.disconnected")),await m(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),F.error(e("settings.github.page.toast.disconnectFailed"))}finally{v(!1)}},[m,n,k,e]),N=o.useCallback(async I=>{if(I){v(!0);try{const M=n?await n.authActivate(I):await(async()=>{const H=await xt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),U=await H.json().catch(()=>null);if(!H.ok||!U)throw new Error(U?.error||H.statusText);return U})();c(M),F.success(e("settings.github.page.toast.accountSwitched"))}catch(M){console.error("Failed to switch GitHub account:",M),F.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{v(!1)}}},[n,c,e]);if(r&&!l)return null;const h=!!i?.connected,y=i?.user,T=(i?.accounts??[]).filter(I=>!I.current),P=i?.ghCli??null,D=P?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),V=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[h?s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[y?.avatarUrl?s.jsx("img",{src:y.avatarUrl,alt:y.login?e("settings.github.page.avatarAlt.withLogin",{login:y.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:y?.name?.trim()||y?.login||"GitHub"}),s.jsxs("div",{className:ye("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:y?.login||e("settings.github.page.label.unknownUser")}),y?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),y?.email&&s.jsx("span",{children:y.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:D})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),P?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),P?.active?s.jsx(G,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:u,className:ye(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(G,{size:"sm",variant:"outline",onClick:A,disabled:u,className:ye("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:u,children:e("settings.github.page.actions.connect")})]}),T.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:T.map(I=>{const M=I.user,H=I.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:H})]})]})]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>N(I.id),disabled:u,children:e("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),h&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(G,{size:"sm",variant:"outline",onClick:p,disabled:u,className:ye(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),d&&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(dn,{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:d.userCode}),s.jsx(G,{size:"sm",asChild:!0,children:s.jsx("a",{href:d.verificationUriComplete||d.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:u,onClick:()=>{k(),j(null)},children:e("settings.common.actions.cancel")})]})]})]}),$=P?.available&&!P?.active&&(!P.user||P.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[P.user?.avatarUrl?s.jsx("img",{src:P.user.avatarUrl,alt:P.user.login?e("settings.github.page.avatarAlt.withLogin",{login:P.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:[!P.disabled&&P.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:P.user.name?.trim()||P.user.login||"GitHub"}),!P.disabled&&P.user?.login&&s.jsxs("div",{className:ye("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:P.user.login}),P.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),P.user.email&&s.jsx("span",{children:P.user.email})]}),s.jsx("div",{className:ye("typography-meta text-muted-foreground",P.disabled?"opacity-60":void 0),children:P.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>E(!P.disabled),disabled:u,className:ye(a?"w-full":void 0),children:P.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:[V,$?s.jsxs("div",{className:"space-y-2",children:[s.jsx(dn,{children:e("settings.github.page.ghCli.title")}),$]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(ze,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:V}),$?s.jsx(ze,{title:e("settings.github.page.ghCli.title"),children:$}):null]})},Of=()=>{const t=ct.c(37),{t:e}=et(),a=Vn(Lf),n=Vn(Kf),i=Vn(zf),[r,l]=o.useState(!1),m=a?.connected===!0;let c;t[0]!==m||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!i?e("common.loading"):m?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=m,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const x=c,u=m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let v;t[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=v):v=t[6];let d;t[7]!==e?(d=e("settings.integrations.github.title"),t[7]=e,t[8]=d):d=t[8];let j;t[9]!==d?(j=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:d}),t[9]=d,t[10]=j):j=t[10];let g;t[11]!==e?(g=e("settings.integrations.github.description"),t[11]=e,t[12]=g):g=t[12];let w;t[13]!==g?(w=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:g}),t[13]=g,t[14]=w):w=t[14];let b;t[15]!==j||t[16]!==w?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[j,w]}),t[15]=j,t[16]=w,t[17]=b):b=t[17];let k;t[18]!==u?(k=ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",u),t[18]=u,t[19]=k):k=t[19];let p;t[20]!==x||t[21]!==k?(p=s.jsx("span",{"aria-live":"polite",className:k,children:x}),t[20]=x,t[21]=k,t[22]=p):p=t[22];const C=r&&"rotate-180";let E;t[23]!==C?(E=ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",C),t[23]=C,t[24]=E):E=t[24];let A;t[25]!==E?(A=s.jsx(B,{name:"arrow-down-s",className:E}),t[25]=E,t[26]=A):A=t[26];let N;t[27]!==A||t[28]!==b||t[29]!==p?(N=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:[v,b,p,A]}),t[27]=A,t[28]=b,t[29]=p,t[30]=N):N=t[30];let h;t[31]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Sn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(Ff,{embedded:!0})}),t[31]=h):h=t[31];let y;t[32]!==N?(y=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[N,h]}),t[32]=N,t[33]=y):y=t[33];let R;return t[34]!==r||t[35]!==y?(R=s.jsx(kn,{open:r,onOpenChange:l,children:y}),t[34]=r,t[35]=y,t[36]=R):R=t[36],R};function Lf(t){return t.status}function Kf(t){return t.isLoading}function zf(t){return t.hasChecked}const Di="__none__",Mi="__inherit__";function Uf({linear:t,connected:e,organizationId:a}){const{t:n}=et(),i=en(b=>b.projects),[r,l]=o.useState(null),[m,c]=o.useState(!1),[x,u]=o.useState(!1),v=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(()=>{v()},[v,a]);const d=o.useCallback(async b=>{const k={};for(const p of b.teams??[])p.projectPath&&(k[p.id]=p.projectPath);u(!0),ys("saving");try{const p=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(p.connected===!1){l(null),ys("error");return}l(p),c(!1),ys("saved")}catch(p){console.error("Failed to save Linear mapping:",p),ys("error")}finally{u(!1)}},[t]);if(!e)return null;if(m&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const j=b=>i.find(p=>p.path===b)?.label?.trim()||b,g=b=>!b||b===Di?n("settings.integrations.linear.mapping.defaultProject.placeholder"):j(b),w=b=>!b||b===Mi?n("settings.integrations.linear.mapping.teams.useDefault"):j(b);return s.jsxs("div",{className:_s,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ft,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Tt,{value:r.defaultProjectPath||Di,disabled:x||i.length===0,onValueChange:b=>{d({...r,defaultProjectPath:b===Di?null:b})},children:[s.jsx(Et,{size:Bt,className:ln,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Ut,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:g})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:Di,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(b=>b.path===r.defaultProjectPath)?s.jsx(dt,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(b=>s.jsx(dt,{value:b.path,children:j(b.path)},b.id))]})]})}),s.jsx(As,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(r.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:_s,children:(r.teams??[]).map(b=>s.jsx(Ft,{label:`${b.key} · ${b.name}`,children:s.jsxs(Tt,{value:b.projectPath||Mi,disabled:x||i.length===0,onValueChange:k=>{d({...r,teams:(r.teams??[]).map(p=>p.id===b.id?{...p,projectPath:k===Mi?null:k}:p)})},children:[s.jsx(Et,{size:Bt,className:ln,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(Ut,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:w})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:Mi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!i.some(k=>k.path===b.projectPath)?s.jsx(dt,{value:b.projectPath,children:b.projectPath}):null,i.map(k=>s.jsx(dt,{value:k.path,children:j(k.path)},k.id))]})]})},b.id))})})]})}function _f({linear:t,connected:e}){const{t:a}=et(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[m,c]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let u=!1;return t.preferencesGet().then(v=>{u||(i(v.sessionComments),l(!1))}).catch(()=>{u||l(!0)}),()=>{u=!0}},[e,t]);const x=o.useCallback(async u=>{const v=n;i(u),c(!0);try{const d=await t.preferencesSet({sessionComments:u});i(d.sessionComments),ys("saved")}catch{i(v),ys("error")}finally{c(!1)}},[n,t]);return e?r?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:_s,children:s.jsx(Ft,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(si,{checked:n===!0,disabled:n===null||m,onCheckedChange:u=>{x(u)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const $f=3*6e4,Bf=1500;function Tl(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 Vf(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Hf=()=>{const{t}=et(),e=Fa()?.linear,a=Sa(P=>P.status),n=Sa(P=>P.isLoading),i=Sa(P=>P.hasChecked),r=Sa(P=>P.refreshStatus),l=Sa(P=>P.setStatus),[m,c]=o.useState(!1),[x,u]=o.useState(!1),[v,d]=o.useState(!1),j=o.useRef(null),g=o.useCallback(()=>{j.current!=null&&(window.clearInterval(j.current),j.current=null),u(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{g()}},[i,r,e,g]);const w=o.useCallback(async()=>{if(!e)return;g(),c(!0);const P=Tl(Sa.getState().status);try{const D=await e.authStart(cs()?"desktop":"web");u(!0),d(!0),bn(D.authorizationUrl);const V=Date.now()+$f;j.current=window.setInterval(()=>{(async()=>{if(Date.now()>V){g(),F.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const $=await r(e,{force:!0});Vf(P,Tl($))&&(g(),F.success(t("settings.integrations.linear.toast.connected")),wc())})()},Bf)}catch(D){console.error("Failed to start Linear connect:",D),F.error(t("settings.integrations.linear.toast.startConnectFailed")),g()}finally{c(!1)}},[r,e,g,t]),b=o.useCallback(async P=>{if(!(!e||!P)){c(!0);try{const D=await e.authActivate(P);l(D),F.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(D){console.error("Failed to switch Linear workspace:",D),F.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),k=o.useCallback(async()=>{if(e){c(!0);try{g(),await e.authDisconnect(),F.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(P){console.error("Failed to disconnect Linear:",P),F.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[r,e,g,t]);if(!e)return null;const p=!!a?.connected,C=a?.user,E=a?.organization,N=(a?.workspaces??[]).filter(P=>!P.current),h=C?.displayName?.trim()||C?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),y=x?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):p?E?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),R=x?"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",T=x||v;return s.jsx(kn,{open:T,onOpenChange:P=>{if(x){d(!0);return}d(P)},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:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",R),children:y}),s.jsx(B,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T&&"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:[C?.avatarUrl?s.jsx("img",{src:C.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:h}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(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:h}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[E?.name,C?.email].filter(Boolean).join(" · ")})]})]}):x?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(Uf,{linear:e,connected:p,organizationId:E?.id??null}),s.jsx(_f,{linear:e,connected:p}),N.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:N.map(P=>{const D=P.user,V=P.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:V}),D?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.email}):null]}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(P.id)},disabled:m,children:t("settings.integrations.linear.actions.switchTo")})]},P.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(G,{type:"button",size:"sm",variant:"outline",onClick:()=>{w()},disabled:m||x,"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:m,children:t("settings.integrations.linear.actions.disconnect")})]})]}):x?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(G,{type:"button",size:"sm",variant:"ghost",disabled:m,onClick:g,children:t("settings.common.actions.cancel")})]}):s.jsxs(G,{type:"button",size:"sm",variant:"default",onClick:()=>{w()},disabled:m||n&&!i,children:[m?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},qf=()=>{const t=ct.c(23),{t:e}=et();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=ds(),t[0]=a):a=t[0];const n=!a,i=!!Fa()?.linear,r=Zs(Gf),l=Zs(Wf);let m,c,x,u,v,d;if(t[1]!==r||t[2]!==l||t[3]!==e){const w=!ds()&&!kc()?r.filter(Jf):[];c=n||i||w.length>0,m=is,t[10]!==e?(x=e("settings.page.integrations.title"),t[10]=e,t[11]=x):x=t[11],t[12]!==e?(u=e("settings.page.integrations.description"),t[12]=e,t[13]=u):u=t[13],v=!0,d=c?s.jsxs(ze,{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(Of,{}):null,i?s.jsx(Hf,{}):null,w.map(b=>s.jsx(Bc,{guest:b},`${l}:${b.id}`))]}):null,t[1]=r,t[2]=l,t[3]=e,t[4]=m,t[5]=c,t[6]=x,t[7]=u,t[8]=v,t[9]=d}else m=t[4],c=t[5],x=t[6],u=t[7],v=t[8],d=t[9];let j;t[14]!==c?(j=s.jsx(Tf,{divider:c}),t[14]=c,t[15]=j):j=t[15];let g;return t[16]!==m||t[17]!==x||t[18]!==u||t[19]!==v||t[20]!==d||t[21]!==j?(g=s.jsxs(m,{title:x,description:u,showSaveStatus:v,children:[d,j]}),t[16]=m,t[17]=x,t[18]=u,t[19]=v,t[20]=d,t[21]=j,t[22]=g):g=t[22],g};function Gf(t){return t.guests}function Wf(t){return t.runtimeKey}function Jf(t){return t.source==="bundled"&&t.integration&&pc(t)}const Aa="__default__",Qf=500,Yf=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),Zf=(t,e)=>{const a=ct.c(9),n=Xe(tx);let i;e:{if(!t||!e){let c;a[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],a[0]=c):c=a[0],i=c;break e}let r;if(a[1]!==e||a[2]!==t||a[3]!==n){let c;a[5]!==t?(c=u=>u.id===t,a[5]=t,a[6]=c):c=a[6],r=n.find(c)?.models.find(u=>u.id===e),a[1]=e,a[2]=t,a[3]=n,a[4]=r}else r=a[4];const l=r;let m;a[7]!==l?(m=l?.variants?Object.keys(l.variants):[],a[7]=l,a[8]=m):m=a[8],i=m}return i},Vc=t=>{const e=ct.c(33),{providerID:a,modelID:n,value:i,onChange:r,ariaLabel:l,className:m}=t,{t:c}=et(),x=Zf(a,n);let u;e[0]!==c?(u=R=>R===Aa?c("settings.routing.thinking.default"):R.charAt(0).toUpperCase()+R.slice(1),e[0]=c,e[1]=u):u=e[1];const v=u,d=i??Aa;let j;e[2]!==r?(j=R=>r(R===Aa?null:R),e[2]=r,e[3]=j):j=e[3];const g=x.length===0;let w;e[4]!==m?(w=ye(ln,m),e[4]=m,e[5]=w):w=e[5];const b=i??Aa;let k;e[6]!==v||e[7]!==b?(k=v(b),e[6]=v,e[7]=b,e[8]=k):k=e[8];let p;e[9]!==k?(p=s.jsx(Ut,{children:k}),e[9]=k,e[10]=p):p=e[10];let C;e[11]!==l||e[12]!==w||e[13]!==p?(C=s.jsx(Et,{size:Bt,className:w,"aria-label":l,children:p}),e[11]=l,e[12]=w,e[13]=p,e[14]=C):C=e[14];let E;e[15]!==v?(E=v(Aa),e[15]=v,e[16]=E):E=e[16];let A;e[17]!==E?(A=s.jsx(dt,{value:Aa,children:E}),e[17]=E,e[18]=A):A=e[18];let N;if(e[19]!==v||e[20]!==x){let R;e[22]!==v?(R=T=>s.jsx(dt,{value:T,children:v(T)},T),e[22]=v,e[23]=R):R=e[23],N=x.map(R),e[19]=v,e[20]=x,e[21]=N}else N=e[21];let h;e[24]!==A||e[25]!==N?(h=s.jsxs(Dt,{children:[A,N]}),e[24]=A,e[25]=N,e[26]=h):h=e[26];let y;return e[27]!==h||e[28]!==d||e[29]!==j||e[30]!==g||e[31]!==C?(y=s.jsxs(Tt,{value:d,onValueChange:j,disabled:g,children:[C,h]}),e[27]=h,e[28]=d,e[29]=j,e[30]=g,e[31]=C,e[32]=y):y=e[32],y},Xf=t=>{const e=ct.c(49),{category:a,expanded:n,onToggle:i,onChange:r,onReset:l,onRemove:m}=t,{t:c}=et();let x;e[0]!==a.model||e[1]!==a.variant||e[2]!==c?(x=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]=x):x=e[3];const u=x;let v;e[4]!==a.agent||e[5]!==u?(v=[u,a.agent].filter(Boolean),e[4]=a.agent,e[5]=u,e[6]=v):v=e[6];const d=v.join(" · "),j=!a.enabled&&"opacity-60";let g;e[7]!==j?(g=ye("py-1",j),e[7]=j,e[8]=g):g=e[8];const w=n?"arrow-down-s":"arrow-right-s";let b;e[9]!==w?(b=s.jsx(B,{name:w,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[9]=w,e[10]=b):b=e[10];const k=a.name||a.id;let 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 C;e[13]!==d?(C=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:d}),e[13]=d,e[14]=C):C=e[14];let E;e[15]!==n||e[16]!==i||e[17]!==b||e[18]!==p||e[19]!==C?(E=s.jsxs("button",{type:"button",onClick:i,"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,C]}),e[15]=n,e[16]=i,e[17]=b,e[18]=p,e[19]=C,e[20]=E):E=e[20];const A=a.enabled;let N;e[21]!==r?(N=D=>r({enabled:D}),e[21]=r,e[22]=N):N=e[22];let h;e[23]!==a.name||e[24]!==c?(h=c("settings.routing.category.enabledAria",{name:a.name}),e[23]=a.name,e[24]=c,e[25]=h):h=e[25];let y;e[26]!==a.enabled||e[27]!==N||e[28]!==h?(y=s.jsx(si,{checked:A,onCheckedChange:N,"aria-label":h}),e[26]=a.enabled,e[27]=N,e[28]=h,e[29]=y):y=e[29];let R;e[30]!==E||e[31]!==y?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[E,y]}),e[30]=E,e[31]=y,e[32]=R):R=e[32];let T;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]!==r||e[41]!==m||e[42]!==l||e[43]!==c?(T=n?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(En,{children:[s.jsx(At,{label:c("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(Be,{value:a.name,onChange:D=>r({name:D.target.value}),"aria-label":c("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(At,{label:c("settings.routing.category.agent"),info:c("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(Qr,{agentName:a.agent??"",onChange:D=>r({agent:D||null}),filter:sx,className:ye(on,"w-full")})}),s.jsx(At,{label:c("settings.routing.category.model"),info:c("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(na,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(D,V)=>r({model:{providerID:D,modelID:V},variant:null}),className:ye(on,"w-full"),placeholder:c("settings.routing.model.useFallback")})}),s.jsx(At,{label:c("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(Vc,{providerID:a.model?.providerID,modelID:a.model?.modelID,value:a.variant,onChange:D=>r({variant:D}),ariaLabel:c("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(At,{label:c("settings.routing.category.description"),info:c("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(Ms,{value:a.description,onChange:D=>r({description:D.target.value}),"aria-label":c("settings.routing.category.description"),rows:5,maxLength:2e3,className:"w-full"})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l?s.jsx(G,{size:"sm",variant:"outline",onClick:l,children:c("settings.routing.category.reset")}):null,s.jsx(G,{size:"sm",variant:"ghost",onClick:m,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]=r,e[41]=m,e[42]=l,e[43]=c,e[44]=T):T=e[44];let P;return e[45]!==R||e[46]!==T||e[47]!==g?(P=s.jsxs("div",{className:g,children:[R,T]}),e[45]=R,e[46]=T,e[47]=g,e[48]=P):P=e[48],P},ex=()=>{const{t}=et(),e=nn(K=>K.available),a=nn(K=>K.autoReady),n=nn(K=>K.tokenPresent),i=nn(K=>K.config),r=nn(K=>K.builtins),l=nn(K=>K.loaded),m=nn(K=>K.loadError),c=nn(K=>K.load),x=nn(K=>K.saveConfig),u=nn(K=>K.setToken),v=nn(K=>K.clearToken),[d,j]=o.useState(i),[g,w]=o.useState(""),[b,k]=o.useState(!1),[p,C]=o.useState(null),[E,A]=o.useState(""),[N,h]=o.useState(null),y=o.useRef(null),R=o.useRef(null),T=o.useRef(Promise.resolve()),P=o.useRef(0);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{!y.current&&P.current===0&&j(i)},[i]);const D=o.useCallback(()=>{const K=y.current;if(!K||(y.current=null,K.runtimeKey!==Rn()))return T.current;P.current+=1,ys("saving");const z=T.current.then(async()=>{try{if(K.runtimeKey!==Rn()){ys("saved");return}await x(K.config),ys("saved")}catch{ys("error")}finally{P.current-=1}});return T.current=z,z},[x]);o.useEffect(()=>()=>{R.current&&clearTimeout(R.current),D()},[D]);const V=Xe(K=>K.settingsDefaultModel),$=Xe(K=>K.settingsDefaultVariant),I=o.useRef(!1);o.useEffect(()=>{if(I.current||!l||!i||i.fallback)return;const K=la(V);!K||gc(K.providerId,K.modelId)||(I.current=!0,M(z=>z.fallback?z:{...z,fallback:{model:{providerID:K.providerId,modelID:K.modelId},variant:$??null}}))},[l,i,V,$]);const M=o.useCallback(K=>{j(z=>{if(!z)return z;const J=K(z);return y.current={config:J,runtimeKey:Rn()},R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,D()},Qf),J})},[D]),H=o.useCallback((K,z)=>{M(J=>({...J,categories:J.categories.map(oe=>oe.id===K?{...oe,...z}:oe)}))},[M]),U=async()=>{const K=g.trim();if(K){k(!0),C(null);try{await u(K),w("")}catch(z){C(z instanceof Error?z.message:String(z))}finally{k(!1)}}},Z=async()=>{k(!0),C(null);try{await v()}catch(K){C(K instanceof Error?K.message:String(K))}finally{k(!1)}},ee=()=>{const K=E.trim();if(!K||!d)return;const z=Yf(K)||`category-${Date.now()}`;let J=z,oe=2;for(;d.categories.some(re=>re.id===J);)J=`${z}-${oe++}`;M(re=>({...re,categories:[...re.categories,{id:J,builtin:!1,enabled:!0,name:K,description:"",model:null,variant:null,agent:null}]})),A(""),h(J)},O=K=>{const z=r.find(J=>J.id===K);z&&H(K,{name:z.name,description:z.description,model:null,variant:null,agent:null,enabled:!0})},ae=K=>{const z=r.find(J=>J.id===K);z&&M(J=>({...J,categories:[...J.categories,{id:K,builtin:!0,enabled:!0,name:z.name,description:z.description,model:null,variant:null,agent:null}]}))},_=K=>{M(z=>({...z,categories:z.categories.filter(J=>J.id!==K)}))},W=d?.categories.filter(K=>K.enabled).length??0,q=r.filter(K=>!d?.categories.some(z=>z.id===K.id)),L=n?d?.enabled?d.fallback?W<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"):t("settings.routing.status.noToken");return s.jsxs(is,{title:t("settings.page.routing.title"),description:t("settings.page.routing.description"),showSaveStatus:!0,children:[m?s.jsx("p",{className:Oi,children:t("settings.routing.loadError",{error:m})}):null,!l||!d?null:e?s.jsxs(s.Fragment,{children:[s.jsx(ze,{title:t("settings.routing.token.title"),divider:!1,children:s.jsxs("div",{className:_s,children:[s.jsx("p",{className:rn,children:t(n?"settings.routing.token.present":"settings.routing.token.missing")}),s.jsx(Ft,{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(Be,{type:"password",autoComplete:"off",value:g,onChange:K=>w(K.target.value),onKeyDown:K=>{K.key==="Enter"&&U()},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:b}),s.jsx(G,{size:"sm",variant:"outline",onClick:()=>{U()},disabled:b||g.trim().length===0,children:t("settings.routing.token.save")}),n?s.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{Z()},disabled:b,children:t("settings.routing.token.remove")}):null]})}),p?s.jsx("p",{className:Oi,children:p}):null]})}),s.jsx(ze,{title:t("settings.routing.auto.title"),children:s.jsxs("div",{className:_s,children:[s.jsx("div",{className:fs,children:s.jsx(mt,{settingsItem:"routing.enabled",checked:d.enabled,onChange:K=>M(z=>({...z,enabled:K})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:rn,children:L}),s.jsx(Ft,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(na,{providerId:d.fallback?.model.providerID??"",modelId:d.fallback?.model.modelID??"",onChange:(K,z)=>M(J=>({...J,fallback:{model:{providerID:K,modelID:z},variant:null}})),className:on,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(Ft,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(Vc,{providerID:d.fallback?.model.providerID,modelID:d.fallback?.model.modelID,value:d.fallback?.variant??null,onChange:K=>M(z=>z.fallback?{...z,fallback:{...z.fallback,variant:K}}:z),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(ze,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:_s,children:[s.jsx("p",{className:rn,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:d.categories.map(K=>s.jsx(Xf,{category:K,expanded:N===K.id,onToggle:()=>h(z=>z===K.id?null:K.id),onChange:z=>H(K.id,z),onReset:K.builtin?()=>O(K.id):null,onRemove:()=>_(K.id)},K.id))}),q.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:q.map(K=>s.jsx(G,{size:"sm",variant:"outline",onClick:()=>ae(K.id),children:t("settings.routing.category.restore",{name:K.name})},K.id))}):null,s.jsx(Ft,{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(Be,{value:E,onChange:K=>A(K.target.value),onKeyDown:K=>{K.key==="Enter"&&ee()},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:ee,disabled:E.trim().length===0,children:t("settings.routing.categories.add")})]})})]})}),s.jsx(ze,{title:t("settings.routing.safety.title"),children:s.jsxs("div",{className:_s,children:[s.jsx("p",{className:rn,children:t("settings.routing.safety.description")}),s.jsx("div",{className:fs,children:s.jsx(mt,{settingsItem:"routing.safety-enabled",checked:d.safetyNet.enabled,onChange:K=>M(z=>({...z,safetyNet:{...z.safetyNet,enabled:K}})),label:t("settings.routing.safety.enable"),ariaLabel:t("settings.routing.safety.enable"),info:t("settings.routing.safety.enableInfo")})})]})})]}):s.jsx("p",{className:Oi,children:t("settings.routing.unavailable")})]})};function tx(t){return t.providers}function sx(t){return hc(t.mode)}const nx={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"}},ax=t=>{const e=ct.c(69),{guest:a,busy:n,onApprove:i,onDecline:r,onDismiss:l}=t,{t:m}=et();let c;e[0]!==a?.capabilities.requested?(c=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=c):c=e[1];const x=c;let u;e[2]!==a?.filesystem?(u=a?.filesystem??[],e[2]=a?.filesystem,e[3]=u):u=e[3];const v=u;let d;e[4]!==a?.service?.permissions?.exec?(d=a?.service?.permissions?.exec??[],e[4]=a?.service?.permissions?.exec,e[5]=d):d=e[5];const j=d;let g;e[6]!==a?.service?.permissions?.sockets?(g=a?.service?.permissions?.sockets??[],e[6]=a?.service?.permissions?.sockets,e[7]=g):g=e[7];const w=g,b=a?.integration?.apiOrigin??null,k=a!==null;let p;e[8]!==n||e[9]!==l?(p=ae=>{!ae&&!n&&l()},e[8]=n,e[9]=l,e[10]=p):p=e[10];const C=a?.name??"";let E;e[11]!==m||e[12]!==C?(E=m("settings.extensions.dialog.approveTitle",{name:C}),e[11]=m,e[12]=C,e[13]=E):E=e[13];let A;e[14]!==E?(A=s.jsx(Ht,{children:E}),e[14]=E,e[15]=A):A=e[15];const N=a?.name??"",h=a?.version?`v${a.version}`:"";let y;e[16]!==m||e[17]!==N||e[18]!==h?(y=m("settings.extensions.dialog.approveDescription",{name:N,version:h}),e[16]=m,e[17]=N,e[18]=h,e[19]=y):y=e[19];let R;e[20]!==y?(R=s.jsx(qt,{children:y}),e[20]=y,e[21]=R):R=e[21];let T;e[22]!==R||e[23]!==A?(T=s.jsxs(Vt,{children:[A,R]}),e[22]=R,e[23]=A,e[24]=T):T=e[24];let P;if(e[25]!==b||e[26]!==v||e[27]!==x||e[28]!==j||e[29]!==w||e[30]!==m){let ae;e[32]!==b||e[33]!==v||e[34]!==j||e[35]!==w||e[36]!==m?(ae=_=>{const W=nx[_];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:W.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:m(W.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:m(W.detailKey)}),_==="filesystem"&&v.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:v.map(ix)}):null,_==="network"&&b?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[m("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:b})]}):null,_==="service"&&j.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[m("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:j.join(", ")})]}):null,_==="service"&&w.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[m("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:w.join(", ")})]}):null]})]},_)},e[32]=b,e[33]=v,e[34]=j,e[35]=w,e[36]=m,e[37]=ae):ae=e[37],P=x.map(ae),e[25]=b,e[26]=v,e[27]=x,e[28]=j,e[29]=w,e[30]=m,e[31]=P}else P=e[31];let D;e[38]!==P?(D=s.jsx("ul",{className:"space-y-3",children:P}),e[38]=P,e[39]=D):D=e[39];let V;e[40]!==a||e[41]!==r?(V=()=>a&&r(a),e[40]=a,e[41]=r,e[42]=V):V=e[42];let $;e[43]!==m?($=m("settings.extensions.dialog.decline"),e[43]=m,e[44]=$):$=e[44];let I;e[45]!==n||e[46]!==V||e[47]!==$?(I=s.jsx(G,{size:"sm",variant:"ghost",disabled:n,onClick:V,children:$}),e[45]=n,e[46]=V,e[47]=$,e[48]=I):I=e[48];let M;e[49]!==a||e[50]!==i?(M=()=>a&&i(a),e[49]=a,e[50]=i,e[51]=M):M=e[51];let H;e[52]!==m?(H=m("settings.extensions.dialog.approve"),e[52]=m,e[53]=H):H=e[53];let U;e[54]!==n||e[55]!==M||e[56]!==H?(U=s.jsx(G,{size:"sm",disabled:n,onClick:M,children:H}),e[54]=n,e[55]=M,e[56]=H,e[57]=U):U=e[57];let Z;e[58]!==I||e[59]!==U?(Z=s.jsxs(rs,{children:[I,U]}),e[58]=I,e[59]=U,e[60]=Z):Z=e[60];let ee;e[61]!==T||e[62]!==D||e[63]!==Z?(ee=s.jsxs($t,{className:"max-w-md",children:[T,D,Z]}),e[61]=T,e[62]=D,e[63]=Z,e[64]=ee):ee=e[64];let O;return e[65]!==ee||e[66]!==k||e[67]!==p?(O=s.jsx(_t,{open:k,onOpenChange:p,children:ee}),e[65]=ee,e[66]=k,e[67]=p,e[68]=O):O=e[68],O};function ix(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const rx=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 i=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return i.username="",i.password="",i.search="",i.hash="",i.pathname=i.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),i.pathname==="/"?null:i.href}catch{return null}},ox=un({error:io(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","extract-failed","too-large"]),required:as().trim().min(1).max(64).optional(),id:as().trim().min(1).max(128).optional()}),lx=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"}},Hc=async t=>{try{const e=ox.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"}}},qc=async(t,e)=>{if(!t.ok)return{ok:!1,...await Hc(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:fc(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}}},cx=async(t,e={})=>{const a=lx(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 i=await xt("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await qc(i,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},dx=async(t,e={})=>{try{const a=await xt("/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 qc(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},ux=async t=>{try{const e=await xt(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await Hc(e)).code}}catch{return{ok:!1,code:"failed"}}},mx=async(t,e)=>{try{return(await xt(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},px=async(t,e)=>{try{return(await xt(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},Cr=(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}`},gx=un({updates:Or(as().min(1),Bd)}),hx=un({error:io(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found"]),required:as().trim().min(1).max(64).optional()}),El=async t=>{try{const e=await xt("/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=gx.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},fx=async t=>{try{const e=hx.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"}}},xx=async t=>{try{const e=await xt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await fx(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=fc(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},bx=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",Dl=t=>t.name.toLowerCase().endsWith(".zip"),vx=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",yx=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",jx=t=>{const e=(t.service?.socketBindings??[]).map(i=>i.resolved?`${i.id}=${i.resolved}`:`${i.id}?`),a=(t.service?.permissions?.sockets??[]).filter(i=>!(t.service?.socketBindings??[]).some(r=>r.id===i));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},wx=t=>{const e=ct.c(27),{guest:a,binding:n,busy:i,onSaved:r}=t,{t:l}=et(),[m,c]=o.useState(n.override??n.resolved??""),[x,u]=o.useState(!1),[v,d]=o.useState(!n.resolved);let j;e[0]!==n.override||e[1]!==n.resolved?(j=()=>{c(n.override??n.resolved??""),n.resolved||d(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=j):j=e[2];let g;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(g=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=g):g=e[6],o.useEffect(j,g);let w;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==r||e[11]!==l?(w=async E=>{u(!0);const A=await fm(a.id,n.id,E);if(u(!1),!A){F.error(l("settings.extensions.toast.socketSaveFailed"));return}F.success(l("settings.extensions.toast.socketSaved",{name:a.name})),d(!1),await r()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=r,e[11]=l,e[12]=w):w=e[12];const b=w;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&d(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const p=k;let C;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==i||e[20]!==p||e[21]!==v||e[22]!==b||e[23]!==x||e[24]!==l||e[25]!==m?(C=s.jsx("div",{className:"space-y-1",children:v?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(Be,{value:m,onChange:E=>c(E.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:i||x,autoFocus:!0}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:i||x,"aria-label":l("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(m.trim()||null)},children:l("settings.extensions.service.socket.save")}),n.override?s.jsx(G,{type:"button",variant:"ghost",size:"xs",disabled:i||x,"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:i||x,"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:ws,disabled:i||x,"aria-label":l("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>d(!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]=i,e[20]=p,e[21]=v,e[22]=b,e[23]=x,e[24]=l,e[25]=m,e[26]=C):C=e[26],C},kx=t=>{const e=ct.c(143),{guest:a,busy:n,onReview:i,onRemove:r,onSetEnabled:l,onUpdate:m}=t,{t:c}=et(),[x,u]=o.useState(!1),v=a.enabled!==!1;let d;e[0]!==a?(d=Fr(a),e[0]=a,e[1]=d):d=e[1];const j=d;let g,w,b,k,p,C,E,A,N,h,y,R,T,P;if(e[2]!==v||e[3]!==a||e[4]!==j||e[5]!==x||e[6]!==c){const W=jx(a);b=!!(a.source&&a.source!=="bundled");const q=a.source==="bundled";let L;e[21]!==a?(L=rx(a),e[21]=a,e[22]=L):L=e[22],k=L,P=a.source==="git"?a.update:void 0;let K;e[23]!==a.icon||e[24]!==a.id?(K=dc(a.id,a.icon,jc().authenticatedAsset),e[23]=a.icon,e[24]=a.id,e[25]=K):K=e[25];const z=K;let J;e[26]!==q||e[27]!==a.source||e[28]!==c?(J=q?null:c(yx(a.source)),e[26]=q,e[27]=a.source,e[28]=c,e[29]=J):J=e[29];const oe=a.version?`v${a.version}`:null;let re;e[30]!==a.entry||e[31]!==c?(re=a.entry?null:c("settings.extensions.source.noPanel"),e[30]=a.entry,e[31]=c,e[32]=re):re=e[32];let pe;e[33]!==J||e[34]!==oe||e[35]!==re?(pe=[J,oe,re].filter(Boolean),e[33]=J,e[34]=oe,e[35]=re,e[36]=pe):pe=e[36];const ve=pe.join(" · "),be=a.path||a.id;let te;e[37]!==v||e[38]!==j||e[39]!==c?(te=c(j?"settings.extensions.status.needsApproval":v?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[37]=v,e[38]=j,e[39]=c,e[40]=te):te=e[40];const he=te,ie=j?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":v?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";w=kn,T=x,p=u,y="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let ue;e[41]!==a.icon?(ue=mc(a.icon),e[41]=a.icon,e[42]=ue):ue=e[42];let de;e[43]!==z||e[44]!==ue?(de=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(uc,{icon:ue,iconSrc:z,className:"size-5 text-foreground"})}),e[43]=z,e[44]=ue,e[45]=de):de=e[45];let Pe;e[46]!==a.name?(Pe=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[46]=a.name,e[47]=Pe):Pe=e[47];let Ae;e[48]!==ve?(Ae=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:ve}),e[48]=ve,e[49]=Ae):Ae=e[49];let we;e[50]!==Pe||e[51]!==Ae?(we=s.jsxs("div",{className:"min-w-0 flex-1",children:[Pe,Ae]}),e[50]=Pe,e[51]=Ae,e[52]=we):we=e[52];let Le;e[53]!==q||e[54]!==c?(Le=q?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]=q,e[54]=c,e[55]=Le):Le=e[55];let _e;e[56]!==c||e[57]!==P?(_e=P?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:P.version})}):null,e[56]=c,e[57]=P,e[58]=_e):_e=e[58];let Ve;e[59]!==ie?(Ve=ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ie),e[59]=ie,e[60]=Ve):Ve=e[60];let je;e[61]!==he||e[62]!==Ve?(je=s.jsx("span",{"aria-live":"polite",className:Ve,children:he}),e[61]=he,e[62]=Ve,e[63]=je):je=e[63];const ke=x&&"rotate-180";let se;e[64]!==ke?(se=ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ke),e[64]=ke,e[65]=se):se=e[65];let le;e[66]!==se?(le=s.jsx(B,{name:"arrow-down-s",className:se}),e[66]=se,e[67]=le):le=e[67],e[68]!==de||e[69]!==we||e[70]!==Le||e[71]!==_e||e[72]!==je||e[73]!==le?(R=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:[de,we,Le,_e,je,le]}),e[68]=de,e[69]=we,e[70]=Le,e[71]=_e,e[72]=je,e[73]=le,e[74]=R):R=e[74],g=Sn,h="border-t border-[var(--interactive-border)] px-4 py-4",C="space-y-3",e[75]!==be?(E=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:be,children:be}),e[75]=be,e[76]=E):E=e[76],e[77]!==q||e[78]!==c?(A=q?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[77]=q,e[78]=c,e[79]=A):A=e[79],N=W?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:c("settings.extensions.service.permissions",{list:W})}):null,e[2]=v,e[3]=a,e[4]=j,e[5]=x,e[6]=c,e[7]=g,e[8]=w,e[9]=b,e[10]=k,e[11]=p,e[12]=C,e[13]=E,e[14]=A,e[15]=N,e[16]=h,e[17]=y,e[18]=R,e[19]=T,e[20]=P}else g=e[7],w=e[8],b=e[9],k=e[10],p=e[11],C=e[12],E=e[13],A=e[14],N=e[15],h=e[16],y=e[17],R=e[18],T=e[19],P=e[20];let D;e[80]!==a.service||e[81]!==c?(D=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.service.warning")}):null,e[80]=a.service,e[81]=c,e[82]=D):D=e[82];let V;e[83]!==n||e[84]!==v||e[85]!==a?(V=v?(a.service?.socketBindings??[]).map(W=>s.jsx(wx,{guest:a,binding:W,busy:n,onSaved:Bn},W.id)):null,e[83]=n,e[84]=v,e[85]=a,e[86]=V):V=e[86];let $;e[87]!==n||e[88]!==a||e[89]!==m||e[90]!==c||e[91]!==P?($=P?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:P.version}),onClick:()=>{m(a)},children:c("settings.extensions.update.action")}):null,e[87]=n,e[88]=a,e[89]=m,e[90]=c,e[91]=P,e[92]=$):$=e[92];let I;e[93]!==n||e[94]!==a||e[95]!==j||e[96]!==i||e[97]!==c?(I=j?s.jsx(G,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.review.aria",{name:a.name}),onClick:()=>i(a),children:c("settings.extensions.review")}):null,e[93]=n,e[94]=a,e[95]=j,e[96]=i,e[97]=c,e[98]=I):I=e[98];let M;e[99]!==n||e[100]!==v||e[101]!==a.id||e[102]!==a.name||e[103]!==l||e[104]!==c?(M=v?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]=v,e[101]=a.id,e[102]=a.name,e[103]=l,e[104]=c,e[105]=M):M=e[105];let H;e[106]!==n||e[107]!==b||e[108]!==a.id||e[109]!==a.name||e[110]!==r||e[111]!==c?(H=b?s.jsx(G,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":c("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{r(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]=r,e[111]=c,e[112]=H):H=e[112];let U;e[113]!==k||e[114]!==c?(U=k?s.jsxs(G,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{bn(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]=U):U=e[115];let Z;e[116]!==$||e[117]!==I||e[118]!==M||e[119]!==H||e[120]!==U?(Z=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[$,I,M,H,U]}),e[116]=$,e[117]=I,e[118]=M,e[119]=H,e[120]=U,e[121]=Z):Z=e[121];let ee;e[122]!==D||e[123]!==V||e[124]!==Z||e[125]!==C||e[126]!==E||e[127]!==A||e[128]!==N?(ee=s.jsxs("div",{className:C,children:[E,A,N,D,V,Z]}),e[122]=D,e[123]=V,e[124]=Z,e[125]=C,e[126]=E,e[127]=A,e[128]=N,e[129]=ee):ee=e[129];let O;e[130]!==g||e[131]!==ee||e[132]!==h?(O=s.jsx(g,{className:h,children:ee}),e[130]=g,e[131]=ee,e[132]=h,e[133]=O):O=e[133];let ae;e[134]!==O||e[135]!==y||e[136]!==R?(ae=s.jsxs("div",{className:y,children:[R,O]}),e[134]=O,e[135]=y,e[136]=R,e[137]=ae):ae=e[137];let _;return e[138]!==w||e[139]!==p||e[140]!==ae||e[141]!==T?(_=s.jsx(w,{open:T,onOpenChange:p,children:ae}),e[138]=w,e[139]=p,e[140]=ae,e[141]=T,e[142]=_):_=e[142],_},Nx=()=>{const t=ct.c(174),{t:e}=et(),a=Zs(Sx),n=Zs(Cx),i=Zs(Ix),r=Zs(Px),[l,m]=o.useState(null),[c,x]=o.useState(!1),[u,v]=o.useState("global"),d=n==="unsupported",[j,g]=o.useState(""),[w,b]=o.useState(!1),[k,p]=o.useState(!1),C=o.useRef(!1),[E,A]=o.useState(null),[N,h]=o.useState(null),[y,R]=o.useState(!1),T=o.useRef(0),P=o.useRef(null);let D;t[0]===Symbol.for("react.memo_cache_sentinel")?(D=Tu(),t[0]=D):D=t[0];const V=D;let $;t[1]===Symbol.for("react.memo_cache_sentinel")?($=[],t[1]=$):$=t[1],o.useEffect(Ax,$);let I,M;t[2]!==r||t[3]!==d?(I=()=>{let Qe=!1;if(m(null),x(!1),v("global"),A(null),h(null),C.current=!1,!d)return Promise.all([Vd(),Hd()]).then(He=>{const[Ct,Pt]=He;Qe||m({runtimeKey:r,profiles:Ct,global:Pt})}).catch(()=>{Qe||x(!0)}),()=>{Qe=!0}},M=[r,d],t[2]=r,t[3]=d,t[4]=I,t[5]=M):(I=t[4],M=t[5]),o.useEffect(I,M);const H=l?.runtimeKey===r?l:null;let U;t[6]!==e?(U=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=U):U=t[7];const Z=H?.global?.userName??"",ee=H?.global?.userEmail??"";let O;t[8]!==U||t[9]!==Z||t[10]!==ee?(O={id:"global",name:U,userName:Z,userEmail:ee,icon:"fingerprint",color:"info"},t[8]=U,t[9]=Z,t[10]=ee,t[11]=O):O=t[11];let ae;t[12]!==H?.profiles||t[13]!==O?(ae=[O,...H?.profiles.filter(Tx)??[]],t[12]=H?.profiles,t[13]=O,t[14]=ae):ae=t[14];const _=ae;let W;t[15]!==_||t[16]!==u?(W=_.find(Qe=>Qe.id===u)??_[0],t[15]=_,t[16]=u,t[17]=W):W=t[17];const q=W;let L,K;t[18]!==n?(L=()=>{if(n!=="ready"||C.current)return;C.current=!0;const Qe=Zs.getState().runtimeKey;El(!1).then(He=>{He.ok&&Zs.getState().applyUpdates(He.updates,Qe)})},K=[n],t[18]=n,t[19]=L,t[20]=K):(L=t[19],K=t[20]),o.useEffect(L,K);let z;t[21]!==e?(z=async()=>{p(!0);const Qe=Zs.getState().runtimeKey,He=await El(!0);if(p(!1),!He.ok){F.error(e("settings.extensions.toast.checkFailed"));return}Zs.getState().applyUpdates(He.updates,Qe),Object.keys(He.updates).length===0&&F.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=z):z=t[22];const J=z;let oe;t[23]!==e?(oe=async Qe=>{b(!0);const He=await xx(Qe.id);if(b(!1),!He.ok){F.error(He.code==="host-too-old"&&He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e(vx(He.code)));return}xr(Qe.id),F.success(e("settings.extensions.toast.updated",{name:He.guest.name,version:He.guest.version??""})),await Bn(),Fr(He.guest)&&h(He.guest)},t[23]=e,t[24]=oe):oe=t[24];const re=oe;let pe;if(t[25]!==a||t[26]!==e){const Qe=async(He,Ct,Pt)=>{const es=Pt===void 0?{}:Pt;if(!He.ok){if(es.allowConflictDialog!==!1&&(He.code==="id-taken"||He.code==="already-installed")){const ts=He.id?a.find(os=>os.id===He.id):void 0;return A({source:Ct,name:ts?.name??He.id??(Ct.kind==="file"?Ct.file.name:Ct.input)}),!1}return He.code==="host-too-old"?F.error(He.required?e("settings.extensions.toast.hostTooOld",{version:He.required}):e("settings.extensions.toast.failed"),{description:He.diagnostic?Cr(He.diagnostic,e):void 0}):F.error(e(bx(He.code)),{description:He.diagnostic?Cr(He.diagnostic,e):void 0}),!1}return g(""),A(null),F.success(He.replaced?e("settings.extensions.toast.reinstalled",{name:He.guest.name}):e("settings.extensions.toast.added",{name:He.guest.name})),await Bn(),Fr(He.guest)&&h(He.guest),!0};pe=async(He,Ct)=>{const Pt=Ct===void 0?{}:Ct,es=Rn();He.kind==="input"&&g(He.input),b(!0);const ts=He.kind==="file"?await dx(He.file,Pt):await cx(He.input,{...Pt,gitIdentityId:He.gitIdentityId});b(!1),Rn()===es&&await Qe(ts,He,{allowConflictDialog:!Pt.replace})},t[25]=a,t[26]=e,t[27]=pe}else pe=t[27];const ve=pe;let be;t[28]!==j||t[29]!==ve||t[30]!==q||t[31]!==e?(be=async()=>{const Qe=j.trim();if(!Qe){F.error(e("settings.extensions.toast.invalidPath"));return}await ve({kind:"input",input:Qe,gitIdentityId:q.id})},t[28]=j,t[29]=ve,t[30]=q,t[31]=e,t[32]=be):be=t[32];const te=be;let he;t[33]!==ve?(he=async()=>{if(!V)return;const Qe=await Eu("");Qe.success&&Qe.path&&await ve({kind:"input",input:Qe.path})},t[33]=ve,t[34]=he):he=t[34];const ie=he;let ue;t[35]!==ve?(ue=async()=>{if(!V){P.current?.click();return}const Qe=await so({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Qe.success&&Qe.path&&await ve({kind:"input",input:Qe.path})},t[35]=ve,t[36]=ue):ue=t[36];const de=ue;let Pe;t[37]!==ve||t[38]!==e?(Pe=async Qe=>{const He=Qe.target.files?.[0]??null;if(Qe.target.value="",!!He){if(!Dl(He)){F.error(e("settings.extensions.toast.invalidPath"));return}await ve({kind:"file",file:He})}},t[37]=ve,t[38]=e,t[39]=Pe):Pe=t[39];const Ae=Pe;let we;t[40]!==w?(we=Qe=>{w||(Qe.preventDefault(),T.current=T.current+1,R(!0))},t[40]=w,t[41]=we):we=t[41];const Le=we;let _e;t[42]!==w?(_e=Qe=>{w||(Qe.preventDefault(),Qe.dataTransfer.dropEffect="copy")},t[42]=w,t[43]=_e):_e=t[43];const Ve=_e;let je;t[44]===Symbol.for("react.memo_cache_sentinel")?(je=()=>{T.current=Math.max(0,T.current-1),T.current===0&&R(!1)},t[44]=je):je=t[44];const ke=je;let se;t[45]!==w||t[46]!==ve||t[47]!==e?(se=async Qe=>{if(Qe.preventDefault(),T.current=0,R(!1),w)return;const He=Qe.dataTransfer.items[0],Ct=He?.getAsFile()??null,es=(He?.webkitGetAsEntry()??null)?.isDirectory===!0,ts=Ct!==null&&!es&&Dl(Ct),os=Ct&&V?Du(Ct):null;if(os&&(es||ts)){await ve({kind:"input",input:os});return}if(es){F.error(e(V?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!Ct||!ts){F.error(e("settings.extensions.toast.invalidPath"));return}await ve({kind:"file",file:Ct})},t[45]=w,t[46]=ve,t[47]=e,t[48]=se):se=t[48];const le=se;let Ie;t[49]!==E||t[50]!==ve?(Ie=async()=>{E&&await ve(E.source,{replace:!0})},t[49]=E,t[50]=ve,t[51]=Ie):Ie=t[51];const Ne=Ie;let Re;t[52]!==e?(Re=async(Qe,He)=>{b(!0);const Ct=await ux(Qe);if(b(!1),!Ct.ok){F.error(e("settings.extensions.toast.removeFailed"));return}xr(Qe),F.success(e("settings.extensions.toast.removed",{name:He})),await Bn()},t[52]=e,t[53]=Re):Re=t[53];const $e=Re;let De;t[54]!==e?(De=async Qe=>{b(!0);const He=await px(Qe.id,Qe.capabilities.requested);if(b(!1),!He){F.error(e("settings.extensions.toast.approveFailed"));return}h(null),F.success(e("settings.extensions.toast.approved",{name:Qe.name})),await Bn()},t[54]=e,t[55]=De):De=t[55];const Ce=De;let Ye;t[56]!==$e?(Ye=async Qe=>{h(null),await $e(Qe.id,Qe.name)},t[56]=$e,t[57]=Ye):Ye=t[57];const xe=Ye;let Te;t[58]!==e?(Te=async(Qe,He,Ct)=>{b(!0);const Pt=await mx(Qe,Ct);if(b(!1),!Pt){F.error(e("settings.extensions.toast.enabledFailed"));return}Ct||xr(Qe),F.success(Ct?e("settings.extensions.toast.enabled",{name:He}):e("settings.extensions.toast.disabled",{name:He})),await Bn()},t[58]=e,t[59]=Te):Te=t[59];const Ke=Te;let tt;t[60]!==e?(tt=e("settings.page.extensions.title"),t[60]=e,t[61]=tt):tt=t[61];let Y;t[62]!==e?(Y=e("settings.page.extensions.description"),t[62]=e,t[63]=Y):Y=t[63];let Se;t[64]!==te||t[65]!==ie||t[66]!==de||t[67]!==w||t[68]!==y||t[69]!==_||t[70]!==l||t[71]!==c||t[72]!==j||t[73]!==Le||t[74]!==Ve||t[75]!==le||t[76]!==Ae||t[77]!==q||t[78]!==e||t[79]!==d?(Se=d?null:s.jsxs(ze,{title:e("settings.extensions.add.action"),info:e("settings.extensions.add.info"),children:[s.jsx(At,{label:e("settings.extensions.add.label"),info:e(V?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:ye("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",y&&"border-primary bg-primary/5"),onDragEnter:Le,onDragOver:Ve,onDragLeave:ke,onDrop:Qe=>{le(Qe)},children:[y?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(Be,{value:j,onChange:Qe=>g(Qe.target.value),onKeyDown:Qe=>{Qe.key==="Enter"&&(Qe.preventDefault(),te())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:ye("h-8 min-w-0 flex-1 rounded-md pl-3",V?"pr-14":"pr-8"),disabled:w}),s.jsx("input",{ref:P,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Qe=>{Ae(Qe)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[V?s.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:w,onClick:()=>{ie()},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:w,onClick:()=>{de()},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(Yu,{activeProfile:q,identities:_,onSelect:Qe=>v(Qe.id),isApplying:w||!l&&!c,iconOnly:!0})}),s.jsxs(G,{type:"button",size:"sm",disabled:w,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{te()},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]=te,t[65]=ie,t[66]=de,t[67]=w,t[68]=y,t[69]=_,t[70]=l,t[71]=c,t[72]=j,t[73]=Le,t[74]=Ve,t[75]=le,t[76]=Ae,t[77]=q,t[78]=e,t[79]=d,t[80]=Se):Se=t[80];let Ee;t[81]!==e?(Ee=e("settings.extensions.section.installed"),t[81]=e,t[82]=Ee):Ee=t[82];let We;t[83]!==w||t[84]!==J||t[85]!==k||t[86]!==n||t[87]!==e||t[88]!==d?(We=d?null:s.jsxs(G,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:w||k||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{J()},children:[s.jsx(B,{name:"refresh",className:ye("h-4 w-4",k&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[83]=w,t[84]=J,t[85]=k,t[86]=n,t[87]=e,t[88]=d,t[89]=We):We=t[89];let lt;t[90]!==i||t[91]!==n||t[92]!==e?(lt=n==="error"||i?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),i?`
29
- ${Cr(i,e)}`:""]}):null,t[90]=i,t[91]=n,t[92]=e,t[93]=lt):lt=t[93];let at;t[94]!==e||t[95]!==d?(at=d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[94]=e,t[95]=d,t[96]=at):at=t[96];let pt;t[97]!==a.length||t[98]!==n||t[99]!==e?(pt=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]=pt):pt=t[100];let bt;if(t[101]!==w||t[102]!==a||t[103]!==$e||t[104]!==Ke||t[105]!==re){let Qe;t[107]!==w||t[108]!==$e||t[109]!==Ke||t[110]!==re?(Qe=He=>s.jsx(kx,{guest:He,busy:w,onReview:h,onRemove:$e,onSetEnabled:Ke,onUpdate:re},He.id),t[107]=w,t[108]=$e,t[109]=Ke,t[110]=re,t[111]=Qe):Qe=t[111],bt=a.map(Qe),t[101]=w,t[102]=a,t[103]=$e,t[104]=Ke,t[105]=re,t[106]=bt}else bt=t[106];let Q;t[112]!==Ee||t[113]!==We||t[114]!==lt||t[115]!==at||t[116]!==pt||t[117]!==bt?(Q=s.jsxs(ze,{title:Ee,contentClassName:"space-y-3",headerAction:We,children:[lt,at,pt,bt]}),t[112]=Ee,t[113]=We,t[114]=lt,t[115]=at,t[116]=pt,t[117]=bt,t[118]=Q):Q=t[118];let qe;t[119]!==Ce?(qe=Qe=>{Ce(Qe)},t[119]=Ce,t[120]=qe):qe=t[120];let it;t[121]!==xe?(it=Qe=>{xe(Qe)},t[121]=xe,t[122]=it):it=t[122];let ut;t[123]===Symbol.for("react.memo_cache_sentinel")?(ut=()=>h(null),t[123]=ut):ut=t[123];let gt;t[124]!==N||t[125]!==w||t[126]!==qe||t[127]!==it?(gt=s.jsx(ax,{guest:N,busy:w,onApprove:qe,onDecline:it,onDismiss:ut}),t[124]=N,t[125]=w,t[126]=qe,t[127]=it,t[128]=gt):gt=t[128];const Ot=E!==null;let st;t[129]!==w?(st=Qe=>{!Qe&&!w&&A(null)},t[129]=w,t[130]=st):st=t[130];let ft;t[131]!==e?(ft=e("settings.extensions.dialog.reinstallTitle"),t[131]=e,t[132]=ft):ft=t[132];let jt;t[133]!==ft?(jt=s.jsx(Ht,{children:ft}),t[133]=ft,t[134]=jt):jt=t[134];const Je=E?.name??"";let St;t[135]!==e||t[136]!==Je?(St=e("settings.extensions.dialog.reinstallDescription",{name:Je}),t[135]=e,t[136]=Je,t[137]=St):St=t[137];let Oe;t[138]!==St?(Oe=s.jsx(qt,{children:St}),t[138]=St,t[139]=Oe):Oe=t[139];let wt;t[140]!==jt||t[141]!==Oe?(wt=s.jsxs(Vt,{children:[jt,Oe]}),t[140]=jt,t[141]=Oe,t[142]=wt):wt=t[142];let X;t[143]===Symbol.for("react.memo_cache_sentinel")?(X=()=>A(null),t[143]=X):X=t[143];let fe;t[144]!==e?(fe=e("settings.common.actions.cancel"),t[144]=e,t[145]=fe):fe=t[145];let Fe;t[146]!==w||t[147]!==fe?(Fe=s.jsx(G,{size:"sm",variant:"ghost",disabled:w,onClick:X,children:fe}),t[146]=w,t[147]=fe,t[148]=Fe):Fe=t[148];let Me;t[149]!==Ne?(Me=()=>{Ne()},t[149]=Ne,t[150]=Me):Me=t[150];let rt;t[151]!==e?(rt=e("settings.extensions.dialog.reinstall"),t[151]=e,t[152]=rt):rt=t[152];let ot;t[153]!==w||t[154]!==Me||t[155]!==rt?(ot=s.jsx(G,{size:"sm",disabled:w,onClick:Me,children:rt}),t[153]=w,t[154]=Me,t[155]=rt,t[156]=ot):ot=t[156];let Ge;t[157]!==Fe||t[158]!==ot?(Ge=s.jsxs(rs,{children:[Fe,ot]}),t[157]=Fe,t[158]=ot,t[159]=Ge):Ge=t[159];let Nt;t[160]!==wt||t[161]!==Ge?(Nt=s.jsxs($t,{className:"max-w-md",children:[wt,Ge]}),t[160]=wt,t[161]=Ge,t[162]=Nt):Nt=t[162];let ns;t[163]!==Ot||t[164]!==st||t[165]!==Nt?(ns=s.jsx(_t,{open:Ot,onOpenChange:st,children:Nt}),t[163]=Ot,t[164]=st,t[165]=Nt,t[166]=ns):ns=t[166];let Zt;return t[167]!==tt||t[168]!==Y||t[169]!==Se||t[170]!==Q||t[171]!==gt||t[172]!==ns?(Zt=s.jsxs(is,{title:tt,description:Y,outerClassName:"extensions-settings-page",children:[Se,Q,gt,ns]}),t[167]=tt,t[168]=Y,t[169]=Se,t[170]=Q,t[171]=gt,t[172]=ns,t[173]=Zt):Zt=t[173],Zt};function Sx(t){return t.guests}function Cx(t){return t.status}function Ix(t){return t.failure}function Px(t){return t.runtimeKey}function Ax(){Bn()}function Tx(t){return t.id!=="global"}const Bs=ea,Ex=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=qd(e),n=(de,Pe)=>t.colors[de]??Pe,i=de=>de!=="transparent"&&(Gs(de,"#000000")!==1||Gs(de,"#ffffff")!==1),r=(de,Pe)=>{const Ae=n(de,Pe);return i(Ae)?Ae:Pe},l=n("chat.list.background",n("editor.background",a.colors.surface.background)),m=n("interactive-session.foreground",n("foreground",n("editor.foreground",a.colors.surface.foreground))),x=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([de])=>t.colors[de]),u=x?n(x[0],a.colors.surface.elevated):a.colors.surface.elevated,v=Xn(m,u,l),d=x?n(x[1],v):v,j=n("sideBar.background",n("panel.background",a.colors.surface.muted)),g=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),w=n("textBlockQuote.background",j),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),p=n("button.hoverBackground",k),C=t.colors["button.background"]?n("button.foreground",Us(k,l)):Us(k,l),E=Bs(k,.5),N=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(de=>de&&i(de))||Bs(m,e?.25:.2),h=n("toolbar.hoverBackground",n("list.hoverBackground",a.colors.interactive.hover)),y=n("toolbar.activeBackground",h),T=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([de])=>t.colors[de]),P=T.find(([de])=>[l,j,u].every(Pe=>{const Ae=Gs(n(de,""),Pe,l);return Ae===null||Ae>1.01}))??T[0],D=P?n(P[0],a.colors.interactive.selection):a.colors.interactive.selection,V=P?n(P[1],m):m,$=n("focusBorder",n("inputOption.activeBorder",k)),I=$,M=n("editorCursor.foreground",a.colors.interactive.cursor),H=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),U=r("editorError.background",Bs(H,e?.16:.12)),Z=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),ee=r("editorWarning.background",Bs(Z,e?.16:.12)),O=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),ae=Bs(O,e?.16:.12),_=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),W=r("editorInfo.background",Bs(_,e?.16:.12)),q=n("editorLineNumber.foreground",g),L=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),K=n("terminal.ansiBlue",k),z=n("terminal.ansiYellow",a.colors.syntax.base.number),J=n("terminal.ansiCyan",a.colors.syntax.base.function),oe=n("terminal.ansiMagenta",m),re=n("terminal.ansiYellow",a.colors.syntax.base.type),pe=n("chat.requestBorder",N),ve=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",ae)),be=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",U)),te=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",O)),he=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",H)),ie=n("gitDecoration.modifiedResourceForeground",_),ue=n("chat.requestBubbleBackground",n("chat.requestBackground",u));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:C,muted:E},surface:{background:l,foreground:m,muted:j,mutedForeground:g,elevated:u,elevatedForeground:d,overlay:b,subtle:w},interactive:{border:N,borderHover:n("toolbar.hoverOutline",N),borderFocus:$,selection:D,selectionForeground:V,focus:$,focusRing:I,cursor:M,hover:h,active:y},status:{error:H,errorForeground:Us(H,l),errorBackground:U,errorBorder:Bs(H,e?.45:.35),warning:Z,warningForeground:Us(Z,l),warningBackground:ee,warningBorder:Bs(Z,e?.45:.35),success:O,successForeground:Us(O,l),successBackground:ae,successBorder:Bs(O,e?.45:.35),info:_,infoForeground:Us(_,l),infoBackground:W,infoBorder:Bs(_,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:te,diffAddedBackground:ve,diffRemoved:he,diffRemovedBackground:be,diffModified:ie,diffModifiedBackground:Bs(ie,e?.16:.12),lineNumber:n("editorLineNumber.foreground",g),lineNumberActive:n("editorLineNumber.activeForeground",m)},base:{background:n("editor.background",l),foreground:n("editor.foreground",m),comment:q,keyword:K,string:L,number:z,function:J,variable:oe,type:re,operator:k}},tools:{border:pe,icon:n("icon.foreground",g),title:m,description:Bs(g,.8),edit:{added:te,addedBackground:ve,removed:he,removedBackground:be,modified:ie,modifiedBackground:Bs(ie,e?.16:.12),lineNumber:q}},chat:{background:l,userMessage:m,userMessageBackground:ue,assistantMessage:m,assistantMessageBackground:l,timestamp:g,divider:N,typing:n("chat.thinkingShimmer",g),avatarBackground:n("chat.avatarBackground",l),avatarForeground:n("chat.avatarForeground",m),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",C),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",p),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",E)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",p),inlineCode:n("textPreformat.foreground",L),inlineCodeBackground:n("textPreformat.background",n("editor.background",l)),blockquote:m,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",N),listMarker:Bs(k,.6)}}}},Ir=.075;function Dx(t,e,a){const{surface:n,primary:i,status:r,interactive:l}=t.colors,m=n.background,c=t.metadata.variant==="dark",x=Us(n.muted,m),u=[m,n.muted,n.elevated,Ts(l.selection,n.muted,1,m)].filter(k=>Us(k,m)===x),v=k=>u.reduce((p,C)=>Xn(p,C,m),k),d=k=>[m,n.muted].every(p=>(Gs(k,p,m)??0)>=3),j=[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),g=v(j.find(d)??i.base);g!==i.base&&(i.base=g,i.foreground=Us(g,m),i.hover=Ts(n.foreground,g,.08,m),i.active=Ts(n.foreground,g,.16,m),i.muted=ea(g,.5),!e.focusBorder&&!e["inputOption.activeBorder"]&&(l.focus=g,l.focusRing=g,l.borderFocus=g),t.colors.markdown&&(e["textLink.foreground"]||(t.colors.markdown.link=g),e["textLink.activeForeground"]||(t.colors.markdown.linkHover=i.hover),t.colors.markdown.listMarker=ea(g,.6))),u.some(k=>(Gs(l.focusRing,k,m)??0)<1.1)&&(l.focus=i.base,l.focusRing=i.base,l.borderFocus=i.base);const w=(k,p,C)=>u.every(E=>(wo(k,p,E,m)??0)>=C);let b=v(r.info);if(!w(b,i.base,Ir)){const k=E=>w(E,i.base,Ir)&&[r.error,r.warning,r.success].every(A=>w(E,A,.1));let C=[e["notificationsInfoIcon.foreground"],e["editorInfo.foreground"],e["terminal.ansiCyan"],e["terminal.ansiBlue"],e["terminal.ansiMagenta"],e["textLink.foreground"],a.function,a.type].filter(E=>E!==void 0).map(v).find(k);if(!C){const E=Ts(b,m,1,m),N=[E,v(Ts(E,m,.5,m))].flatMap(h=>[.12,.18].flatMap(y=>[0,60,-60,90,-90,120,-120,180].map(R=>v(Gd(h,R,y)))));if(C=N.find(k),!C){const h=y=>Math.min(...[r.error,r.warning,r.success].map(R=>wo(y,R,n.muted,m)??0));C=N.filter(y=>w(y,i.base,Ir)).sort((y,R)=>h(R)-h(y))[0]}}C&&(b=C)}if(b!==r.info&&(r.info=b,r.infoForeground=Us(b,m),r.infoBackground=ea(b,c?.16:.12),r.infoBorder=ea(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((Gs(k,m,m)??1)<1.1){const p=Ts(k,m,1,m);let E=(Gs(p,"#000000")??1)<(Gs(m,"#000000")??1)?"#000000":"#ffffff",A=p;((Gs(E,m,m)??1)<1.1||(Gs(p,m,m)??1)<1.01)&&(A=m,E=n.foreground);let N=0,h=1;for(let R=0;R<16;R++){const T=(N+h)/2,P=Ts(E,A,T,m);(Gs(P,m,m)??1)>=1.1?h=T:N=T}const y=Ts(E,A,h,m);(Gs(n.foreground,y,m)??0)>=4.5&&(t.colors.chat.userMessageBackground=y)}}}const qi=as().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),po=un({foreground:qi.optional()}),Gc=un({scope:Lr([as(),li(as())]).optional(),settings:po}),Mx=un({name:as().trim().min(1).max(160).optional(),author:as().max(160).optional(),description:as().max(1024).optional(),type:io(["light","dark","hc","hc-black","hc-light"]).optional(),include:as().optional(),colors:Or(as(),qi.nullable()).default({}),tokenColors:Lr([li(Gc),as()]).optional(),semanticHighlighting:ao().optional(),semanticTokenColors:Or(as(),Lr([qi,po])).optional()});function Rx(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(i=>({scope:i.trim(),color:e.settings.foreground}))))}function Fx(t,e){for(const a of e){let n,i=-1;for(const r of t)!r.color||!r.scope||(a===r.scope||a.startsWith(`${r.scope}.`))&&r.scope.length>=i&&(n=r.color,i=r.scope.length);if(n)return n}}function Ox(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const i=qi.safeParse(n);if(i.success)return i.data;const r=po.safeParse(n);if(r.success&&r.data.foreground)return r.data.foreground}}function Lx(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function Kx(t,e,a,n){const i=Us(a,a);if(e.some(c=>Us(c,a)!==i))return t;let r=t;for(const c of e)r=Xn(r,c,a);let l=0,m=1;for(let c=0;c<16;c++){const x=(l+m)/2,u=ea(r,x);e.every(v=>(Gs(u,v,a)??0)>=n)?m=x:l=x}return ea(r,m)}function Wc(t,e){if(new TextEncoder().encode(t).byteLength>xc)throw new ta("size");let a;try{a=Mx.parse(JSON.parse(xm(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ta("invalid")}const n=li(Gc).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ta("include");const i={};for(const[R,T]of Object.entries(a.colors))T!==null&&(i[R]=T);const r={...i},l=i["editor.background"];if(!l)throw new ta("background");const m=a.type?["dark","hc","hc-black"].includes(a.type):Us(l,"#ffffff")==="#ffffff",c=m?"dark":"light",x=Ts(l,m?"#000000":"#ffffff",1),u=Rx(n.data),v=n.data.filter(R=>!R.scope&&R.settings.foreground).at(-1)?.settings.foreground,d=i["editor.foreground"]??v??i.foreground??Us(x,x),j=i["chat.list.background"]??x,g=i["interactive-session.foreground"]??i.foreground??d;i["editor.background"]=x,i["editor.foreground"]=d,i.foreground??=g,i["sideBar.background"]??=i["panel.background"]??Ts(g,j,.03,j),!i["editorWidget.background"]&&!i["dropdown.background"]&&!i["input.background"]&&(i["editorWidget.background"]=Ts(g,j,.04,j),i["editorWidget.foreground"]=Xn(g,i["editorWidget.background"],j)),i.descriptionForeground??=Xn(Ts(g,j,.6,j),j),i["widget.border"]??=i["input.border"]??i["panel.border"]??Ts(g,j,.15,j),i["toolbar.hoverBackground"]??=i["list.hoverBackground"]??Ts(g,j,.08,j),i["toolbar.activeBackground"]??=Ts(g,j,.12,j),!i["list.activeSelectionBackground"]&&!i["editor.selectionBackground"]&&(i["list.activeSelectionBackground"]=Ts(g,j,.16,j),i["list.activeSelectionForeground"]=Xn(g,i["list.activeSelectionBackground"],j)),i["button.background"]||(i["button.background"]=i["textLink.foreground"]??i.focusBorder??g,i["button.foreground"]=Us(i["button.background"],j)),i.focusBorder??=i["button.background"],i["editorCursor.foreground"]??=d;const w=a.type?.startsWith("hc")??!1;w&&i.contrastBorder&&(i["widget.border"]=i.contrastBorder);const k=Ex({kind:m&&w?"high-contrast":c,colors:i});if(w)k.colors.interactive.focusRing=i.focusBorder;else{const{surface:R,interactive:T}=k.colors,P=Kx(T.border,[R.background,R.muted,R.elevated],R.background,m?1.15:1.2);T.border=P,i["toolbar.hoverOutline"]||(T.borderHover=P),k.colors.tools&&!i["chat.requestBorder"]&&(k.colors.tools.border=P),k.colors.chat&&(k.colors.chat.divider=P),k.colors.markdown&&!i["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=P)}const p=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},C=(R,T,P)=>Ox(p,R)??Fx(u,T)??P,E={background:x,foreground:d,comment:C(["comment"],["comment","comment.line","comment.block"],Xn(Ts(d,x,.6,x),x)),keyword:C(["keyword"],["keyword","storage","keyword.control","storage.type"],d),string:C(["string"],["string","string.quoted","string.template"],d),number:C(["number"],["constant.numeric"],d),function:C(["function"],["entity.name.function","support.function"],d),variable:C(["variable"],["variable.other.readwrite","variable"],d),type:C(["type"],["entity.name.type","support.type","support.class"],d),operator:C(["operator"],["keyword.operator"],d)},A=C(["class"],["entity.name.type.class","entity.name.class"],E.type),N=C(["property"],["variable.other.property","support.type.property-name"],E.variable),h={base:E,tokens:{className:A,interface:C(["interface"],["entity.name.type.interface"],E.type),enum:C(["enum"],["entity.name.type.enum"],A),method:C(["method"],["entity.name.function.method"],E.function),variableProperty:N,parameter:C(["parameter"],["variable.parameter"],E.variable),constant:C(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],E.number),boolean:C([],["constant.language.boolean","constant.language"],E.number),punctuation:C([],["punctuation","punctuation.separator"],E.operator),stringEscape:C([],["constant.character.escape"],E.string),commentDoc:C([],["comment.block.documentation","comment.documentation"],E.comment),keywordImport:C([],["keyword.control.import","keyword.import"],E.keyword),tag:C([],["entity.name.tag"],E.keyword),tagAttribute:C([],["entity.other.attribute-name"],N)},highlights:k.colors.syntax.highlights},y=Lx(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return Dx(k,r,E),Wd({metadata:{id:`vscode-import-${c}`,name:y,variant:c,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...k.colors,syntax:h,pr:{open:k.colors.status.success,draft:k.colors.surface.mutedForeground,blocked:k.colors.status.warning,merged:A,closed:k.colors.status.error}}})}const zx=un({namespace:as(),name:as(),version:as(),label:as(),icon:as().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Ux(t,e){const a=await xt("/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 un({items:li(zx).max(24)}).parse(await a.json()).items}async function _x(t,e){const a=await xt("/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}=un({items:li(un({path:as(),name:as(),text:as(),error:ao()})).max(40)}).parse(await a.json());return n.map((i,r)=>{const l=`${r}:${i.path}`;try{if(i.error)throw new Error("invalid");const m=Wc(i.text,i.path);return m.metadata.name=i.name,m.metadata.author=t.namespace,{status:"ready",key:l,name:i.name,definition:m,theme:Jd(m)}}catch{return{status:"invalid",key:l,name:i.name}}})}function $x(t){const e=ct.c(3),{extension:a}=t,[n,i]=o.useState(!1);let r;return e[0]!==a.icon||e[1]!==n?(r=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>i(!0)}):s.jsx(B,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=r):r=e[2],r}function Bx(t){const e=ct.c(93),{pickFile:a,fileBusy:n,onClose:i}=t,{t:r}=et(),l=ce(qx),{isMobile:m}=ha(),c=l||m,{importTheme:x}=Ua(),[u,v]=o.useState("");let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={step:"search",status:"idle",results:[]},e[0]=d):d=e[0];const[j,g]=o.useState(d);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=new Set,e[1]=w):w=e[1];const[b,k]=o.useState(w);let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=new Set,e[2]=p):p=e[2];const[C,E]=o.useState(p),[A,N]=o.useState(!1),[h,y]=o.useState(null),R=o.useRef(null);let T,P;e[3]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const L=new AbortController;R.current=L;const K=Wi(()=>L.abort());return()=>{K(),L.abort()}},P=[],e[3]=T,e[4]=P):(T=e[3],P=e[4]),o.useEffect(T,P);let D,V;e[5]!==u||e[6]!==j.step?(D=()=>{if(j.step!=="search")return;const L=new AbortController,K=u.trim(),z=setTimeout(async()=>{if(!K){g({step:"search",status:"idle",results:[]});return}g({step:"search",status:"loading",results:[]});try{const J=await Ux(K,L.signal);L.signal.aborted||g({step:"search",status:"ready",results:J})}catch{L.signal.aborted||g({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(z),L.abort()}},V=[u,j.step],e[5]=u,e[6]=j.step,e[7]=D,e[8]=V):(D=e[7],V=e[8]),o.useEffect(D,V);let $,I;if(e[9]!==n||e[10]!==x||e[11]!==c||e[12]!==a||e[13]!==u||e[14]!==h||e[15]!==C||e[16]!==A||e[17]!==b||e[18]!==j.extension||e[19]!==j.results||e[20]!==j.status||e[21]!==j.step||e[22]!==j.variants||e[23]!==r){const L=async ie=>{const ue=R.current?.signal;if(ue){g({step:"package",status:"loading",extension:ie}),E(new Set),y(null),k(new Set);try{const de=await _x(ie,ue);ue.aborted||g({step:"variants",extension:ie,variants:de})}catch{ue.aborted||g({step:"package",status:"error",extension:ie})}}};let K;e[26]!==x||e[27]!==C||e[28]!==A||e[29]!==b||e[30]!==j.step||e[31]!==j.variants||e[32]!==r?(K=async()=>{if(j.step!=="variants"||A)return;const ie=R.current?.signal;if(!ie)return;N(!0),y(null);let ue=!1;for(const de of j.variants){if(ie.aborted)break;if(!(de.status!=="ready"||!b.has(de.key)||C.has(de.key)))try{if(await x(de.definition,{activate:!1}),ie.aborted)break;E(Pe=>new Set(Pe).add(de.key)),k(Pe=>{const Ae=new Set(Pe);return Ae.delete(de.key),Ae})}catch{ue=!0}}ie.aborted||(N(!1),y(ue?"partial":null),ue?Oa.error(r("settings.themeImport.partialError")):Oa.success(r("settings.themeImport.complete")))},e[26]=x,e[27]=C,e[28]=A,e[29]=b,e[30]=j.step,e[31]=j.variants,e[32]=r,e[33]=K):K=e[33];const z=K;let J,oe;e[34]!==C||e[35]!==b||e[36]!==j.step||e[37]!==j.variants?(J=j.step==="variants"?j.variants.filter(ie=>ie.status==="ready"&&!C.has(ie.key)):[],oe=J.length>0&&J.every(ie=>b.has(ie.key)),e[34]=C,e[35]=b,e[36]=j.step,e[37]=j.variants,e[38]=J,e[39]=oe):(J=e[38],oe=e[39]);const re=oe;let pe;e[40]!==n||e[41]!==z||e[42]!==A||e[43]!==b||e[44]!==j.step||e[45]!==r?(pe=j.step==="variants"&&s.jsx(G,{disabled:!b.size||A||n,onClick:()=>{z()},children:r(A?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=z,e[42]=A,e[43]=b,e[44]=j.step,e[45]=r,e[46]=pe):pe=e[46];const ve=A||n;let be;e[47]!==r?(be=r("settings.themeImport.chooseFile"),e[47]=r,e[48]=be):be=e[48];let te;e[49]!==a||e[50]!==ve||e[51]!==be?(te=s.jsx(G,{variant:"outline",className:"self-start",disabled:ve,onClick:a,children:be}),e[49]=a,e[50]=ve,e[51]=be,e[52]=te):te=e[52];let he;e[53]!==pe||e[54]!==te?(he=s.jsxs(s.Fragment,{children:[pe,te]}),e[53]=pe,e[54]=te,e[55]=he):he=e[55],$=he,I=s.jsx(s.Fragment,{children:j.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(Be,{autoFocus:!0,"aria-label":r("settings.themeImport.search"),placeholder:r("settings.themeImport.search"),value:u,maxLength:160,onChange:ie=>v(ie.target.value)}),s.jsxs("div",{className:c?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[j.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:r("common.loading")}),j.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.catalogError")}),j.status==="ready"&&!j.results.length&&s.jsx("p",{className:"text-muted-foreground",children:r("settings.themeImport.empty")}),j.results.map(ie=>s.jsxs(G,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{L(ie)},children:[s.jsx($x,{extension:ie}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ie.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ie.namespace})]})]},`${ie.namespace}.${ie.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(G,{variant:"ghost",size:"sm",className:"justify-start",disabled:A||j.step==="package"&&j.status==="loading",onClick:()=>g({step:"search",status:"idle",results:[]}),children:[s.jsx(B,{name:"arrow-left",className:"size-4"}),r("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:j.extension.label}),h==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.partialError")}),j.step==="package"?j.status==="loading"?s.jsx("p",{role:"status",children:r("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[j.variants.length>1&&s.jsx(G,{variant:"ghost",size:"sm",className:"self-start",disabled:A||n||!J.length,onClick:()=>k(re?new Set:new Set(J.map(Hx))),children:r(re?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:c?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:j.variants.map(ie=>s.jsxs("div",{className:"flex items-center gap-3",children:[ie.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:ie.theme.colors.surface.background,color:ie.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ie.theme.colors.syntax.base.keyword,ie.theme.colors.syntax.base.string,ie.theme.colors.syntax.base.function].map(Vx)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[C.has(ie.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:ie.name})]}):s.jsx(mt,{checked:b.has(ie.key),disabled:ie.status!=="ready"||A||n,label:ie.name,onChange:ue=>k(de=>{const Pe=new Set(de);return ue?Pe.add(ie.key):Pe.delete(ie.key),Pe})}),s.jsx("p",{className:C.has(ie.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ie.status!=="ready"?r("settings.themeImport.error.invalid"):C.has(ie.key)?r("settings.themeImport.installed"):r(ie.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ie.key))})]})]})}),e[9]=n,e[10]=x,e[11]=c,e[12]=a,e[13]=u,e[14]=h,e[15]=C,e[16]=A,e[17]=b,e[18]=j.extension,e[19]=j.results,e[20]=j.status,e[21]=j.step,e[22]=j.variants,e[23]=r,e[24]=$,e[25]=I}else $=e[24],I=e[25];const M=I;if(c){let L;e[56]!==r?(L=r("settings.themeImport.catalogTitle"),e[56]=r,e[57]=L):L=e[57];let K;e[58]!==$?(K=s.jsx("div",{className:"flex flex-col gap-2",children:$}),e[58]=$,e[59]=K):K=e[59];let z;e[60]!==r?(z=r("settings.themeImport.catalogHint"),e[60]=r,e[61]=z):z=e[61];let J;e[62]!==z?(J=s.jsx("p",{className:"typography-meta text-muted-foreground",children:z}),e[62]=z,e[63]=J):J=e[63];let oe;e[64]!==M||e[65]!==J?(oe=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[J,M]}),e[64]=M,e[65]=J,e[66]=oe):oe=e[66];let re;return e[67]!==i||e[68]!==K||e[69]!==oe||e[70]!==L?(re=s.jsx(Qd,{open:!0,title:L,onClose:i,footer:K,children:oe}),e[67]=i,e[68]=K,e[69]=oe,e[70]=L,e[71]=re):re=e[71],re}let H;e[72]!==i?(H=L=>{L||i()},e[72]=i,e[73]=H):H=e[73];let U;e[74]===Symbol.for("react.memo_cache_sentinel")?(U={forceRender:!0},e[74]=U):U=e[74];let Z;e[75]!==r?(Z=r("settings.themeImport.catalogTitle"),e[75]=r,e[76]=Z):Z=e[76];let ee;e[77]!==Z?(ee=s.jsx(Ht,{children:Z}),e[77]=Z,e[78]=ee):ee=e[78];let O;e[79]!==r?(O=r("settings.themeImport.catalogHint"),e[79]=r,e[80]=O):O=e[80];let ae;e[81]!==O?(ae=s.jsx(qt,{children:O}),e[81]=O,e[82]=ae):ae=e[82];let _;e[83]!==ee||e[84]!==ae?(_=s.jsxs(Vt,{children:[ee,ae]}),e[83]=ee,e[84]=ae,e[85]=_):_=e[85];let W;e[86]!==$||e[87]!==M||e[88]!==_?(W=s.jsxs($t,{className:"max-w-lg",backdropProps:U,children:[_,M,$]}),e[86]=$,e[87]=M,e[88]=_,e[89]=W):W=e[89];let q;return e[90]!==W||e[91]!==H?(q=s.jsx(_t,{open:!0,onOpenChange:H,children:W}),e[90]=W,e[91]=H,e[92]=q):q=e[92],q}function Vx(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function Hx(t){return t.key}function qx(t){return t.isMobile}function Gx(){const{t}=et(),{importTheme:e,customThemesLoading:a}=Ua(),n=to(),[i,r]=o.useState(!1),l=o.useCallback(()=>r(!1),[]),m=o.useRef(null),c=o.useRef(0),x=o.useRef(null),[u,v]=o.useState(!1);o.useEffect(()=>Wi(()=>{c.current+=1,r(!1)}),[]);const d=async(w,b)=>{v(!0);try{if(w.size>xc)throw new ta("size");const k=await w.text();if(b.key!==Rn()||b.generation!==c.current)throw new ta("connection");const p=await e(Wc(k,w.name));Oa.success(t("settings.themeImport.success",{name:p.metadata.name})),r(!1)}catch(k){const p=k instanceof ta?k.code:"invalid";Oa.error(t(`settings.themeImport.error.${p}`))}finally{v(!1)}},j=async()=>{if(u)return;const w={key:Rn(),generation:c.current};if(x.current=w,!n.themeFiles){m.current?.click();return}v(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const k=b.file;await d({name:k.name,size:k.size,text:async()=>k.text},w)}return}m.current?.click()}catch{Oa.error(t("settings.themeImport.error.invalid"))}finally{v(!1)}},g=async w=>{const b=w.target.files?.[0];w.target.value="",b&&!u&&x.current&&await d(b,x.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:u||a,onClick:()=>r(!0),children:[s.jsx(B,{name:u?"loader":"add",className:u?"size-3.5 animate-spin":"size-3.5"}),t(u?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Yt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:m,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:g}),i&&s.jsx(Bx,{pickFile:()=>{j()},fileBusy:u,onClose:l})]})}function Ml({id:t,label:e}){const{deleteImportedTheme:a,customThemeIds:n}=Ua(),{t:i}=et(),[r,l]=o.useState(!1),m=o.useRef(null),c=o.useRef(null),x=async()=>{if(r)return;l(!0);const u=c.current?.closest('[data-slot="select-content"]');try{await a(t),requestAnimationFrame(()=>{u?.isConnected&&document.activeElement===document.body&&u.querySelector('[role="option"][aria-selected="true"]')?.focus()})}catch{Oa.error(i("settings.themeImport.deleteError"))}finally{l(!1)}};return n.includes(t)?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(dt,{ref:m,value:t,className:"min-w-0 flex-1","aria-keyshortcuts":"Delete ArrowRight",onKeyDown:u=>{u.key!=="ArrowRight"&&u.key!=="Delete"||(u.preventDefault(),u.stopPropagation(),u.key==="ArrowRight"?c.current?.focus():x())},children:e}),s.jsx(G,{ref:c,variant:"ghost",size:"icon",disabled:r,"aria-label":i("settings.themeImport.delete",{name:e}),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&u.stopPropagation(),u.key==="ArrowLeft"&&(u.preventDefault(),u.stopPropagation(),m.current?.focus())},onClick:u=>{u.stopPropagation(),x()},children:s.jsx(B,{name:r?"loader":"delete-bin",className:r?"size-4 animate-spin":"size-4"})})]}):s.jsx(dt,{value:t,children:e})}const Wx=[{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"}],Jx=[{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"}],Qx=[{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"}],Ya="OpenChamber - AI Coding Assistant",Rl=[{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"}],Fl=[{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"}],Pr=t=>t==="portrait"||t==="landscape"?t:"system",Yx=[{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"}],Zx=[{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"}],Ol=[{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"}],Xx=[{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"}],Ll=[{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"}],Kl=[{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"}],eb=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],tb=[{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"}],sb=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],nb=t=>t==="markdown"?"markdown":"plain",ab=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],ib=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],Ji=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=et(),l=o.useCallback(f=>r(f),[r]),{isMobile:m}=ha(),{terminal:c}=to(),{browserTab:x}=Zu(),u=Mu(),v=ce(f=>f.showReasoningTraces),d=ce(f=>f.sessionRecapEnabled),j=ce(f=>f.sessionSuggestionEnabled),g=ce(f=>f.setSessionRecapEnabled),w=ce(f=>f.setSessionSuggestionEnabled),b=ce(f=>f.sessionGoalEnabled),k=ce(f=>f.setSessionGoalEnabled),p=ce(f=>f.sessionGoalDefaultBudgetEnabled),C=ce(f=>f.setSessionGoalDefaultBudgetEnabled),E=ce(f=>f.sessionGoalDefaultBudget),A=ce(f=>f.setSessionGoalDefaultBudget),N=ce(f=>f.setShowReasoningTraces),h=ce(f=>f.streamingAutoFollowEnabled),y=ce(f=>f.setStreamingAutoFollowEnabled),R=ce(f=>f.collapsibleThinkingBlocks),T=ce(f=>f.setCollapsibleThinkingBlocks),P=ce(f=>f.mermaidRenderingMode),D=ce(f=>f.setMermaidRenderingMode),V=ce(f=>f.userMessageRenderingMode),$=ce(f=>f.setUserMessageRenderingMode),I=ce(f=>f.collapsibleUserMessages),M=ce(f=>f.setCollapsibleUserMessages),H=ce(f=>f.stickyUserHeader),U=ce(f=>f.promptNavigatorEnabled),Z=ce(f=>f.setStickyUserHeader),ee=ce(f=>f.setPromptNavigatorEnabled),O=ce(f=>f.autoSaveEnabled),ae=ce(f=>f.setAutoSaveEnabled),_=ce(f=>f.wideChatLayoutEnabled),W=ce(f=>f.setWideChatLayoutEnabled),q=ce(f=>f.codeBlockLineWrap),L=ce(f=>f.setCodeBlockLineWrap),K=ce(f=>f.chatRenderMode),z=ce(f=>f.setChatRenderMode),J=ce(f=>f.activityRenderMode),oe=ce(f=>f.setActivityRenderMode),re=ce(f=>f.fontSize),pe=ce(f=>f.setFontSize),ve=ce(f=>f.terminalFontSize),be=ce(f=>f.setTerminalFontSize),te=ce(f=>f.terminalShell),he=ce(f=>f.setTerminalShell),ie=ce(f=>f.terminalLoginShells),ue=ce(f=>f.setTerminalLoginShells),de=ce(f=>f.editorFontSize),Pe=ce(f=>f.setEditorFontSize),Ae=ce(f=>f.uiFont),we=ce(f=>f.setUiFont),Le=ce(f=>f.monoFont),_e=ce(f=>f.setMonoFont),Ve=ce(f=>f.padding),je=ce(f=>f.setPadding),ke=ce(f=>f.inputBarOffset),se=ce(f=>f.setInputBarOffset),le=ce(f=>f.mobileKeyboardMode),Ie=ce(f=>f.setMobileKeyboardMode),Ne=ce(f=>f.diffLayoutPreference),Re=ce(f=>f.setDiffLayoutPreference),$e=ce(f=>f.showTerminalQuickKeysOnDesktop),De=ce(f=>f.sessionTabsEnabled),Ce=ce(f=>f.setSessionTabsEnabled),Ye=ce(f=>f.setShowTerminalQuickKeysOnDesktop),xe=ce(f=>f.fileEditorKeymap),Te=ce(f=>f.setFileEditorKeymap),Ke=Do(f=>f.followUpBehavior),tt=Do(f=>f.setFollowUpBehavior),Y=ki(f=>f.scope),Se=ki(f=>f.entryLimit),Ee=ki(f=>f.applyScope),We=ki(f=>f.applyEntryLimit),lt=ce(f=>f.persistChatDraft),at=ce(f=>f.setPersistChatDraft),pt=ce(f=>f.inputSpellcheckEnabled),bt=ce(f=>f.setInputSpellcheckEnabled),Q=ce(f=>f.largeTextPasteBehavior),qe=ce(f=>f.setLargeTextPasteBehavior),it=ce(f=>f.enterToSend),ut=ce(f=>f.setEnterToSend),gt=ce(f=>f.enterToSendConfigured),Ot=ce(f=>f.setEnterToSendConfigured),st=gt?it:!m,ft=ce(f=>f.showToolFileIcons),jt=ce(f=>f.setShowToolFileIcons),Je=ce(f=>f.showTurnChangedFiles),St=ce(f=>f.setShowTurnChangedFiles),Oe=ce(f=>f.showExpandedBashTools),wt=ce(f=>f.setShowExpandedBashTools),X=ce(f=>f.showExpandedEditTools),fe=ce(f=>f.setShowExpandedEditTools),Fe=ce(f=>f.timeFormatPreference),Me=ce(f=>f.setTimeFormatPreference),rt=ce(f=>f.weekStartPreference),ot=ce(f=>f.setWeekStartPreference),Ge=ce(f=>f.showSplitAssistantMessageActions),Nt=ce(f=>f.setShowSplitAssistantMessageActions),ns=ce(f=>f.allowPromptingSubagentSessions),Zt=ce(f=>f.setAllowPromptingSubagentSessions),Qe=ce(f=>f.draftStartersVisible),He=ce(f=>f.setDraftStartersVisible),Ct=Xe(f=>f.settingsMessageStreamTransport),Pt=Xe(f=>f.setSettingsMessageStreamTransport),es=Ct,ts=Xe(f=>f.settingsDefaultFileViewerPreview),os=Xe(f=>f.setSettingsDefaultFileViewerPreview),xs=ce(f=>f.isSettingsDialogOpen),{themeMode:Fs,setThemeMode:me,availableThemes:ht,customThemesLoading:kt,reloadCustomThemes:Xt,lightThemeId:ss,darkThemeId:Jt,setLightThemePreference:ps,setDarkThemePreference:Ss}=Ua(),[us,It]=o.useState(!1),Lt=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Wt=ce(f=>f.dockBadgeEnabled),Gt=ce(f=>f.setDockBadgeEnabled),ms=ce(f=>f.alwaysShowScrollbars===!0),Os=ce(f=>f.setAlwaysShowScrollbars),Qi=Ru(),Yi=ce(f=>f.desktopWindowControlsPosition),di=ce(f=>f.setDesktopWindowControlsPosition),Zi=ce(f=>f.desktopWindowControlsStyle),$s=ce(f=>f.setDesktopWindowControlsStyle),[_a,Xi]=o.useState(0),ui=ce(f=>f.reportUsage),mi=ce(f=>f.setReportUsage),er=o.useCallback(f=>{mi(f),yt({reportUsage:f})},[mi]),tr=o.useCallback(f=>{di(f),yt({desktopWindowControlsPosition:f})},[di]),sr=o.useCallback(f=>{$s(f),yt({desktopWindowControlsStyle:f})},[$s]),pi=(xs||m||ds())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!pi)return;let f=null,vt=Date.now();const vs=()=>{const hn=Date.now();hn-vt>=420&&(Xi(Qn=>(Qn+1)%24),vt=hn),f=requestAnimationFrame(vs)};(typeof document>"u"||document.visibilityState==="visible")&&(f=requestAnimationFrame(vs));const Ks=()=>{document.visibilityState==="visible"&&f===null?f=requestAnimationFrame(vs):document.visibilityState!=="visible"&&f!==null&&(cancelAnimationFrame(f),f=null)};return document.addEventListener("visibilitychange",Ks),()=>{document.removeEventListener("visibilitychange",Ks),f!==null&&cancelAnimationFrame(f)}},[pi]);const Cs=o.useCallback(f=>{$(f),yt({userMessageRenderingMode:f})},[$]),tn=o.useCallback(f=>{Z(f),yt({stickyUserHeader:f})},[Z]),fa=o.useCallback(f=>{ee(f),yt({promptNavigatorEnabled:f})},[ee]),Pn=o.useCallback(f=>{He(f),yt({draftStartersVisible:f})},[He]),Fn=o.useCallback(f=>{M(f),yt({collapsibleUserMessages:f})},[M]),fo=o.useCallback(f=>{W(f),yt({wideChatLayoutEnabled:f})},[W]),mn=o.useCallback(f=>{Nt(f),yt({showSplitAssistantMessageActions:f})},[Nt]),nr=o.useCallback(f=>{bt(f),yt({inputSpellcheckEnabled:f})},[bt]),Hn=o.useCallback(f=>{ut(f),Ot(!0),yt({enterToSend:f,enterToSendConfigured:!0})},[ut,Ot]),xa=o.useCallback(f=>{z(f),yt({chatRenderMode:f})},[z]),qn=o.useCallback(f=>{Pt(f),yt({messageStreamTransport:f})},[Pt]),$a=o.useCallback(f=>{Ee(f),yt({inputHistoryScope:f})},[Ee]),ar=o.useCallback(f=>{const vt=Math.round(f);Fu(vt)&&(We(vt),yt({inputHistoryLimit:vt}))},[We]),gs=o.useCallback(f=>{oe(f),yt({activityRenderMode:f})},[oe]),ir=o.useCallback(f=>{D(f),yt({mermaidRenderingMode:f})},[D]),ba=o.useCallback(f=>{jt(f),yt({showToolFileIcons:f})},[jt]),va=o.useCallback(f=>{St(f),yt({showTurnChangedFiles:f})},[St]),rr=o.useCallback(f=>{os(f),yt({defaultFileViewerPreview:f}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:f}}))},[os]),gi=o.useCallback(f=>{wt(f),yt({showExpandedBashTools:f})},[wt]),or=o.useCallback(f=>{fe(f),yt({showExpandedEditTools:f})},[fe]),hi=o.useCallback(f=>{Me(f),yt({timeFormatPreference:f})},[Me]),ya=o.useCallback(f=>{ot(f),yt({weekStartPreference:f})},[ot]),An=o.useMemo(()=>ht.filter(f=>f.metadata.variant==="light").sort((f,vt)=>f.metadata.name.localeCompare(vt.metadata.name)),[ht]),Gn=o.useMemo(()=>ht.filter(f=>f.metadata.variant==="dark").sort((f,vt)=>f.metadata.name.localeCompare(vt.metadata.name)),[ht]),Ba=o.useMemo(()=>An.find(f=>f.metadata.id===ss)??An[0],[An,ss]),On=o.useMemo(()=>Gn.find(f=>f.metadata.id===Jt)??Gn[0],[Gn,Jt]),ja=o.useCallback((f,vt)=>{const vs=vt==="dark"?" Dark":" Light";return f.endsWith(vs)?f.slice(0,-vs.length):f},[]),ge=f=>t?t.includes(f):!0,hs=ds(),wa=ge("theme")&&!hs,fi=ge("windowControlsPosition")&&Qi,xi=ge("theme")||ge("timeFormat")||ge("weekStart"),bi=hs?xi:ge("theme")||fi||ge("pwaInstallName")||ge("pwaOrientation")||ge("timeFormat")||ge("weekStart"),vi=ge("fontSize")||ge("terminalFontSize")||ge("editorFontSize")||ge("spacing")||ge("scrollbars")&&!wa||ge("inputBarOffset")&&m,yi=ge("terminalQuickKeys")&&!m||(ge("terminalShell")||ge("terminalLoginShell"))&&!hs||ge("fileEditorKeymap")||ge("autoSaveEnabled")||ge("sessionTabs")&&!hs&&!m,lr=ge("mermaidRendering")||ge("sessionGoal")&&!hs||ge("userMessageRendering")||ge("chatRenderMode")||ge("messageTransport")||ge("activityRenderMode")||ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("codeBlockLineWrap")||ge("splitAssistantMessageActions")||ge("subagentReadOnlyBanner")||ge("diffLayout")||ge("dotfiles")||ge("fileViewerPreview")||ge("reasoning")||ge("followUpBehavior")||ge("inputHistoryScope")||ge("inputHistoryLimit")||ge("persistDraft")||ge("largeTextPaste")||ge("showToolFileIcons")||ge("expandedTools")||!m&&ge("inputSpellcheck")||ge("enterToSend"),pn=ge("chatRenderMode")||ge("activityRenderMode"),Ln=ge("messageTransport"),ka=ge("userMessageRendering")||ge("mermaidRendering")||ge("diffLayout")&&!hs||ge("followUpBehavior")||ge("inputHistoryScope")||ge("inputHistoryLimit"),cr=ge("sessionAssist")||ge("sessionGoal")&&!hs||ge("subagentReadOnlyBanner")||ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("codeBlockLineWrap")||ge("splitAssistantMessageActions")||ge("dotfiles")||ge("fileViewerPreview")||ge("persistDraft")||ge("largeTextPaste")||ge("showToolFileIcons")||ge("showTurnChangedFiles")||!m&&ge("inputSpellcheck")||ge("enterToSend")||ge("reasoning")||ge("expandedTools"),S=bi||vi||yi,ne=ge("pwaInstallName")&&ra()&&x&&!cs()&&!hs,Ue=ge("pwaOrientation")&&ra()&&!cs()&&!hs,nt=ge("mobileKeyboardMode")&&ra()&&!cs()&&!hs&&Ou(),zt=(ge("terminalShell")||ge("terminalLoginShell"))&&!hs,[Is,bs]=o.useState([]),[Js,Ps]=o.useState(0);o.useEffect(()=>Wi(()=>{bs([]),Ps(f=>f+1)}),[]),o.useEffect(()=>{let f=!1;if(!(!zt||!c.listShells))return c.listShells().then(vt=>{f||bs(vt)}).catch(()=>{f||bs([])}),()=>{f=!0}},[zt,c,Js]);const sn=o.useMemo(()=>{const f=Is.filter(vt=>vt.id!=="auto");return te==="auto"||f.some(vt=>vt.id===te)?f:[{id:te,name:te,supportsLogin:!1},...f]},[Is,te]),Va=Is.find(f=>f.id===te)?.supportsLogin===!0,Wn=ie.includes(te),Ha=f=>{ue(f?[...ie.filter(vt=>vt!==te),te]:ie.filter(vt=>vt!==te))},[Mt,Qt]=o.useState(""),[gn,Rt]=o.useState("system"),Ls=o.useMemo(()=>{const f=Ll.find(vt=>vt.id===Fe);return l(f?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Fe,l]),Jn=o.useMemo(()=>{const f=Kl.find(vt=>vt.id===rt);return l(f?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[rt,l]),Na=o.useMemo(()=>{const f=Rl.find(vt=>vt.id===gn);return f?l(f.labelKey):void 0},[gn,l]),ji=o.useMemo(()=>{const f=Fl.find(vt=>vt.id===le);return f?l(f.labelKey):void 0},[le,l]),dr=o.useCallback(async f=>{if(typeof window>"u")return;const vt=window,Ks=f.trim().replace(/\s+/g," ").slice(0,64);if(await yt({pwaAppName:Ks}),typeof vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const hn=vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ks);Qt(hn);return}Qt(Ks||Ya),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),xo=o.useCallback(async f=>{if(typeof window>"u")return;const vt=window,vs=Pr(f);if(await yt({pwaOrientation:vs}),typeof vt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ks=vt.__OPENCHAMBER_SET_PWA_ORIENTATION__(vs);Rt(Ks);return}Rt(vs),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!ne&&!Ue&&!nt)return;let f=!1;return(async()=>{try{const vs=await In();if(!vs){f||Qt(Ya);return}const hn=(vs.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Qn=Pr(vs.pwaOrientation),wi=Lo(vs.mobileKeyboardMode);f||(ne&&Qt(hn||Ya),Ue&&Rt(Qn),nt&&Ie(wi))}catch{f||(ne&&Qt(Ya),Ue&&Rt("system"),nt&&Ie("native"))}})(),()=>{f=!0}},[Ie,nt,ne,Ue]);const ur=ge("scrollbars")?s.jsx(mt,{checked:ms,onChange:Os,label:r("settings.openchamber.visual.field.alwaysShowScrollbars"),info:r("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[bi&&s.jsxs("div",{className:"space-y-0",children:[wa&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(En,{children:[s.jsx("div",{className:_s,children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:Wx.map(f=>s.jsx(Ys,{selected:Fs===f.value,onSelect:()=>me(f.value),label:l(f.labelKey),ariaLabel:l(f.labelKey)},f.value))})}),s.jsxs("div",{className:_s,children:[s.jsx(At,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Tt,{value:Ba?.metadata.id??"",onValueChange:ps,children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Bt,className:Kn,children:s.jsx(Ut,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:Ba?ja(Ba.metadata.name,"light"):void 0})}),s.jsx(Dt,{children:An.map(f=>s.jsx(Ml,{id:f.metadata.id,label:ja(f.metadata.name,"light")},f.metadata.id))})]})}),s.jsx(At,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Tt,{value:On?.metadata.id??"",onValueChange:Ss,children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Bt,className:Kn,children:s.jsx(Ut,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:On?ja(On.metadata.name,"dark"):void 0})}),s.jsx(Dt,{children:Gn.map(f=>s.jsx(Ml,{id:f.metadata.id,label:ja(f.metadata.name,"dark")},f.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:kt||us,onClick:()=>{const f=Date.now();It(!0),Xt().finally(()=>{const vt=Date.now()-f;if(vt<500){window.setTimeout(()=>{It(!1)},500-vt);return}It(!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:ye("h-3.5 w-3.5",us&&"animate-spin")}),r(us?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Yt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(Gx,{})]})]}),Lt&&s.jsx(za,{settingsItem:"appearance.dock-badge",children:s.jsx(mt,{checked:Wt,onChange:Gt,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})}),ur&&s.jsx(za,{children:ur})]}),fi&&s.jsx(ze,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:wa,children:s.jsxs(En,{children:[s.jsx(At,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(cn,{value:Yi,options:ab.map(f=>({value:f.id,label:l(f.labelKey)})),onChange:tr,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(At,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(cn,{value:Zi,options:ib.map(f=>({value:f.id,label:l(f.labelKey)})),onChange:sr,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),xi&&s.jsx(ze,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(En,{children:[s.jsx(At,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Tt,{value:e,onValueChange:f=>n(f),children:[s.jsx(Et,{"aria-label":r("settings.appearance.language.select"),size:Bt,className:Kn,children:s.jsx(Ut,{children:i(e)})}),s.jsx(Dt,{children:a.map(f=>s.jsx(dt,{value:f,children:i(f)},f))})]})}),(ge("timeFormat")||ge("weekStart"))&&s.jsxs("div",{className:_s,children:[ge("timeFormat")&&s.jsx(At,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Tt,{value:Fe,onValueChange:f=>hi(f),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Bt,className:Kn,children:s.jsx(Ut,{children:Ls})}),s.jsx(Dt,{children:Ll.map(f=>s.jsx(dt,{value:f.id,children:l(f.labelKey)},f.id))})]})}),ge("weekStart")&&s.jsx(At,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Tt,{value:rt,onValueChange:f=>ya(f),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Bt,className:Kn,children:s.jsx(Ut,{children:Jn})}),s.jsx(Dt,{children:Kl.map(f=>s.jsx(dt,{value:f.id,children:l(f.labelKey)},f.id))})]})})]})]})}),(ne||Ue||nt)&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:_s,children:[ne&&s.jsxs(Ft,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Hs,children:[s.jsx(Be,{value:Mt,onChange:f=>{Qt(f.target.value)},onBlur:()=>{dr(Mt)},onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),dr(Mt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Qt(Ya),dr("")},className:ws,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),Ue&&s.jsxs(Ft,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Hs,children:[s.jsxs(Tt,{value:gn,onValueChange:f=>{const vt=Pr(f);Rt(vt),xo(vt)},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Bt,className:ko,children:s.jsx(Ut,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Na})}),s.jsx(Dt,{children:Rl.map(f=>s.jsx(dt,{value:f.id,children:l(f.labelKey)},f.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Rt("system"),xo("system")},disabled:gn==="system",className:ws,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),nt&&s.jsxs(Ft,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Hs,children:[s.jsxs(Tt,{value:le,onValueChange:f=>{const vt=Lo(f);Ie(vt),yt({mobileKeyboardMode:vt})},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Bt,className:ko,children:s.jsx(Ut,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:ji})}),s.jsx(Dt,{children:Fl.map(f=>s.jsx(dt,{value:f.id,children:l(f.labelKey)},f.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ie("native"),yt({mobileKeyboardMode:"native"})},disabled:le==="native",className:ws,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),vi&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:_s,children:[ge("fontSize")&&!m||ge("terminalFontSize")?s.jsxs(En,{children:[ge("fontSize")&&!m&&s.jsxs(At,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Tt,{value:Ae,onValueChange:f=>we(f),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Bt,className:Kn,children:s.jsx(Ut,{children:Mo.find(f=>f.id===Ae)?.label})}),s.jsx(Dt,{children:Mo.map(f=>s.jsx(dt,{value:f.id,children:s.jsx("span",{style:{fontFamily:f.stack},children:f.label})},f.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>we(Ro),disabled:Ae===Ro,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),ge("terminalFontSize")&&s.jsxs(At,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Tt,{value:Le,onValueChange:f=>_e(f),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Bt,className:Kn,children:s.jsx(Ut,{children:Fo.find(f=>f.id===Le)?.label})}),s.jsx(Dt,{children:Fo.map(f=>s.jsx(dt,{value:f.id,children:s.jsx("span",{style:{fontFamily:f.stack},children:f.label})},f.id))})]}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>_e(Oo),disabled:Le===Oo,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ge("fontSize")&&!m||ge("terminalFontSize")||ge("editorFontSize")?s.jsxs(En,{children:[ge("fontSize")&&!m&&s.jsx(At,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:re,onValueChange:pe,min:50,max:200,step:5,className:Ds,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Ia,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>pe(100),disabled:re===100,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("terminalFontSize")&&s.jsx(At,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:ve,onValueChange:be,min:9,max:52,step:1,className:Ds}),s.jsx("span",{className:Ia,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(13),disabled:ve===13,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("editorFontSize")&&s.jsx(At,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:de,onValueChange:Pe,min:9,max:32,step:1,className:Ds}),s.jsx("span",{className:Ia,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>Pe(13),disabled:de===13,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ge("spacing")||ge("inputBarOffset")&&m?s.jsxs(En,{children:[ge("spacing")&&s.jsx(At,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:Ve,onValueChange:je,min:50,max:200,step:5,className:Ds}),s.jsx("span",{className:Ia,children:"%"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>je(100),disabled:Ve===100,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("inputBarOffset")&&m&&s.jsx(At,{label:r("settings.openchamber.visual.field.inputBarOffset"),info:r("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:ke,onValueChange:se,min:0,max:100,step:5,className:Ds}),s.jsx("span",{className:Ia,children:"px"}),s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>se(0),disabled:ke===0,className:ws,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!wa&&ur]}),yi&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ge("fileEditorKeymap")&&s.jsx(As,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(f=>s.jsx(Ys,{selected:xe===f,onSelect:()=>Te(f),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${f}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${f}`)},f))})}),s.jsxs("div",{className:fs,children:[ge("autoSaveEnabled")&&s.jsx(mt,{checked:O,onChange:ae,label:r("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:r("settings.openchamber.visual.field.autoSaveEnabledAria"),info:r("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),zt&&s.jsx(At,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Tt,{value:te,onValueChange:f=>{Lu(f)&&he(f)},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Bt,className:Kn,children:s.jsx(Ut,{})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),sn.map(f=>s.jsx(dt,{value:f.id,children:f.name},f.id))]})]})}),zt&&Va&&s.jsx(mt,{checked:Wn,onChange:Ha,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ge("terminalQuickKeys")&&!m&&s.jsx(mt,{checked:$e,onChange:Ye,label:r("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:r("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:ca("ctrl"),alt:ca("alt")})})]}),ge("sessionTabs")&&!hs&&!m&&s.jsx(As,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(mt,{checked:De,onChange:Ce,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),lr&&s.jsxs(s.Fragment,{children:[pn&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:S,contentClassName:"space-y-6",children:[ge("chatRenderMode")&&s.jsx(As,{title:r("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Zx.map(f=>{const vt=K===f.id,vs=_a%12;return s.jsxs("button",{type:"button",onClick:()=>xa(f.id),"aria-pressed":vt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:ye("typography-ui-label",vt?"text-inherit":"text-muted-foreground"),children:l(f.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:f.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ks=>{const hn=Ks*3+1,Qn=vs-hn+1,wi=Qn<=0?0:Qn===1?42:Qn===2?68:92,od=wi>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",od?"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:`${wi}%`}})]},Ks)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ks=>{const hn=vs>=(Ks+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",hn?"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%"}})]},Ks)})})})]},f.id)})})}),ge("activityRenderMode")&&s.jsx(As,{title:r("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:Xx.map(f=>s.jsx(Ys,{selected:J===f.id,onSelect:()=>gs(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(f.labelKey)})},f.id))})})]}),Ln&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:pn||S,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(cn,{value:es,options:Ol.map(f=>({value:f.id,label:l(f.labelKey)})),onChange:qn,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const f=Ol.find(vt=>vt.id===es);return f?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(f.descriptionKey)}):null})()]}),ka&&s.jsx(ze,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:pn||Ln||S,children:s.jsxs(En,{className:"lg:gap-y-6",children:[ge("userMessageRendering")&&s.jsx(As,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:Yx.map(f=>s.jsx(Ys,{selected:nb(V)===f.id,onSelect:()=>Cs(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(f.labelKey)})},f.id))})}),ge("mermaidRendering")&&s.jsx(As,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:Qx.map(f=>s.jsx(Ys,{selected:P===f.id,onSelect:()=>ir(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(f.labelKey)})},f.id))})}),ge("diffLayout")&&!hs&&s.jsx(As,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:Jx.map(f=>s.jsx(Ys,{selected:Ne===f.id,onSelect:()=>Re(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(f.labelKey)})},f.id))})}),ge("followUpBehavior")&&s.jsx(As,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:eb.map(f=>s.jsx(Ys,{selected:Ke===f.id,onSelect:()=>tt(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(f.labelKey)})},f.id))})}),ge("inputHistoryScope")&&s.jsx(As,{title:r("settings.openchamber.visual.field.inputHistoryScope"),info:r("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.section.inputHistoryScopeAria"),children:sb.map(f=>s.jsx(Ys,{selected:Y===f.id,onSelect:()=>$a(f.id),label:l(f.labelKey),ariaLabel:l(f.labelKey)},f.id))})}),ge("inputHistoryLimit")&&s.jsx(As,{title:r("settings.openchamber.visual.field.inputHistoryLimit"),description:r("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Hs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:Ca,children:[s.jsx(ks,{value:Se,onValueChange:ar,min:zu,max:Ku,step:1,className:Ds,deferExternalValueWhileFocused:!0,"aria-label":r("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Ia,children:r("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),cr&&s.jsxs(s.Fragment,{children:[ge("expandedTools")&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:pn||Ln||ka||S,contentClassName:fs,children:[s.jsx(mt,{checked:Oe,onChange:gi,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(mt,{checked:X,onChange:or,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(ze,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(mt,{checked:Qe,onChange:Pn,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ge("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(mt,{checked:d,onChange:g,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(mt,{checked:j,onChange:w,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ge("subagentReadOnlyBanner")&&s.jsx(mt,{checked:ns,onChange:Zt,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ge("sessionGoal")&&!hs&&s.jsxs(ze,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:fs,children:[s.jsx(mt,{checked:b,onChange:k,label:r("settings.openchamber.visual.field.sessionGoal"),ariaLabel:r("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(mt,{checked:p,onChange:C,disabled:!b,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),b&&p?s.jsx(ks,{value:E,onValueChange:f=>{typeof f=="number"&&Number.isFinite(f)&&f>0&&A(Math.floor(f))},min:1e3,max:1e8,step:5e4}):null]})]}),ge("reasoning")&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(mt,{checked:v,onChange:N,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),v&&s.jsx(mt,{checked:R,onChange:T,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(ze,{title:r("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(mt,{checked:h,onChange:y,label:r("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:r("settings.openchamber.visual.field.streamingAutoFollowAria"),info:r("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("splitAssistantMessageActions")||ge("codeBlockLineWrap"))&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[ge("collapsibleUserMessages")&&s.jsx(mt,{checked:I,onChange:Fn,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ge("stickyUserHeader")&&s.jsx(mt,{checked:H,onChange:tn,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ge("promptNavigatorEnabled")&&!hs&&s.jsx(mt,{checked:U,onChange:fa,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ge("wideChatLayout")&&s.jsx(mt,{checked:_,onChange:fo,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ge("splitAssistantMessageActions")&&s.jsx(mt,{checked:Ge,onChange:mn,label:r("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ge("codeBlockLineWrap")&&s.jsx(mt,{checked:q,onChange:L,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ge("showToolFileIcons")||ge("showTurnChangedFiles")||ge("dotfiles")&&!ds()||ge("fileViewerPreview"))&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[ge("showToolFileIcons")&&s.jsx(mt,{checked:ft,onChange:ba,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ge("showTurnChangedFiles")&&s.jsx(mt,{checked:Je,onChange:va,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ge("dotfiles")&&!ds()&&s.jsx(mt,{checked:u,onChange:Uu,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ge("fileViewerPreview")&&s.jsx(mt,{checked:ts,onChange:rr,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ge("persistDraft")||ge("largeTextPaste")||!m&&ge("inputSpellcheck")||ge("enterToSend"))&&s.jsxs(ze,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ge("persistDraft")||!m&&ge("inputSpellcheck"))&&s.jsxs("div",{className:fs,children:[ge("persistDraft")&&s.jsx(mt,{checked:lt,onChange:at,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!m&&ge("inputSpellcheck")&&s.jsx(mt,{checked:pt,onChange:nr,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ge("largeTextPaste")&&s.jsx(As,{title:r("settings.openchamber.visual.field.largeTextPaste"),description:r("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(an,{"aria-label":r("settings.openchamber.visual.field.largeTextPasteAria"),children:tb.map(f=>s.jsx(Ys,{selected:Q===f.id,onSelect:()=>qe(f.id),label:l(f.labelKey),ariaLabel:r("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(f.labelKey)})},f.id))})}),ge("enterToSend")&&s.jsx(As,{title:r("settings.openchamber.visual.field.enterToSend"),description:r("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(an,{"aria-label":r("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(Ys,{selected:st,onSelect:()=>Hn(!0),label:r("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:r("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(Ys,{selected:!st,onSelect:()=>Hn(!1),label:r("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:r("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ge("reportUsage")&&s.jsx(ze,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(mt,{checked:ui,onChange:er,label:r("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:r("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},rb=1,ob=365,zl=30,lb=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Jc=()=>{const t=ct.c(105),{t:e}=et(),a=ce(cb),n=ce(db),i=ce(ub),r=ce(mb),l=ce(pb),m=ce(gb),c=ce(hb);let x;t[0]===Symbol.for("react.memo_cache_sentinel")?(x={autoRun:!1},t[0]=x):x=t[0];const{candidates:u,isRunning:v,runCleanup:d,action:j,status:g}=Yd(x),w=u.length;let b;t[1]!==d||t[2]!==e?(b=async()=>{const ue=await d({force:!0}).catch(()=>(F.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!ue||ue.skippedReason&&ue.skippedReason!=="no-candidates")){if(ue.completedIds.length===0&&ue.failedIds.length===0){F.message(ue.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ue.completedIds.length>0&&F.success(ue.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ue.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ue.completedIds.length})),ue.failedIds.length>0&&F.error(ue.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ue.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ue.failedIds.length}))}},t[1]=d,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 C=i?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let E;t[6]!==e||t[7]!==C?(E=e(C),t[6]=e,t[7]=C,t[8]=E):E=t[8];let A;t[9]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=A):A=t[10];let N;t[11]!==e?(N=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=N):N=t[12];let h;t[13]!==a||t[14]!==r||t[15]!==A||t[16]!==N?(h=s.jsx(mt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:A,ariaLabel:N}),t[13]=a,t[14]=r,t[15]=A,t[16]=N,t[17]=h):h=t[17];let y;t[18]!==e?(y=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=y):y=t[19];let R;t[20]!==e?(R=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=R):R=t[21];let T;t[22]!==e?(T=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=T):T=t[23];let P;t[24]!==v||t[25]!==i||t[26]!==c||t[27]!==T||t[28]!==y||t[29]!==R?(P=s.jsx(mt,{settingsItem:"sessions.retention-only-archived",checked:i,onChange:c,disabled:v,label:y,ariaLabel:R,info:T}),t[24]=v,t[25]=i,t[26]=c,t[27]=T,t[28]=y,t[29]=R,t[30]=P):P=t[30];let D;t[31]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=D):D=t[32];let V;t[33]!==e?(V=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=V):V=t[34];let $;t[35]===Symbol.for("react.memo_cache_sentinel")?($=ye(Ds,"tabular-nums"),t[35]=$):$=t[35];let I;t[36]!==n||t[37]!==l||t[38]!==V?(I=s.jsx(ks,{value:n,onValueChange:l,min:rb,max:ob,step:1,"aria-label":V,className:$}),t[36]=n,t[37]=l,t[38]=V,t[39]=I):I=t[39];let M;t[40]!==e?(M=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=M):M=t[41];let H;t[42]!==M?(H=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M}),t[42]=M,t[43]=H):H=t[43];let U;t[44]!==l?(U=()=>l(zl),t[44]=l,t[45]=U):U=t[45];const Z=n===zl;let ee;t[46]!==e?(ee=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=ee):ee=t[47];let O;t[48]!==e?(O=e("settings.common.actions.reset"),t[48]=e,t[49]=O):O=t[49];let ae;t[50]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=ae):ae=t[50];let _;t[51]!==U||t[52]!==Z||t[53]!==ee||t[54]!==O?(_=s.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:U,disabled:Z,className:ws,"aria-label":ee,title:O,children:ae}),t[51]=U,t[52]=Z,t[53]=ee,t[54]=O,t[55]=_):_=t[55];let W;t[56]!==D||t[57]!==I||t[58]!==H||t[59]!==_?(W=s.jsxs(Ft,{settingsItem:"sessions.retention-period",label:D,children:[I,H,_]}),t[56]=D,t[57]=I,t[58]=H,t[59]=_,t[60]=W):W=t[60];let q;t[61]!==e?(q=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=q):q=t[62];let L;t[63]!==i||t[64]!==e?(L=lb.map(ue=>({value:ue.value,label:e(ue.labelKey),disabled:i&&ue.value==="archive"})),t[63]=i,t[64]=e,t[65]=L):L=t[65];let K;t[66]!==j||t[67]!==m||t[68]!==L?(K=s.jsx(cn,{value:j,onChange:m,options:L}),t[66]=j,t[67]=m,t[68]=L,t[69]=K):K=t[69];let z;t[70]!==q||t[71]!==K?(z=s.jsx(Ft,{settingsItem:"sessions.retention-action",label:q,children:K}),t[70]=q,t[71]=K,t[72]=z):z=t[72];let J;t[73]!==P||t[74]!==W||t[75]!==z?(J=s.jsxs(za,{className:"space-y-0",children:[P,W,z]}),t[73]=P,t[74]=W,t[75]=z,t[76]=J):J=t[76];let oe;t[77]!==e?(oe=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=oe):oe=t[78];let re;t[79]!==v||t[80]!==e?(re=e(v?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=v,t[80]=e,t[81]=re):re=t[81];let pe;t[82]!==k||t[83]!==v||t[84]!==re?(pe=s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:k,disabled:v,className:"!font-normal",children:re}),t[82]=k,t[83]=v,t[84]=re,t[85]=pe):pe=t[85];let ve;t[86]!==oe||t[87]!==pe?(ve=s.jsx(Ft,{label:oe,children:pe}),t[86]=oe,t[87]=pe,t[88]=ve):ve=t[88];let be;t[89]!==j||t[90]!==w||t[91]!==g||t[92]!==e?(be=g==="error"?e("sessions.sidebar.group.empty.loadFailed"):g!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):j==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:w}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:w}),t[89]=j,t[90]=w,t[91]=g,t[92]=e,t[93]=be):be=t[93];let te;t[94]!==be?(te=s.jsx("p",{className:"typography-meta text-muted-foreground",children:be}),t[94]=be,t[95]=te):te=t[95];let he;t[96]!==ve||t[97]!==te?(he=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[ve,te]}),t[96]=ve,t[97]=te,t[98]=he):he=t[98];let ie;return t[99]!==p||t[100]!==J||t[101]!==he||t[102]!==E||t[103]!==h?(ie=s.jsxs(ze,{title:p,info:E,children:[h,J,he]}),t[99]=p,t[100]=J,t[101]=he,t[102]=E,t[103]=h,t[104]=ie):ie=t[104],ie};function cb(t){return t.autoDeleteEnabled}function db(t){return t.autoDeleteAfterDays}function ub(t){return t.sessionRetentionOnlyArchived}function mb(t){return t.setAutoDeleteEnabled}function pb(t){return t.setAutoDeleteAfterDays}function gb(t){return t.setSessionRetentionAction}function hb(t){return t.setSessionRetentionOnlyArchived}const Ul=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(eo(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Qc=()=>{const{t}=et(),e=ce(h=>h.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,m]=o.useState(!1),[c,x]=o.useState(null),[u,v]=o.useState(!1),[d,j]=o.useState([]),[g,w]=o.useState(Zd),[b,k]=o.useState(""),p=o.useMemo(()=>Xd(),[]),C=o.useCallback(async()=>{r(!0),k("");try{const h=await eu();j(h)}catch(h){const y=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.loadFailed");k(y)}finally{r(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!p.supported){h||(n(!1),r(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const y=await pr();if(w(y),!y.enabled){j([]),r(!1);return}await C()}})(),()=>{h=!0,No()}},[C,p.supported]);const E=o.useCallback(async()=>{if(!g.enabled){const h=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(h),F.message(h);return}if(!a){k(p.reason),F.message(p.reason);return}if(l){No(),m(!1);return}k(""),m(!0);try{await tu(),w(await pr()),await C(),F.success(t("settings.openchamber.passkeys.toast.added"))}catch(h){if(su(h)){F.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const y=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.addFailed");k(y),F.error(y)}finally{m(!1)}},[l,C,g.enabled,p.reason,a,t]),A=o.useCallback(async h=>{x(h),k("");try{await nu(h),w(await pr()),await C(),F.success(t("settings.openchamber.passkeys.toast.removed"))}catch(y){const R=y instanceof Error?y.message:t("settings.openchamber.passkeys.toast.removeFailed");k(R),F.error(R)}finally{x(null)}},[C,t]),N=o.useCallback(async()=>{v(!0),k("");try{await au(),window.location.reload()}catch(h){const y=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(y),F.error(y),v(!1)}},[t]);return s.jsxs(ze,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ft,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(G,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{E()},disabled:i||u,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:()=>{N()},disabled:i||l||u,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(u?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!g.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),g.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:p.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):d.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:d.map(h=>s.jsxs(Ft,{label:s.jsx("span",{title:h.label,children:h.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Ul(h.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Ul(h.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A(h.id)},disabled:c===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===h.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},Yc=()=>{const t=ct.c(14),{t:e}=et(),a=So(fb),n=So(xb);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=r):r=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):a.map(x=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${x}://`}),s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(x),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${x}://`}),children:e("settings.common.actions.delete")})]},x)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let m;t[8]!==l?(m=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=m):m=t[9];let c;return t[10]!==i||t[11]!==r||t[12]!==m?(c=s.jsx(ze,{title:i,description:r,children:m}),t[10]=i,t[11]=r,t[12]=m,t[13]=c):c=t[13],c};function fb(t){return t.trustedSchemes}function xb(t){return t.removeTrustedScheme}const Ar=t=>{const e=la(t);return e||{providerId:"",modelId:""}},Zc=()=>{const{t}=et(),e=Xe(te=>te.setProvider),a=Xe(te=>te.setModel),n=Xe(te=>te.setAgent),i=Xe(te=>te.setCurrentVariant),r=Xe(te=>te.setCurrentVariantOverride),l=Xe(te=>te.setSettingsDefaultModel),m=Xe(te=>te.setSettingsDefaultVariant),c=Xe(te=>te.setSettingsDefaultAgent),x=Xe(te=>te.selectionSource==="manual"),u=iu(te=>te.currentSessionId),v=Co(te=>te.getSessionModelSelection),d=Co(te=>te.getSessionAgentSelection),j=Xe(te=>te.agentSelectionSource==="manual"),w=!!(Xe(te=>{if(te.agentSelectionSource!=="manual")return!1;const he=te.agents.find(ie=>ie.name===te.currentAgentName);return!!(he?.model?.providerID&&he.model.modelID)})||x&&u&&v(u)),b=!!(j&&u&&d(u)),k=ce(te=>te.showDeletionDialog),p=ce(te=>te.setShowDeletionDialog),C=Xe(te=>te.providers),E=Xe(te=>te.modelsMetadata),[A,N]=o.useState(),[h,y]=o.useState(),[R,T]=o.useState(),[P,D]=o.useState(!0),[V,$]=o.useState(),[I,M]=o.useState([]),[H,U]=o.useState(),[Z,ee]=o.useState(!0),O=o.useMemo(()=>Ar(A),[A]);o.useEffect(()=>{(async()=>{try{const he=await In();if(he){const ie=he.defaultModel?.trim()||void 0,ue=he.defaultVariant?.trim()||void 0,de=he.defaultAgent?.trim()||void 0;ie!==void 0&&N(ie),ue!==void 0&&y(ue),de!==void 0&&T(de),he.smallModelUseDefault!==void 0&&D(he.smallModelUseDefault);const Pe=he.smallModelOverride?.trim();Pe&&$(Pe);const Ae=he.walkthroughModelOverride?.trim();Ae&&U(Ae)}}catch(he){console.warn("Failed to load defaults settings:",he)}finally{ee(!1)}})()},[]);const ae=o.useCallback(async(te,he)=>{const ie=te&&he?`${te}/${he}`:void 0;N(ie),y(void 0),m(void 0),l(ie),w||(i(void 0),te&&he&&(C.find(de=>de.id===te)||gc(te,he))&&(e(te),a(he)));try{await yt({defaultModel:ie??"",defaultVariant:""})}catch(ue){console.warn("Failed to save default model:",ue)}},[w,C,i,a,e,l,m]),_="__default__",W=o.useCallback(te=>te===_?t("settings.openchamber.defaults.option.default"):te.charAt(0).toUpperCase()+te.slice(1),[t]),q=o.useCallback(async te=>{const he=te===_?void 0:te||void 0;y(he),m(he),w||r(he??null,he);try{await yt({defaultVariant:he??""})}catch(ie){console.warn("Failed to save default variant:",ie)}},[w,r,m]),L=o.useCallback(async te=>{const he=te||void 0;T(he),c(he),te&&!b&&n(te);try{await yt({defaultAgent:he??""})}catch(ie){console.warn("Failed to save default agent:",ie)}},[b,n,c]),K=o.useCallback(async te=>{D(te);try{await yt({smallModelUseDefault:te})}catch(he){console.warn("Failed to save small model preference:",he)}},[]),z=o.useCallback(async(te,he)=>{const ie=te&&he?`${te}/${he}`:void 0;$(ie);try{await yt({smallModelOverride:ie??""})}catch(ue){console.warn("Failed to save small model override:",ue)}},[]),J=o.useCallback(async(te,he)=>{const ie=te&&he?`${te}/${he}`:void 0;U(ie);try{await yt({walkthroughModelOverride:ie??""})}catch(ue){console.warn("Failed to save walkthrough model override:",ue)}},[]),oe=o.useCallback((te,he)=>E.get(`${te}/${he}`)?.structured_output!==!1,[E]),re=o.useMemo(()=>Ar(V),[V]),pe=o.useMemo(()=>Ar(H),[H]);o.useEffect(()=>{let te=!1;return(async()=>{try{const he=await xt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!he.ok)return;const ie=await he.json().catch(()=>null);!te&&Array.isArray(ie?.authenticatedProviders)&&M(ie.authenticatedProviders.filter(ue=>typeof ue=="string"))}catch{}})(),()=>{te=!0}},[]);const ve=o.useMemo(()=>{if(!O.providerId||!O.modelId)return[];const ie=C.find(ue=>ue.id===O.providerId)?.models.find(ue=>ue.id===O.modelId)?.variants;return ie?Object.keys(ie):[]},[O.modelId,O.providerId,C]),be=ve.length>0;return Z?null:s.jsx(s.Fragment,{children:s.jsx(ze,{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")," ",O.providerId?s.jsxs("span",{className:"text-foreground",children:[O.providerId,"/",O.modelId,be?` (${h??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),R&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:R})]})]}),s.jsxs("div",{children:[s.jsx(Ft,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(na,{providerId:O.providerId,modelId:O.modelId,onChange:ae,className:on,offerAuto:!0})}),s.jsx(Ft,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Tt,{value:h??_,onValueChange:q,disabled:!be,children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:W(h??_)})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:_,children:t("settings.openchamber.defaults.option.default")}),ve.map(te=>s.jsx(dt,{value:te,children:W(te)},te))]})]})}),s.jsx(Ft,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(Qr,{agentName:R||"",onChange:L,filter:te=>hc(te.mode),className:on})})]}),s.jsx(za,{className:fs,children:s.jsx(mt,{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(dn,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(mt,{settingsItem:"sessions.small-model",checked:P,onChange:te=>{K(te)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),P?null:s.jsx(Ft,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(na,{providerId:re.providerId,modelId:re.modelId,onChange:z,allowedProviderIds:I,className:on})}),s.jsxs(za,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(dn,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ft,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(na,{providerId:pe.providerId,modelId:pe.modelId,onChange:J,allowedProviderIds:I,isModelAllowed:oe,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:on})})]})]})]})})})},_l={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"}},bb={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"},vb=()=>{const{t}=et(),e=o.useMemo(()=>cs(),[]),a=o.useMemo(()=>ds(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=ce(_=>_.nativeNotificationsEnabled),l=ce(_=>_.setNativeNotificationsEnabled),m=ce(_=>_.notificationMode),c=ce(_=>_.setNotificationMode),x=ce(_=>_.notifyOnSubtasks),u=ce(_=>_.setNotifyOnSubtasks),v=ce(_=>_.notifyOnCompletion),d=ce(_=>_.setNotifyOnCompletion),j=ce(_=>_.notifyOnError),g=ce(_=>_.setNotifyOnError),w=ce(_=>_.notifyOnQuestion),b=ce(_=>_.setNotifyOnQuestion),k=ce(_=>_.notificationTemplates),p=ce(_=>_.setNotificationTemplates),[C,E]=o.useState("default"),[A,N]=o.useState(!1),[h,y]=o.useState(!1),[R,T]=o.useState(!1);o.useEffect(()=>{if(!i){N(!1),y(!1);return}typeof Notification<"u"&&E(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;N(_),(async()=>{if(!_){y(!1);return}try{const q=await navigator.serviceWorker.getRegistration();if(!q){y(!1);return}const L=await q.pushManager.getSubscription();y(!!L)}catch{y(!1)}})()},[i]);const P=async _=>{if(e){l(_);return}if(!i){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const W=await Notification.requestPermission();E(W),W==="granted"?l(!0):F.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(W){console.error("Failed to request notification permission:",W),F.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&C==="granted"))},D=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",V=(_,W,q)=>{p(L=>({...L,[_]:{...L[_],[W]:q}}))},$=_=>{const W="=".repeat((4-_.length%4)%4),q=(_+W).replace(/-/g,"+").replace(/_/g,"/"),L=atob(q),K=new Uint8Array(L.length);for(let z=0;z<L.length;z+=1)K[z]=L.charCodeAt(z);return K},I=async(_,W,q)=>{let L=null;const K=new Promise((z,J)=>{L=setTimeout(()=>{J(new Error(q))},W)});try{return await Promise.race([_,K])}finally{L&&clearTimeout(L)}},M=async _=>{if(_.active)return;const W=_.installing||_.waiting;W&&W.state!=="activated"&&await I(new Promise(q=>{const L=()=>{W.state==="activated"&&(W.removeEventListener("statechange",L),q())};W.addEventListener("statechange",L),L()}),15e3,"Service worker activation timed out")},H=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const _=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let W=null;for(const q of _)try{const L=q.opts?navigator.serviceWorker.register("/sw.js",q.opts):navigator.serviceWorker.register("/sw.js");return await I(L,1e4,`Service worker registration timed out (${q.label})`)}catch(L){W=L}throw W instanceof Error?W:new Error("Service worker registration failed")},U=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const W=await H();try{await W.update()}catch{}return await M(W),W},Z=_=>{const W=_,q=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(W?.name??"")}`,`message=${String(W?.message??"")}`];let L="";try{L=JSON.stringify(_)}catch{}return{summary:q.filter(Boolean).join(" | "),json:L,stack:typeof W?.stack=="string"?W.stack:""}},ee=async()=>{const _=Fa();if(!_?.notifications){F.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await _.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?F.success(t("settings.notifications.page.toast.testNotificationSent")):F.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(W){console.error("Test notification failed:",W),F.error(t("settings.notifications.page.toast.testNotificationFailed"))}},O=async()=>{if(!A){F.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=Fa();if(!_?.push){F.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const re=await Notification.requestPermission();if(E(re),re!=="granted"){F.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){F.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const W=await _.push.getVapidPublicKey();if(!W?.publicKey){F.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const q=await U();await M(q);const L=await q.pushManager.getSubscription();if(!("pushManager"in q)||!q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const z=(L??await I(q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:$(W.publicKey)}),15e3,"Push subscription timed out")).toJSON(),J=z.keys;if(!z.endpoint||!J?.p256dh||!J.auth)throw new Error("Push subscription missing keys");if(!(await I(_.push.subscribe({endpoint:z.endpoint,keys:{p256dh:J.p256dh,auth:J.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:_u()}),15e3,"Push subscribe request timed out"))?.ok){F.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}y(!0),F.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(W){console.error("[Push] Enable failed:",W);const q=Z(W);F.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:q.summary})}finally{T(!1)}},ae=async()=>{if(!A){y(!1);return}const _=Fa();if(!_?.push){F.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const q=await(await U()).pushManager.getSubscription();if(!q){y(!1);return}const L=q.endpoint;await q.unsubscribe(),await _.push.unsubscribe({endpoint:L}),y(!1),F.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(ze,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(mt,{checked:r&&D,onChange:_=>{P(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&D&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(mt,{checked:m==="always",onChange:_=>c(_?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{ee()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[C==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),C==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&D&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(mt,{checked:v,onChange:d,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(mt,{checked:x,onChange:u,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(mt,{checked:j,onChange:g,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(mt,{checked:w,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(ze,{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(En,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(_=>s.jsxs("section",{className:"p-2",children:[s.jsx(dn,{className:"capitalize",children:t(bb[_])}),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(Be,{value:k[_].title,onChange:W=>V(_,"title",W.target.value),className:"h-7",placeholder:t(_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(Be,{value:k[_].message,onChange:W=>V(_,"message",W.target.value),className:"h-7",placeholder:t(_l[_].messageKey)})]})]})]},_))})})]}),i&&s.jsx(ze,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(mt,{checked:A?h:!1,disabled:!A||R,onChange:_=>{_?O():ae()},label:t("settings.notifications.page.push.enableLabel"),description:A?void 0:t("settings.notifications.page.push.unsupportedHint"),info:A?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:R?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})})]})},zs=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Tn="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",yb=[{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"}],$l=t=>{const e=ct.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let m;e[2]!==n?(m=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=m):m=e[3];let c;return e[4]!==i||e[5]!==l||e[6]!==m?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,m]}),e[4]=i,e[5]=l,e[6]=m,e[7]=c):c=e[7],c},jb=({selectedModelId:t,onSelect:e})=>{const{t:a}=et(),n=Ze.useCallback(d=>a(d),[a]),[i,r]=Ze.useState(new Map),[l,m]=Ze.useState(null),c=Ze.useCallback(async()=>{try{const d=await xt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const j=await d.json();Array.isArray(j?.models)&&r(new Map(j.models.map(g=>[g.id,g])))}catch{}},[]);Ze.useEffect(()=>{c()},[c]);const x=Array.from(i.values()).some(d=>d.downloading);Ze.useEffect(()=>{if(!x)return;const d=setInterval(()=>{c()},2e3);return()=>clearInterval(d)},[x,c]);const u=async d=>{m(d);try{await xt(`/api/dictation/models/${encodeURIComponent(d)}/download`,{method:"POST"}),await c()}catch{}finally{m(null)}},v=async d=>{m(d);try{await xt(`/api/dictation/models/${encodeURIComponent(d)}`,{method:"DELETE"}),await c()}catch{}finally{m(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:yb.map(d=>{const j=t===d.id,g=i.get(d.id)??null;return s.jsx("div",{className:ye("rounded-lg border border-[var(--interactive-border)] p-3",j&&"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(d.id),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),e(d.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(Yr,{checked:j,onChange:()=>e(d.id),ariaLabel:n(d.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:ye("typography-ui-label font-normal",j?"text-foreground":"text-foreground/50"),children:n(d.labelKey)}),d.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(d.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx($l,{value:d.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx($l,{value:d.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:d.size})]}),g?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:g.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:g?.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===d.id,onClick:()=>{v(d.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")})]}):g?.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 g.downloadProgress=="number"?`${g.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===d.id,onClick:()=>{u(d.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"})})})]})},d.id)})})},wb=[{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)"}],qr="kokoro-en-v0_19",kb="kokoro-multi-lang-v1_1",Nb=[{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)"}],Za=(t,e)=>`${t}:${e}`,Sb=()=>{const[t,e]=Ze.useState([]),[a,n]=Ze.useState(null),i=Ze.useCallback(async()=>{try{const m=await xt("/api/dictation/status",{query:{provider:"local"}});if(!m.ok)return;const c=await m.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);Ze.useEffect(()=>{i()},[i]);const r=t.some(m=>m.downloading);Ze.useEffect(()=>{if(!r)return;const m=setInterval(()=>{i()},2e3);return()=>clearInterval(m)},[r,i]);const l=Ze.useCallback(async(m,c)=>{n(m);try{const x=c==="POST"?`/api/dictation/models/${m}/download`:`/api/dictation/models/${m}`;await xt(x,{method:c}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},Cb=t=>{const e=wb.map(a=>({modelId:qr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===qr||!a.installed)){if(a.id===kb){for(const n of Nb)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},Ib=t=>{const e=ct.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=et();let l,m,c;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){c=Symbol.for("react.early_return_sentinel");e:{const u=a.filter(Tb);if(u.length===0){c=null;break e}l="flex flex-col";let v;e[7]!==i||e[8]!==n||e[9]!==r?(v=d=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:d.description??d.id}),d.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("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:()=>{i(d.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})]}):d.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 d.downloadProgress=="number"?`${d.downloadProgress}%`:""})]}):s.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(d.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(B,{name:"download",className:"h-4 w-4"})}),d.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:d.downloadError}):null]},d.id),e[7]=i,e[8]=n,e[9]=r,e[10]=v):v=e[10],m=u.map(v)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=m,e[6]=c}else l=e[4],m=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let x;return e[11]!==l||e[12]!==m?(x=s.jsx("div",{className:l,children:m}),e[11]=l,e[12]=m,e[13]=x):x=e[13],x},Pb=[{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"}],Ab=()=>{const{t}=et(),{isMobile:e}=ha(),a=Xe(Q=>Q.voiceProvider),n=Xe(Q=>Q.setVoiceProvider),i=Xe(Q=>Q.speechRate),r=Xe(Q=>Q.setSpeechRate),l=Xe(Q=>Q.speechPitch),m=Xe(Q=>Q.setSpeechPitch),c=Xe(Q=>Q.speechVolume),x=Xe(Q=>Q.setSpeechVolume),u=Xe(Q=>Q.sayVoice),v=Xe(Q=>Q.setSayVoice),d=Xe(Q=>Q.localTtsVoiceId),j=Xe(Q=>Q.localTtsModelId),g=Xe(Q=>Q.setLocalTtsModelId),w=Sb(),b=Ze.useMemo(()=>Cb(w.models),[w.models]),k=Xe(Q=>Q.ttsFollowTextLanguage),p=Xe(Q=>Q.setTtsFollowTextLanguage),C=Xe(Q=>Q.setLocalTtsVoiceId),{speak:E,stop:A,isPlaying:N,error:h}=ru(),y=Ze.useCallback(()=>{if(N){A();return}const Q=b.find(qe=>qe.modelId===j&&qe.speakerId===d)?.label??String(d);E(t("settings.voice.page.preview.voiceLine",{voiceName:Q}),{model:j,speakerId:d,speed:Xe.getState().speechRate})},[N,j,d,b,E,A,t]),R=Xe(Q=>Q.browserVoice),T=Xe(Q=>Q.setBrowserVoice),P=Xe(Q=>Q.openaiVoice),D=Xe(Q=>Q.setOpenaiVoice),V=Xe(Q=>Q.openaiApiKey),$=Xe(Q=>Q.setOpenaiApiKey),I=Xe(Q=>Q.openaiCompatibleUrl),M=Xe(Q=>Q.setOpenaiCompatibleUrl),H=Xe(Q=>Q.openaiCompatibleApiKey),U=Xe(Q=>Q.setOpenaiCompatibleApiKey),Z=Xe(Q=>Q.openaiCompatibleVoice),ee=Xe(Q=>Q.setOpenaiCompatibleVoice),O=Xe(Q=>Q.openaiCompatibleTtsModel),ae=Xe(Q=>Q.setOpenaiCompatibleTtsModel),_=Xe(Q=>Q.showMessageTTSButtons),W=Xe(Q=>Q.ttsInputMode),q=Xe(Q=>Q.setTtsInputMode),L=Xe(Q=>Q.sttProvider),K=Xe(Q=>Q.setSttProvider),z=Xe(Q=>Q.sttServerUrl),J=Xe(Q=>Q.setSttServerUrl),oe=Xe(Q=>Q.sttApiKey),re=Xe(Q=>Q.setSttApiKey),pe=Xe(Q=>Q.sttModel),ve=Xe(Q=>Q.setSttModel),be=Xe(Q=>Q.sttLocalModel),te=Xe(Q=>Q.setSttLocalModel),he=Xe(Q=>Q.sttLanguage),ie=Xe(Q=>Q.setSttLanguage),ue=Xe(Q=>Q.setShowMessageTTSButtons),de=Xe(Q=>Q.dictationEnabled),Pe=Xe(Q=>Q.setDictationEnabled),[Ae,we]=Ze.useState(!1),[Le,_e]=Ze.useState([]),[Ve,je]=Ze.useState(!1),[ke,se]=Ze.useState(null),[le,Ie]=Ze.useState(!1),[Ne,Re]=Ze.useState(!1),[$e,De]=Ze.useState(null),[Ce,Ye]=Ze.useState(!1),[xe,Te]=Ze.useState(null),[Ke,tt]=Ze.useState([]),[Y,Se]=Ze.useState(!1);Ze.useEffect(()=>((async()=>{const qe=await gr.waitForVoices();tt(qe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{tt(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ee=Ze.useMemo(()=>Ke.filter(Q=>Q.lang).sort((Q,qe)=>{const it=Q.lang.startsWith("en"),ut=qe.lang.startsWith("en");if(it&&!ut)return-1;if(!it&&ut)return 1;const gt=Q.lang.localeCompare(qe.lang);return gt!==0?gt:Q.name.localeCompare(qe.name)}),[Ke]),We=Ze.useCallback(()=>{if(Y){gr.cancelSpeech(),Se(!1);return}const Q=Ke.find(gt=>gt.name===R),qe=Q?.name??t("settings.voice.page.preview.browserVoiceFallback"),it=t("settings.voice.page.preview.voiceLine",{voiceName:qe});Se(!0);const ut=new SpeechSynthesisUtterance(it);ut.rate=i,ut.pitch=l,ut.volume=c,Q&&(ut.voice=Q,ut.lang=Q.lang),ut.onend=()=>Se(!1),ut.onerror=()=>Se(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(ut)},[R,Ke,i,l,c,Y,t]);Ze.useEffect(()=>()=>{Y&&gr.cancelSpeech()},[Y]),Ze.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){Ie(V.trim().length>0);return}(async()=>{try{const ut=(await(await xt("/api/tts/status")).json()).available,gt=V.trim().length>0;Ie(ut||gt)}catch{Ie(V.trim().length>0)}})()},[V,_,a]),Ze.useEffect(()=>{if(!_){we(!1),_e([]);return}xt("/api/tts/say/status").then(Q=>Q.json()).then(Q=>{if(we(Q.available),Q.voices){const qe=Q.voices.filter((it,ut,gt)=>gt.findIndex(Ot=>Ot.name===it.name)===ut).sort((it,ut)=>it.name.localeCompare(ut.name));_e(qe)}}).catch(()=>{we(!1)})},[_]);const lt=Ze.useCallback(async()=>{if(ke){zs(ke),se(null),je(!1);return}je(!0);let Q=null;try{const qe=await xt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:u}),voice:u,rate:Math.round(100+(i-.5)*200)})});if(!qe.ok)throw new Error("Preview failed");const it=await qe.blob(),ut=URL.createObjectURL(it);Q=new Audio(ut),Q.onended=()=>{zs(Q),se(null),je(!1)},Q.onerror=()=>{zs(Q),se(null),je(!1)},se(Q),await Q.play()}catch{zs(Q),se(null),je(!1)}},[u,i,ke,t]);Ze.useEffect(()=>()=>{zs(ke)},[ke]);const at=Ze.useCallback(async()=>{if($e){zs($e),De(null),Re(!1);return}Re(!0);let Q=null;try{const qe=await xt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:P}),voice:P,speed:i,apiKey:V||void 0})});if(!qe.ok){const gt=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(gt.error||`HTTP ${qe.status}`)}const it=await qe.blob(),ut=URL.createObjectURL(it);Q=new Audio(ut),Q.onended=()=>{zs(Q),De(null),Re(!1)},Q.onerror=()=>{zs(Q),De(null),Re(!1)},De(Q),await Q.play()}catch{zs(Q),De(null),Re(!1)}},[P,i,$e,V,t]);Ze.useEffect(()=>()=>{zs($e)},[$e]);const pt=Ze.useCallback(async()=>{if(xe){zs(xe),Te(null),Ye(!1);return}if(!I.trim())return;Ye(!0);let Q=null;try{const qe=await xt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:Z,model:O||void 0,speed:i,baseURL:I,apiKey:H||void 0})});if(!qe.ok){const gt=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(gt.error||`HTTP ${qe.status}`)}const it=await qe.blob(),ut=URL.createObjectURL(it);Q=new Audio(ut),Q.onended=()=>{zs(Q),Te(null),Ye(!1)},Q.onerror=()=>{zs(Q),Te(null),Ye(!1)},Te(Q),await Q.play()}catch{zs(Q),Te(null),Ye(!1)}},[I,Z,O,H,i,xe,t]);Ze.useEffect(()=>()=>{zs(xe)},[xe]);const bt="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(ze,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(mt,{checked:_,onChange:ue,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),_&&s.jsxs(s.Fragment,{children:[s.jsx(As,{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(cn,{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")},...Ae?[{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:ye(Kt,!le&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye(rn,!le&&"text-[var(--status-error)]/80"),children:t(le&&!V?"settings.voice.page.field.apiKeyHintUsingConfig":le?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ye("relative",Hs),children:[s.jsx("input",{type:"password",value:V,onChange:Q=>$(Q.target.value),placeholder:"sk-...",className:Tn}),V&&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"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Kt,!I.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ye("relative",Hs),children:[s.jsx("input",{type:"text",value:I,onChange:Q=>M(Q.target.value),placeholder:"http://localhost:8880/v1",className:Tn}),I&&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:Kt,children:"API Key"}),s.jsx("span",{className:rn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Hs),children:[s.jsx("input",{type:"password",value:H,onChange:Q=>U(Q.target.value),placeholder:"sk-...",className:Tn}),H&&s.jsx("button",{type:"button",onClick:()=>U(""),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:Kt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Hs),children:s.jsx("input",{type:"text",value:O,onChange:Q=>ae(Q.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:Tn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Kt,children:t("settings.voice.page.field.voice")}),s.jsx(Yt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ye("flex items-center gap-2",Hs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:Z,onChange:Q=>ee(Q.target.value),placeholder:"af_sky",className:Tn})}),s.jsx(G,{size:"xs",variant:"ghost",onClick:pt,title:t("settings.voice.page.actions.preview"),disabled:!I.trim(),children:Ce?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(Ib,{...w}),(a==="local"||a==="say")&&s.jsx(mt,{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(Ft,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:Za(j,d),onValueChange:Q=>{const qe=b.find(it=>Za(it.modelId,it.speakerId)===Q);qe&&(g(qe.modelId),C(qe.speakerId))},children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:Q=>b.find(qe=>Za(qe.modelId,qe.speakerId)===Q)?.label??Q})}),s.jsx(Dt,{children:b.map(Q=>s.jsx(dt,{value:Za(Q.modelId,Q.speakerId),children:Q.label},Za(Q.modelId,Q.speakerId)))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:y,title:t("settings.voice.page.actions.preview"),children:N?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})}),h?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:h}):null]}),a==="openai"&&le&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:P,onValueChange:D,children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Dt,{children:Pb.map(Q=>s.jsx(dt,{value:Q.value,children:Q.label},Q.value))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:at,title:t("settings.voice.page.actions.preview"),children:Ne?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:rn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Ae&&Le.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:u,onValueChange:v,children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Dt,{children:Le.map(Q=>s.jsx(dt,{value:Q.name,children:Q.name},Q.name))})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:lt,title:t("settings.voice.page.actions.preview"),children:Ve?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"&&Ee.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:R||"$auto",onValueChange:Q=>T(Q==="$auto"?"":Q),children:[s.jsx(Et,{size:Bt,className:ln,children:s.jsx(Ut,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Dt,{children:[s.jsx(dt,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ee.map(Q=>s.jsxs(dt,{value:Q.name,children:[Q.name," (",Q.lang,")"]},Q.name))]})]}),s.jsx(G,{size:"xs",variant:"ghost",onClick:We,title:t("settings.voice.page.actions.preview"),children:Y?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(Ft,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:Q=>r(Number(Q.target.value)),className:bt}),s.jsx(ks,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:ye(Ds,"tabular-nums")})]}),s.jsxs(Ft,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:Q=>m(Number(Q.target.value)),className:bt}),s.jsx(ks,{value:l,onValueChange:m,min:.5,max:2,step:.1,className:ye(Ds,"tabular-nums")})]}),s.jsxs(Ft,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:Q=>x(Number(Q.target.value)),className:bt}),e?s.jsx(ks,{value:Math.round(c*100),onValueChange:Q=>x(Q/100),min:0,max:100,step:10,className:ye(Ds,"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(As,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(cn,{value:W,onChange:q,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(ze,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(mt,{checked:de,onChange:Pe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),de&&s.jsxs(s.Fragment,{children:[s.jsx(As,{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(cn,{value:L,onChange:K,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),L==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Kt,children:t("settings.voice.page.field.model")}),s.jsx(jb,{selectedModelId:be,onSelect:te})]}),L==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Kt,!z.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ye("relative",Hs),children:[s.jsx("input",{type:"text",value:z,onChange:Q=>J(Q.target.value),placeholder:"http://localhost:8001/v1",className:Tn}),z&&s.jsx("button",{type:"button",onClick:()=>J(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Kt,children:"API Key"}),s.jsx("span",{className:rn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Hs),children:[s.jsx("input",{type:"password",value:oe,onChange:Q=>re(Q.target.value),placeholder:"sk-...",className:Tn}),oe&&s.jsx("button",{type:"button",onClick:()=>re(""),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:Kt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Hs),children:s.jsx("input",{type:"text",value:pe,onChange:Q=>ve(Q.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:Tn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Kt,children:t("settings.voice.page.field.language")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:he,onChange:Q=>ie(Q.target.value),placeholder:"auto",className:Tn})})]})]})]})]})]})};function Tb(t){return t.id===qr||t.installed||t.downloading}const Ri=[{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}],Fi=[{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}],Eb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Db="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Tr=[{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"}],Mb=[".yml",".yaml",".json"],Rb="settings.openchamber.tunnel.error.invalidConfigExtension",Xa=t=>{const e=t.trim().toLowerCase();return Mb.some(a=>e.endsWith(a))},Fb=t=>t==="ngrok"?"ngrok":"cloudflared",Xc=()=>{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"},Ob=(t,e=Xc())=>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/",Er=(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():Fb(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Xc(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Ob(a,i);return{provider:a,dependency:n,installCommand:r}},ed=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Bl=t=>{const e=ct.c(11),{provider:a}=t;let n;e[0]!==a?(n=ed(a),e[0]=a,e[1]=n):n=e[1];const i=n,m=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==m?(c=ye("size-4 shrink-0",m),e[2]=m,e[3]=c):c=e[3];let x;e[4]!==c?(x=s.jsx(B,{name:"cloud",className:c}),e[4]=c,e[5]=x):x=e[5];let u;e[6]!==i?(u=s.jsx("span",{children:i}),e[6]=i,e[7]=u):u=e[7];let v;return e[8]!==x||e[9]!==u?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,u]}),e[8]=x,e[9]=u,e[10]=v):v=e[10],v},$n=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Gr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Vl=(t,e,a)=>{const n=Gr(t,e,a);return t.find(i=>i.value===n)?.label||n},Hl=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},Lb=(t,e)=>cc(t,e,{hour:"2-digit",precision:"second"}),_i=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()}},Kb=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",m=typeof r.name=="string"?r.name.trim():"",c=_i(typeof r.hostname=="string"?r.hostname:"");!l||!m||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:m,hostname:c}))}return n},zb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Ub=()=>{const{t}=et(),e=ce(X=>X.timeFormatPreference),a=o.useCallback(X=>t(X),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[m,c]=o.useState(null),[x,u]=o.useState(null),[v,d]=o.useState(null),[j,g]=o.useState(null),[w,b]=o.useState(!1),[k,p]=o.useState(!1),[C,E]=o.useState(!1),[A,N]=o.useState("cloudflare"),[h,y]=o.useState(()=>Er("cloudflare")),[R,T]=o.useState([]),[P,D]=o.useState("quick"),[V,$]=o.useState(null),[I,M]=o.useState([]),[H,U]=o.useState({}),[Z,ee]=o.useState(""),[O,ae]=o.useState({}),[_,W]=o.useState(new Set),[q,L]=o.useState(!1),[K,z]=o.useState(""),[J,oe]=o.useState(""),[re,pe]=o.useState(""),[ve,be]=o.useState(1800*1e3),[te,he]=o.useState(480*60*1e3),[ie,ue]=o.useState(""),[de,Pe]=o.useState([]),[Ae,we]=o.useState(()=>Date.now()),[Le,_e]=o.useState(null),Ve=t(Rb),je=o.useRef(null),ke=o.useMemo(()=>V?!Xa(V):!1,[V]),se=o.useMemo(()=>I.find(X=>X.id===Z)||I[0]||null,[I,Z]),le=o.useMemo(()=>de.map(X=>{const fe=X.expiresAt<=Ae,Fe=X.status==="active"&&!fe,Me=Fe?Hl(X.expiresAt-Ae):X.inactiveReason==="expired"||fe?"expired":"inactive",rt=Me==="expired"?t("settings.openchamber.tunnel.state.expired"):X.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ot=$n(X.mode);return{...X,isActive:Fe,mode:ot,remainingTextForSession:Me,inactiveLabel:rt}}),[Ae,de,t]),Ie=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Ae:!1,[Ae,r?.bootstrapExpiresAt,r?.connectUrl]),Ne=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:m===P,[m,n,r,P]),Re=o.useMemo(()=>!r||n!=="active"||!m?!1:m!==P,[m,n,r,P]),$e=o.useMemo(()=>{if(typeof Le=="number"&&Number.isFinite(Le)&&Le>0)return Le;if(typeof window>"u")return null;const fe=ri()||window.location.href;let Fe=0;try{Fe=Number(new URL(fe).port)}catch{Fe=Number(window.location.port)}return Number.isFinite(Fe)&&Fe>0?Fe:null},[Le]),De=o.useMemo(()=>R.find(X=>X.provider===A)??null,[R,A]),Ce=o.useMemo(()=>{const X=new Set(De?.modes?.map(fe=>fe.key).filter(fe=>fe==="quick"||fe==="managed-remote"||fe==="managed-local"));return X.size===0?Tr:Tr.filter(fe=>X.has(fe.value))},[De]),Ye=o.useMemo(()=>Ce.some(X=>X.value==="managed-remote"||X.value==="managed-local"),[Ce]),xe=o.useMemo(()=>h.provider===A?h:Er(A),[h,A]),Te=o.useCallback(async X=>{await bn(X)},[]),Ke=o.useCallback((X,fe)=>(y(Er(fe,X)),X.available===!0),[]),tt=o.useCallback(async(X,fe)=>{try{const Fe=await xt("/api/openchamber/tunnel/check",{query:{provider:X},...fe?{signal:fe}:{}});if(!Fe.ok)return null;const Me=await Fe.json();if(fe?.aborted)return null;const rt=Ke(Me,X);return i(ot=>ot==="checking"||ot==="starting"||ot==="active"||ot==="stopping"?ot:rt?"idle":"not-available"),rt}catch{return null}},[Ke]),Y=o.useCallback(async X=>{try{const[fe,Fe,Me,rt]=await Promise.all([xt("/api/openchamber/tunnel/check",{signal:X}),xt("/api/openchamber/tunnel/status",{signal:X}),In(),xt("/api/openchamber/tunnel/providers",{signal:X})]),ot=await fe.json(),Ge=await Fe.json(),Nt=Me??{},ns=rt.ok?await rt.json():{},Zt=Ge.ttlConfig?.bootstrapTtlMs??(Nt.tunnelBootstrapTtlMs===void 0?1800*1e3:Nt.tunnelBootstrapTtlMs),Qe=typeof Ge.ttlConfig?.sessionTtlMs=="number"?Ge.ttlConfig.sessionTtlMs:Nt.tunnelSessionTtlMs??480*60*1e3,He=$n(Ge.mode??Nt.tunnelMode),Ct=Nt.tunnelProvider??"cloudflare",Pt=Nt.managedLocalTunnelConfigPath??null,es=Ke(ot,Ct),ts=Kb(Ge?.managedRemoteTunnelPresets),os=typeof Ge.managedRemoteTunnelHostname=="string"?Ge.managedRemoteTunnelHostname:"",xs=ts.length>0?ts:os?[{id:`legacy-${_i(os)}`,name:os,hostname:_i(os)}]:[],Fs=xs[0]?.id||"";if(be(Zt),he(Qe),N(Ct),T(Array.isArray(ns?.providers)?ns.providers:[]),D(He),$(Pt),M(xs),ee(Fs),Pe(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),c(Ge.activeTunnelMode?$n(Ge.activeTunnelMode):Ge.active&&Ge.mode?$n(Ge.mode):null),W(new Set(Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)?Ge.managedRemoteTunnelTokenPresetIds:[])),_e(typeof Ge.localPort=="number"?Ge.localPort:null),Ge.active&&Ge.url){l({url:Ge.url,connectUrl:null,bootstrapExpiresAt:typeof Ge.bootstrapExpiresAt=="number"?Ge.bootstrapExpiresAt:null}),i("active");return}i(es?"idle":"not-available")}catch{X.aborted||(i("error"),d(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Ke,t]);o.useEffect(()=>{const X=new AbortController;return Y(X.signal),()=>X.abort()},[Y]),o.useEffect(()=>{if(!r?.connectUrl){u(null);return}let X=!1;return Pc.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(fe=>{X||u(fe)}).catch(()=>{X||u(null)}),()=>{X=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){ue(t("settings.openchamber.tunnel.state.noExpiry"));return}let X=null,fe=Date.now();const Fe=()=>{const ot=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;ot<=0?ue(t("settings.openchamber.tunnel.state.expired")):ue(Hl(ot))},Me=()=>{const ot=Date.now();ot-fe>=1e3&&(Fe(),fe=ot),X=requestAnimationFrame(Me)};Fe(),(typeof document>"u"||document.visibilityState==="visible")&&(X=requestAnimationFrame(Me));const rt=()=>{document.visibilityState==="visible"&&X===null?X=requestAnimationFrame(Me):document.visibilityState!=="visible"&&X!==null&&(cancelAnimationFrame(X),X=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),X!==null&&cancelAnimationFrame(X)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let X=null,fe=Date.now();const Fe=()=>{const rt=Date.now();rt-fe>=1e3&&(we(rt),fe=rt),X=requestAnimationFrame(Fe)};(typeof document>"u"||document.visibilityState==="visible")&&(X=requestAnimationFrame(Fe));const Me=()=>{document.visibilityState==="visible"&&X===null?X=requestAnimationFrame(Fe):document.visibilityState!=="visible"&&X!==null&&(cancelAnimationFrame(X),X=null)};return document.addEventListener("visibilitychange",Me),()=>{document.removeEventListener("visibilitychange",Me),X!==null&&cancelAnimationFrame(X)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let X=!1;const fe=async()=>{try{const Me=await xt("/api/openchamber/tunnel/status");if(!Me.ok||X)return;const rt=await Me.json();if(X)return;Pe(Array.isArray(rt.activeSessions)?rt.activeSessions:[]),W(new Set(Array.isArray(rt.managedRemoteTunnelTokenPresetIds)?rt.managedRemoteTunnelTokenPresetIds:[])),_e(typeof rt.localPort=="number"?rt.localPort:null)}catch{}},Fe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||fe()},5e3);return()=>{X=!0,window.clearInterval(Fe)}},[n]);const Se=o.useCallback(async X=>{E(!0);try{await yt(X),Object.prototype.hasOwnProperty.call(X,"tunnelMode")&&X.tunnelMode&&D(X.tunnelMode),Object.prototype.hasOwnProperty.call(X,"tunnelProvider")&&typeof X.tunnelProvider=="string"&&N(X.tunnelProvider),Object.prototype.hasOwnProperty.call(X,"managedLocalTunnelConfigPath")&&$(X.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(X,"managedRemoteTunnelPresets")&&X.managedRemoteTunnelPresets&&M(X.managedRemoteTunnelPresets)}catch{F.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{E(!1)}},[t]),Ee=o.useCallback(async(X,fe)=>{p(!0);try{await yt({tunnelBootstrapTtlMs:X,tunnelSessionTtlMs:fe})}catch{F.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{p(!1)}},[t]),We=o.useCallback(async X=>{const fe=X.token.trim();if(fe)try{const Fe={...O,[X.presetId]:fe};await yt({managedRemoteTunnelPresetTokens:Fe}),W(Me=>{const rt=new Set(Me);return rt.add(X.presetId),rt})}catch{F.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[O,t]),lt=o.useCallback(async X=>{g(null),d(null);const fe=R.find(Me=>Me.provider===X),Fe=fe?.modes?.some(Me=>Me.key===P)?P:$n(fe?.modes?.[0]?.key);await Se({tunnelProvider:X,tunnelMode:Fe}),tt(X)},[R,tt,Se,P]),at=o.useCallback(async()=>{const X=await so({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(X.success&&typeof X.path=="string"&&X.path.trim().length>0){const fe=X.path.trim();if(!Xa(fe)){F.error(Ve);return}$(fe),await Se({managedLocalTunnelConfigPath:fe});return}je.current?.click()},[Ve,Se]),pt=o.useCallback(X=>{const fe=X.trim();$(fe.length>0?fe:null)},[]),bt=o.useCallback(async()=>{if(V&&!Xa(V)){F.error(Ve);return}await Se({managedLocalTunnelConfigPath:V})},[Ve,V,Se]),Q=o.useCallback(async()=>{$(null),await Se({managedLocalTunnelConfigPath:null})},[Se]),qe=o.useCallback(async X=>{const fe=X.target.files?.[0];if(!fe)return;const Fe=fe.name.trim();if(Fe.length!==0){if(!Xa(Fe)){F.error(Ve);return}$(Fe),await Se({managedLocalTunnelConfigPath:Fe}),X.target.value=""}},[Ve,Se]),it=o.useCallback(async()=>{if(d(null),g(null),P==="managed-local"&&V&&!Xa(V)){d(Ve),F.error(Ve);return}i("starting");try{let X="",fe="";if(P==="managed-remote"){if(!se){i("idle"),g(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),F.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}X=se.hostname,fe=(O[se.id]||"").trim(),await Se({tunnelMode:"managed-remote",managedRemoteTunnelPresets:I})}const Fe=await xt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:P,...P==="managed-remote"&&se?{managedRemoteTunnelPresetId:se.id,managedRemoteTunnelPresetName:se.name}:{},...P==="managed-remote"&&X?{managedRemoteTunnelHostname:X}:{},...P==="managed-remote"&&fe?{managedRemoteTunnelToken:fe}:{},...P==="managed-local"&&V?{configPath:V}:{}})}),Me=await Fe.json();if(!Fe.ok||!Me.ok){if(P==="managed-remote"&&typeof Me.error=="string"&&Me.error.includes("Managed remote tunnel token is required")){i("idle"),g(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),F.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),d(Me.error||t("settings.openchamber.tunnel.toast.startFailed")),F.error(Me.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const rt=typeof Me.url=="string"?Me.url:"";if(!rt){i("error"),d(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),F.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:rt,connectUrl:typeof Me.connectUrl=="string"?Me.connectUrl:null,bootstrapExpiresAt:typeof Me.bootstrapExpiresAt=="number"?Me.bootstrapExpiresAt:null}),c(Me.activeTunnelMode?$n(Me.activeTunnelMode):Me.mode?$n(Me.mode):P),Pe(Array.isArray(Me.activeSessions)?Me.activeSessions:[]),Array.isArray(Me.managedRemoteTunnelTokenPresetIds)&&W(new Set(Me.managedRemoteTunnelTokenPresetIds)),typeof Me.localPort=="number"&&_e(Me.localPort),typeof Me.mode=="string"&&D($n(Me.mode)),i("active"),Me.replacedTunnel){const ot=typeof Me.revokedBootstrapCount=="number"?Me.revokedBootstrapCount:0,Ge=typeof Me.invalidatedSessionCount=="number"?Me.invalidatedSessionCount:0;ot===1&&Ge===1?F.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ot===1?F.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Ge})):Ge===1?F.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ot})):F.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ot,invalidatedSessionCount:Ge}))}else F.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),d(t("settings.openchamber.tunnel.toast.startFailed")),F.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Ve,I,Se,se,O,t,A,P,V]),ut=o.useCallback(async()=>{i("stopping");try{await xt("/api/openchamber/tunnel/stop",{method:"POST"});const X=await xt("/api/openchamber/tunnel/status");if(X.ok){const fe=await X.json();Pe(Array.isArray(fe.activeSessions)?fe.activeSessions:[]),W(new Set(Array.isArray(fe.managedRemoteTunnelTokenPresetIds)?fe.managedRemoteTunnelTokenPresetIds:[])),_e(typeof fe.localPort=="number"?fe.localPort:null)}l(null),c(null),u(null),i("idle"),F.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),d(t("settings.openchamber.tunnel.toast.stopFailed")),F.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),gt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),b(!0),F.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{F.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Ot=o.useCallback(async X=>{const fe=Ri.find(Fe=>Fe.value===X);fe&&(be(fe.ms),await Ee(fe.ms,te))},[Ee,te]),st=o.useCallback(async X=>{const fe=Fi.find(Fe=>Fe.value===X);!fe||fe.ms===null||(he(fe.ms),await Ee(ve,fe.ms))},[ve,Ee]),ft=o.useCallback(async X=>{g(null),d(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Se({tunnelMode:X,managedRemoteTunnelPresets:I})},[I,Se,n]),jt=o.useCallback(async(X,fe)=>{try{await yt({managedRemoteTunnelPresets:fe})}catch{F.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Je=o.useCallback(X=>{const fe=I.find(Fe=>Fe.id===X);fe&&(ee(fe.id),g(null),jt(fe,I))},[I,jt]),St=o.useCallback(async()=>{const X=K.trim(),fe=_i(J),Fe=re.trim();if(!X){F.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!fe){F.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Fe){F.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(I.some(ot=>ot.hostname===fe)){F.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Me={id:zb(),name:X,hostname:fe},rt=[...I,Me];M(rt),ee(Me.id),U(ot=>({...ot,[Me.id]:!0})),ae(ot=>({...ot,[Me.id]:Fe})),g(null),L(!1),z(""),oe(""),pe(""),await Se({tunnelMode:"managed-remote",managedRemoteTunnelPresets:rt,managedRemoteTunnelPresetTokens:{...O,[Me.id]:Fe}}),await We({presetId:Me.id,presetName:Me.name,hostname:Me.hostname,token:Fe}),F.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[I,J,K,re,We,Se,O,t]),Oe=o.useCallback(async X=>{const fe=I.find(Ge=>Ge.id===X);if(!fe)return;const Fe=I.filter(Ge=>Ge.id!==fe.id),Me=Fe[0]?.id||"",rt=Z===fe.id?Me:Z,ot=Object.fromEntries(Object.entries(O).filter(([Ge,Nt])=>Ge!==fe.id&&Nt.trim().length>0));M(Fe),ee(rt),U(Ge=>{const Nt={...Ge};return delete Nt[fe.id],Nt}),ae(Ge=>{const Nt={...Ge};return delete Nt[fe.id],Nt}),W(Ge=>{const Nt=new Set(Ge);return Nt.delete(fe.id),Nt}),g(null),await Se({managedRemoteTunnelPresets:Fe,managedRemoteTunnelPresetTokens:ot}),F.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[I,Se,Z,O,t]),wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsx(ze,{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:[le.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:Io,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:le.map(X=>{const fe=X.mode==="quick",Fe=X.mode==="managed-remote",Me=fe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Fe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",rt=X.isActive?fe?"text-[var(--status-warning)]":Fe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ot=t(fe?"settings.openchamber.tunnel.badge.quick":Fe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(B,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",rt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",Me),children:ot}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Lb(X.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:X.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:X.remainingTextForSession}):X.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:X.inactiveLabel})})]},X.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:Io,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:xe.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:xe.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:Kt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Tt,{value:A,onValueChange:X=>{lt(X)},disabled:C||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:Bt,className:"max-w-[16rem]",children:s.jsx(Ut,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:ed(A)})}),s.jsxs(Dt,{children:[R.length>0?R.map(X=>s.jsx(dt,{value:X.provider,children:s.jsx(Bl,{provider:X.provider})},X.provider)):s.jsx(dt,{value:"cloudflare",children:s.jsx(Bl,{provider:"cloudflare"})}),s.jsx(dt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Kt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ce.map(X=>s.jsxs(Zr,{children:[s.jsx(Xr,{asChild:!0,children:s.jsx(G,{variant:"chip",size:"xs","aria-pressed":P===X.value,className:"!font-normal",onClick:()=>{ft(X.value)},disabled:C||n==="starting"||n==="stopping",children:a(X.labelKey)})}),s.jsx(ac,{sideOffset:8,className:"max-w-xs",children:a(X.tooltipKey)})]},X.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Kt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Tt,{value:Gr(Ri,ve,"1800000"),onValueChange:X=>{Ot(X)},disabled:k||C||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:Bt,className:"max-w-[11rem] min-w-0",children:s.jsx(Ut,{className:"truncate",children:Vl(Ri,ve,"1800000")})}),s.jsx(Dt,{children:Ri.map(X=>s.jsx(dt,{value:X.value,children:X.label},X.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Kt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Tt,{value:Gr(Fi,te,"28800000"),onValueChange:X=>{st(X)},disabled:k||C||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:Bt,className:"max-w-[11rem] min-w-0",children:s.jsx(Ut,{className:"truncate",children:Vl(Fi,te,"28800000")})}),s.jsx(Dt,{children:Fi.map(X=>s.jsx(dt,{value:X.value,children:X.label},X.value))})]})]})]}),P==="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")}),Ye&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),P==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof $e=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",$e]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(dn,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>L(X=>!X),disabled:n==="starting"||n==="stopping"||C,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),I.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:I.map((X,fe)=>{const Fe=O[X.id]||"",Me=_.has(X.id),rt=H[X.id]??!1;return s.jsx("div",{className:ye(fe<I.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(kn,{open:rt,onOpenChange:ot=>{U(Ge=>({...Ge,[X.id]:ot})),ot&&Je(X.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"||C,children:[rt?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:X.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:X.name}),onClick:()=>{Oe(X.id)},disabled:n==="starting"||n==="stopping"||C,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:X.hostname})]}),s.jsx(Be,{type:"password",value:Fe,onChange:ot=>{const Ge=ot.target.value;g(null),ae(Nt=>({...Nt,[X.id]:Ge}))},onBlur:ot=>{const Ge=ot.currentTarget.value.trim();Ge&&We({presetId:X.id,presetName:X.name,hostname:X.hostname,token:Ge})},placeholder:t(Me?"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"||Fe.trim().length===0,onClick:()=>{We({presetId:X.id,presetName:X.name,hostname:X.hostname,token:Fe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},X.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),q&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Be,{value:K,onChange:X=>z(X.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:C||n==="starting"||n==="stopping"}),s.jsx(Be,{value:J,onChange:X=>oe(X.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:C||n==="starting"||n==="stopping"}),s.jsx(Be,{type:"password",value:re,onChange:X=>pe(X.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:C||n==="starting"||n==="stopping"}),typeof $e=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",$e]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{St()},disabled:C||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{L(!1),z(""),oe(""),pe("")},disabled:C||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Yt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!se&&j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:j})]}),P==="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:Kt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:je,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:X=>{qe(X)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:V||"",onChange:X=>{pt(X.target.value)},onBlur:()=>{bt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||C}),s.jsx(G,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{at()},disabled:n==="starting"||n==="stopping"||C,children:s.jsx(B,{name:"folder",className:"size-3.5"})}),V&&s.jsx(G,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Q()},disabled:n==="starting"||n==="stopping"||C,children:s.jsx(B,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(V?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),ke&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ve})]})}),!Ne&&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:[P==="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:()=>{Te(Eb)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(B,{name:"external-link",className:"size-3.5"})]})]}),P==="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:()=>{Te(Db)},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(Tr.find(X=>X.value===P)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),P==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Kt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Tt,{value:Z||(I[0]?.id??""),onValueChange:X=>{Je(X)},disabled:C||n==="starting"||n==="stopping"||I.length<=1,children:[s.jsx(Et,{size:Bt,children:s.jsx(Ut,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:se?.name})}),s.jsx(Dt,{fitContent:!0,children:I.map(X=>s.jsx(dt,{value:X.id,children:X.name},X.id))})]})]}),Re&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(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:it,disabled:n==="starting"||C||P==="managed-remote"&&!se||P==="managed-local"&&ke,className:ye(wt,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")})]})]}),Ne&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),Ie&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(G,{size:"sm",variant:"ghost",onClick:gt,className:"shrink-0 gap-1.5",children:[w?s.jsx(B,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(B,{name:"file-copy",className:"size-3.5"}),t(w?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",r.bootstrapExpiresAt?ie:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[x?s.jsx("img",{src:x,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(G,{size:"sm",variant:"outline",onClick:it,disabled:n==="stopping"||C||P==="managed-local"&&ke,className:wt,children:[s.jsx(B,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(G,{size:"sm",variant:"ghost",onClick:ut,disabled:n==="stopping"||C,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"&&v&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v}),s.jsx(G,{size:"sm",variant:"ghost",onClick:it,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},td=()=>{const{t}=et(),[e,a]=Ze.useState(""),[n,i]=Ze.useState(!0),[r,l]=Ze.useState(!1),m=ce(d=>d.showOpenCodeUpdateNotifications),c=ce(d=>d.setShowOpenCodeUpdateNotifications);Ze.useEffect(()=>{let d=!1;return(async()=>{try{const j=await In();if(d||!j)return;a(j.opencodeBinary??"")}catch{}finally{d||i(!1)}})(),()=>{d=!0}},[]);const x=Ze.useCallback(async()=>{if(!(typeof window>"u")&&cs())try{const d=await so();d.success&&d.path&&d.path.trim().length>0&&a(d.path.trim())}catch{}},[]),u=Ze.useCallback(async()=>{l(!0);try{const d=e.trim(),j=d.length>=2&&(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'"))?d.slice(1,-1).trim():d;await yt({opencodeBinary:j}),aa("cli",{id:"opencode-binary"}),F.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=Ze.useCallback(d=>{c(d),yt({showOpenCodeUpdateNotifications:d})},[c]);return s.jsx(ze,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ft,{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(Be,{value:e,onChange:d=>a(d.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:x,disabled:n||r||!cs(),className:ws,"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(za,{className:fs,children:[!Nc()&&s.jsx(mt,{settingsItem:"sessions.opencode-update-notifications",checked:m,onChange:v,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(G,{type:"button",size:"xs",onClick:u,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},sd=()=>{const t=ct.c(44),{t:e}=et(),a=ce(_b),n=ce($b),i=ce(Bb),r=ce(Vb),l=ce(Hb),m=ce(qb),c=ce(Gb);let x;t[0]!==n?(x=P=>{n(P),yt({agentControlToolEnabled:P}),aa("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=x):x=t[1];const u=x;let v;t[2]!==r?(v=P=>{r(P),yt({agentWebToolEnabled:P}),aa("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const d=v;let j;t[4]!==c?(j=P=>{c(P),yt({agentMemoryToolEnabled:P}).finally(()=>{P&&ou.getState().refresh()}),aa("cli",{id:"agent-memory-tool"})},t[4]=c,t[5]=j):j=t[5];const g=j;let w;t[6]!==e?(w=e("settings.openchamber.tools.title"),t[6]=e,t[7]=w):w=t[7];let b;t[8]!==e?(b=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=b):b=t[9];let k;t[10]!==e?(k=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=k):k=t[11];let p;t[12]!==e?(p=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=p):p=t[13];let C;t[14]!==a||t[15]!==u||t[16]!==b||t[17]!==k||t[18]!==p?(C=s.jsx(mt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:u,label:b,ariaLabel:k,info:p}),t[14]=a,t[15]=u,t[16]=b,t[17]=k,t[18]=p,t[19]=C):C=t[19];let E;t[20]!==e?(E=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=E):E=t[21];let A;t[22]!==e?(A=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=A):A=t[23];let N;t[24]!==e?(N=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=N):N=t[25];let h;t[26]!==i||t[27]!==d||t[28]!==N||t[29]!==E||t[30]!==A?(h=s.jsx(mt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:d,label:E,ariaLabel:A,info:N}),t[26]=i,t[27]=d,t[28]=N,t[29]=E,t[30]=A,t[31]=h):h=t[31];let y;t[32]!==m||t[33]!==l||t[34]!==g||t[35]!==e?(y=m?s.jsx(mt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:g,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=m,t[33]=l,t[34]=g,t[35]=e,t[36]=y):y=t[36];let R;t[37]!==h||t[38]!==y||t[39]!==C?(R=s.jsxs("div",{className:fs,children:[C,h,y]}),t[37]=h,t[38]=y,t[39]=C,t[40]=R):R=t[40];let T;return t[41]!==R||t[42]!==w?(T=s.jsx(ze,{title:w,children:R}),t[41]=R,t[42]=w,t[43]=T):T=t[43],T};function _b(t){return t.agentControlToolEnabled}function $b(t){return t.setAgentControlToolEnabled}function Bb(t){return t.agentWebToolEnabled}function Vb(t){return t.setAgentWebToolEnabled}function Hb(t){return t.agentMemoryToolEnabled}function qb(t){return t.agentMemoryFeatureAvailable}function Gb(t){return t.setAgentMemoryToolEnabled}const nd=()=>{const{t}=et(),e=cs()&&oi(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Ze.useState(!1),[r,l]=Ze.useState(!1),[m,c]=Ze.useState(!1),[x,u]=Ze.useState(""),[v,d]=Ze.useState(!1),[j,g]=Ze.useState(!1),[w,b]=Ze.useState(null),[k,p]=Ze.useState(!0),[C,E]=Ze.useState(!1),[A,N]=Ze.useState(!1),[h,y]=Ze.useState(!1),[R,T]=Ze.useState(!1),[P,D]=Ze.useState(!1),[V,$]=Ze.useState(!1),[I,M]=Ze.useState(!1),[H,U]=Ze.useState(!0),[Z,ee]=Ze.useState(!0),[O,ae]=Ze.useState(!1),[_,W]=Ze.useState(!1),[q,L]=Ze.useState(!1),[K,z]=Ze.useState(null),[J,oe]=Ze.useState(null);Ze.useEffect(()=>{if(!e){p(!1);return}let je=!1;return(async()=>{try{const ke=await In();if(!ke)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(je)return;const se=ke.desktopLanAccessEnabled===!0;i(se),l(se),c(ke.hasDesktopUiPassword===!0),u(""),d(!1),g(ke.desktopLanAccessActive===!0),b(ke.desktopLanAccessBlockedReason??null);const le=ke.desktopMacMenuBarEnabled!==!1;U(le),ee(le),z(null)}catch(ke){je||z(ke instanceof Error?ke.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{je||p(!1)}})(),()=>{je=!0}},[e,t]),Ze.useEffect(()=>{if(!e){N(!1);return}let je=!1;return(async()=>{const ke=await $u();je||(N(ke?.supported===!0),y(ke?.enabled===!0))})(),()=>{je=!0}},[e]),Ze.useEffect(()=>{if(!e){D(!1);return}let je=!1;return(async()=>{const ke=await Bu();je||(D(ke?.supported===!0),$(ke?.enabled===!0))})(),()=>{je=!0}},[e]),Ze.useEffect(()=>{if(!e){ae(!1);return}let je=!1;return(async()=>{const ke=await Vu();je||(ae(ke?.supported===!0),W(ke?.enabled===!0))})(),()=>{je=!0}},[e]),Ze.useEffect(()=>{if(!e||!r){oe(null);return}let je=!1;return(async()=>{const ke=await yc();je||oe(ke)})(),()=>{je=!0}},[r,e]);const re=x.trim(),pe=re.length>0||v,ve=r!==n||pe||Z!==H,be=Ze.useMemo(()=>{if(typeof window>"u")return null;const ke=ri()||window.location.href;let se=0;try{se=Number(new URL(ke).port)}catch{se=Number(window.location.port)}return Number.isFinite(se)&&se>0?se:null},[]),te=r&&j&&J&&be?`http://${J}:${be}`:null,he=re.length>0||m&&!v,ie=r&&!he,ue=n&&!j&&w==="missing-password",de=k||C||!ve||ie,Pe=Ze.useCallback(je=>{u(je),je.trim()&&d(!1)},[]),Ae=Ze.useCallback(()=>{u(""),d(!0),l(!1)},[]),we=Ze.useCallback(async()=>{if(!A||R)return;const je=!h;y(je),T(!0),z(null);try{const ke=await Hu(je);if(!ke?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));y(ke.enabled)}catch(ke){y(!je),z(ke instanceof Error?ke.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[R,h,A,t]),Le=Ze.useCallback(async()=>{if(!P||I)return;const je=!V;$(je),M(!0),z(null);try{const ke=await qu(je);if(!ke)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!ke.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));$(ke.enabled)}catch(ke){$(!je),z(ke instanceof Error?ke.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{M(!1)}},[I,V,P,t]),_e=Ze.useCallback(async()=>{if(!O||q)return;const je=!_;W(je),L(!0),z(null);try{const ke=await Gu(je);if(!ke?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));W(ke.enabled)}catch(ke){W(!je),z(ke instanceof Error?ke.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{L(!1)}},[q,_,O,t]),Ve=Ze.useCallback(async()=>{if(ve){E(!0),z(null);try{if(!(await yt({desktopLanAccessEnabled:r,...re?{desktopUiPassword:re}:v?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:Z})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),re?c(!0):v&&c(!1),u(""),d(!1),U(Z),!await Wu())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(je){z(je instanceof Error?je.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),E(!1)}}},[Z,r,ve,re,v,t]);return e?s.jsx(ze,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[A||a||P||O?s.jsxs("div",{className:fs,children:[A?s.jsx(mt,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:je=>{je!==h&&we()},disabled:R,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(mt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Z,onChange:ee,disabled:k||C,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,P?s.jsx(mt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:V,onChange:je=>{je!==V&&Le()},disabled:I,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,O?s.jsx(mt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:je=>{je!==_&&_e()},disabled:q,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(At,{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(Be,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:x,onChange:je=>Pe(je.target.value),placeholder:t(m&&!v?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||C,required:r&&!he,"aria-invalid":ie}),m&&!v?s.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:Ae,disabled:k||C,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:fs,children:s.jsx(mt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:k||C,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")}),ie||ue?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),K?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:K}):null,te?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ve&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:te})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(G,{type:"button",size:"xs",onClick:Ve,disabled:de,className:"shrink-0 !font-normal",children:t(C?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},ad=new Set(["shift","control","alt","meta"]),go=3,Wb=3e3;function ho(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 Jb(t){return t.action.customizable}function ql(t){if(ho(t)>go)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?Gi(e.join("+")):null}function Qb(t){if(ad.has(t.key.toLowerCase())||ho(t,!0)>go)return null;const e=du(uu(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),Gi(a.join("+"))}function Yb(t){const e=t.key.toLowerCase();if(!ad.has(e)||ho(t,!0)>go)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?Gi(a.join("+")):null}function Gl(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Zb(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:ql(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Qb(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:ql(e)}}const Xb=t=>{const e=ct.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=et();let m;e[0]!==l?(m=be=>l(be.settingsLabelKey),e[0]=l,e[1]=m):m=e[1];const c=m;let x;e[2]!==c?(x=be=>be.action.customizable?c(be.action):ca(be.action.defaultBinding),e[2]=c,e[3]=x):x=e[3];const u=x;let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={chords:[],livePreview:null,settled:!1},e[4]=v):v=e[4];const[d,j]=o.useState(v),g=o.useRef(null);let w,b;e[5]!==a?(w=()=>{a&&(j({chords:[],livePreview:null,settled:!1}),g.current?.focus())},b=[a],e[5]=a,e[6]=w,e[7]=b):(w=e[6],b=e[7]),o.useEffect(w,b);const k=d.chords.length===1&&!d.settled;let p,C;e[8]!==k?(p=()=>{if(!k)return;const be=window.setTimeout(()=>j(Gl),Wb);return()=>window.clearTimeout(be)},C=[k],e[8]=k,e[9]=p,e[10]=C):(p=e[9],C=e[10]),o.useEffect(p,C);let E;e[11]!==d.chords?(E=Gi(d.chords.join(" ")),e[11]=d.chords,e[12]=E):E=e[12];const A=E;let N;e[13]!==a||e[14]!==A||e[15]!==n?(N=a&&A?lu(a.id,A,n):[],e[13]=a,e[14]=A,e[15]=n,e[16]=N):N=e[16];const h=N;let y;e[17]!==h?(y=h.find(ev),e[17]=h,e[18]=y):y=e[18];const R=y;let T,P,D,V,$,I,M,H,U,Z,ee,O,ae,_,W;if(e[19]!==a||e[20]!==c||e[21]!==A||e[22]!==u||e[23]!==h||e[24]!==r||e[25]!==i||e[26]!==R||e[27]!==d||e[28]!==l){const be=h.filter(Jb);$=be.find(tv);const te=be.find(sv),he=h.find(nv);let ie;e[44]!==r?(ie=()=>r(!1),e[44]=r,e[45]=ie):ie=e[45],D=ie,V=()=>{d.settled||j(Gl),!(!a||!A||R||$)&&(i(a.id,A,te?.action.id),D())};let ue;e[46]!==a||e[47]!==d?(ue=(Ne,Re)=>{Ne.preventDefault(),Ne.stopPropagation();const $e=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Re==="keyup"&&$e&&d.chords.length===0){const Ce=Yb(Ne);if(Ce){j({chords:[Ce],livePreview:null,settled:!0});return}}const De=Zb(d,{altKey:Ne.altKey,code:Ne.nativeEvent.code,ctrlKey:Ne.ctrlKey,isComposing:Ne.nativeEvent.isComposing,key:Ne.key,metaKey:Ne.metaKey,repeat:Ne.repeat,shiftKey:Ne.shiftKey},Re);j($e&&De.chords.length>1?d:De)},e[46]=a,e[47]=d,e[48]=ue):ue=e[48];const de=ue;P=_t,_=a!==null,W=av,T=$t,I="max-w-md",M=g,H=!1;let Pe;e[49]!==a||e[50]!==c||e[51]!==l?(Pe=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=Pe):Pe=e[52];let Ae;e[53]!==Pe?(Ae=s.jsx(Ht,{children:Pe}),e[53]=Pe,e[54]=Ae):Ae=e[54];let we;e[55]!==l?(we=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=we):we=e[56];let Le;e[57]!==we?(Le=s.jsx(qt,{children:we}),e[57]=we,e[58]=Le):Le=e[58],e[59]!==Ae||e[60]!==Le?(U=s.jsxs(Vt,{children:[Ae,Le]}),e[59]=Ae,e[60]=Le,e[61]=U):U=e[61];let _e,Ve;e[62]!==de?(_e=Ne=>de(Ne,"keydown"),Ve=Ne=>de(Ne,"keyup"),e[62]=de,e[63]=_e,e[64]=Ve):(_e=e[63],Ve=e[64]);let je;e[65]===Symbol.for("react.memo_cache_sentinel")?(je=()=>j(iv),e[65]=je):je=e[65];let ke;e[66]!==d.chords?(ke=d.chords.map(rv),e[66]=d.chords,e[67]=ke):ke=e[67];let se;e[68]!==d.livePreview?(se=d.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:ca(d.livePreview)}):null,e[68]=d.livePreview,e[69]=se):se=e[69];let le;e[70]!==d.chords.length||e[71]!==d.livePreview||e[72]!==l?(le=d.chords.length===0&&!d.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=d.chords.length,e[71]=d.livePreview,e[72]=l,e[73]=le):le=e[73];let Ie;e[74]!==ke||e[75]!==se||e[76]!==le?(Ie=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[ke,se,le]}),e[74]=ke,e[75]=se,e[76]=le,e[77]=Ie):Ie=e[77],e[78]!==_e||e[79]!==Ve||e[80]!==Ie?(Z=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:g,onKeyDown:_e,onKeyUp:Ve,onBlur:je,children:Ie}),e[78]=_e,e[79]=Ve,e[80]=Ie,e[81]=Z):Z=e[81],ee=d.settled&&R?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):d.settled&&$?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c($.action)})}):null,O=d.settled&&te&&!R&&!$?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(te.action)})}):null,ae=d.settled&&he&&!R&&!$?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:u(he)})}):null,e[19]=a,e[20]=c,e[21]=A,e[22]=u,e[23]=h,e[24]=r,e[25]=i,e[26]=R,e[27]=d,e[28]=l,e[29]=T,e[30]=P,e[31]=D,e[32]=V,e[33]=$,e[34]=I,e[35]=M,e[36]=H,e[37]=U,e[38]=Z,e[39]=ee,e[40]=O,e[41]=ae,e[42]=_,e[43]=W}else T=e[29],P=e[30],D=e[31],V=e[32],$=e[33],I=e[34],M=e[35],H=e[36],U=e[37],Z=e[38],ee=e[39],O=e[40],ae=e[41],_=e[42],W=e[43];let q;e[82]!==A||e[83]!==d.settled||e[84]!==l?(q=d.settled&&A&&cu(A)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=A,e[83]=d.settled,e[84]=l,e[85]=q):q=e[85];let L;e[86]!==l?(L=l("settings.common.actions.cancel"),e[86]=l,e[87]=L):L=e[87];let K;e[88]!==D||e[89]!==L?(K=s.jsx(G,{type:"button",variant:"ghost",size:"sm",onClick:D,children:L}),e[88]=D,e[89]=L,e[90]=K):K=e[90];const z=!A||d.settled&&(!!R||!!$);let J;e[91]!==l?(J=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=J):J=e[92];let oe;e[93]!==V||e[94]!==z||e[95]!==J?(oe=s.jsx(G,{type:"button",size:"sm",disabled:z,onClick:V,children:J}),e[93]=V,e[94]=z,e[95]=J,e[96]=oe):oe=e[96];let re;e[97]!==K||e[98]!==oe?(re=s.jsxs(rs,{children:[K,oe]}),e[97]=K,e[98]=oe,e[99]=re):re=e[99];let pe;e[100]!==T||e[101]!==I||e[102]!==M||e[103]!==H||e[104]!==U||e[105]!==Z||e[106]!==ee||e[107]!==O||e[108]!==ae||e[109]!==q||e[110]!==re?(pe=s.jsxs(T,{className:I,initialFocus:M,showCloseButton:H,children:[U,Z,ee,O,ae,q,re]}),e[100]=T,e[101]=I,e[102]=M,e[103]=H,e[104]=U,e[105]=Z,e[106]=ee,e[107]=O,e[108]=ae,e[109]=q,e[110]=re,e[111]=pe):pe=e[111];let ve;return e[112]!==P||e[113]!==_||e[114]!==W||e[115]!==pe?(ve=s.jsx(P,{open:_,onOpenChange:W,children:pe}),e[112]=P,e[113]=_,e[114]=W,e[115]=pe,e[116]=ve):ve=e[116],ve};function ev(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function tv(t){return t.kind==="prefix"}function sv(t){return t.kind==="exact"}function nv(t){return t.kind==="contextual-prefix"}function av(t,e){t||e.cancel()}function iv(t){return{...t,livePreview:null}}function rv(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:ca(t)},`${t}-${e}`)}const ov=["session","models","panels","navigation","application"],lv=()=>{const t=ct.c(24),{t:e}=et(),a=ce(cv),n=ce(dv),i=ce(uv),r=ce(mv),[l,m]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const A=mu();c=ds()?A.filter(pv):A,t[0]=c}else c=t[0];const x=c,u=gv;let v;t[1]!==n||t[2]!==a?(v=(A,N,h)=>{const y={...a,[A]:N};h&&(y[h]=hr),n(A,N),h&&n(h,hr),u(y)},t[1]=n,t[2]=a,t[3]=v):v=t[3];const d=v;let j;t[4]!==i||t[5]!==a?(j=A=>{const N={...a};delete N[A],i(A),u(N)},t[4]=i,t[5]=a,t[6]=j):j=t[6];const g=j;let w;t[7]!==a||t[8]!==e?(w=A=>{const N="prefixStyle"in A&&A.prefixStyle,h=N?pu(A.id,a):bc(A.id,a),y=ca(h,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!N||!h||h===hr)return y;const R=A.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${y}${R}`},t[7]=a,t[8]=e,t[9]=w):w=t[9];const b=w;let k;t[10]!==r||t[11]!==g||t[12]!==b||t[13]!==a||t[14]!==e?(k=ov.map((A,N)=>{const h=x.filter(y=>y.category===A);return h.length===0?null:s.jsx(ze,{settingsItem:N===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${A}`),divider:N!==0,info:N===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:N===0?s.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{r(),u({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:h.map(y=>s.jsxs(Ft,{label:e(y.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(y)}),s.jsx(G,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>m(y),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),y.id in a?s.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>g(y.id),children:e("settings.common.actions.reset")}):null]},y.id))})},A)}),t[10]=r,t[11]=g,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=A=>{A||m(null)},t[16]=p):p=t[16];let C;t[17]!==l||t[18]!==d||t[19]!==a?(C=s.jsx(Xb,{action:l,overrides:a,onSave:d,onOpenChange:p}),t[17]=l,t[18]=d,t[19]=a,t[20]=C):C=t[20];let E;return t[21]!==k||t[22]!==C?(E=s.jsxs(s.Fragment,{children:[k,C]}),t[21]=k,t[22]=C,t[23]=E):E=t[23],E};function cv(t){return t.shortcutOverrides}function dv(t){return t.setShortcutOverride}function uv(t){return t.clearShortcutOverride}function mv(t){return t.resetAllShortcutOverrides}function pv(t){return t.id!=="toggle_prompt_navigator"}function gv(t){yt({shortcutOverrides:t})}const id=()=>{const t=ct.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Wi(()=>a(Sv)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},hv=t=>{const e=ct.c(83),{section:a}=t,{t:n}=et(),{isMobile:i}=ha(),r=id();let l;e[0]!==i?(l=i&&ra(),e[0]=i,e[1]=l):l=e[1];const m=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=ds(),e[2]=c):c=e[2];const x=c;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=cs()&&oi(),e[3]=u):u=e[3];const v=u;if(!a){let ae;e[4]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(Ji,{}),e[4]=ae):ae=e[4];let _;e[5]!==r?(_=s.jsx(Zc,{},r),e[5]=r,e[6]=_):_=e[6];let W,q,L,K,z,J;e[7]===Symbol.for("react.memo_cache_sentinel")?(L=v&&s.jsx(nd,{}),K=!x&&s.jsx(td,{}),z=!x&&s.jsx(sd,{}),J=s.jsx(Jc,{}),W=s.jsx(Yc,{}),q=ra()&&!cs()&&!x&&!Sc()&&s.jsx(Qc,{}),e[7]=W,e[8]=q,e[9]=L,e[10]=K,e[11]=z,e[12]=J):(W=e[7],q=e[8],L=e[9],K=e[10],z=e[11],J=e[12]);let oe;e[13]!==m?(oe=m&&s.jsx(Ac,{}),e[13]=m,e[14]=oe):oe=e[14];let re;return e[15]!==oe||e[16]!==_?(re=s.jsxs(is,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[ae,_,L,K,z,J,W,q,oe]}),e[15]=oe,e[16]=_,e[17]=re):re=e[17],re}let d;e[18]!==r||e[19]!==a?(d=()=>{switch(a){case"general":return s.jsx(xv,{});case"visual":return s.jsx(bv,{});case"chat":return s.jsx(vv,{});case"sessions":return s.jsx(yv,{runtimeEndpointEpoch:r});case"shortcuts":return s.jsx(fv,{});case"git":return s.jsx(jv,{});case"notifications":return s.jsx(wv,{});case"voice":return s.jsx(kv,{});case"tunnel":return s.jsx(Nv,{});default:return null}},e[18]=r,e[19]=a,e[20]=d):d=e[20];const j=d;let g;e[21]!==n?(g=n("settings.page.general.title"),e[21]=n,e[22]=g):g=e[22];let w;e[23]!==n?(w=n("settings.page.appearance.title"),e[23]=n,e[24]=w):w=e[24];let b;e[25]!==n?(b=n("settings.page.chat.title"),e[25]=n,e[26]=b):b=e[26];let k;e[27]!==n?(k=n("settings.page.sessions.title"),e[27]=n,e[28]=k):k=e[28];let p;e[29]!==n?(p=n("settings.page.shortcuts.title"),e[29]=n,e[30]=p):p=e[30];let C;e[31]!==n?(C=n("settings.page.git.title"),e[31]=n,e[32]=C):C=e[32];let E;e[33]!==n?(E=n("settings.page.git.title"),e[33]=n,e[34]=E):E=e[34];let A;e[35]!==n?(A=n("settings.page.notifications.title"),e[35]=n,e[36]=A):A=e[36];let N;e[37]!==n?(N=n("settings.page.voice.title"),e[37]=n,e[38]=N):N=e[38];let h;e[39]!==n?(h=n("settings.page.tunnel.title"),e[39]=n,e[40]=h):h=e[40];let y;e[41]!==C||e[42]!==E||e[43]!==A||e[44]!==N||e[45]!==h||e[46]!==g||e[47]!==w||e[48]!==b||e[49]!==k||e[50]!==p?(y={general:g,visual:w,chat:b,sessions:k,shortcuts:p,git:C,github:E,notifications:A,voice:N,tunnel:h},e[41]=C,e[42]=E,e[43]=A,e[44]=N,e[45]=h,e[46]=g,e[47]=w,e[48]=b,e[49]=k,e[50]=p,e[51]=y):y=e[51];const R=y[a];let T;e[52]!==n?(T=n("settings.page.general.description"),e[52]=n,e[53]=T):T=e[53];let P;e[54]!==n?(P=n("settings.page.appearance.description"),e[54]=n,e[55]=P):P=e[55];let D;e[56]!==n?(D=n("settings.page.chat.description"),e[56]=n,e[57]=D):D=e[57];let V;e[58]!==n?(V=n("settings.page.sessions.description"),e[58]=n,e[59]=V):V=e[59];let $;e[60]!==n?($=n("settings.page.shortcuts.description"),e[60]=n,e[61]=$):$=e[61];let I;e[62]!==n?(I=n("settings.page.notifications.description"),e[62]=n,e[63]=I):I=e[63];let M;e[64]!==n?(M=n("settings.page.voice.description"),e[64]=n,e[65]=M):M=e[65];let H;e[66]!==n?(H=n("settings.page.tunnel.description"),e[66]=n,e[67]=H):H=e[67];let U;e[68]!==T||e[69]!==P||e[70]!==D||e[71]!==V||e[72]!==$||e[73]!==I||e[74]!==M||e[75]!==H?(U={general:T,visual:P,chat:D,sessions:V,shortcuts:$,git:void 0,github:void 0,notifications:I,voice:M,tunnel:H},e[68]=T,e[69]=P,e[70]=D,e[71]=V,e[72]=$,e[73]=I,e[74]=M,e[75]=H,e[76]=U):U=e[76];const Z=U[a];let ee;e[77]!==j?(ee=j(),e[77]=j,e[78]=ee):ee=e[78];let O;return e[79]!==Z||e[80]!==R||e[81]!==ee?(O=s.jsx(is,{title:R,description:Z,showSaveStatus:!0,className:"openchamber-page-body",children:ee}),e[79]=Z,e[80]=R,e[81]=ee,e[82]=O):O=e[82],O},fv=()=>{const t=ct.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lv,{}),t[0]=e):e=t[0],e},xv=()=>{const t=ct.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;id();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=cs()&&oi(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=ra()&&!cs()&&!a&&!Sc(),t[2]=r):r=t[2];const l=r;let m,c,x,u,v;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=i&&s.jsx(nd,{}),c=l&&s.jsx(Qc,{}),x=s.jsx(Yc,{}),u=!a&&s.jsx(td,{}),v=!a&&s.jsx(sd,{}),t[3]=m,t[4]=c,t[5]=x,t[6]=u,t[7]=v):(m=t[3],c=t[4],x=t[5],u=t[6],v=t[7]);let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=a?[]:["sessionTabs"],t[8]=d):d=t[8];let j;return t[9]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsxs(s.Fragment,{children:[m,c,x,u,v,s.jsx(Ji,{visibleSettings:["fileEditorKeymap",...d,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=j):j=t[9],j},bv=()=>{const t=ct.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ji,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset"]}),t[1]=n):n=t[1],n},vv=()=>{const t=ct.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ji,{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},yv=t=>{const e=ct.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(Zc,{},a),e[0]=a,e[1]=n):n=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Jc,{}),e[2]=i):i=e[2];let r;return e[3]!==n?(r=s.jsxs(s.Fragment,{children:[n,i]}),e[3]=n,e[4]=r):r=e[4],r},jv=()=>{const t=ct.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx($c,{}),t[0]=e):e=t[0],e},wv=()=>{const t=ct.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vb,{}),t[0]=e):e=t[0],e},kv=()=>{const t=ct.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ab,{}),t[0]=e):e=t[0],e},Nv=()=>{const t=ct.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ub,{}),t[0]=e):e=t[0],e};function Sv(t){return t+1}const Cv=t=>{const e=ct.c(85),{className:a}=t,{t:n}=et(),i=ia(vc),r=ia(Iv),l=ce(Pv),m=ce(Av),[c,x]=Ze.useState(!1),[u,v]=Ze.useState(!1),d=i>0;let j;e[0]!==n?(j=async()=>{try{const ie=await gu({message:n("settings.view.pendingRestart.applying")});if(ie.requiresManualRestart){F.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}ie.ok&&F.success(n("settings.view.pendingRestart.applied"))}catch(ie){const ue=ie,de=ue instanceof Error&&ue.message?ue.message:n("settings.view.pendingRestart.applyFailed");F.error(de)}},e[0]=n,e[1]=j):j=e[1];const g=j;let w;e[2]!==n?(w=async()=>{try{await oc({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),ia.getState().clear()}catch{}},e[2]=n,e[3]=w):w=e[3];const b=w;let k;e[4]!==u||e[5]!==g||e[6]!==m?(k=()=>{u&&m(!1),x(!1),v(!1),g()},e[4]=u,e[5]=g,e[6]=m,e[7]=k):k=e[7];const p=k;let C;e[8]!==d||e[9]!==g||e[10]!==b||e[11]!==l?(C=()=>{if(!d){b();return}if(l){v(!1),x(!0);return}g()},e[8]=d,e[9]=g,e[10]=b,e[11]=l,e[12]=C):C=e[12];const E=C;let A;e[13]!==d||e[14]!==r||e[15]!==n?(A=n(d?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=d,e[14]=r,e[15]=n,e[16]=A):A=e[16];const N=A;let h;e[17]!==d||e[18]!==i||e[19]!==n?(h=d?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=d,e[18]=i,e[19]=n,e[20]=h):h=e[20];const y=h,R=d?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",T=r&&"opacity-80";let P;e[21]!==a||e[22]!==R||e[23]!==T?(P=ye("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",R,T,a),e[21]=a,e[22]=R,e[23]=T,e[24]=P):P=e[24];let D;e[25]!==d||e[26]!==i?(D=d?s.jsx("span",{className:ye("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(B,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=d,e[26]=i,e[27]=D):D=e[27];let V;e[28]!==N?(V=s.jsx("span",{className:"truncate",children:N}),e[28]=N,e[29]=V):V=e[29];let $;e[30]!==E||e[31]!==r||e[32]!==D||e[33]!==V||e[34]!==P||e[35]!==y?($=s.jsxs("button",{type:"button",disabled:r,title:y,"aria-label":y,onClick:E,className:P,children:[D,V]}),e[30]=E,e[31]=r,e[32]=D,e[33]=V,e[34]=P,e[35]=y,e[36]=$):$=e[36];let I;e[37]===Symbol.for("react.memo_cache_sentinel")?(I=ie=>{x(ie),ie||v(!1)},e[37]=I):I=e[37];let M;e[38]!==n?(M=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=M):M=e[39];let H;e[40]!==M?(H=s.jsx(Ht,{children:M}),e[40]=M,e[41]=H):H=e[41];let U;e[42]!==n?(U=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=U):U=e[43];let Z;e[44]!==U?(Z=s.jsx(qt,{children:U}),e[44]=U,e[45]=Z):Z=e[45];let ee;e[46]!==H||e[47]!==Z?(ee=s.jsxs(Vt,{children:[H,Z]}),e[46]=H,e[47]=Z,e[48]=ee):ee=e[48];let O;e[49]===Symbol.for("react.memo_cache_sentinel")?(O={width:"40%"},e[49]=O):O=e[49];let ae;e[50]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>x(!1),e[50]=ae):ae=e[50];let _;e[51]!==n?(_=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=_):_=e[52];let W;e[53]!==_?(W=s.jsx("div",{className:"min-w-0 shrink-0",style:O,children:s.jsx(G,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:ae,children:_})}),e[53]=_,e[54]=W):W=e[54];let q;e[55]===Symbol.for("react.memo_cache_sentinel")?(q={width:"40%"},e[55]=q):q=e[55];let L;e[56]!==n?(L=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=L):L=e[57];let K;e[58]!==p||e[59]!==L?(K=s.jsx("div",{className:"min-w-0 shrink-0",style:q,children:s.jsx(G,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:p,children:L})}),e[58]=p,e[59]=L,e[60]=K):K=e[60];let z;e[61]!==W||e[62]!==K?(z=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[W,K]}),e[61]=W,e[62]=K,e[63]=z):z=e[63];let J;e[64]===Symbol.for("react.memo_cache_sentinel")?(J=()=>v(Tv),e[64]=J):J=e[64];let oe;e[65]!==u?(oe=u?s.jsx(B,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(B,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=u,e[66]=oe):oe=e[66];let re;e[67]!==n?(re=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=re):re=e[68];let pe;e[69]!==u||e[70]!==oe||e[71]!==re?(pe=s.jsxs("button",{type:"button",onClick:J,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","aria-pressed":u,children:[oe,re]}),e[69]=u,e[70]=oe,e[71]=re,e[72]=pe):pe=e[72];let ve;e[73]!==z||e[74]!==pe?(ve=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[z,pe]}),e[73]=z,e[74]=pe,e[75]=ve):ve=e[75];let be;e[76]!==ee||e[77]!==ve?(be=s.jsxs($t,{showCloseButton:!1,className:"max-w-md gap-5",children:[ee,ve]}),e[76]=ee,e[77]=ve,e[78]=be):be=e[78];let te;e[79]!==c||e[80]!==be?(te=s.jsx(_t,{open:c,onOpenChange:I,children:be}),e[79]=c,e[80]=be,e[81]=te):te=e[81];let he;return e[82]!==$||e[83]!==te?(he=s.jsxs(s.Fragment,{children:[$,te]}),e[82]=$,e[83]=te,e[84]=he):he=e[84],he};function Iv(t){return t.isApplying}function Pv(t){return t.showOpenCodeRestartConfirm}function Av(t){return t.setShowOpenCodeRestartConfirm}function Tv(t){return!t}const Ev=[{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.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"]},{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.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],isAvailable:t=>!t.isVSCode&&ce.getState().agentMemoryFeatureAvailable},{id:"routing.token",page:"routing",titleKey:"settings.routing.token.label",descriptionKey:"settings.routing.token.info",keywords:["jev","typesafe","api key","token","routing"],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-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{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 Wl(t){return t.trim().toLocaleLowerCase()}function Dv({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Wl(t);if(!r)return[];const l=a?new Set(a):null,m=r.split(/\s+/).filter(Boolean);return Ev.flatMap(c=>{if(l&&!l.has(c.page))return[];const x=Ea(c.page);if(!x||x.isAvailable&&!x.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const u=n(c.titleKey),v=c.descriptionKey?n(c.descriptionKey):null,d=Wl([u,v,i(c.page),...c.keywords??[]].filter(Boolean).join(" "));return m.every(j=>d.includes(j))?[{...c,title:u,description:v,pageTitle:i(c.page)}]:[]})}const Jl=256,Ql=280,rd="__openchamberSettingsDetail",Mv=["general","appearance","chat","notifications","sessions","routing","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],Rv=["general","projects","opencode","content"],Fv="__add_provider__";function Ov(t,e,a){const n=ds(),i=!t&&ra();return{isVSCode:n,isWeb:i,isDesktop:t,isMobile:e,routingAvailable:a}}function Yl(t,e){return t.isAvailable?t.isAvailable(e):!0}function Wr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ei(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Dr(t){if(!Wr(t))return null;const e=t[rd];if(!Wr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Cc(a),stage:n}}function Lv(){return typeof window>"u"||!Wr(window.history.state)?{}:window.history.state}const Zv=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav",registerBackHandler:r})=>{const{t:l}=et(),m=ha(),c=e??m.isMobile,x=ia(vc),u=ce(se=>se.settingsPage),v=ce(se=>se.isSettingsDialogOpen),d=ce(se=>se.setSettingsPage),j=ce(se=>se.shortcutOverrides.open_settings),g=Cc(u),[w,b]=o.useState(i),k=o.useRef(i==="nav"?g:null);o.useEffect(()=>{!c&&g==="home"&&d("general")},[c,d,g]);const[p,C]=o.useState(""),[E,A]=o.useState(null),[N,h]=o.useState(0),y=o.useRef(null),R=o.useRef(!1),T=o.useRef([]),P=o.useRef(0),D=o.useRef(!1),V=o.useMemo(()=>cs(),[]),$=o.useMemo(()=>cs()&&oi(),[]),I=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),M=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),H=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),U=o.useMemo(()=>Nc(),[]),Z=ce(se=>se.routingFeatureAvailable),ee=o.useMemo(()=>Ov(V,c,Z),[V,c,Z]),O=o.useMemo(()=>{const se=n?new Set(n):null;return Xu.filter(le=>le.slug!=="home").filter(le=>!se||se.has(le.slug)).filter(le=>Yl(le,ee)).filter(le=>!(ee.isVSCode&&le.slug==="projects")).filter(le=>!(c&&le.slug==="shortcuts"))},[ee,c,n]),ae=o.useMemo(()=>{const se=new Map(Mv.map((le,Ie)=>[le,Ie]));return O.slice().sort((le,Ie)=>(se.get(le.slug)??999)-(se.get(Ie.slug)??999))},[O]),_=en(se=>se.activeProjectId),W=Ws();o.useEffect(()=>{if(!(!v&&!ee.isVSCode&&!a)){if(g==="agents"){oa.getState().loadAgents(W);return}if(g==="commands"){La.getState().loadCommands(W);return}if(g==="mcp"){Ka.getState().loadMcpConfigs({directory:W});return}if(g==="plugins"){js.getState().loadPlugins();return}(g==="skills.installed"||g==="skills.catalog")&&(Xs.getState().loadSkills(W),Dn.getState().loadCatalog()),g==="snippets"&&Vi.getState().loadSnippets()}},[_,v,a,ee.isVSCode,W,g]);const q=o.useCallback(se=>{if(d(se),k.current=se,!c)return;const le=Ea(se);if(!le||le.slug==="home"){b("nav");return}b(le.kind==="split"?"page-sidebar":"page-content")},[c,d]),L=o.useMemo(()=>Ea(g),[g]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),z=o.useCallback(se=>{switch(se){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"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]),J=o.useMemo(()=>Dv({query:p,runtimeCtx:{...ee,isDesktopLocalOrigin:$,isMac:I,isWindows:M,isLinux:H,isWindowsArm64:U},visiblePageSlugs:n,t:l,getPageTitle:z}),[z,U,$,I,M,H,ee,p,l,n]),oe=o.useCallback(se=>{if(se.id.startsWith("agents.")){const le=oa.getState(),Ie=ei("new-agent",le.agents.map(Ne=>Ne.name));return le.setAgentDraft({name:Ie,scope:"user"}),le.setSelectedAgent(Ie),se.id==="agents.create"?"agents.name":se.id}if(se.id.startsWith("commands.")){const le=La.getState(),Ie=ei("new-command",le.commands.map(Ne=>Ne.name));return le.setCommandDraft({name:Ie,scope:"user"}),le.setSelectedCommand(Ie),se.id==="commands.create"?"commands.name":se.id}if(se.id.startsWith("mcp.")){const le=Ka.getState(),Ie=ei("new-mcp-server",le.mcpServers.map(Ne=>Ne.name));return le.setMcpDraft({name:Ie,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),le.setSelectedMcp(Ie),se.id==="mcp.create"?"mcp.server":se.id}if(se.id.startsWith("snippets.")){const le=Vi.getState(),Ie=ei("new-snippet",le.snippets.map(Ne=>Ne.name));return le.setSnippetDraft({name:Ie,scope:"global"}),le.setSelectedSnippet(Ie),se.id==="snippets.create"?"snippets.content":se.id}if(se.id.startsWith("skills.")){const le=Xs.getState(),Ie=ei("new-skill",le.skills.map(Ne=>Ne.name));return le.setSkillDraft({name:Ie,scope:"user",source:"opencode",description:"",instructions:""}),le.setSelectedSkill(Ie),se.id==="skills.create"?"skills.basic-information":se.id}return se.id==="providers.connect"&&Xe.getState().setSelectedProvider(Fv),se.id==="plugins.create"?"plugins.spec":se.id},[]),re=o.useMemo(()=>{const se=[],le=new Map;for(const Ie of J){let Ne=le.get(Ie.page);Ne||(Ne={page:Ie.page,pageTitle:Ie.pageTitle,results:[]},le.set(Ie.page,Ne),se.push(Ne)),Ne.results.push(Ie)}return se},[J]);o.useEffect(()=>{h(0),P.current=0,D.current=!1},[p]),o.useEffect(()=>{P.current=N},[N]),o.useEffect(()=>{T.current[N]?.scrollIntoView({block:"nearest"})},[N]),o.useEffect(()=>{N>=J.length&&h(Math.max(0,J.length-1)),T.current.length=J.length},[N,J.length]);const pe=o.useCallback(se=>{const le=oe(se);A(le),q(se.page),c&&b("page-content"),se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,q,oe]),ve=o.useCallback(se=>{if(p.trim()){if(se.key==="Escape"){se.preventDefault(),C("");return}if(J.length!==0){if(se.key==="ArrowDown"){se.preventDefault(),D.current=!0,h(le=>(le+1)%J.length);return}if(se.key==="ArrowUp"){se.preventDefault(),D.current=!0,h(le=>(le-1+J.length)%J.length);return}if(se.key==="Enter"){se.preventDefault();const le=(P.current%J.length+J.length)%J.length,Ie=J[le]??J[0];Ie&&pe(Ie)}}}},[pe,p,J]);o.useEffect(()=>{const se=E;if(!se)return;let le=!1;const Ie=window.requestAnimationFrame(()=>{if(le)return;const Ne=typeof CSS<"u"&&CSS.escape?CSS.escape(se):se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=y.current?.querySelector(`[data-settings-item="${Ne}"]`);Re&&(A(null),Re.scrollIntoView({block:"center",behavior:"smooth"}),Re.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Re.removeAttribute("data-settings-search-highlight")},1600))});return()=>{le=!0,window.cancelAnimationFrame(Ie)}},[E,g]);const be=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:ic,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),te=o.useCallback((se,le)=>{switch(se){case"projects":return s.jsx(Kg,{onItemSelect:le.onItemSelect});case"agents":return s.jsx(Dm,{onItemSelect:le.onItemSelect});case"commands":return s.jsx(Ym,{onItemSelect:le.onItemSelect});case"mcp":return s.jsx(ip,{onItemSelect:le.onItemSelect});case"plugins":return s.jsx(qp,{onItemSelect:le.onItemSelect});case"skills.installed":return s.jsx(rg,{onItemSelect:le.onItemSelect});case"providers":return s.jsx(mh,{onItemSelect:le.onItemSelect});case"usage":return s.jsx(Jh,{onItemSelect:le.onItemSelect});case"magic-prompts":return s.jsx(pf,{onItemSelect:le.onItemSelect});case"snippets":return s.jsx(xf,{onItemSelect:le.onItemSelect});default:return null}},[]),he=o.useCallback(se=>{const le=Ea(se);if(le&&!Yl(le,ee))return be();switch(se){case"projects":return s.jsx(Bg,{});case"remote-instances":return s.jsx(ch,{});case"agents":return s.jsx(Bm,{});case"behavior":return s.jsx(Qm,{});case"commands":return s.jsx(ap,{});case"mcp":return s.jsx(Ip,{});case"plugins":return s.jsx(ag,{});case"skills.installed":return s.jsx(nl,{view:"installed"});case"skills.catalog":return s.jsx(nl,{view:"catalog"});case"providers":return s.jsx(Gh,{});case"usage":return s.jsx(uf,{});case"about":return s.jsx(is,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Ac,{})});case"magic-prompts":return s.jsx(ff,{});case"snippets":return s.jsx(jf,{});case"git":return s.jsx(Cf,{});case"integrations":return s.jsx(qf,{});case"routing":return s.jsx(ex,{});case"extensions":return s.jsx(Nx,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const Ie=K[se]??"visual";return s.jsx(hv,{section:Ie})}default:return null}},[K,be,ee,l]);o.useEffect(()=>{if(!c||w!=="nav"||g==="home"||k.current===g)return;const se=Ea(g);!se||se.slug==="home"||(k.current=g,b(se.kind==="split"?"page-sidebar":"page-content"))},[c,w,g]);const ie=c&&w!=="nav",ue=c&&w==="page-content"&&L?.kind==="split",de=l(ue?"settings.view.actions.back":ie?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),Pe=bc("open_settings",j===void 0?void 0:{open_settings:j}),Ae=Pe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:ca(Pe)}):l("settings.view.actions.closeSettings"),we=o.useCallback(se=>{if(typeof window>"u"||ee.isVSCode)return;const le=Dr(window.history.state);le?.page===se&&le.stage==="page-content"||window.history.pushState({...Lv(),[rd]:{page:se,stage:"page-content"}},"",window.location.href)},[ee.isVSCode]),Le=o.useCallback(()=>{R.current=!0,b("page-content"),we(g)},[we,g]);o.useEffect(()=>{if(!c||w!=="page-content"||!R.current)return;R.current=!1;const se=window.requestAnimationFrame(()=>{y.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(se)}},[c,w,g]);const _e=o.useCallback(()=>{if(ue){if((typeof window<"u"?Dr(window.history.state):null)?.page===g&&!ee.isVSCode){window.history.back();return}b("page-sidebar");return}b("nav")},[ue,ee.isVSCode,g]);o.useEffect(()=>{if(r)return r(()=>!c||w==="nav"?!1:(_e(),!0)),()=>r(null)},[_e,c,w,r]),o.useEffect(()=>{if(!c||ee.isVSCode)return;const se=le=>{if(Ea(g)?.kind!=="split")return;if(Dr(le.state)?.page===g){b("page-content");return}b(Ne=>Ne==="page-content"?"page-sidebar":Ne)};return window.addEventListener("popstate",se),()=>{window.removeEventListener("popstate",se)}},[c,ee.isVSCode,g]);const Ve=()=>{const se=p.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"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:p,onChange:le=>C(le.target.value),onKeyDown:ve,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"}),se&&s.jsx("button",{type:"button",onClick:()=>C(""),"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(Ns,{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:se?J.length>0?(()=>{let le=0;return re.map(Ie=>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:Ie.pageTitle}),Ie.results.map(Ne=>{const Re=le;le+=1;const $e=Re===N,De=!!Ne.description;return s.jsxs("button",{type:"button",ref:Ce=>{T.current[Re]=Ce},onMouseMove:()=>{D.current=!1,h(Re)},onClick:()=>pe(Ne),className:ye("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",De?"min-h-11 py-1.5":"py-2",$e?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ne.title}),De&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Ne.description})]},Ne.id)})]},Ie.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const le=new Map;for(const Ne of ae){const Re=Ne.group,$e=le.get(Re);$e?$e.push(Ne):le.set(Re,[Ne])}return Rv.map(Ne=>({group:Ne,pages:le.get(Ne)??[]})).filter(Ne=>Ne.pages.length>0).map(({group:Ne,pages:Re},$e)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ye("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",$e===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${Ne}`)}),Re.map(De=>{const Ce=g===De.slug&&!(c&&w==="nav"),Ye=em(De.slug);return!Ye&&De.slug!=="mcp"?null:s.jsx(Zr,{children:s.jsx(Xr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>q(De.slug),"aria-current":Ce?"page":void 0,className:ye("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Ce?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[De.slug==="mcp"?s.jsx(hu,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(B,{name:Ye,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:z(De.slug)}),De.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")})]})]})})},De.slug)})]},Ne))})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!ee.isVSCode||x>0)&&s.jsx(Cv,{})})})]})},je=()=>{if(w==="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(zn,{children:Ve()})})});if(!L)return s.jsx("div",{className:"flex-1 bg-background"});if(w==="page-sidebar"){if(L.kind!=="split"){const le=he(g);return s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(zn,{children:le})})}return s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(zn,{children:te(g,{onItemSelect:Le})})})}const se=he(g);return s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(zn,{children:se})})},ke=()=>!L||g==="home"?null:L.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("border-r",ee.isVSCode?"bg-background":"bg-sidebar"),style:{width:Ql,minWidth:Ql,borderColor:"var(--interactive-border)"},children:s.jsx(zn,{children:te(g,{})})}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(zn,{children:he(g)})})]}):s.jsx(Ns,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(zn,{children:he(g)})});return s.jsxs("div",{ref:y,"data-settings-view":"true",className:ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:ye("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",w!=="nav"&&"border-b","bg-background"),style:w!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ie?s.jsx("button",{type:"button",onClick:_e,"aria-label":de,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:w==="nav"?l("settings.view.home.title"):L?z(L.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:Ae,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ie&&s.jsx("div",{className:ye("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:_e,"aria-label":l("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:ye("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:Ae,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?je():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",V?"bg-sidebar":ee.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Jl}px`,minWidth:`${Jl}px`,borderColor:"var(--interactive-border)"},children:s.jsx(zn,{children:Ve()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ke()})]})})]})};export{Ac as A,Zv as S};