@vantran-se/openchamber-web 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/README.md +32 -24
  2. package/bin/cli.js +1 -3
  3. package/bin/cli.test.js +40 -16
  4. package/bin/lib/DOCUMENTATION.md +6 -5
  5. package/bin/lib/cli-args.js +6 -1
  6. package/bin/lib/cli-args.test.js +34 -0
  7. package/bin/lib/cli-lifecycle.js +0 -1
  8. package/bin/lib/cli-network.js +8 -2
  9. package/bin/lib/cli-process.js +1 -1
  10. package/bin/lib/cli-settings-accessors.test.js +21 -13
  11. package/bin/lib/cli-startup.js +17 -11
  12. package/bin/lib/cli-startup.test.js +92 -2
  13. package/bin/lib/commands-connect-url.js +8 -1
  14. package/bin/lib/commands-schedule.js +8 -2
  15. package/bin/lib/commands-serve.js +15 -21
  16. package/bin/lib/commands-update.js +12 -24
  17. package/bin/lib/commands-update.test.js +14 -46
  18. package/dist/assets/DiffView-Cv9MSXl1.js +4 -0
  19. package/dist/assets/FilePreviewCommentMenu-D4kLseHj.js +4 -0
  20. package/dist/assets/FilesView-BVoD8I2x.js +14 -0
  21. package/dist/assets/{GitView-DzuzhIPx.js → GitView-Bzb8p-ew.js} +4 -4
  22. package/dist/assets/GuestSurfacePane-Crdbvsxo.js +1 -0
  23. package/dist/assets/InProgressOperationBanner-CwMjNQgk.js +2 -0
  24. package/dist/assets/{JsonTreeView-B_EPRjzy.js → JsonTreeView-DRKHZfsn.js} +1 -1
  25. package/dist/assets/MarkdownImageGallery-DZtqT1Zn.js +1 -0
  26. package/dist/assets/MarkdownRendererImpl-CqG7HCNd.js +10 -0
  27. package/dist/assets/OnboardingScreen-DMIxwYK5.js +1 -0
  28. package/dist/assets/{PatchDiff-6yh1csza.js → PatchDiff-CUcCg1jk.js} +1 -1
  29. package/dist/assets/PierreDiffViewer-CnnR-dnD.js +228 -0
  30. package/dist/assets/PlanView-RCBadcY7.js +5 -0
  31. package/dist/assets/SettingsView-CjBjZFRO.js +30 -0
  32. package/dist/assets/SettingsWindow-DyM7QuhI.js +1 -0
  33. package/dist/assets/SubmoduleDiffSummary-BWIfgMED.js +1 -0
  34. package/dist/assets/ToolOutputDialog-Q0P3FuAi.js +15 -0
  35. package/dist/assets/ToolPartDiffPreview-p7qR9FpU.js +8 -0
  36. package/dist/assets/{VirtualizedFileDiff-BTJVRkyo.js → VirtualizedFileDiff-CFpjL8Ns.js} +3 -3
  37. package/dist/assets/{Virtualizer-xCEYz34p.js → Virtualizer-C0IsclZn.js} +1 -1
  38. package/dist/assets/WalkthroughView-DI31zD02.js +4 -0
  39. package/dist/assets/appThemeRegistry-B9gkFq9i.js +1 -0
  40. package/dist/assets/{computeVirtualFileMetrics-CmPe29DM.js → computeVirtualFileMetrics-C2WM6JC2.js} +2 -2
  41. package/dist/assets/de-YKfk5MmC.js +14 -0
  42. package/dist/assets/es-_gwT0kr-.js +20 -0
  43. package/dist/assets/fileTreeStatus-D438yi8M.js +1 -0
  44. package/dist/assets/fr-DqzvXmIm.js +18 -0
  45. package/dist/assets/index-BLaHKdtx.js +1 -0
  46. package/dist/assets/index-BkMXRrVQ.css +1 -0
  47. package/dist/assets/index-DxNa7xYB.js +65 -0
  48. package/dist/assets/initializeSharedPreferences-Bck5EAWP.js +1 -0
  49. package/dist/assets/{isDiffPlainText-CQmDCnEv.js → isDiffPlainText-Dgbw8VKk.js} +1 -1
  50. package/dist/assets/{isFilePlainText-CYBUzW4I.js → isFilePlainText-_ZS5UYRj.js} +1 -1
  51. package/dist/assets/ja-B-GFYhQE.js +20 -0
  52. package/dist/assets/ko-mzksfqDC.js +20 -0
  53. package/dist/assets/main-C5Xx8dn_.js +2 -0
  54. package/dist/assets/main-CfBSQM1H.js +990 -0
  55. package/dist/assets/markdownCore-BmWwW1ll.js +7 -0
  56. package/dist/assets/miniChat-mnKwy4vQ.js +2 -0
  57. package/dist/assets/mobile-DeEQd0wZ.js +2 -0
  58. package/dist/assets/nl-CWQr6NSq.js +20 -0
  59. package/dist/assets/{parseDiffFromFile-Cy0PNxun.js → parseDiffFromFile-BUgn-T9p.js} +2 -2
  60. package/dist/assets/patchFileDiff-Dt8LhgBh.js +13 -0
  61. package/dist/assets/pl-UmRcDUX2.js +20 -0
  62. package/dist/assets/pt-BR-BSLybvVF.js +20 -0
  63. package/dist/assets/relocateRestoredSession-B5E9xb3T.js +1 -0
  64. package/dist/assets/renderElectronMiniChatApp-C0a9A5_J.js +2 -0
  65. package/dist/assets/renderMobileApp-BNncg3Pk.js +25 -0
  66. package/dist/assets/runtimeEndpointReset-CZ5aafpl.js +62 -0
  67. package/dist/assets/{selectionMarkdown-TkYk5h9l.js → selectionMarkdown-CUN3wUld.js} +9 -9
  68. package/dist/assets/{sessionOwnership-Bs1xbRfB.js → sessionOwnership-BSuxCEhb.js} +1 -1
  69. package/dist/assets/shikiHighlight-DHDx-6eM.js +1 -0
  70. package/dist/assets/space-apply-DM_2pRW7.js +1 -0
  71. package/dist/assets/space-close-Bpomt8z0.js +1 -0
  72. package/dist/assets/{surface-B6n7wJtt.js → surface-C-jQaGnL.js} +1 -1
  73. package/dist/assets/{textMateThemeFromAppTheme-CDlKffWz.js → textMateThemeFromAppTheme-DlsTphbY.js} +1 -1
  74. package/dist/assets/tr-gaTrX_HK.js +11 -0
  75. package/dist/assets/uk-CnJF6ykl.js +20 -0
  76. package/dist/assets/{useAppFontEffects-DCqCVGlT.js → useAppFontEffects-DGlvOqP_.js} +194 -233
  77. package/dist/assets/useInlineCommentController-kMN4Wg_D.js +2 -0
  78. package/dist/assets/{useRootScrollLock-BowwS8kq.js → useRootScrollLock-DMPpvpNP.js} +2 -2
  79. package/dist/assets/{vendor-base-ui-DX96QhTP.js → vendor-base-ui-Det7U81h.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-autocomplete-DW1FQz9_.js → vendor-codemirror-autocomplete-BSHQHbKu.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-commands-DpmhalwN.js → vendor-codemirror-commands-C4G_dPWe.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-angular-BqExbN1M.js → vendor-codemirror-lang-angular-B6LbBGHB.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-cpp-DZA36HfS.js → vendor-codemirror-lang-cpp-BWWXBx7W.js} +1 -1
  84. package/dist/assets/{vendor-codemirror-lang-css-B07blnnZ.js → vendor-codemirror-lang-css-Cayfb29q.js} +1 -1
  85. package/dist/assets/{vendor-codemirror-lang-go-BM8K9D1-.js → vendor-codemirror-lang-go-BoKlCNKw.js} +1 -1
  86. package/dist/assets/{vendor-codemirror-lang-html-DaH9adfE.js → vendor-codemirror-lang-html-BQWerHsJ.js} +1 -1
  87. package/dist/assets/{vendor-codemirror-lang-java-CsdC0viz.js → vendor-codemirror-lang-java-DWX7Fq_K.js} +1 -1
  88. package/dist/assets/{vendor-codemirror-lang-javascript-CpGYXGuo.js → vendor-codemirror-lang-javascript-DbpEcZM0.js} +2 -2
  89. package/dist/assets/{vendor-codemirror-lang-jinja-BBeGzXw5.js → vendor-codemirror-lang-jinja-D1JIJRA7.js} +1 -1
  90. package/dist/assets/{vendor-codemirror-lang-json-58T70Hqs.js → vendor-codemirror-lang-json-BzgckzmB.js} +1 -1
  91. package/dist/assets/{vendor-codemirror-lang-less-BI-xCA59.js → vendor-codemirror-lang-less-B9EpDXFi.js} +1 -1
  92. package/dist/assets/{vendor-codemirror-lang-liquid-zEcMa-zy.js → vendor-codemirror-lang-liquid-9U7kRbSf.js} +1 -1
  93. package/dist/assets/{vendor-codemirror-lang-markdown-BLKnlLP4.js → vendor-codemirror-lang-markdown-D2TEBIvZ.js} +1 -1
  94. package/dist/assets/{vendor-codemirror-lang-php-9f35M83-.js → vendor-codemirror-lang-php-BT6sDVzE.js} +1 -1
  95. package/dist/assets/vendor-codemirror-lang-python-jAMtYiA9.js +3 -0
  96. package/dist/assets/{vendor-codemirror-lang-rust-MNDL_jZQ.js → vendor-codemirror-lang-rust-CVO56EiL.js} +1 -1
  97. package/dist/assets/{vendor-codemirror-lang-sass-p9epsSNm.js → vendor-codemirror-lang-sass-DZlOoUWu.js} +1 -1
  98. package/dist/assets/{vendor-codemirror-lang-sql-Bqzh0EXX.js → vendor-codemirror-lang-sql-fZ6t1DPw.js} +1 -1
  99. package/dist/assets/{vendor-codemirror-lang-vue-BnNUWV-p.js → vendor-codemirror-lang-vue-DxbqrLiE.js} +1 -1
  100. package/dist/assets/{vendor-codemirror-lang-wast-C2a-oLmk.js → vendor-codemirror-lang-wast-DyU1Gt-I.js} +1 -1
  101. package/dist/assets/vendor-codemirror-lang-xml-C9a_K5_p.js +1 -0
  102. package/dist/assets/{vendor-codemirror-lang-yaml-C0sjswB0.js → vendor-codemirror-lang-yaml-Cptq8l0e.js} +1 -1
  103. package/dist/assets/{vendor-codemirror-language-ByBn5zIW.js → vendor-codemirror-language-DufXoQvE.js} +2 -2
  104. package/dist/assets/vendor-codemirror-language-data-CtwSWKtX.js +2 -0
  105. package/dist/assets/{vendor-codemirror-search-ib-sHD5W.js → vendor-codemirror-search-CvXM_pZg.js} +1 -1
  106. package/dist/assets/{vendor-codemirror-state-G3UuR-be.js → vendor-codemirror-state-Dek9sMtw.js} +1 -1
  107. package/dist/assets/{vendor-codemirror-view-Bniqp7p5.js → vendor-codemirror-view-1e0FQ6Wn.js} +1 -1
  108. package/dist/assets/vendor-framer-motion-DxDVhOLc.js +9 -0
  109. package/dist/assets/vendor-katex-CuQvj9-L.js +257 -0
  110. package/dist/assets/vendor-katex-DdZNUVNG.css +1 -0
  111. package/dist/assets/{vendor-motion-dom-DcCgeG69.js → vendor-motion-dom-HXPOMxb7.js} +1 -1
  112. package/dist/assets/{vendor-opencode-client-DHzhmLwV.js → vendor-opencode-client-BmFcUkbQ.js} +1 -1
  113. package/dist/assets/{vendor-replit-codemirror-vim-DkzqxN2H.js → vendor-replit-codemirror-vim-BlJRn-cW.js} +2 -2
  114. package/dist/assets/{vendor-tanstack-react-virtual-H_JmXOFV.js → vendor-tanstack-react-virtual-CvuLsk7D.js} +1 -1
  115. package/dist/assets/{vendor-tanstack-virtual-core-Dxc8hSTB.js → vendor-tanstack-virtual-core-DPaNcJcT.js} +1 -1
  116. package/dist/assets/zh-CN-t2vigSB1.js +20 -0
  117. package/dist/assets/zh-TW-jAgqBokB.js +20 -0
  118. package/dist/index.html +6 -6
  119. package/dist/mini-chat.html +6 -6
  120. package/dist/mobile.html +6 -6
  121. package/package.json +8 -5
  122. package/server/index.js +80 -36
  123. package/server/lib/agent-memory/actions.js +1 -6
  124. package/server/lib/agent-memory/routes.js +1 -2
  125. package/server/lib/agent-memory/runtime.js +1 -8
  126. package/server/lib/agent-tool/DOCUMENTATION.md +7 -3
  127. package/server/lib/agent-tool/runtime.js +3 -6
  128. package/server/lib/agent-tool/runtime.test.js +0 -2
  129. package/server/lib/browser-control/DOCUMENTATION.md +6 -0
  130. package/server/lib/changelog/update-notes.js +1 -1
  131. package/server/lib/context-obligatory/runtime.js +1 -2
  132. package/server/lib/dev-tunnel/DOCUMENTATION.md +8 -0
  133. package/server/lib/dev-tunnel/client.js +21 -10
  134. package/server/lib/dev-tunnel/tunnel.test.js +34 -0
  135. package/server/lib/dispatch-results/runtime.js +1 -1
  136. package/server/lib/enterprise-mode.d.ts +1 -0
  137. package/server/lib/enterprise-mode.js +13 -2
  138. package/server/lib/enterprise-mode.test.js +21 -0
  139. package/server/lib/event-stream/DOCUMENTATION.md +2 -2
  140. package/server/lib/event-stream/index.js +1 -3
  141. package/server/lib/event-stream/translate-v2.js +1 -9
  142. package/server/lib/event-stream/translate-v2.test.js +0 -11
  143. package/server/lib/fs/DOCUMENTATION.md +5 -2
  144. package/server/lib/fs/routes.js +62 -15
  145. package/server/lib/fs/routes.test.js +278 -48
  146. package/server/lib/fs/workspace-file-names.js +104 -0
  147. package/server/lib/fs/workspace-file-names.test.js +62 -0
  148. package/server/lib/git/DOCUMENTATION.md +17 -5
  149. package/server/lib/git/contributor-provenance-storage.js +9 -6
  150. package/server/lib/git/contributor-provenance-storage.test.js +29 -0
  151. package/server/lib/git/credential-broker.js +1 -1
  152. package/server/lib/git/credential-resolver.js +1 -4
  153. package/server/lib/git/credentials.js +1 -0
  154. package/server/lib/git/discovery-endpoint.js +1 -1
  155. package/server/lib/git/identity-provisioning.js +2 -1
  156. package/server/lib/git/identity-storage.js +3 -4
  157. package/server/lib/git/lfs-discovery.js +14 -14
  158. package/server/lib/git/lfs-discovery.test.js +16 -6
  159. package/server/lib/git/network-operation-plan.js +50 -62
  160. package/server/lib/git/network-operation-plan.test.js +103 -1
  161. package/server/lib/git/network-operation-registry.js +4 -6
  162. package/server/lib/git/network-operation-storage.js +4 -6
  163. package/server/lib/git/network-operations.js +12 -4
  164. package/server/lib/git/network-operations.test.js +19 -6
  165. package/server/lib/git/redaction.js +2 -1
  166. package/server/lib/git/repository-credential-runtime.js +5 -3
  167. package/server/lib/git/repository-credential-runtime.test.js +22 -0
  168. package/server/lib/git/routes.js +31 -137
  169. package/server/lib/git/routes.test.js +2 -2
  170. package/server/lib/git/service.js +143 -27
  171. package/server/lib/git/service.test.js +215 -1
  172. package/server/lib/git/ssh-credential-storage.js +1 -4
  173. package/server/lib/git/submodule-discovery.js +1 -1
  174. package/server/lib/git/worktree-bootstrap-storage.js +3 -4
  175. package/server/lib/git/worktree-bootstrap-storage.test.js +15 -0
  176. package/server/lib/git/worktree-creation.js +194 -0
  177. package/server/lib/git/worktree-creation.test.js +155 -0
  178. package/server/lib/github/DOCUMENTATION.md +11 -6
  179. package/server/lib/github/auth.js +2 -4
  180. package/server/lib/github/device-flow.js +2 -2
  181. package/server/lib/github/gh-cli-credential.js +1 -0
  182. package/server/lib/github/octokit.js +31 -0
  183. package/server/lib/github/pr-status.js +35 -18
  184. package/server/lib/github/pr-status.test.js +271 -3
  185. package/server/lib/github/reference-search.js +102 -13
  186. package/server/lib/github/reference-search.test.js +48 -7
  187. package/server/lib/github/routes.auth.test.js +18 -0
  188. package/server/lib/github/routes.js +360 -6
  189. package/server/lib/github/routes.mutations.test.js +239 -0
  190. package/server/lib/github/routes.test.js +134 -2
  191. package/server/lib/gitlab/DOCUMENTATION.md +5 -1
  192. package/server/lib/gitlab/auth-storage.test.js +1 -0
  193. package/server/lib/gitlab/mappers.js +30 -1
  194. package/server/lib/gitlab/resources.js +230 -6
  195. package/server/lib/gitlab/resources.test.js +179 -0
  196. package/server/lib/gitlab/routes.js +200 -6
  197. package/server/lib/gitlab/routes.test.js +186 -2
  198. package/server/lib/gitlab/validation.js +1 -5
  199. package/server/lib/guests/DOCUMENTATION.md +1 -1
  200. package/server/lib/guests/oauth.js +2 -2
  201. package/server/lib/guests/service.js +1 -1
  202. package/server/lib/guests/sockets.js +1 -1
  203. package/server/lib/injected-env.d.ts +8 -0
  204. package/server/lib/injected-env.js +50 -0
  205. package/server/lib/injected-env.test.js +56 -0
  206. package/server/lib/linear/DOCUMENTATION.md +5 -6
  207. package/server/lib/linear/issues.js +62 -4
  208. package/server/lib/linear/issues.test.js +68 -0
  209. package/server/lib/linear/oauth.js +5 -5
  210. package/server/lib/linear/parse.js +2 -9
  211. package/server/lib/message-queue/DOCUMENTATION.md +23 -1
  212. package/server/lib/message-queue/runtime.js +85 -12
  213. package/server/lib/message-queue/runtime.test.js +172 -2
  214. package/server/lib/notifications/apns-runtime.js +5 -6
  215. package/server/lib/notifications/apns-runtime.test.js +20 -4
  216. package/server/lib/openchamber-control/DOCUMENTATION.md +19 -1
  217. package/server/lib/openchamber-control/actions.js +2 -1
  218. package/server/lib/openchamber-control/service.js +119 -20
  219. package/server/lib/openchamber-control/service.test.js +166 -0
  220. package/server/lib/openchamber-sessions/archive-store.js +1 -6
  221. package/server/lib/openchamber-sessions/routes.js +47 -12
  222. package/server/lib/openchamber-sessions/routes.test.js +65 -2
  223. package/server/lib/openchamber-sessions/session-metadata-store.js +1 -6
  224. package/server/lib/opencode/DOCUMENTATION.md +22 -8
  225. package/server/lib/opencode/agents.js +62 -0
  226. package/server/lib/opencode/auth-state-runtime.js +3 -1
  227. package/server/lib/opencode/auth.d.ts +1 -1
  228. package/server/lib/opencode/auth.js +8 -0
  229. package/server/lib/opencode/auth.test.js +31 -0
  230. package/server/lib/opencode/config-entity-routes.js +16 -0
  231. package/server/lib/opencode/config-entity-v2.test.js +16 -1
  232. package/server/lib/opencode/config-paths.test.js +2 -2
  233. package/server/lib/opencode/config-v2.js +2 -4
  234. package/server/lib/opencode/feature-routes-runtime.js +89 -49
  235. package/server/lib/opencode/lifecycle.js +41 -21
  236. package/server/lib/opencode/lifecycle.test.js +50 -2
  237. package/server/lib/opencode/model-discovery.js +1 -1
  238. package/server/lib/opencode/model-discovery.test.js +17 -0
  239. package/server/lib/opencode/models-metadata.js +0 -2
  240. package/server/lib/opencode/openchamber-routes.test.js +3 -3
  241. package/server/lib/opencode/plugins.js +6 -9
  242. package/server/lib/opencode/provider-source-route.test.js +101 -3
  243. package/server/lib/opencode/providers-disabled.test.js +59 -0
  244. package/server/lib/opencode/providers.js +34 -0
  245. package/server/lib/opencode/proxy.js +11 -3
  246. package/server/lib/opencode/routes.js +40 -2
  247. package/server/lib/opencode/settings-helpers.js +27 -1
  248. package/server/lib/opencode/settings-helpers.test.js +19 -7
  249. package/server/lib/opencode/settings-registry.json +27 -16
  250. package/server/lib/opencode/settings-runtime.test.js +18 -0
  251. package/server/lib/opencode/shared-service-runtime.js +23 -104
  252. package/server/lib/opencode/shared.js +77 -46
  253. package/server/lib/opencode/shared.test.js +12 -12
  254. package/server/lib/opencode/shutdown-runtime.test.js +2 -3
  255. package/server/lib/opencode/skill-routes.js +123 -38
  256. package/server/lib/opencode/skill-routes.test.js +201 -0
  257. package/server/lib/opencode/skills.js +81 -34
  258. package/server/lib/opencode/skills.test.js +176 -21
  259. package/server/lib/opencode/startup-pipeline-runtime.js +6 -3
  260. package/server/lib/opencode/startup-pipeline-runtime.test.js +2 -1
  261. package/server/lib/opencode/watcher.test.js +0 -54
  262. package/server/lib/outbound-proxy.js +52 -0
  263. package/server/lib/outbound-proxy.test.js +55 -0
  264. package/server/lib/package-manager.js +23 -17
  265. package/server/lib/package-manager.test.js +5 -18
  266. package/server/lib/permission-auto-accept/DOCUMENTATION.md +1 -1
  267. package/server/lib/permission-auto-accept/runtime.js +19 -47
  268. package/server/lib/permission-auto-accept/runtime.test.js +2 -2
  269. package/server/lib/project-context/DOCUMENTATION.md +7 -1
  270. package/server/lib/project-context/routes.js +1 -2
  271. package/server/lib/project-context/runtime.js +12 -14
  272. package/server/lib/project-context/runtime.test.js +78 -2
  273. package/server/lib/projects/project-config.js +30 -15
  274. package/server/lib/projects/project-config.test.js +30 -0
  275. package/server/lib/projects/project-setup.js +1 -2
  276. package/server/lib/projects/routes.js +1 -2
  277. package/server/lib/quota/DOCUMENTATION.md +35 -7
  278. package/server/lib/quota/index.js +1 -0
  279. package/server/lib/quota/providers/claude/index.js +1 -1
  280. package/server/lib/quota/providers/cline-pass.js +1 -1
  281. package/server/lib/quota/providers/exe-dev.js +1 -1
  282. package/server/lib/quota/providers/google/index.js +1 -1
  283. package/server/lib/quota/providers/hyper.js +1 -1
  284. package/server/lib/quota/providers/kimi.js +116 -36
  285. package/server/lib/quota/providers/kimi.test.js +128 -3
  286. package/server/lib/quota/providers/opencode-go.js +144 -21
  287. package/server/lib/quota/providers/opencode-go.test.js +229 -6
  288. package/server/lib/quota/providers/openrouter.js +1 -1
  289. package/server/lib/quota/providers/zenmux.js +1 -1
  290. package/server/lib/quota/utils/auth.js +1 -0
  291. package/server/lib/quota/utils/transformers.js +2 -6
  292. package/server/lib/relay/DOCUMENTATION.md +18 -3
  293. package/server/lib/relay/e2ee.js +7 -7
  294. package/server/lib/relay/host-client.js +84 -13
  295. package/server/lib/relay/host-client.test.js +201 -1
  296. package/server/lib/relay/identity.js +6 -29
  297. package/server/lib/relay/identity.test.js +18 -28
  298. package/server/lib/relay/key-store.js +141 -0
  299. package/server/lib/relay/key-store.test.js +138 -0
  300. package/server/lib/relay/service.js +8 -8
  301. package/server/lib/relay/service.test.js +10 -5
  302. package/server/lib/relay/signing-key.js +13 -36
  303. package/server/lib/relay/tunnel-codec.js +10 -10
  304. package/server/lib/route-module-exports.test.js +22 -0
  305. package/server/lib/routing/DOCUMENTATION.md +23 -3
  306. package/server/lib/routing/cache.js +87 -0
  307. package/server/lib/routing/defaults.js +11 -0
  308. package/server/lib/routing/history.js +12 -4
  309. package/server/lib/routing/runtime.js +39 -3
  310. package/server/lib/routing/runtime.test.js +81 -2
  311. package/server/lib/routing/store.js +12 -1
  312. package/server/lib/routing/store.test.js +13 -0
  313. package/server/lib/scheduled-tasks/DOCUMENTATION.md +59 -1
  314. package/server/lib/scheduled-tasks/existing-session.js +119 -0
  315. package/server/lib/scheduled-tasks/existing-session.test.js +350 -0
  316. package/server/lib/scheduled-tasks/loops.js +1 -8
  317. package/server/lib/scheduled-tasks/routes.js +8 -8
  318. package/server/lib/scheduled-tasks/runtime.js +103 -13
  319. package/server/lib/scheduled-tasks/runtime.test.js +48 -0
  320. package/server/lib/scheduled-tasks/service.js +33 -11
  321. package/server/lib/scheduled-tasks/service.test.js +128 -2
  322. package/server/lib/scheduled-tasks/session-defaults.js +27 -0
  323. package/server/lib/scheduled-tasks/session-defaults.test.js +19 -0
  324. package/server/lib/session-assist/context.js +1 -0
  325. package/server/lib/session-folders/routes.js +2 -2
  326. package/server/lib/session-goal/objectives.js +1 -1
  327. package/server/lib/session-knowledge/routes.js +2 -2
  328. package/server/lib/session-knowledge/runtime.js +1 -2
  329. package/server/lib/session-work/DOCUMENTATION.md +39 -14
  330. package/server/lib/session-work/questions.js +31 -2
  331. package/server/lib/session-work/runtime.js +22 -13
  332. package/server/lib/session-work/runtime.test.js +43 -26
  333. package/server/lib/session-work/state.js +10 -4
  334. package/server/lib/session-work/state.test.js +8 -1
  335. package/server/lib/shared/DOCUMENTATION.md +89 -0
  336. package/server/lib/shared/guards.js +53 -0
  337. package/server/lib/shared/guards.test.js +112 -0
  338. package/server/lib/skills-catalog/DOCUMENTATION.md +10 -8
  339. package/server/lib/skills-catalog/cache.js +3 -2
  340. package/server/lib/skills-catalog/curated-sources.js +5 -1
  341. package/server/lib/skills-catalog/git.js +107 -20
  342. package/server/lib/skills-catalog/git.test.js +78 -0
  343. package/server/lib/skills-catalog/install.js +21 -12
  344. package/server/lib/skills-catalog/scan.js +25 -15
  345. package/server/lib/skills-catalog/source.js +26 -1
  346. package/server/lib/skills-catalog/source.test.js +27 -0
  347. package/server/lib/source-control/DOCUMENTATION.md +2 -1
  348. package/server/lib/source-control/audit-storage.js +7 -6
  349. package/server/lib/source-control/audit-storage.test.js +11 -0
  350. package/server/lib/source-control/binding-service.js +2 -5
  351. package/server/lib/source-control/change-request-worktree.js +90 -0
  352. package/server/lib/source-control/change-request-worktree.test.js +121 -0
  353. package/server/lib/source-control/mutation-executor.js +1 -1
  354. package/server/lib/source-control/mutation-storage.js +11 -5
  355. package/server/lib/source-control/provider-instance.js +1 -2
  356. package/server/lib/source-control/repository-identity.js +1 -1
  357. package/server/lib/source-control/routes.js +14 -2
  358. package/server/lib/spaces/DOCUMENTATION.md +42 -17
  359. package/server/lib/spaces/command-stream.test.js +15 -0
  360. package/server/lib/spaces/dispatcher.js +7 -0
  361. package/server/lib/spaces/dispatcher.test.js +17 -0
  362. package/server/lib/spaces/hardening.js +2 -2
  363. package/server/lib/spaces/hardening.test.js +1 -1
  364. package/server/lib/spaces/host.js +2 -0
  365. package/server/lib/spaces/journey.js +66 -5
  366. package/server/lib/spaces/journey.test.js +95 -4
  367. package/server/lib/spaces/layout.js +1 -1
  368. package/server/lib/spaces/places/docker-disk.js +38 -14
  369. package/server/lib/spaces/places/docker-disk.test.js +80 -1
  370. package/server/lib/spaces/places/docker.js +35 -11
  371. package/server/lib/spaces/places/fake-docker.js +22 -3
  372. package/server/lib/spaces/places/memory-place.js +3 -0
  373. package/server/lib/spaces/places/packed.docker.live.test.js +1 -1
  374. package/server/lib/spaces/routes.js +5 -0
  375. package/server/lib/spaces/routes.test.js +4 -2
  376. package/server/lib/spaces/run-command.js +9 -2
  377. package/server/lib/spaces/tools.js +4 -5
  378. package/server/lib/spaces/tools.test.js +2 -2
  379. package/server/lib/terminal/runtime.js +18 -6
  380. package/server/lib/terminal/runtime.test.js +66 -0
  381. package/server/lib/tts/index.js +3 -0
  382. package/server/lib/tts/service.js +4 -2
  383. package/server/lib/walkthrough/DOCUMENTATION.md +3 -1
  384. package/server/lib/walkthrough/index.js +2 -3
  385. package/server/lib/walkthrough/pr-source.test.js +22 -0
  386. package/server/lib/walkthrough/sources.js +6 -1
  387. package/server/opencode-proxy.test.js +127 -0
  388. package/bin/lib/commands-startup.test.js +0 -15
  389. package/dist/assets/CodeMirrorCommentWidgets-CVDSjcrP.js +0 -1
  390. package/dist/assets/DiffView-Ct7vL3fD.js +0 -4
  391. package/dist/assets/FilesView-DT0uEYgT.js +0 -17
  392. package/dist/assets/GuestSurfacePane-DVvk1VPu.js +0 -1
  393. package/dist/assets/LinearIssuesView-C10MwA9h.js +0 -1
  394. package/dist/assets/MarkdownImageGallery-BbN_K_3d.js +0 -1
  395. package/dist/assets/MarkdownRendererImpl-BLt2Tkk9.js +0 -10
  396. package/dist/assets/OnboardingScreen-Bgp5A3WB.js +0 -1
  397. package/dist/assets/PierreDiffViewer-CWJLj-S-.js +0 -210
  398. package/dist/assets/PlanView-DsRWnsOI.js +0 -5
  399. package/dist/assets/PublishDialog-CCeKloRu.js +0 -2
  400. package/dist/assets/SettingsView-BuPPsNPp.js +0 -30
  401. package/dist/assets/SettingsWindow-CM5fL8Ot.js +0 -1
  402. package/dist/assets/SubmoduleDiffSummary-CfsMcfiQ.js +0 -1
  403. package/dist/assets/ToolOutputDialog-mZrfSofz.js +0 -15
  404. package/dist/assets/ToolPartDiffPreview-BUGCRYEL.js +0 -8
  405. package/dist/assets/WalkthroughView-ClBo7PPd.js +0 -4
  406. package/dist/assets/appThemeRegistry-CxzMxR-H.js +0 -1
  407. package/dist/assets/de-CBla4hjd.js +0 -14
  408. package/dist/assets/es-BmnZtxTD.js +0 -20
  409. package/dist/assets/fileTreeStatus-BSHFIGEg.js +0 -1
  410. package/dist/assets/fr-OVKIBUZO.js +0 -18
  411. package/dist/assets/index-CKCFKmjF.js +0 -1
  412. package/dist/assets/index-Dbx4V4GN.css +0 -1
  413. package/dist/assets/index-vQ1Pg1cr.js +0 -61
  414. package/dist/assets/ja-6v-yr-gE.js +0 -20
  415. package/dist/assets/ko-I_ZLvgQ9.js +0 -20
  416. package/dist/assets/main-CmO4dRtR.js +0 -2
  417. package/dist/assets/main-b9vqhlYM.js +0 -999
  418. package/dist/assets/markdownCore-BPEZRQfP.js +0 -7
  419. package/dist/assets/miniChat-B5Oi7B-6.js +0 -2
  420. package/dist/assets/mobile-CVtShif9.js +0 -2
  421. package/dist/assets/nl-DcvIJf46.js +0 -20
  422. package/dist/assets/patchFileDiff-CW3wCH1O.js +0 -13
  423. package/dist/assets/pl-JxCUl0sd.js +0 -20
  424. package/dist/assets/pt-BR-L89mjja2.js +0 -20
  425. package/dist/assets/relocateRestoredSession-DYh_9oBa.js +0 -1
  426. package/dist/assets/renderElectronMiniChatApp-BD-1JHSg.js +0 -2
  427. package/dist/assets/renderMobileApp-7s5InXt1.js +0 -25
  428. package/dist/assets/runtimeEndpointReset-DqLJC6L1.js +0 -53
  429. package/dist/assets/shikiHighlight-CXgZnvHh.js +0 -1
  430. package/dist/assets/space-apply-1trGVIl8.js +0 -1
  431. package/dist/assets/space-close-y7j-NuBv.js +0 -1
  432. package/dist/assets/tr-ka5J1flt.js +0 -11
  433. package/dist/assets/uk-PyGe6Q_u.js +0 -20
  434. package/dist/assets/useInlineCommentController-CrjSGCpi.js +0 -2
  435. package/dist/assets/vendor-codemirror-lang-python-B7ClrMIT.js +0 -3
  436. package/dist/assets/vendor-codemirror-lang-xml-C8tGnS64.js +0 -1
  437. package/dist/assets/vendor-codemirror-language-data-q2bKO1EM.js +0 -2
  438. package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +0 -1
  439. package/dist/assets/vendor-katex-CHD9BdDO.js +0 -257
  440. package/dist/assets/vendor-katex-Cp579UoJ.css +0 -1
  441. package/dist/assets/zh-CN-B0P2tybJ.js +0 -20
  442. package/dist/assets/zh-TW-Bs9C5cN8.js +0 -20
@@ -0,0 +1,30 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-capacitor-core-B4EWRrHz.js"])))=>i.map(i=>d[i]);
2
+ import{R as d,j as s,f as Ke,r as _e}from"./vendor-react-BUCujlKS.js";import{f as ze,B as q,I as Q,o as Ss,bJ as qn,fv as $m,t as G,O as _m,jj as Bm,fa as Ve,gi as Nt,fH as Vd,g as za,b as dn,_ as xa,h as Ie,aT as Vm,hR as gr,hS as Hm,c_ as Kt,cZ as Pt,d0 as at,c$ as At,cY as Tt,a8 as Be,fO as vn,jk as Hd,jl as qm,fU as bo,jm as Wl,ai as Ii,jn as Gm,jo as wi,jp as zn,cA as Ps,b_ as Ft,bZ as Lt,bW as zt,bU as Ut,bV as $t,cz as Xt,jq as xl,aU as Gn,bH as Fn,db as Ga,dd as Wa,aS as Wn,aR as Jn,df as Ja,dg as Qa,jr as fr,js as Jr,jt as xn,as as Dn,ar as cn,g4 as Gt,ju as Vs,jv as vl,gg as Mt,l as rt,gl as ht,gf as _t,i2 as Et,d1 as Ns,fQ as ga,gk as en,gm as tn,gh as as,i6 as ps,jw as xs,gj as qd,jx as Wm,dI as st,jy as Gd,jz as Jm,jA as Qm,jB as Pi,jC as Ym,jD as ns,dX as Un,f_ as ks,jE as $s,iK as Va,iS as Bs,jF as Ua,jG as Wd,jH as yl,fS as jl,aw as fa,jI as Qr,aj as Qn,jJ as Jl,jK as Zm,b4 as kl,jL as Ql,jM as Ln,jN as Ot,gF as wl,jO as Sl,jP as da,jQ as Jd,jR as bn,hl as Xm,fT as Ai,d9 as Nl,jS as Yl,aY as ep,fG as tp,dT as sp,$ as np,a0 as ap,a1 as ip,N as Ya,h9 as Ti,jT as op,jU as rp,dm as lp,P as sn,jV as Wt,jW as Yr,jX as cp,iD as ws,jY as xo,jZ as dp,gn as Qd,j_ as up,n as ls,fp as vo,y as Yd,x as mp,i as pp,j as gp,fq as fp,j$ as hp,p as bp,k0 as xp,k1 as vp,k2 as Zl,hB as Zd,k3 as yp,k4 as hr,k5 as Xl,k6 as jp,k7 as kp,k8 as wp,k9 as Sp,ka as yo,kb as bs,iC as vs,aE as Hs,cQ as Cl,kc as Np,cG as Xd,aD as Cp,aG as Ip,a_ as Pp,iR as br,ea as eu,cu as tu,eb as su,kd as Ap,ke as Tp,kf as Ep,kg as Dp,kh as Mp,ki as Rp,kj as Op,kk as Fp,cv as ys,kl as Zs,km as Il,cE as ln,cD as nu,bc as Da,kn as Lp,ko as Kp,kp as zp,kq as Up,kr as Ha,b1 as $p,ks as Si,kt as Pn,ku as au,fZ as _p,fY as Bp,kv as Vp,kw as Fs,kx as js,ir as oa,ky as Tn,kz as mo,kA as Hp,fD as qp,kB as iu,kC as ua,kD as Gp,kE as Wp,Z as ou,dU as Jp,d$ as Qp,e0 as Yp,dt as Zp,hO as Xp,e1 as eg,dR as tg,bQ as sg,kF as ng,kG as Hn,kH as ag,kI as Mo,kJ as ra,b6 as ig,ge as Ma,kK as ec,kL as Ra,cw as Kn,kM as og,kN as rg,kO as lg,kP as cg,kQ as xr,kR as tc,kS as dg,kT as ug,kU as mg,kV as pg,kW as sc,kX as gg,z as fg,m as nc,fP as hg,kY as bg,kZ as vr,at as ru,au as lu,av as xg,fu as vg,k_ as Ro,k$ as yg,l0 as jg,l1 as kg,l2 as wg,l3 as Sg,l4 as Pl,l5 as En,dJ as Ng,cx as cu,dY as Cg,b2 as aa,b3 as Ig}from"./useAppFontEffects-DGlvOqP_.js";import{h as Dt,i as Al,u as re,V as is,ft as Pg,fu as ac,c4 as Ni,bc as Mn,c3 as du,c5 as Ag,D as gt,aC as jn,M as Ls,fv as Tg,a as Yt,be as Eg,O as rs,P as Za,Y as yr,aL as ic,dS as oc,a1 as mi,p as Dg,fw as Mg,k as Rg,aN as la,fx as Og,aH as rc,dP as Fg,fy as Lg,fz as Kg,s as lc,e as Ei,aO as zg,dQ as Ug,fA as uu,b7 as Zt,fB as $g,F as _g,fC as Bg,bl as Tl,E as Vg,au as mu,fD as pu,cn as gu,I as ha,ca as fu,az as Hg,aA as qg,br as El,fE as Gg,J as Oo,fF as cc,fG as Wg,a9 as Jg,y as jo,bA as dc,cr as Ji,bW as Qg,fH as Yg,as as ba,fI as Zg,fr as Oa,fJ as uc,fp as mc,fK as pc,by as gc,fL as Xg,fM as ef,fN as tf,fO as sf,fP as fc,b as nf,fQ as hu,fR as af,fS as Zr,fT as of,fU as rf,fV as lf,fW as cf,fX as bu,fY as df,fZ as uf,f_ as mf,f$ as Xr,aZ as pf}from"./index-DxNa7xYB.js";import{u as Ms,c as gf}from"./vendor-zustand-BAGL70zf.js";import{o as ts,s as wt,b as Di,l as ff,a as qs,r as Rn,c as el,n as ko,_ as Dl,u as tl}from"./vendor-zod-CxRSdNoV.js";import{u as hf,aQ as bf,au as jr,b9 as xf,bc as vf,bd as yf,be as Gs,bf as Ws,bg as Js,n as ma,aP as jf,ac as Is,bh as kf,bi as wf,bj as Sf,bk as Nf,I as Cf,b7 as If,aL as xu,bl as Pf,bm as Af,bn as Tf,bo as sl,bp as La,bq as nl,aM as Ef,aN as Df}from"./runtimeEndpointReset-CZ5aafpl.js";import{s as Mf,p as Rf}from"./vendor-yaml-3778uTud.js";import{c as hc,s as Of,C as bc,P as Ff,p as Lf}from"./shikiHighlight-DHDx-6eM.js";import{getResolvedShikiTheme as Kf}from"./appThemeRegistry-B9gkFq9i.js";import{E as xc}from"./vendor-codemirror-view-1e0FQ6Wn.js";import{Q as vu}from"./vendor-qrcode-DTJ12-WC.js";import{toast as $a}from"./vendor-sonner-DFyL3AvE.js";import{s as zf}from"./vendor-strip-json-comments-5dJlOkP1.js";import{m as Uf,P as $f,j as _f,k as Bf,l as Vf}from"./vendor-base-ui-Det7U81h.js";import{_ as Hf}from"./vendor-vite-runtime-DD1OZmLC.js";const vc=()=>{const{t}=ze(),[e,a]=d.useState(null);d.useEffect(()=>{let o=!1;const i=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const l=await Dt("/api/system/info",{signal:i?.signal,headers:{Accept:"application/json"}});if(!l.ok)return;const u=await l.json().catch(()=>null);if(!u||o)return;const m=typeof u.port=="number"&&Number.isFinite(u.port)&&u.port>0?u.port:null,c=typeof u.tunnelUrl=="string"&&u.tunnelUrl.trim().length>0?u.tunnelUrl.trim():null;a({port:m,tunnelUrl:c})}catch{}})(),()=>{o=!0,i?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(o=>s.jsxs(q,{type:"button",variant:"outline",size:"sm",title:o.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Ss(o.url)},children:[s.jsx(Q,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:o.url})]},o.key))})},yc="https://github.com/openchamber/openchamber",qf="https://discord.gg/ZYRSdnwwKA",jc="https://x.com/openchamber_dev",Gf=800,Wf={info:null,checking:!1,available:!1,error:null};function Jf(t){const e=Ke.c(5),[a,n]=d.useState(Wf);let o;e[0]!==t?(o=async()=>{if(t){n(Qf);try{const l=await xf();n({info:l,checking:!1,available:l.available,error:null})}catch(l){const u=l;n({info:null,checking:!1,available:!1,error:u instanceof Error?u.message:String(u)})}}},e[0]=t,e[1]=o):o=e[1];const i=o;let r;return e[2]!==i||e[3]!==a?(r={...a,check:i},e[2]=i,e[3]=a,e[4]=r):r=e[4],r}function Qf(t){return{...t,checking:!0,error:null}}function Yf(t){const e=Ke.c(11),[a,n]=d.useState(null);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={kind:"idle"},e[0]=o):o=e[0];const[i,r]=d.useState(o);let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=async()=>{try{const b=await vf();return n(b),b}catch{return null}},e[1]=l):l=e[1];const u=l;let m,c;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{u()},c=[u],e[2]=m,e[3]=c):(m=e[2],c=e[3]),d.useEffect(m,c);let f;e[4]!==t?(f=async()=>{r({kind:"upgrading"});try{const b=await yf(t);r({kind:"installed",version:b})}catch(b){const j=b;r({kind:"failed",error:j instanceof Error?j.message:t})}},e[4]=t,e[5]=f):f=e[5];const p=f;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=async b=>{await b().catch(Zf);const j=await u();j?.currentVersion&&r(x=>x.kind!=="installed"||x.version&&x.version.replace(/^v/,"")!==j.currentVersion?x:{kind:"idle"})},e[6]=g):g=e[6];const h=g;let k;return e[7]!==i||e[8]!==a||e[9]!==p?(k={status:a,phase:i,refresh:u,upgrade:p,reloadAfterUpgrade:h},e[7]=i,e[8]=a,e[9]=p,e[10]=k):k=e[10],k}function Zf(){}function Xf(t){const[e,a]=d.useState(null);return d.useEffect(()=>{if(!t)return;let n=!1;return Hf(async()=>{const{App:o}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:o}},__vite__mapDeps([0,1,2])).then(({App:o})=>o.getInfo()).then(o=>{n||a(o.version.trim()||null)}).catch(()=>{}),()=>{n=!0}},[t]),e}const yu=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=ze(),[a,n]=d.useState(t),[o,i]=d.useState(!1),[r,l]=d.useState(null),u=hf(Ms(ie=>({info:ie.info,checking:ie.checking,available:ie.available,error:ie.error,downloading:ie.downloading,downloaded:ie.downloaded,installing:ie.installing,progress:ie.progress,runtimeType:ie.runtimeType,checkForUpdates:ie.checkForUpdates,downloadUpdate:ie.downloadUpdate,restartToUpdate:ie.restartToUpdate}))),{isMobile:m}=qn(),c=d.useMemo(()=>Al(),[]),f=bf(),p=Jf(c||f),g=f?p:null,h=p.check;d.useEffect(()=>{f&&h()},[f,h]);const[k,b]=d.useState(!1),[j,x]=d.useState(null);d.useEffect(()=>{if(!f)return;let ie=!1;return $m().then(pe=>{ie||x(pe)}),()=>{ie=!0}},[f]);const S=Xf(c),v=c?{info:p.info,checking:p.checking,available:p.available,error:p.error,checkForUpdates:p.check,runtimeType:"web"}:{info:u.info,checking:u.checking,available:u.available,error:u.error,checkForUpdates:u.checkForUpdates,runtimeType:u.runtimeType},N=r||v.info?.currentVersion||"unknown",y=j||u.info?.currentVersion||"unknown",I=r||g?.info?.currentVersion||"unknown",w=Yf(e("opencodeUpdate.toast.failed.description")),D=w.status?.currentVersion??null,C=w.phase.kind==="installed"?null:w.status?.availableVersion??null,[A,T]=d.useState(!1),O=ie=>{const pe=ie?.version||"";return ie?.packageManager==="electron"?e("settings.openchamber.about.actions.updateDesktopToVersion",{version:pe}):e("settings.openchamber.about.actions.updateServerToVersion",{version:pe})},z=(()=>{const ie=v.info?.version||"";return c?O(v.info):f?e("settings.openchamber.about.actions.updateAppToVersion",{version:ie}):e("settings.openchamber.about.actions.updateOpenChamberToVersion",{version:ie})})(),M=ie=>ie?.installBlocked==="service-manager",P=v.available&&M(v.info),R=!!(g?.available&&M(g.info)),F=()=>{v.checkForUpdates(),g&&g.check(),w.refresh()},_=async ie=>{(await za(ie)).ok&&(T(!0),setTimeout(()=>T(!1),2e3))},B=()=>{w.reloadAfterUpgrade(async()=>{await Vd({message:e("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})})},V=ie=>{const pe=ie?.updateCommand||"openchamber update";return s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.serviceManagerUpdate",{version:ie?.version||""})}),s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-elevated/50 p-1 pl-3",children:[s.jsx("code",{className:"flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm text-foreground",children:pe}),s.jsx(q,{type:"button",variant:"ghost",size:"icon",onClick:()=>{_(pe)},"aria-label":e(A?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:s.jsx(Q,{name:A?"check":"clipboard",className:"size-4"})})]})]})},ee=P?V(v.info):null,L=!g?.available||g.checking?null:R?V(g.info):s.jsxs(q,{type:"button",size:"sm",variant:"outline",onClick:()=>b(!0),children:[s.jsx(Q,{name:"download",className:"size-4"}),O(g.info)]}),$=g?s.jsx(jr,{open:k,onOpenChange:b,info:g.info,downloading:!1,downloaded:!1,progress:null,error:g.error,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"}):null,H=(()=>{const{phase:ie}=w;if(ie.kind==="installed")return s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:ie.version?e("settings.openchamber.about.openCode.installedVersion",{version:ie.version}):e("settings.openchamber.about.openCode.installed")}),s.jsx(q,{type:"button",size:"sm",variant:"outline",onClick:B,children:e("opencodeUpdate.toast.actions.reload")})]});if(!C)return null;if(!w.status?.supported)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.openCode.manualUpdate",{version:C})});const pe=ie.kind==="upgrading";return s.jsxs("div",{className:"space-y-2",children:[s.jsxs(q,{type:"button",size:"sm",variant:"outline",onClick:()=>{w.upgrade()},disabled:pe,children:[s.jsx(Q,{name:pe?"loader":"download",className:pe?"size-4 animate-spin":"size-4"}),pe?e("opencodeUpdate.toast.upgrading.title"):e("settings.openchamber.about.actions.updateOpenCodeToVersion",{version:C})]}),ie.kind==="failed"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ie.error})]})})();d.useEffect(()=>{let ie=!1;return(async()=>{try{const X=await Dt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!X.ok)return;const xe=await X.json().catch(()=>null),Y=typeof xe?.openchamberVersion=="string"&&xe.openchamberVersion.trim().length>0?xe.openchamberVersion.trim():null;ie||l(Y)}catch{ie||l(null)}})(),()=>{ie=!0}},[]);const W=g?.checking??!1,Z=g?.available??!1,te=d.useRef(!1);d.useEffect(()=>{if(v.checking)i(!0),te.current=!0;else if(o){const ie=setTimeout(()=>{i(!1);const pe=W||Z;te.current&&!v.available&&!v.error&&!pe&&(G.success(e(c?"settings.openchamber.about.toast.serverLatestVersion":"settings.openchamber.about.toast.latestVersion")),te.current=!1)},Gf);return()=>clearTimeout(ie)}},[e,c,v.checking,o,v.available,v.error,W,Z]);const J=v.checking||o;return m?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(_m,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Bm}`,children:"OpenChamber"}),s.jsx("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:c?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:N})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:D||e("settings.openchamber.about.state.unknown")})}),S&&s.jsx("p",{children:e("settings.openchamber.about.native.appVersion",{version:S})})]}):f?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.appVersionLabel",{version:y})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:I})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:D||e("settings.openchamber.about.state.unknown")})})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:N})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:D||e("settings.openchamber.about.state.unknown")})})]})}),s.jsx(vc,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!v.available&&!v.error&&s.jsxs(q,{type:"button",variant:"outline",size:"sm",onClick:F,disabled:J,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[J?s.jsx(Q,{name:"loader",className:"size-4 animate-spin"}):s.jsx(Q,{name:"refresh",className:"size-4"}),e(J?"settings.openchamber.about.state.checking":c?"settings.openchamber.about.actions.checkServerForUpdates":"settings.openchamber.about.actions.checkForUpdates")]}),!J&&v.available&&!P&&s.jsxs(q,{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(Q,{name:"download",className:"size-4"}),z]})]}),ee,L&&s.jsx("div",{className:"flex justify-center text-center",children:L}),H&&s.jsx("div",{className:"flex justify-center text-center",children:H}),[v.error,g?.error].filter(Boolean).map(ie=>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:ie},ie)),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:yc,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(Q,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:qf,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(Q,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:jc,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(Q,{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(jr,{open:a,onOpenChange:n,info:v.info,downloading:u.downloading,downloaded:u.downloaded,installing:u.installing,progress:u.progress,error:v.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:v.runtimeType}),$]}):s.jsxs(Ve,{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:[f?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.appVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:y})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.serverVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:I})]})]}):s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:N})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:D||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[v.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(Q,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!v.checking&&v.available&&!P&&s.jsxs(q,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(Q,{name:"download",className:"h-4 w-4 mr-1"}),z]}),!v.checking&&!v.available&&!v.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(q,{size:"sm",variant:"outline",onClick:F,disabled:v.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),ee&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:ee}),L&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:L}),H&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:H}),[v.error,g?.error].filter(Boolean).map(ie=>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:ie})},ie)),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Nt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(vc,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:yc,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(Q,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:jc,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(Q,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(jr,{open:a,onOpenChange:n,info:v.info,downloading:u.downloading,downloaded:u.downloaded,installing:u.installing,progress:u.progress,error:v.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:v.runtimeType}),$]})},eh=(t,e,a)=>t&&e.some(o=>o.path===t)?t:(e.find(o=>o.id===a)??e[0])?.path??null,Ks=()=>{const t=Ke.c(4),e=re(th),a=dn(sh),n=dn(nh);let o;return t[0]!==n||t[1]!==a||t[2]!==e?(o=eh(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=o):o=t[3],o};function th(t){return t.settingsProjectPath}function sh(t){return t.projects}function nh(t){return t.activeProjectId}const ah=t=>[...t].sort((e,a)=>(e.label||e.path).localeCompare(a.label||a.path)),Mi=t=>{const e=Ke.c(75),{className:a}=t,{t:n}=ze(),{currentTheme:o}=xa(),i=re(ih),[r,l]=d.useState(!1),u=dn(oh),m=Ks(),c=re(rh),f=is();let p;e[0]!==u?(p=ah(u),e[0]=u,e[1]=p):p=e[1];const g=p;let h;e[2]!==m||e[3]!==g?(h=g.find(O=>O.path===m)??g[0]??null,e[2]=m,e[3]=g,e[4]=h):h=e[4];const k=h;if(f||!k)return null;let b;e[5]!==c||e[6]!==g?(b=O=>{const z=g.find(M=>M.id===O);z&&c(z.path)},e[5]=c,e[6]=g,e[7]=b):b=e[7];const j=b;if(i){let O;e[8]!==a?(O=Ie(a),e[8]=a,e[9]=O):O=e[9];let z;e[10]!==n?(z=n("settings.shared.projectSelector.switchProjectAria"),e[10]=n,e[11]=z):z=e[11];let M;e[12]!==n?(M=n("settings.shared.projectSelector.switchProjectTitle"),e[12]=n,e[13]=M):M=e[13];let P,R;e[14]===Symbol.for("react.memo_cache_sentinel")?(P=()=>l(!0),R=Ie(Vm({size:"touch"}),"w-full min-w-0"),e[14]=P,e[15]=R):(P=e[14],R=e[15]);let F;e[16]!==k||e[17]!==o?(F=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(gr,{project:k,theme:o})}),e[16]=k,e[17]=o,e[18]=F):F=e[18];let _;e[19]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Q,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=_):_=e[19];let B;e[20]!==r||e[21]!==z||e[22]!==M||e[23]!==R||e[24]!==F?(B=s.jsxs("button",{type:"button","aria-label":z,title:M,"aria-haspopup":"dialog","aria-expanded":r,onClick:P,className:R,children:[F,_]}),e[20]=r,e[21]=z,e[22]=M,e[23]=R,e[24]=F,e[25]=B):B=e[25];let V;e[26]!==B||e[27]!==O?(V=s.jsx("div",{className:O,children:B}),e[26]=B,e[27]=O,e[28]=V):V=e[28];let ee;e[29]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>l(!1),e[29]=ee):ee=e[29];const L=k.id;let $;e[30]!==n?($=n("settings.shared.projectSelector.sheetTitle"),e[30]=n,e[31]=$):$=e[31];let H;e[32]!==n?(H=n("settings.shared.projectSelector.searchPlaceholder"),e[32]=n,e[33]=H):H=e[33];let W;e[34]!==k.id||e[35]!==o||e[36]!==j||e[37]!==r||e[38]!==g||e[39]!==$||e[40]!==H?(W=s.jsx(Hm,{open:r,onClose:ee,projects:g,selectedProjectId:L,onSelectProject:j,theme:o,title:$,searchPlaceholder:H}),e[34]=k.id,e[35]=o,e[36]=j,e[37]=r,e[38]=g,e[39]=$,e[40]=H,e[41]=W):W=e[41];let Z;return e[42]!==V||e[43]!==W?(Z=s.jsxs(s.Fragment,{children:[V,W]}),e[42]=V,e[43]=W,e[44]=Z):Z=e[44],Z}let x;e[45]!==a?(x=Ie(a),e[45]=a,e[46]=x):x=e[46];const S=k.id;let v;e[47]!==j?(v=O=>{O&&j(O)},e[47]=j,e[48]=v):v=e[48];let N;e[49]!==n?(N=n("settings.shared.projectSelector.switchProjectAria"),e[49]=n,e[50]=N):N=e[50];let y;e[51]!==n?(y=n("settings.shared.projectSelector.switchProjectTitle"),e[51]=n,e[52]=y):y=e[52];let I;e[53]!==k||e[54]!==o?(I=s.jsx(Kt,{children:s.jsx(gr,{project:k,theme:o})}),e[53]=k,e[54]=o,e[55]=I):I=e[55];let w;e[56]!==N||e[57]!==y||e[58]!==I?(w=s.jsx(Pt,{size:"settings",className:"w-full","aria-label":N,title:y,children:I}),e[56]=N,e[57]=y,e[58]=I,e[59]=w):w=e[59];let D;if(e[60]!==o||e[61]!==g){let O;e[63]!==o?(O=z=>s.jsx(at,{value:z.id,className:"max-w-[24rem] truncate",children:s.jsx(gr,{project:z,theme:o})},z.id),e[63]=o,e[64]=O):O=e[64],D=g.map(O),e[60]=o,e[61]=g,e[62]=D}else D=e[62];let C;e[65]!==D?(C=s.jsx(At,{fitContent:!0,children:D}),e[65]=D,e[66]=C):C=e[66];let A;e[67]!==k.id||e[68]!==w||e[69]!==C||e[70]!==v?(A=s.jsxs(Tt,{value:S,onValueChange:v,children:[w,C]}),e[67]=k.id,e[68]=w,e[69]=C,e[70]=v,e[71]=A):A=e[71];let T;return e[72]!==A||e[73]!==x?(T=s.jsx("div",{className:x,children:A}),e[72]=A,e[73]=x,e[74]=T):T=e[74],T};function ih(t){return t.isMobile}function oh(t){return t.projects}function rh(t){return t.setSettingsProjectPath}const Ml=t=>{const e=Ke.c(16),{value:a,onChange:n}=t,{t:o}=ze();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Q,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),e[0]=i):i=e[0];let r;e[1]!==n?(r=f=>n(f.target.value),e[1]=n,e[2]=r):r=e[2];let l;e[3]!==n||e[4]!==a?(l=f=>{f.key==="Escape"&&a&&(f.preventDefault(),f.stopPropagation(),n(""))},e[3]=n,e[4]=a,e[5]=l):l=e[5];let u;e[6]!==o?(u=o("settings.common.sidebar.searchPlaceholder"),e[6]=o,e[7]=u):u=e[7];let m;e[8]!==o?(m=o("settings.common.sidebar.searchPlaceholder"),e[8]=o,e[9]=m):m=e[9];let c;return e[10]!==r||e[11]!==l||e[12]!==u||e[13]!==m||e[14]!==a?(c=s.jsxs("div",{className:"relative mt-3",children:[i,s.jsx(Be,{value:a,onChange:r,onKeyDown:l,placeholder:u,"aria-label":m,className:"h-8 pl-7 typography-meta"})]}),e[10]=r,e[11]=l,e[12]=u,e[13]=m,e[14]=a,e[15]=c):c=e[15],c},Rl=t=>{const e=Ke.c(5),{query:a}=t,{t:n}=ze();let o;e[0]!==a||e[1]!==n?(o=n("settings.common.sidebar.noMatches",{query:a.trim()}),e[0]=a,e[1]=n,e[2]=o):o=e[2];let i;return e[3]!==o?(i=s.jsx("p",{className:"px-2 py-6 text-center typography-meta text-muted-foreground",children:o}),e[3]=o,e[4]=i):i=e[4],i};function lh(t,e){return`opencode:sidebar-group:${t}:${e}`}const al=t=>{const e=Ke.c(33),{label:a,count:n,storageKey:o,defaultExpanded:i,children:r}=t,l=i===void 0?!0:i;let u;e[0]!==a||e[1]!==o?(u=lh(o,a),e[0]=a,e[1]=o,e[2]=u):u=e[2];const m=u,c=d.useId();let f;e[3]!==l||e[4]!==m?(f=()=>{try{const A=localStorage.getItem(m);if(A!==null)return A==="true"}catch{}return l},e[3]=l,e[4]=m,e[5]=f):f=e[5];const[p,g]=_e.useState(f);let h,k;e[6]!==p||e[7]!==m?(h=()=>{try{localStorage.setItem(m,String(p))}catch{}},k=[m,p],e[6]=p,e[7]=m,e[8]=h,e[9]=k):(h=e[8],k=e[9]),_e.useEffect(h,k);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>g(ch),e[10]=b):b=e[10];let j;e[11]===Symbol.for("react.memo_cache_sentinel")?(j=Ie("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),e[11]=j):j=e[11];const x=!p&&"-rotate-90";let S;e[12]!==x?(S=Ie("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",x),e[12]=x,e[13]=S):S=e[13];let v;e[14]!==S?(v=s.jsx(Q,{name:"arrow-down-s",className:S}),e[14]=S,e[15]=v):v=e[15];let N;e[16]!==a?(N=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=N):N=e[17];let y;e[18]!==n?(y=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=y):y=e[19];let I;e[20]!==c||e[21]!==p||e[22]!==v||e[23]!==N||e[24]!==y?(I=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":p,"aria-controls":c,className:j,children:[v,N,y]}),e[20]=c,e[21]=p,e[22]=v,e[23]=N,e[24]=y,e[25]=I):I=e[25];const w=!p;let D;e[26]!==r||e[27]!==c||e[28]!==w?(D=s.jsx("div",{id:c,hidden:w,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:r}),e[26]=r,e[27]=c,e[28]=w,e[29]=D):D=e[29];let C;return e[30]!==I||e[31]!==D?(C=s.jsxs("div",{children:[I,D]}),e[30]=I,e[31]=D,e[32]=C):C=e[32],C};function ch(t){return!t}const dh=({onItemSelect:t})=>{const{t:e}=ze(),[a,n]=d.useState(""),[o,i]=d.useState(null),[r,l]=d.useState(""),[u,m]=d.useState(null),[c,f]=d.useState(!1),[p,g]=d.useState(null),{selectedAgentName:h,setSelectedAgent:k,setAgentDraft:b,createAgent:j,deleteAgent:x,loadAgents:S,loadDisabledAgents:v,updateAgent:N,fetchAgentEntity:y}=vn(Ms(X=>({selectedAgentName:X.selectedAgentName,setSelectedAgent:X.setSelectedAgent,setAgentDraft:X.setAgentDraft,createAgent:X.createAgent,deleteAgent:X.deleteAgent,loadAgents:X.loadAgents,loadDisabledAgents:X.loadDisabledAgents,updateAgent:X.updateAgent,fetchAgentEntity:X.fetchAgentEntity}))),I=Ks(),w=vn(X=>Hd(X,I)),D=vn(X=>qm(X,I)),[C,A]=d.useState(null);d.useEffect(()=>{S(I),v(I)},[S,v,I]);const T=w.filter(X=>bo(X.mode)&&!Wl(X)).length,O=X=>!(bo(X.mode)&&!Wl(X)&&T<=1),z=async(X,xe)=>{A(X);try{await N(X,{disabled:xe},I),xe&&h===X&&k(null),G.success(xe?e("settings.agents.sidebar.toast.agentDisabled",{name:X}):e("settings.agents.sidebar.toast.agentEnabled",{name:X}))}catch{G.error(e(xe?"settings.agents.sidebar.toast.disableFailed":"settings.agents.sidebar.toast.enableFailed"))}finally{A(null)}},M=D.filter(X=>Ii([X.name,X.description],a)),P="bg-background",R=()=>{const X="new-agent";let xe=X,Y=1;for(;w.some(be=>be.name===xe);)xe=`${X}-${Y}`,Y++;b({name:xe,scope:"user"}),k(xe),t?.()},F=async X=>{if(wi(X)){G.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}m(X)},_=()=>{m(null)},B=async()=>{if(u){f(!0);try{(await x(u.name,u.scope,I)).ok?(G.success(e("settings.agents.sidebar.toast.agentDeleted",{name:u.name})),_()):G.error(e("settings.agents.sidebar.toast.deleteFailed"))}catch(X){const xe=X instanceof Error?X.message:"",Y=/built-in|not deletable|not found/i.test(xe);G.error(e(Y?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed"))}f(!1)}},V=async X=>{const xe=X.name;let Y=1,be=`${xe}-copy`;for(;w.some(ge=>ge.name===be);)Y++,be=`${xe}-copy-${Y}`;const De=X,ve=await y(X.name,I);if(!ve){G.error(e("settings.agents.sidebar.toast.renameFailed"));return}const se=ve.config.request?.body;b({name:be,scope:ve.scope??De.scope??"user",description:ve.config.description??void 0,model:ve.config.model??null,system:ve.config.system??void 0,steps:ve.config.steps??void 0,temperature:se?.temperature,top_p:se?.top_p,mode:ve.config.mode??De.mode,permissions:ve.config.permissions??void 0,hidden:ve.config.hidden}),k(be),t?.()},ee=X=>{l(X.name),i(X)},L=async()=>{if(!o)return;const X=r.trim().replace(/\s+/g,"-");if(!X){G.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(X===o.name){i(null);return}if(w.some(De=>De.name===X)){G.error(e("settings.agents.sidebar.toast.agentExists"));return}const xe=o,Y=await y(o.name,I);if(!Y){G.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await j({...Y.config,name:X,scope:Y.scope??xe.scope},I)).ok?(await x(o.name,xe.scope,I)).ok?(G.success(e("settings.agents.sidebar.toast.agentRenamed",{name:X})),k(X)):G.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):G.error(e("settings.agents.sidebar.toast.renameFailed")),i(null)},$=X=>{switch(X){case"primary":return s.jsx(Q,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(Q,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(Q,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},H=new Set(D.map(X=>X.name)),W=w.filter(X=>Gm(X)&&!H.has(X.name)),Z=W.filter(X=>Ii([X.name,X.description],a)),te=Z.filter(wi),J=Z.filter(X=>!wi(X)),{groupedCustomAgents:ie,ungroupedCustomAgents:pe}=_e.useMemo(()=>{const X={},xe=[];for(const be of J){const De=be;De.group?(X[De.group]||(X[De.group]=[]),X[De.group].push(be)):xe.push(be)}return{groupedCustomAgents:Object.keys(X).sort((be,De)=>be.localeCompare(De)).map(be=>({name:be,agents:X[be]})),ungroupedCustomAgents:xe}},[J]);return s.jsxs("div",{className:Ie("flex h-full flex-col",P),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${zn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Mi,{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:W.length})}),s.jsx(q,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:R,children:s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"})})]}),W.length>0?s.jsx(Ml,{value:a,onChange:n}):null]}),s.jsxs(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:[W.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Q,{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")})]}):Z.length===0?s.jsx(Rl,{query:a}):s.jsxs(s.Fragment,{children:[te.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")}),te.map(X=>s.jsx(kr,{agent:X,isSelected:h===X.name,onSelect:()=>{k(X.name),t?.()},onDuplicate:()=>{V(X)},onDisable:O(X)?()=>{z(X.name,!0)}:void 0,getAgentModeIcon:$,isMenuOpen:p===X.name,onMenuOpenChange:xe=>g(xe?X.name:null)},X.name))]}),J.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")}),ie.map(({name:X,agents:xe})=>s.jsx(al,{label:X,count:xe.length,storageKey:"agents",children:xe.map(Y=>s.jsx(kr,{agent:Y,isSelected:h===Y.name,onSelect:()=>{k(Y.name),t?.()},onRename:()=>ee(Y),onDelete:()=>F(Y),onDuplicate:()=>{V(Y)},onDisable:O(Y)?()=>{z(Y.name,!0)}:void 0,getAgentModeIcon:$,isMenuOpen:p===Y.name,onMenuOpenChange:be=>g(be?Y.name:null)},Y.name))},X)),pe.map(X=>s.jsx(kr,{agent:X,isSelected:h===X.name,onSelect:()=>{k(X.name),t?.()},onRename:()=>ee(X),onDelete:()=>F(X),onDuplicate:()=>{V(X)},onDisable:O(X)?()=>{z(X.name,!0)}:void 0,getAgentModeIcon:$,isMenuOpen:p===X.name,onMenuOpenChange:xe=>g(xe?X.name:null)},X.name))]})]}),M.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.disabled")}),M.map(X=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-1.5 py-1",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label truncate text-muted-foreground",children:X.name}),X.description?s.jsx("div",{className:"typography-micro truncate leading-tight text-muted-foreground/60",children:X.description}):null]}),s.jsx(q,{size:"xs",variant:"outline",disabled:C===X.name,onClick:()=>{z(X.name,!1)},"aria-label":e("settings.agents.sidebar.actions.enableAria",{name:X.name}),children:e("settings.agents.sidebar.actions.enable")})]},X.name))]})]}),s.jsx(Ft,{open:u!==null,onOpenChange:X=>{!X&&!c&&_()},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:e("settings.agents.sidebar.dialog.deleteTitle")}),s.jsx($t,{children:e("settings.agents.sidebar.dialog.deleteDescription",{name:u?.name??""})})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:_,disabled:c,children:e("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",onClick:B,disabled:c,children:e("settings.common.actions.delete")})]})]})}),s.jsx(Ft,{open:o!==null,onOpenChange:X=>!X&&i(null),children:s.jsxs(Lt,{children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.description",{name:o?.name??""})})]}),s.jsx(Be,{value:r,onChange:X=>l(X.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:X=>{X.key==="Enter"&&L()}}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>i(null),children:e("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",onClick:L,children:e("settings.common.actions.rename")})]})]})})]})},kr=t=>{const e=Ke.c(52),{agent:a,isSelected:n,onSelect:o,onDelete:i,onRename:r,onDuplicate:l,onDisable:u,getAgentModeIcon:m,isMenuOpen:c,onMenuOpenChange:f}=t,{t:p}=ze(),g=a;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=xl(),e[0]=h):h=e[0];const k=h,[b,j]=d.useState(!1);let x;e[1]!==i||e[2]!==u||e[3]!==l||e[4]!==r||e[5]!==p?(x=ee=>s.jsxs(s.Fragment,{children:[r&&s.jsxs(ee,{onClick:L=>{L.stopPropagation(),r()},children:[s.jsx(Q,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(ee,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(Q,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),u&&s.jsxs(ee,{onClick:L=>{L.stopPropagation(),u()},children:[s.jsx(Q,{name:"eye-off",className:"h-4 w-4 mr-px"}),p("settings.agents.sidebar.actions.disable")]}),i&&s.jsxs(ee,{onClick:L=>{L.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=u,e[3]=l,e[4]=r,e[5]=p,e[6]=x):x=e[6];const S=x,v=n?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==v?(N=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[7]=v,e[8]=N):N=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=k?void 0:ee=>{ee.preventDefault(),j(!0)},e[9]=y):y=e[9];let I;e[10]!==N?(I=s.jsx("div",{className:N,onContextMenu:y}),e[10]=N,e[11]=I):I=e[11];let w;e[12]!==a.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=w):w=e[13];let D;e[14]!==a.mode||e[15]!==m?(D=m(a.mode),e[14]=a.mode,e[15]=m,e[16]=D):D=e[16];let C;e[17]!==a||e[18]!==g.scope||e[19]!==p?(C=(g.scope||wi(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:wi(a)?p("settings.agents.sidebar.badge.system"):g.scope}),e[17]=a,e[18]=g.scope,e[19]=p,e[20]=C):C=e[20];let A;e[21]!==w||e[22]!==D||e[23]!==C?(A=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,D,C]}),e[21]=w,e[22]=D,e[23]=C,e[24]=A):A=e[24];let T;e[25]!==a.description?(T=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=T):T=e[26];let O;e[27]!==o||e[28]!==A||e[29]!==T?(O=s.jsxs("button",{onClick:o,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:[A,T]}),e[27]=o,e[28]=A,e[29]=T,e[30]=O):O=e[30];let z;e[31]!==f?(z=ee=>{ee&&j(!1),f(ee)},e[31]=f,e[32]=z):z=e[32];let M;e[33]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(Wn,{asChild:!0,children:s.jsx(q,{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(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=M):M=e[33];let P;e[34]!==S?(P=s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:S(Fn)}),e[34]=S,e[35]=P):P=e[35];let R;e[36]!==c||e[37]!==z||e[38]!==P?(R=s.jsxs(Jn,{open:c,onOpenChange:z,children:[M,P]}),e[36]=c,e[37]=z,e[38]=P,e[39]=R):R=e[39];let F;e[40]!==O||e[41]!==R?(F=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,R]}),e[40]=O,e[41]=R,e[42]=F):F=e[42];let _;e[43]!==F||e[44]!==I?(_=s.jsx(Ja,{render:I,children:F}),e[43]=F,e[44]=I,e[45]=_):_=e[45];let B;e[46]!==S?(B=s.jsx(Ga,{className:"w-fit min-w-20",children:S(Wa)}),e[46]=S,e[47]=B):B=e[47];let V;return e[48]!==b||e[49]!==_||e[50]!==B?(V=s.jsxs(Qa,{open:b,onOpenChange:j,children:[_,B]}),e[48]=b,e[49]=_,e[50]=B,e[51]=V):V=e[51],V},kc=["#e5484d","#f76b15","#d6a312","#30a46c","#12a594","#3e63dd","#8e4ec6","#d6409f"],wr="flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition-shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Sr="ring-2 ring-foreground ring-offset-2 ring-offset-background",uh=t=>{const e=Ke.c(46),{value:a,onChange:n}=t,{t:o}=ze(),i=a.toLowerCase(),r=kc.some(L=>L===i),l=i!==""&&!r,u=d.useRef(null),[m,c]=d.useState(a);let f;e[0]!==c||e[1]!==a?(f=()=>c(a),e[0]=c,e[1]=a,e[2]=f):f=e[2];let p;e[3]!==a?(p=[a],e[3]=a,e[4]=p):p=e[4],d.useEffect(f,p);let g;e[5]!==m?(g=m.trim()!==""&&!fr(m.trim()),e[5]=m,e[6]=g):g=e[6];const h=g;let k;e[7]!==m||e[8]!==n?(k=()=>{const L=m.trim();(L===""||fr(L))&&n(L.toLowerCase())},e[7]=m,e[8]=n,e[9]=k):k=e[9];const b=k;let j;e[10]!==n?(j=()=>n(""),e[10]=n,e[11]=j):j=e[11];const x=i==="",S=i===""&&Sr;let v;e[12]!==S?(v=Ie(wr,"border border-border text-muted-foreground",S),e[12]=S,e[13]=v):v=e[13];let N;e[14]!==o?(N=o("settings.agents.page.field.colorAutomatic"),e[14]=o,e[15]=N):N=e[15];let y;e[16]!==o?(y=o("settings.agents.page.field.colorAutomatic"),e[16]=o,e[17]=y):y=e[17];let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"}),e[18]=I):I=e[18];let w;e[19]!==y||e[20]!==j||e[21]!==x||e[22]!==v||e[23]!==N?(w=s.jsx("button",{type:"button",onClick:j,"aria-pressed":x,className:v,title:N,"aria-label":y,children:I}),e[19]=y,e[20]=j,e[21]=x,e[22]=v,e[23]=N,e[24]=w):w=e[24];const D=kc.map(L=>s.jsx("button",{type:"button",onClick:()=>n(L),"aria-pressed":i===L,className:Ie(wr,i===L&&Sr),style:{backgroundColor:L},title:L,"aria-label":o("settings.agents.page.field.colorSwatchAria",{color:L})},L));let C;e[25]===Symbol.for("react.memo_cache_sentinel")?(C=()=>u.current?.click(),e[25]=C):C=e[25];const A=l?Sr:"border border-dashed border-border text-muted-foreground hover:text-foreground";let T;e[26]!==A?(T=Ie(wr,A),e[26]=A,e[27]=T):T=e[27];let O;e[28]!==o?(O=o("settings.agents.page.field.colorCustomAria"),e[28]=o,e[29]=O):O=e[29];let z;e[30]!==o?(z=o("settings.agents.page.field.colorCustomAria"),e[30]=o,e[31]=z):z=e[31];let M;e[32]!==l?(M=l?null:s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),e[32]=l,e[33]=M):M=e[33];const P="color",R=-1,F="true",_=fr(i)?i:"#808080";let B;e[34]!==n?(B=L=>n(L.target.value.toLowerCase()),e[34]=n,e[35]=B):B=e[35];let V;e[36]!==_||e[37]!==B?(V=s.jsx("input",{ref:u,type:P,tabIndex:R,"aria-hidden":F,value:_,onChange:B,className:"sr-only"}),e[36]=_,e[37]=B,e[38]=V):V=e[38];let ee;return e[39]!==b||e[40]!==m||e[41]!==h||e[42]!==l||e[43]!==c||e[44]!==o?(ee=l?s.jsx(Be,{value:m,onChange:L=>c(L.target.value),onBlur:b,onKeyDown:L=>{L.key==="Enter"&&b()},placeholder:"#RRGGBB","aria-invalid":h,"aria-label":o("settings.agents.page.field.colorHexAria"),className:"h-7 w-24 rounded-md px-2 font-mono typography-meta"}):null,e[39]=b,e[40]=m,e[41]=h,e[42]=l,e[43]=c,e[44]=o,e[45]=ee):ee=e[45],s.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[w,D,s.jsx("button",{type:"button",onClick:C,"aria-pressed":l,className:T,style:l?{backgroundColor:i}:void 0,title:O,"aria-label":z,children:M}),V,ee]})},ju=d.createContext(0),Qt=t=>{const e=Ke.c(23),{children:a,className:n,outerClassName:o,title:i,titleLeading:r,titleAccessory:l,description:u,headerEnd:m,showSaveStatus:c,onBlurCapture:f}=t,p=c===void 0?!1:c,g=d.useContext(ju),h=i!=null||u!=null||m!=null||p,k=typeof i=="string"||typeof i=="number",b=r!=null||l!=null;let j;e[0]!==o?(j=Ie("h-full overlay-scrollbar-wrapper--stable-gutter",o),e[0]=o,e[1]=j):j=e[1];let x;e[2]!==n?(x=Ie("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=x):x=e[3];let S;e[4]!==u||e[5]!==h||e[6]!==b||e[7]!==m||e[8]!==k||e[9]!==p||e[10]!==i||e[11]!==l||e[12]!==r?(S=h&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[i!=null?k?b?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Ie(Jr,"min-w-0 truncate"),children:i}),s.jsx("span",{className:"shrink-0",children:l})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Jr,children:i}):i:null,u!=null?typeof u=="string"||typeof u=="number"?s.jsx("p",{className:xn,children:u}):u:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[m,p&&s.jsx(ph,{})]})]}),e[4]=u,e[5]=h,e[6]=b,e[7]=m,e[8]=k,e[9]=p,e[10]=i,e[11]=l,e[12]=r,e[13]=S):S=e[13];let v;e[14]!==a||e[15]!==f||e[16]!==x||e[17]!==S?(v=s.jsxs("div",{className:x,onBlurCapture:f,children:[S,a]}),e[14]=a,e[15]=f,e[16]=x,e[17]=S,e[18]=v):v=e[18];let N;return e[19]!==g||e[20]!==j||e[21]!==v?(N=s.jsx(Ps,{outerClassName:j,className:"w-full @container",verticalTrackStart:g,children:v}),e[19]=g,e[20]=j,e[21]=v,e[22]=N):N=e[22],N},mh=500,ph=()=>{const t=Ke.c(13),{t:e}=ze(),a=d.useSyncExternalStore(Pg,ac,ac),[n,o]=d.useState(!1);let i,r;if(t[0]!==a?(i=()=>{if(a!=="saving"){o(!1);return}const c=setTimeout(()=>o(!0),mh);return()=>clearTimeout(c)},r=[a],t[0]=a,t[1]=i,t[2]=r):(i=t[1],r=t[2]),d.useEffect(i,r),a==="error"){let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Q,{name:"error-warning",className:"size-3.5"}),t[3]=c):c=t[3];let f;t[4]!==e?(f=e("settings.common.status.saveFailed"),t[4]=e,t[5]=f):f=t[5];let p;return t[6]!==f?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[c,s.jsx("span",{children:f})]}),t[6]=f,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let l;t[8]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=l):l=t[8];let u;t[9]!==e?(u=e("settings.common.actions.saving"),t[9]=e,t[10]=u):u=t[10];let m;return t[11]!==u?(m=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[l,s.jsx("span",{children:u})]}),t[11]=u,t[12]=m):m=t[12],m},Ds={ok:!0,changed:!1},yn={ok:!0,changed:!0},gs=t=>({ok:!1,reason:t}),gh=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,Xa=t=>{const{t:e}=ze(),[a,n]=d.useState(0),o=d.useRef(t);o.current=t;const i=d.useRef(e);i.current=e;const r=d.useRef(!1),l=d.useRef(!1),u=d.useRef(!1),m=d.useCallback(()=>{n(p=>p+1)},[]),c=d.useCallback(p=>{gh(p.target)&&m()},[m]),f=d.useCallback(async()=>{r.current=!0;try{for(;;){l.current=!1;let p;try{p=await o.current()}catch(g){p={ok:!1,reason:g instanceof Error?g.message:String(g)}}if(!u.current)return;if(!l.current){p.ok||G.error(i.current("settings.common.status.saveFailedReason",{reason:p.reason}));return}}}finally{r.current=!1}},[]);return d.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]),d.useEffect(()=>{if(a!==0){if(r.current){l.current=!0;return}f()}},[a,f]),{requestSave:m,onBlurCapture:c}},fh=["allow","ask","deny"],hh=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],bh=["openchamber","openchamber_web","openchamber_memory","openchamber_notify"],xh=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),ku=t=>xh.has(t),vh=[{action:"*",resource:"*",effect:"allow"},{action:"external_directory",resource:"*",effect:"ask"},{action:"read",resource:"*.env",effect:"ask"},{action:"read",resource:"*.env.*",effect:"ask"},{action:"read",resource:"*.env.example",effect:"allow"}],wc=()=>({global:null,keys:{},source:[]}),ia=t=>({global:t.global,source:t.source,keys:Object.fromEntries(Object.entries(t.keys).map(([e,a])=>[e,{effect:a.effect,patterns:a.patterns.map(n=>({...n}))}]))}),yh=t=>{const e={global:null,keys:{},source:t.map(a=>({...a}))};for(const a of t){if(ku(a.action))continue;if(a.action==="*"){a.resource==="*"&&(e.global=a.effect);continue}const n=e.keys[a.action]??{effect:null,patterns:[]};if(a.resource==="*")n.effect=a.effect;else{const o=n.patterns.findIndex(i=>i.pattern===a.resource);o>=0?n.patterns[o]={pattern:a.resource,effect:a.effect}:n.patterns.push({pattern:a.resource,effect:a.effect})}e.keys[a.action]=n}return e},jh=t=>t.action!=="*"||t.resource==="*",pa=(t,e)=>`${t}\0${e}`,kh=t=>{const e=new Map;t.global!==null&&e.set(pa("*","*"),t.global);for(const[a,n]of Object.entries(t.keys)){n.effect!==null&&e.set(pa(a,"*"),n.effect);for(const o of n.patterns){const i=o.pattern.trim();i.length!==0&&e.set(pa(a,i),o.effect)}}return e},il=t=>{const e=kh(t),a=new Set,n=[];for(const i of t.source){if(ku(i.action))continue;if(!jh(i)){n.push({...i});continue}const r=pa(i.action,i.resource),l=e.get(r);l!==void 0&&(n.push({action:i.action,resource:i.resource,effect:l}),a.add(r))}const o=pa("*","*");t.global!==null&&!a.has(o)&&n.unshift({action:"*",resource:"*",effect:t.global});for(const[i,r]of Object.entries(t.keys)){const l=pa(i,"*");if(r.effect!==null&&!a.has(l)){const u=n.findIndex(c=>c.action===i),m={action:i,resource:"*",effect:r.effect};u>=0?n.splice(u,0,m):n.push(m)}for(const u of r.patterns){const m=u.pattern.trim();if(m.length===0)continue;const c=pa(i,m),f=e.get(c);f===void 0||a.has(c)||(a.add(c),n.push({action:i,resource:m,effect:f}))}}return n},wh=(t,e)=>JSON.stringify(il(t))===JSON.stringify(il(e)),Sh=(t,e)=>{const a=[...vh,...e.global,...e.agentGlobal?[{action:"*",resource:"*",effect:e.agentGlobal}]:[]];let n="ask";for(const o of a)o.resource==="*"&&(o.action==="*"||o.action===t)&&(n=o.effect);return n},Nh=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Ch=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),Ih={effect:null,patterns:[]},Ph=t=>{const e=Ke.c(163),{agent:a,registerSave:n,requestSave:o}=t,{t:i}=ze(),r=vn(Ah),l=vn(Th);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[m,c]=d.useState(u),[f,p]=d.useState(wc),[g,h]=d.useState(wc),[k,b]=d.useState(!0),[j,x]=d.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S={},e[1]=S):S=e[1];const[v,N]=d.useState(S),[y,I]=d.useState(""),[w,D]=d.useState(0),C=a.name,A=Ks(),T=Dn(Eh);let O;e[2]!==A?(O=qe=>vl(qe,A),e[2]=A,e[3]=O):O=e[3];const z=Dn(O);let M;e[4]!==A?(M=qe=>qe.getStatusForDirectory(A),e[4]=A,e[5]=M):M=e[5];const P=cn(M);let R,F;e[6]!==T||e[7]!==A?(R=()=>{T({directory:A})},F=[T,A],e[6]=T,e[7]=A,e[8]=R,e[9]=F):(R=e[8],F=e[9]),d.useEffect(R,F);let _;e[10]!==C||e[11]!==l||e[12]!==A?(_=()=>{let qe=!1;return b(!0),x(!1),(async()=>{const lt=await l(C,A);if(qe)return;if(!lt){x(!0),b(!1);return}const ae=yh(lt.agent);c(lt.global),p(ia(ae)),h(ae),N({}),b(!1)})(),()=>{qe=!0}},e[10]=C,e[11]=l,e[12]=A,e[13]=_):_=e[13];let B;e[14]!==C||e[15]!==l||e[16]!==w||e[17]!==A?(B=[C,l,w,A],e[14]=C,e[15]=l,e[16]=w,e[17]=A,e[18]=B):B=e[18],d.useEffect(_,B);let V;e[19]!==C||e[20]!==f||e[21]!==g||e[22]!==A||e[23]!==i||e[24]!==r?(V=async()=>wh(g,f)?Ds:(await r(C,{permissions:il(g)},A)).ok?(p(ia(g)),yn):gs(i("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=C,e[20]=f,e[21]=g,e[22]=A,e[23]=i,e[24]=r,e[25]=V):V=e[25];const ee=V;let L,$;e[26]!==n||e[27]!==ee?(L=()=>(n(ee),()=>n(null)),$=[n,ee],e[26]=n,e[27]=ee,e[28]=L,e[29]=$):(L=e[28],$=e[29]),d.useEffect(L,$);let H;e[30]!==z?(H=z.map(Dh),e[30]=z,e[31]=H):H=e[31];const W=H;let Z;if(e[32]!==W||e[33]!==g.keys){Z=[...hh,...bh];const qe=new Set(W.map(Mh));let lt;e[35]!==g.keys?(lt=Object.keys(g.keys),e[35]=g.keys,e[36]=lt):lt=e[36];for(const ae of lt)!Z.includes(ae)&&!qe.has(ae)&&Z.push(ae);e[32]=W,e[33]=g.keys,e[34]=Z}else Z=e[34];const te=Z;let J;e[37]!==P||e[38]!==i?(J=qe=>{switch(P?.[qe]?.status.status){case"connected":return i("settings.mcp.page.status.label.connected");case"failed":return i("settings.mcp.page.status.label.failed");case"needs_auth":return i("settings.mcp.page.status.label.needsAuth");case"disabled":return i("settings.agents.page.permissionsEditor.mcpStatus.disabled");case"pending":return i("settings.agents.page.permissionsEditor.mcpStatus.pending");default:return null}},e[37]=P,e[38]=i,e[39]=J):J=e[39];const ie=J;let pe;e[40]!==m||e[41]!==g.global?(pe=qe=>Sh(qe,{global:m,agentGlobal:g.global}),e[40]=m,e[41]=g.global,e[42]=pe):pe=e[42];const X=pe;let xe;e[43]!==o?(xe=qe=>{h(lt=>({...lt,global:qe})),o()},e[43]=o,e[44]=xe):xe=e[44];const Y=xe;let be;e[45]!==o?(be=(qe,lt)=>{h(ae=>{const fe=ia(ae),ye=fe.keys[qe]??{effect:null,patterns:[]};return ye.effect=lt,ye.effect===null&&ye.patterns.length===0?delete fe.keys[qe]:fe.keys[qe]=ye,fe}),o()},e[45]=o,e[46]=be):be=e[46];const De=be;let ve;e[47]!==o?(ve=(qe,lt,ae,fe,ye)=>{h(we=>{const Ge=ia(we),et=Ge.keys[qe]??{effect:null,patterns:[]};return et.patterns[lt]={pattern:ae,effect:fe},Ge.keys[qe]=et,Ge}),ye&&o()},e[47]=o,e[48]=ve):ve=e[48];const se=ve;let ge;e[49]===Symbol.for("react.memo_cache_sentinel")?(ge=qe=>{h(lt=>{const ae=ia(lt),fe=ae.keys[qe]??{effect:null,patterns:[]};return fe.patterns.push({pattern:"",effect:"allow"}),ae.keys[qe]=fe,ae}),N(lt=>({...lt,[qe]:!0}))},e[49]=ge):ge=e[49];const ne=ge;let Se;e[50]!==o?(Se=(qe,lt)=>{h(ae=>{const fe=ia(ae),ye=fe.keys[qe];return ye?(ye.patterns.splice(lt,1),ye.effect===null&&ye.patterns.length===0&&delete fe.keys[qe],fe):ae}),o()},e[50]=o,e[51]=Se):Se=e[51];const ke=Se;let Te;e[52]!==y||e[53]!==o?(Te=()=>{const qe=y.trim();!qe||qe==="*"||(h(lt=>{if(lt.keys[qe])return lt;const ae=ia(lt);return ae.keys[qe]={effect:"ask",patterns:[]},ae}),I(""),o())},e[52]=y,e[53]=o,e[54]=Te):Te=e[54];const Ee=Te;let Le;e[55]!==i?(Le=qe=>i(qe==="allow"?"settings.agents.page.permissionsEditor.action.allow":qe==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=i,e[56]=Le):Le=e[56];const ce=Le;let Me,Fe,me,de,Pe,he,Ue,Ae,Re;if(e[57]!==ce||e[58]!==X||e[59]!==v||e[60]!==k||e[61]!==j||e[62]!==W||e[63]!==ie||e[64]!==g.global||e[65]!==g.keys||e[66]!==ke||e[67]!==Y||e[68]!==De||e[69]!==se||e[70]!==i||e[71]!==te){Re=Symbol.for("react.early_return_sentinel");e:{const qe=i("settings.agents.page.permissionsEditor.action.inherit"),lt=i("settings.agents.page.permissionsEditor.action.default");let ae;e[81]!==ce?(ae=Ze=>[...Ze?[{value:"inherit",label:Ze}]:[],...fh.map(ut=>({value:ut,label:ce(ut)}))],e[81]=ce,e[82]=ae):ae=e[82];const fe=ae,ye=(Ze,ut,ft,K)=>{const ue=K===void 0?qe:K;return s.jsx(Vs,{value:Ze??"inherit",options:fe(ue),onChange:Ne=>ut(Ne==="inherit"?null:Ne),"aria-label":ft})};if(k){let Ze;e[83]!==i?(Ze=i("settings.agents.page.section.toolPermissions"),e[83]=i,e[84]=Ze):Ze=e[84];let ut;e[85]!==i?(ut=i("common.loading"),e[85]=i,e[86]=ut):ut=e[86];let ft;e[87]!==ut?(ft=s.jsx("p",{className:Mt,children:ut}),e[87]=ut,e[88]=ft):ft=e[88];let K;e[89]!==Ze||e[90]!==ft?(K=s.jsx(Ve,{title:Ze,children:ft}),e[89]=Ze,e[90]=ft,e[91]=K):K=e[91],Re=K;break e}if(j){let Ze;e[92]!==i?(Ze=i("settings.agents.page.section.toolPermissions"),e[92]=i,e[93]=Ze):Ze=e[93];let ut;e[94]!==i?(ut=i("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=i,e[95]=ut):ut=e[95];let ft;e[96]!==ut?(ft=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ut}),e[96]=ut,e[97]=ft):ft=e[97];let K;e[98]===Symbol.for("react.memo_cache_sentinel")?(K=()=>D(Rh),e[98]=K):K=e[98];let ue;e[99]!==i?(ue=i("settings.agents.page.permissionsEditor.actions.retry"),e[99]=i,e[100]=ue):ue=e[100];let Ne;e[101]!==ue?(Ne=s.jsx(q,{variant:"outline",size:"xs",onClick:K,children:ue}),e[101]=ue,e[102]=Ne):Ne=e[102];let Ce;e[103]!==ft||e[104]!==Ne?(Ce=s.jsxs("div",{className:"flex items-center gap-3",children:[ft,Ne]}),e[103]=ft,e[104]=Ne,e[105]=Ce):Ce=e[105];let He;e[106]!==Ze||e[107]!==Ce?(He=s.jsx(Ve,{title:Ze,children:Ce}),e[106]=Ze,e[107]=Ce,e[108]=He):He=e[108],Re=He;break e}const we=(Ze,ut,ft)=>{const K=g.keys[Ze]??Ih,ue=Ch.has(Ze)||K.patterns.length>0,Ne=v[Ze]===!0;return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:ue?()=>N(Ce=>({...Ce,[Ze]:!Ne})):void 0,className:Ie("flex min-w-0 items-center gap-1.5 text-left",!ue&&"cursor-default"),"aria-expanded":ue?Ne:void 0,children:[s.jsx(Q,{name:Ne&&ue?"arrow-down-s":"arrow-right-s",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ue&&"opacity-0")}),s.jsx("span",{className:Nt,children:ut}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:Ze}),ft&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:ft}),K.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:ce(X(Ze))})}),K.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:i("settings.agents.page.permissionsEditor.ruleCount",{count:String(K.patterns.length)})})]}),ye(K.effect,Ce=>De(Ze,Ce),i("settings.agents.page.permissionsEditor.keyAria",{key:Ze}))]}),Ne&&ue&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[K.patterns.map((Ce,He)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Be,{value:Ce.pattern,onChange:le=>se(Ze,He,le.target.value,Ce.effect,!1),placeholder:i("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ze}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Vs,{value:Ce.effect,options:fe(),onChange:le=>se(Ze,He,Ce.pattern,le,!0),"aria-label":i("settings.agents.page.permissionsEditor.patternActionAria",{key:Ze})}),s.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>ke(Ze,He),"aria-label":i("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]},He)),s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ne(Ze),children:[s.jsx(Q,{name:"add",className:"mr-1 h-3.5 w-3.5"}),i("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},Ze)};Me=Ve,e[109]!==i?(Fe=i("settings.agents.page.section.toolPermissions"),e[109]=i,e[110]=Fe):Fe=e[110],me="agents.permissions",e[111]!==i?(de=i("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=i,e[112]=de):de=e[112],Pe="space-y-4";let Ge;e[113]!==i?(Ge=i("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=i,e[114]=Ge):Ge=e[114];let et;e[115]!==Ge?(et=s.jsx("span",{className:Nt,children:Ge}),e[115]=Ge,e[116]=et):et=e[116];let mt;e[117]!==i?(mt=i("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=i,e[118]=mt):mt=e[118];let jt;e[119]!==mt?(jt=s.jsx(Gt,{children:mt}),e[119]=mt,e[120]=jt):jt=e[120];let vt;e[121]!==ce||e[122]!==X||e[123]!==g.global||e[124]!==i?(vt=g.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("settings.agents.page.permissionsEditor.effectiveHint",{action:ce(X("*"))})}),e[121]=ce,e[122]=X,e[123]=g.global,e[124]=i,e[125]=vt):vt=e[125];let Ct;e[126]!==et||e[127]!==jt||e[128]!==vt?(Ct=s.jsxs("div",{className:"flex items-center gap-1.5",children:[et,jt,vt]}),e[126]=et,e[127]=jt,e[128]=vt,e[129]=Ct):Ct=e[129];const Bt=g.global;let Ye;e[130]!==i?(Ye=i("settings.agents.page.permissionsEditor.defaultAria"),e[130]=i,e[131]=Ye):Ye=e[131],he=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[Ct,ye(Bt,Y,Ye,lt)]}),Ue=s.jsx("div",{children:te.map(Ze=>we(Ze,Nh(Ze),null))}),Ae=W.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/40 pt-3 pb-1",children:[s.jsx("span",{className:Nt,children:i("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(Gt,{children:i("settings.agents.page.permissionsEditor.mcpInfo")})]}),W.map(Ze=>we(Ze.key,Ze.server,ie(Ze.server)))]})}e[57]=ce,e[58]=X,e[59]=v,e[60]=k,e[61]=j,e[62]=W,e[63]=ie,e[64]=g.global,e[65]=g.keys,e[66]=ke,e[67]=Y,e[68]=De,e[69]=se,e[70]=i,e[71]=te,e[72]=Me,e[73]=Fe,e[74]=me,e[75]=de,e[76]=Pe,e[77]=he,e[78]=Ue,e[79]=Ae,e[80]=Re}else Me=e[72],Fe=e[73],me=e[74],de=e[75],Pe=e[76],he=e[77],Ue=e[78],Ae=e[79],Re=e[80];if(Re!==Symbol.for("react.early_return_sentinel"))return Re;let $e;e[132]===Symbol.for("react.memo_cache_sentinel")?($e=qe=>I(qe.target.value),e[132]=$e):$e=e[132];let nt;e[133]!==Ee?(nt=qe=>{qe.key==="Enter"&&(qe.preventDefault(),Ee())},e[133]=Ee,e[134]=nt):nt=e[134];let pt;e[135]!==i?(pt=i("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=i,e[136]=pt):pt=e[136];let kt;e[137]!==y||e[138]!==nt||e[139]!==pt?(kt=s.jsx(Be,{value:y,onChange:$e,onKeyDown:nt,placeholder:pt,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=y,e[138]=nt,e[139]=pt,e[140]=kt):kt=e[140];let bt;e[141]!==y?(bt=y.trim(),e[141]=y,e[142]=bt):bt=e[142];const yt=!bt;let Je;e[143]===Symbol.for("react.memo_cache_sentinel")?(Je=s.jsx(Q,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=Je):Je=e[143];let ct;e[144]!==i?(ct=i("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=i,e[145]=ct):ct=e[145];let Qe;e[146]!==Ee||e[147]!==yt||e[148]!==ct?(Qe=s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:Ee,disabled:yt,children:[Je,ct]}),e[146]=Ee,e[147]=yt,e[148]=ct,e[149]=Qe):Qe=e[149];let it;e[150]!==kt||e[151]!==Qe?(it=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[kt,Qe]}),e[150]=kt,e[151]=Qe,e[152]=it):it=e[152];let dt;return e[153]!==Me||e[154]!==Fe||e[155]!==me||e[156]!==de||e[157]!==Pe||e[158]!==he||e[159]!==Ue||e[160]!==Ae||e[161]!==it?(dt=s.jsxs(Me,{title:Fe,settingsItem:me,info:de,contentClassName:Pe,children:[he,Ue,Ae,it]}),e[153]=Me,e[154]=Fe,e[155]=me,e[156]=de,e[157]=Pe,e[158]=he,e[159]=Ue,e[160]=Ae,e[161]=it,e[162]=dt):dt=e[162],dt};function Ah(t){return t.updateAgent}function Th(t){return t.fetchAgentPermissions}function Eh(t){return t.loadMcpConfigs}function Dh(t){return{key:`${t.name}_*`,server:t.name}}function Mh(t){return t.key}function Rh(t){return t+1}const Ol=t=>{const e=Ke.c(11),{legacy:a,path:n,className:o}=t,{t:i}=ze();if(!a)return null;let r;e[0]!==o?(r=Ie("mb-4 flex items-start gap-1.5",Mt,o),e[0]=o,e[1]=r):r=e[1];const l=n??void 0;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(Q,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),e[2]=u):u=e[2];let m;e[3]!==i?(m=i("settings.common.legacyFormat.note"),e[3]=i,e[4]=m):m=e[4];let c;e[5]!==m?(c=s.jsx("span",{children:m}),e[5]=m,e[6]=c):c=e[6];let f;return e[7]!==r||e[8]!==l||e[9]!==c?(f=s.jsxs("p",{className:r,title:l,children:[u,c]}),e[7]=r,e[8]=l,e[9]=c,e[10]=f):f=e[10],f},Oh=(t,e)=>{const a=Mn(e);if(!a)return[];const n=t.find(i=>i.id===a.providerId),o=Ag(n?.models,a.modelId);return qd(o)},Fh=t=>Wm(t)?.toLowerCase()??"",Lh=()=>{const{t}=ze(),e=rt(ce=>ce.providers),{selectedAgentName:a,getAgentByName:n,createAgent:o,updateAgent:i,fetchAgentEntity:r,agentDraft:l,setAgentDraft:u,setSelectedAgent:m}=vn(Ms(ce=>({selectedAgentName:ce.selectedAgentName,getAgentByName:ce.getAgentByName,createAgent:ce.createAgent,updateAgent:ce.updateAgent,fetchAgentEntity:ce.fetchAgentEntity,agentDraft:ce.agentDraft,setAgentDraft:ce.setAgentDraft,setSelectedAgent:ce.setSelectedAgent}))),c=Ks(),f=vn(ce=>Hd(ce,c)),p=a?n(a,c):null,g=!!(l&&l.name===a&&!p),h=g?"":p?.description?.trim()??"",k=g?"":p?.system?.trim()??"",[b,j]=d.useState(""),[x,S]=d.useState("user"),[v,N]=d.useState(""),[y,I]=d.useState("subagent"),[w,D]=d.useState(""),[C,A]=d.useState(""),[T,O]=d.useState(void 0),[z,M]=d.useState(void 0),[P,R]=d.useState(void 0),[F,_]=d.useState(""),[B,V]=d.useState(""),[ee,L]=d.useState(!1),[$,H]=d.useState(null),W=d.useRef({}),Z=d.useRef(null),te=d.useCallback(ce=>{Z.current=ce},[]),J=d.useRef(null),ie=JSON.stringify([a,c,g]),pe=d.useRef(ie);pe.current=ie;const X=d.useRef(null),xe={description:v,mode:y,model:w,variant:C,steps:T,temperature:z,topP:P,system:F,color:B},Y=d.useRef(xe);Y.current=xe;const be=d.useMemo(()=>Oh(e,w),[w,e]),De=be.length>0,ve=C||"__default",se=De,ge=d.useMemo(()=>C&&!be.includes(C)?[C,...be]:be,[C,be]);d.useEffect(()=>{if(!g||!l)return;X.current=null;const ce=Ni(l.model),Me=l.name||"",Fe=l.scope||"user",me=l.description||"",de=l.mode||"subagent",Pe=ce?`${ce.providerID}/${ce.modelID}`:"",he=ce?.variant||"",Ue=l.steps??void 0,Ae=l.temperature??void 0,Re=l.top_p??void 0,$e=l.system||"",nt="";W.current={},H(null),j(Me),S(Fe),N(me),I(de),D(Pe),A(he),O(Ue),M(Ae),R(Re),_($e),V(nt),J.current={draftName:Me,draftScope:Fe,description:me,mode:de,model:Pe,variant:he,steps:Ue,temperature:Ae,topP:Re,system:$e,color:nt}},[l,g]),d.useEffect(()=>{if(g||!a)return;let ce=!1;return(async()=>{const Me=await r(a,c);if(ce||pe.current!==ie||!Me)return;const Fe=Me.config;W.current=Fe;const me=Ni(Fe.model),de=Fe.request?.body,Pe={draftName:"",draftScope:"user",description:Fe.description||"",mode:Fe.mode||p?.mode||"subagent",model:me?`${me.providerID}/${me.modelID}`:"",variant:me?.variant||"",steps:Fe.steps??void 0,temperature:de?.temperature,topP:de?.top_p,system:Fe.system||"",color:Fh(Fe.color)},he=J.current,Ue=Y.current,Ae=he!==null&&(Ue.description!==he.description||Ue.mode!==he.mode||Ue.model!==he.model||Ue.variant!==he.variant||Ue.steps!==he.steps||Ue.temperature!==he.temperature||Ue.topP!==he.topP||Ue.system!==he.system||Ue.color!==he.color);H({legacy:Me.legacy===!0,path:Me.path,source:Me.source}),!(X.current===ie&&Ae)&&(X.current=ie,N(Pe.description),I(Pe.mode),D(Pe.model),A(Pe.variant),O(Pe.steps),M(Pe.temperature),R(Pe.topP),_(Pe.system),V(Pe.color),J.current=Pe)})(),()=>{ce=!0}},[r,g,p,a,c,ie]);const ne=d.useCallback(ce=>{const Me=Mn(w.trim()),Fe=Me?du({providerID:Me.providerId,modelID:Me.modelId,variant:C.trim()||void 0}):null,me=W.current.request,de={...me?.body};z===void 0?delete de.temperature:de.temperature=z,P===void 0?delete de.top_p:de.top_p=P;const Pe=me?.headers,he={};Pe&&Object.keys(Pe).length>0&&(he.headers=Pe),Object.keys(de).length>0&&(he.body=de);const Ue=v.trim(),Ae=F.trim(),Re={name:ce,mode:y,model:Fe,steps:T??null,system:Ae||(g?void 0:null),request:Object.keys(he).length>0?he:null};return Ue&&(Re.description=Ue),B!==(J.current?.color??"")&&(Re.color=B||null),g&&x&&(Re.scope=x),g&&l?.hidden!==void 0&&(Re.hidden=l.hidden),g&&l?.permissions?.length&&(Re.permissions=l.permissions),Re},[l,B,v,x,g,y,w,T,F,z,P,C]),Se=d.useCallback(async()=>{const ce=J.current,Me=a?.trim();if(g||!ce||!Me)return Ds;const Fe=Z.current?await Z.current():Ds;if(v===ce.description&&y===ce.mode&&w===ce.model&&C===ce.variant&&T===ce.steps&&z===ce.temperature&&P===ce.topP&&F===ce.system&&B===ce.color||!Fe.ok)return Fe;const de=ne(Me);return(await i(Me,de,c)).ok?(pe.current!==ie||(W.current={...W.current,model:de.model,system:de.system??void 0,steps:de.steps,request:de.request??void 0},J.current={...ce,description:v,mode:y,model:w,variant:C,steps:T,temperature:z,topP:P,system:F,color:B}),yn):gs(t("settings.agents.page.toast.updateFailed"))},[ne,B,v,g,y,w,a,ie,c,T,F,t,z,P,i,C]),ke=Xa(Se),{requestSave:Te}=ke,Ee=async()=>{const ce=b.trim().replace(/\s+/g,"-");if(!ce){G.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(f.some(Me=>Me.name===ce)){G.error(t("settings.agents.sidebar.toast.agentExists"));return}L(!0);try{(await o(ne(ce),c)).ok?(u(null),G.success(t("settings.agents.page.toast.created"))):G.error(t("settings.agents.page.toast.createFailed"))}catch(Me){console.error("Error creating agent:",Me);const Fe=Me instanceof Error&&Me.message?Me.message:t("settings.agents.page.toast.saveUnexpectedError");G.error(Fe)}finally{L(!1)}},Le=()=>{u(null),m(null)};return a?s.jsxs(Qt,{title:g?t("settings.agents.page.title.new"):a,description:t(g?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:ke.onBlurCapture,children:[!g&&$&&s.jsx(Ol,{legacy:$.legacy,path:$.path}),!g&&$?.source==="none"&&s.jsxs("p",{className:`mb-4 flex items-start gap-1.5 ${Mt}`,children:[s.jsx(Q,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),s.jsx("span",{children:t("settings.agents.page.runtimeProvided.note")})]}),s.jsxs(Ve,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-3",children:[g&&s.jsxs(ht,{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:b,onChange:ce=>j(ce.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:x,onValueChange:ce=>S(ce),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[100px]",children:s.jsx(Kt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Et,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ns,{value:v,onChange:ce=>N(ce.target.value),placeholder:h||t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Et,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Vs,{"aria-label":t("settings.agents.page.field.mode"),value:y,onChange:ce=>{I(ce),Te()},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.jsx(Et,{settingsItem:"agents.color",label:t("settings.agents.page.field.color"),info:t("settings.agents.page.field.colorTooltip"),children:s.jsx(uh,{value:B,onChange:ce=>{V(ce),Te()}})})]}),s.jsxs(Ve,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(ht,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ga,{providerId:Mn(w)?.providerId??"",modelId:Mn(w)?.modelId??"",onChange:(ce,Me)=>{D(ce&&Me?`${ce}/${Me}`:""),A(""),Te()},className:en})}),s.jsx(ht,{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:se?s.jsxs(Tt,{value:ve,onValueChange:ce=>{A(ce==="__default"?"":ce),Te()},children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:ce=>ce==="__default"?t("chat.modelControls.default"):ce})}),s.jsxs(At,{children:[s.jsx(at,{value:"__default",children:t("chat.modelControls.default")}),ge.map(ce=>s.jsx(at,{value:ce,children:ce},ce))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Be,{value:C,onChange:ce=>A(ce.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!w&&!C,className:"h-8 w-40 rounded-md px-3"}),C&&s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{A(""),Te()},className:as,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(ht,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(ps,{value:z,fallbackValue:.7,onValueChange:M,onClear:()=>{M(void 0),Te()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:xs}),z!==void 0&&s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{M(void 0),Te()},className:as,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(ht,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(ps,{value:P,fallbackValue:.9,onValueChange:R,onClear:()=>{R(void 0),Te()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:xs}),P!==void 0&&s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{R(void 0),Te()},className:as,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(ht,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(ps,{value:T,fallbackValue:20,onValueChange:O,onClear:()=>{O(void 0),Te()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:xs}),T!==void 0&&s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{O(void 0),Te()},className:as,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ve,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ns,{value:F,onChange:ce=>_(ce.target.value),placeholder:k||t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent"})}),!g&&p&&s.jsx(Ph,{agent:p,registerSave:te,requestSave:Te}),g&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(q,{onClick:()=>{Ee()},disabled:ee||!b.trim(),size:"xs",className:"!font-normal",children:t(ee?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(q,{variant:"ghost",onClick:Le,disabled:ee,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Q,{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 Kh(t,e){return t.kind==="file"?t.content:e??""}const Sc=ts({content:wt(),exists:Di(),path:wt().min(1).optional()}),zh=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Uh=t=>t.length>0&&!t.endsWith(`
3
+ `)?`${t}
4
+ `:t,Qi={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},$h=(t,e)=>t==="custom"?e:Qm(t),_h=t=>t==="custom"?"custom":Gd(t)?t:"concise",Nc={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"},Bh=()=>{const{t}=ze(),[e,a]=d.useState(""),[n,o]=d.useState("AGENTS.md"),[i,r]=d.useState(Qi.responseStyleEnabled),[l,u]=d.useState(Qi.responseStylePreset),[m,c]=d.useState(Qi.responseStyleCustomInstructions),[f,p]=d.useState(!0),g=d.useRef(null),h=d.useRef(null);d.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[y,I]=await Promise.all([jn(),Dt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:v.signal})]);let w=Qi,D;y&&(w={...w,responseStyleEnabled:y.responseStyleEnabled===!0,responseStylePreset:_h(y.responseStylePreset),responseStyleCustomInstructions:y.responseStyleCustomInstructions??""},y.globalBehaviorPrompt!==void 0&&(D=y.globalBehaviorPrompt));let C={kind:"missing"};if(I.ok){const A=Sc.parse(await I.json());if(v.signal.aborted)return;o(A.path??"AGENTS.md"),h.current=A.exists?A.content:null,A.exists&&(C={kind:"file",content:A.content})}w={...w,prompt:Kh(C,D)},a(w.prompt),r(w.responseStyleEnabled),u(w.responseStylePreset),c(w.responseStyleCustomInstructions),g.current=w}catch(y){y.name!=="AbortError"&&console.warn("Failed to load behavior settings:",y)}finally{p(!1)}})(),()=>v.abort()},[]);const k=d.useRef(e);k.current=e,d.useEffect(()=>{let v=null;const N=async()=>{if(document.visibilityState!=="visible"||!g.current)return;v?.abort();const I=new AbortController;v=I;try{const w=await Dt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:I.signal});if(!w.ok)return;const D=Sc.parse(await w.json()),C=g.current;if(I.signal.aborted||!C||!D.exists||D.content===h.current||k.current!==C.prompt)return;h.current=D.content,g.current={...C,prompt:D.content},a(D.content)}catch(w){w instanceof DOMException&&w.name==="AbortError"||console.warn("Failed to refresh AGENTS.md:",w)}},y=()=>{N()};return window.addEventListener("focus",y),document.addEventListener("visibilitychange",y),()=>{v?.abort(),window.removeEventListener("focus",y),document.removeEventListener("visibilitychange",y)}},[]);const b=d.useCallback(async()=>{const v=g.current;if(!v||f)return Ds;const N=e!==v.prompt,y=i!==v.responseStyleEnabled||l!==v.responseStylePreset||m!==v.responseStyleCustomInstructions;if(!N&&!y)return Ds;const I=N?Uh(e):v.prompt;if(N){const D=await Dt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:I,expectedContent:h.current})});if(D.status===409)return gs(t("settings.behavior.page.toast.agentsMdChangedOnDisk"));if(!D.ok)return gs(await zh(D,t("settings.behavior.page.toast.saveFailed")));h.current=I,a(C=>C===e?I:C)}return(await gt({...N?{globalBehaviorPrompt:I}:{},responseStyleEnabled:i,responseStylePreset:l,responseStyleCustomInstructions:m})).ok?(g.current={prompt:I,responseStyleEnabled:i,responseStylePreset:l,responseStyleCustomInstructions:m},yn):gs(t("settings.behavior.page.toast.saveFailed"))},[f,e,m,i,l,t]),j=Xa(b),{requestSave:x}=j,S=$h(l,m);return s.jsxs(Qt,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:j.onBlurCapture,children:[s.jsx(Ve,{title:t("settings.behavior.page.section.systemPrompt"),divider:!1,info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:n})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:s.jsx(Ns,{value:e,onChange:v=>a(v.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"})}),s.jsxs(Ve,{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(st,{checked:i,onChange:v=>{r(v),x()},disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(ht,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Tt,{value:l,onValueChange:v=>{u(v),x()},disabled:f||!i,children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Gd(v)?t(Nc[v]):null})}),s.jsxs(At,{children:[Jm.map(v=>s.jsx(at,{value:v,children:t(Nc[v])},v)),s.jsx(at,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ns,{value:S,onChange:v=>c(v.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!i||l!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Vh=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),Hh=t=>{const e=Ke.c(73),{snapshot:a}=t,{t:n}=ze(),o=Pi(Jh),i=a.selection,r=a.projectOverride!==null;let l;e[0]!==r||e[1]!==i||e[2]!==o||e[3]!==n?(l=z=>{r||Vh(z,i)||o(z).then(M=>{M||G.error(n("settings.webSearch.toast.saveFailed"))})},e[0]=r,e[1]=i,e[2]=o,e[3]=n,e[4]=l):l=e[4];const u=l,m=i.kind==="provider"&&!a.providers.some(z=>z.id===i.id)?i.id:null;let c;e[5]!==n?(c=n("settings.webSearch.section.provider"),e[5]=n,e[6]=c):c=e[6];let f;e[7]!==n?(f=n("settings.webSearch.section.providerInfo"),e[7]=n,e[8]=f):f=e[8];let p;e[9]!==n?(p=n("settings.webSearch.section.provider"),e[9]=n,e[10]=p):p=e[10];const g=i.kind==="default";let h;e[11]!==u?(h=()=>u({kind:"default"}),e[11]=u,e[12]=h):h=e[12];let k;e[13]!==n?(k=n("settings.webSearch.option.default"),e[13]=n,e[14]=k):k=e[14];let b;e[15]!==n?(b=n("settings.webSearch.option.defaultDescription"),e[15]=n,e[16]=b):b=e[16];let j;e[17]!==r||e[18]!==g||e[19]!==h||e[20]!==k||e[21]!==b?(j=s.jsx(ns,{selected:g,onSelect:h,disabled:r,label:k,description:b}),e[17]=r,e[18]=g,e[19]=h,e[20]=k,e[21]=b,e[22]=j):j=e[22];let x;e[23]!==u||e[24]!==r||e[25]!==i.kind||e[26]!==a.providers.length||e[27]!==n?(x=a.providers.length>0?s.jsx(ns,{selected:i.kind==="random",onSelect:()=>u({kind:"random"}),disabled:r,label:n("settings.webSearch.option.random"),description:n("settings.webSearch.option.randomDescription")}):null,e[23]=u,e[24]=r,e[25]=i.kind,e[26]=a.providers.length,e[27]=n,e[28]=x):x=e[28];let S;if(e[29]!==u||e[30]!==r||e[31]!==i.id||e[32]!==i.kind||e[33]!==a.providers){let z;e[35]!==u||e[36]!==r||e[37]!==i.id||e[38]!==i.kind?(z=M=>s.jsx(ns,{selected:i.kind==="provider"&&i.id===M.id,onSelect:()=>u({kind:"provider",id:M.id}),disabled:r,label:M.name},M.id),e[35]=u,e[36]=r,e[37]=i.id,e[38]=i.kind,e[39]=z):z=e[39],S=a.providers.map(z),e[29]=u,e[30]=r,e[31]=i.id,e[32]=i.kind,e[33]=a.providers,e[34]=S}else S=e[34];let v;e[40]!==m||e[41]!==n?(v=m?s.jsx(ns,{selected:!0,onSelect:Qh,label:m,description:n("settings.webSearch.option.missing")}):null,e[40]=m,e[41]=n,e[42]=v):v=e[42];const N=i.kind==="off";let y;e[43]!==u?(y=()=>u({kind:"off"}),e[43]=u,e[44]=y):y=e[44];let I;e[45]!==n?(I=n("settings.webSearch.option.off"),e[45]=n,e[46]=I):I=e[46];let w;e[47]!==r||e[48]!==N||e[49]!==y||e[50]!==I?(w=s.jsx(ns,{selected:N,onSelect:y,disabled:r,label:I}),e[47]=r,e[48]=N,e[49]=y,e[50]=I,e[51]=w):w=e[51];let D;e[52]!==x||e[53]!==S||e[54]!==v||e[55]!==w||e[56]!==p||e[57]!==j?(D=s.jsxs($s,{"aria-label":p,children:[j,x,S,v,w]}),e[52]=x,e[53]=S,e[54]=v,e[55]=w,e[56]=p,e[57]=j,e[58]=D):D=e[58];let C;e[59]!==a.projectOverride||e[60]!==n?(C=a.projectOverride?s.jsx("p",{className:`${Mt} mt-2 break-all`,children:n("settings.webSearch.state.projectOverride",{path:a.projectOverride})}):null,e[59]=a.projectOverride,e[60]=n,e[61]=C):C=e[61];let A;e[62]!==a.providers.length||e[63]!==n?(A=a.providers.length===0?s.jsx("p",{className:`${Mt} mt-2`,children:n("settings.webSearch.state.noProviders")}):null,e[62]=a.providers.length,e[63]=n,e[64]=A):A=e[64];let T;e[65]!==D||e[66]!==C||e[67]!==A?(T=s.jsxs("div",{children:[D,C,A]}),e[65]=D,e[66]=C,e[67]=A,e[68]=T):T=e[68];let O;return e[69]!==c||e[70]!==T||e[71]!==f?(O=s.jsx(Ve,{title:c,info:f,divider:!1,settingsItem:"web-search.provider",children:T}),e[69]=c,e[70]=T,e[71]=f,e[72]=O):O=e[72],O},qh=t=>{const e=Ke.c(27),{provider:a,access:n,locked:o}=t,{t:i}=ze(),r=Pi(Yh),l=Pi(Zh),[u,m]=d.useState(""),[c,f]=d.useState(!1);let p;e[0]!==n.envNames||e[1]!==i?(p=n.envNames.length>0?i("settings.webSearch.keys.envHint",{names:n.envNames.join(", ")}):void 0,e[0]=n.envNames,e[1]=i,e[2]=p):p=e[2];const g=p;let h;e[3]!==u||e[4]!==a.id||e[5]!==a.name||e[6]!==r||e[7]!==i?(h=async()=>{const N=u.trim();if(!N)return;f(!0);const y=await r(a.id,N);f(!1),y?(m(""),G.success(i("settings.webSearch.toast.keySaved",{provider:a.name}))):G.error(i("settings.webSearch.toast.keySaveFailed"))},e[3]=u,e[4]=a.id,e[5]=a.name,e[6]=r,e[7]=i,e[8]=h):h=e[8];const k=h;let b;e[9]!==a.id||e[10]!==l||e[11]!==i?(b=async()=>{f(!0);const N=await l(a.id);f(!1),N||G.error(i("settings.webSearch.toast.keyRemoveFailed"))},e[9]=a.id,e[10]=l,e[11]=i,e[12]=b):b=e[12];const j=b,x=n.key;let S;e[13]!==c||e[14]!==u||e[15]!==j||e[16]!==k||e[17]!==o||e[18]!==a.name||e[19]!==x.kind||e[20]!==x.name||e[21]!==i?(S=x.kind==="stored"?s.jsxs("div",{className:`${ks} flex items-center justify-end gap-2`,children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.webSearch.keys.saved")}),s.jsx(q,{variant:"outline",size:"xs",disabled:c,onClick:()=>{j()},children:i("settings.webSearch.keys.remove")})]}):x.kind==="env"?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.webSearch.keys.fromEnv",{name:x.name})}):o?null:s.jsxs("div",{className:`${ks} flex items-center gap-2`,children:[s.jsx(Be,{type:"password",value:u,onChange:N=>m(N.target.value),onKeyDown:N=>{N.key==="Enter"&&k()},placeholder:i("settings.webSearch.keys.placeholder"),"aria-label":i("settings.webSearch.keys.inputAria",{provider:a.name}),className:"h-8 min-w-0 flex-1 rounded-md px-3 font-mono text-xs"}),s.jsx(q,{size:"xs",disabled:c||u.trim().length===0,onClick:()=>{k()},children:i("settings.webSearch.keys.save")})]}),e[13]=c,e[14]=u,e[15]=j,e[16]=k,e[17]=o,e[18]=a.name,e[19]=x.kind,e[20]=x.name,e[21]=i,e[22]=S):S=e[22];let v;return e[23]!==g||e[24]!==a.name||e[25]!==S?(v=s.jsx(ht,{label:a.name,info:g,children:S}),e[23]=g,e[24]=a.name,e[25]=S,e[26]=v):v=e[26],v},Gh=t=>{const e=Ke.c(29),{snapshot:a}=t,{t:n}=ze(),o=Un(),i=a.access;let r,l,u,m,c,f,p,g;if(e[0]!==i||e[1]!==o||e[2]!==a.providers||e[3]!==n){g=Symbol.for("react.early_return_sentinel");e:{const b=i?a.providers.flatMap(j=>{const x=i[j.id];return x&&x.key.kind!=="unsupported"?[{provider:j,access:x}]:[]}):[];if(i&&b.length===0){g=null;break e}r=Ve,e[12]!==n?(c=n("settings.webSearch.section.keys"),e[12]=n,e[13]=c):c=e[13],e[14]!==n?(f=n("settings.webSearch.section.keysInfo"),e[14]=n,e[15]=f):f=e[15],p="web-search.keys",l="space-y-4",e[16]!==o||e[17]!==n?(u=o?s.jsx("p",{className:Mt,children:n("settings.webSearch.keys.enterpriseMode")}):null,e[16]=o,e[17]=n,e[18]=u):u=e[18],m=i===null?s.jsx("p",{className:Mt,children:n("settings.webSearch.state.keysUnavailable")}):b.map(j=>{const{provider:x,access:S}=j;return s.jsx(qh,{provider:x,access:S,locked:o},x.id)})}e[0]=i,e[1]=o,e[2]=a.providers,e[3]=n,e[4]=r,e[5]=l,e[6]=u,e[7]=m,e[8]=c,e[9]=f,e[10]=p,e[11]=g}else r=e[4],l=e[5],u=e[6],m=e[7],c=e[8],f=e[9],p=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let h;e[19]!==l||e[20]!==u||e[21]!==m?(h=s.jsxs("div",{className:l,children:[u,m]}),e[19]=l,e[20]=u,e[21]=m,e[22]=h):h=e[22];let k;return e[23]!==r||e[24]!==c||e[25]!==f||e[26]!==p||e[27]!==h?(k=s.jsx(r,{title:c,info:f,settingsItem:p,children:h}),e[23]=r,e[24]=c,e[25]=f,e[26]=p,e[27]=h,e[28]=k):k=e[28],k},Wh=()=>{const t=Ke.c(17),{t:e}=ze(),a=Pi(Xh),n=Pi(eb);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=Ym(),t[0]=o):o=t[0];const i=o;let r,l;t[1]!==n?(r=()=>{n()},l=[n,i],t[1]=n,t[2]=r,t[3]=l):(r=t[2],l=t[3]),d.useEffect(r,l);const u=a.kind==="ready"&&a.snapshot.scope===i?a.snapshot:null;let m;t[4]!==e?(m=e("settings.page.webSearch.title"),t[4]=e,t[5]=m):m=t[5];let c;t[6]!==e?(c=e("settings.page.webSearch.description"),t[6]=e,t[7]=c):c=t[7];let f;t[8]!==n||t[9]!==u||t[10]!==a.kind||t[11]!==e?(f=u?s.jsxs(s.Fragment,{children:[s.jsx(Hh,{snapshot:u}),s.jsx(Gh,{snapshot:u})]}):a.kind==="failed"?s.jsx(Ve,{divider:!1,children:s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.webSearch.state.loadFailed")}),s.jsx(q,{variant:"outline",size:"xs",onClick:()=>{n()},children:e("settings.webSearch.actions.retry")})]})}):s.jsx(Ve,{divider:!1,children:s.jsx("p",{className:Mt,children:e("settings.webSearch.state.loading")})}),t[8]=n,t[9]=u,t[10]=a.kind,t[11]=e,t[12]=f):f=t[12];let p;return t[13]!==m||t[14]!==c||t[15]!==f?(p=s.jsx(Qt,{title:m,description:c,showSaveStatus:!0,children:f}),t[13]=m,t[14]=c,t[15]=f,t[16]=p):p=t[16],p};function Jh(t){return t.setSelection}function Qh(){}function Yh(t){return t.saveKey}function Zh(t){return t.removeKey}function Xh(t){return t.state}function eb(t){return t.load}const tb=t=>{const e=Ke.c(183),{onItemSelect:a}=t,{t:n}=ze(),[o,i]=d.useState(""),[r,l]=d.useState(null),[u,m]=d.useState(""),[c,f]=d.useState(null),[p,g]=d.useState(null),[h,k]=d.useState(!1),[b,j]=d.useState(null),{selectedCommandName:x,setSelectedCommand:S,setCommandDraft:v,createCommand:N,deleteCommand:y,loadCommands:I}=Va(Ms(sb)),w=Ks();let D;e[0]!==w?(D=Ye=>Wd(Ye,w),e[0]=w,e[1]=D):D=e[1];const C=Va(D);let A;e[2]!==w?(A=Ye=>yl(Ye,w),e[2]=w,e[3]=A):A=e[3];const T=Bs(A),O=Bs(nb);let z,M;e[4]!==I||e[5]!==O||e[6]!==w?(z=()=>{I(w),O(w)},M=[I,O,w],e[4]=I,e[5]=O,e[6]=w,e[7]=z,e[8]=M):(z=e[7],M=e[8]),d.useEffect(z,M);let P;e[9]!==T?(P=new Set(T.map(ab)),e[9]=T,e[10]=P):P=e[10];const R=P;let F;if(e[11]!==C||e[12]!==R){let Ye;e[14]!==R?(Ye=Ze=>!R.has(Ze.name),e[14]=R,e[15]=Ye):Ye=e[15],F=C.filter(Ye),e[11]=C,e[12]=R,e[13]=F}else F=e[13];const _=F;let B,V;e[16]!==x||e[17]!==S||e[18]!==R?(B=()=>{x&&R.has(x)&&S(null)},V=[x,S,R],e[16]=x,e[17]=S,e[18]=R,e[19]=B,e[20]=V):(B=e[19],V=e[20]),d.useEffect(B,V);let ee;e[21]!==C||e[22]!==a||e[23]!==v||e[24]!==S?(ee=()=>{let Ye="new-command",Ze=1;for(;C.some(ut=>ut.name===Ye);)Ye=`new-command-${Ze}`,Ze++;v({name:Ye,scope:"user"}),S(Ye),a?.()},e[21]=C,e[22]=a,e[23]=v,e[24]=S,e[25]=ee):ee=e[25];const L=ee;let $;e[26]!==n?($=async Ye=>{if(Ua(Ye)){G.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(Ye),g("delete")},e[26]=n,e[27]=$):$=e[27];const H=$;let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=async Ye=>{Ua(Ye)&&(f(Ye),g("reset"))},e[28]=W):W=e[28];const Z=W;let te;e[29]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{f(null),g(null)},e[29]=te):te=e[29];const J=te;let ie;e[30]!==c||e[31]!==p||e[32]!==y||e[33]!==w||e[34]!==n?(ie=async()=>{if(!c||!p)return;k(!0),await y(c.name,w)?(p==="delete"?G.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):G.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),J()):p==="delete"?G.error(n("settings.commands.sidebar.toast.deleteFailed")):G.error(n("settings.commands.sidebar.toast.resetFailed")),k(!1)},e[30]=c,e[31]=p,e[32]=y,e[33]=w,e[34]=n,e[35]=ie):ie=e[35];const pe=ie;let X;e[36]!==C||e[37]!==v||e[38]!==S?(X=Ye=>{const Ze=Ye.name;let ut=1,ft=`${Ze}-copy`;for(;C.some(K=>K.name===ft);)ut++,ft=`${Ze}-copy-${ut}`;v({name:ft,scope:Ye.scope||"user",description:Ye.description,template:Ye.template,agent:Ye.agent,model:Ye.model,subagent:Ye.subagent}),S(ft)},e[36]=C,e[37]=v,e[38]=S,e[39]=X):X=e[39];const xe=X;let Y;e[40]===Symbol.for("react.memo_cache_sentinel")?(Y=Ye=>{m(Ye.name),l(Ye)},e[40]=Y):Y=e[40];const be=Y;let De;e[41]!==C||e[42]!==N||e[43]!==y||e[44]!==r||e[45]!==u||e[46]!==S||e[47]!==w||e[48]!==n?(De=async()=>{if(!r)return;const Ye=u.trim().replace(/\s+/g,"-");if(!Ye){G.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ye===r.name){l(null);return}if(C.some(ut=>ut.name===Ye)){G.error(n("settings.commands.sidebar.toast.commandExists"));return}await N({name:Ye,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},w)?await y(r.name,w)?(G.success(`Command renamed to "${Ye}"`),S(Ye)):G.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):G.error(n("settings.commands.sidebar.toast.renameFailed")),l(null)},e[41]=C,e[42]=N,e[43]=y,e[44]=r,e[45]=u,e[46]=S,e[47]=w,e[48]=n,e[49]=De):De=e[49];const ve=De;let se,ge,ne,Se,ke,Te;if(e[50]!==_||e[51]!==L||e[52]!==H||e[53]!==xe||e[54]!==a||e[55]!==b||e[56]!==o||e[57]!==x||e[58]!==S||e[59]!==n){let Ye;e[66]!==o?(Ye=It=>Ii([It.name,It.description],o),e[66]=o,e[67]=Ye):Ye=e[67];const Ze=_.filter(Ye),ut=Ze.filter(Ua),ft=Ze.filter(ib);e[68]===Symbol.for("react.memo_cache_sentinel")?(ke=Ie("flex h-full flex-col","bg-background"),e[68]=ke):ke=e[68];let K;e[69]!==n?(K=n("settings.commands.sidebar.title"),e[69]=n,e[70]=K):K=e[70];let ue;e[71]!==K?(ue=s.jsx("h2",{className:`${zn} mb-3`,children:K}),e[71]=K,e[72]=ue):ue=e[72];let Ne;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(Mi,{className:"mb-3"}),e[73]=Ne):Ne=e[73];let Ce;e[74]!==_.length||e[75]!==n?(Ce=n("settings.commands.sidebar.total",{count:_.length}),e[74]=_.length,e[75]=n,e[76]=Ce):Ce=e[76];let He;e[77]!==Ce?(He=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ce}),e[77]=Ce,e[78]=He):He=e[78];let le;e[79]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),e[79]=le):le=e[79];let Oe;e[80]!==L?(Oe=s.jsx(q,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:L,children:le}),e[80]=L,e[81]=Oe):Oe=e[81];let ot;e[82]!==He||e[83]!==Oe?(ot=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[He,Oe]}),e[82]=He,e[83]=Oe,e[84]=ot):ot=e[84];let Rt;e[85]!==_.length||e[86]!==o?(Rt=_.length>0?s.jsx(Ml,{value:o,onChange:i}):null,e[85]=_.length,e[86]=o,e[87]=Rt):Rt=e[87],e[88]!==ue||e[89]!==ot||e[90]!==Rt?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ue,Ne,ot,Rt]}),e[88]=ue,e[89]=ot,e[90]=Rt,e[91]=Te):Te=e[91],se=Ps,ge="flex-1 min-h-0",ne="space-y-1 px-3 py-2",Se=_.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Q,{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")})]}):Ze.length===0?s.jsx(Rl,{query:o}):s.jsxs(s.Fragment,{children:[ut.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")}),[...ut].sort(ob).map(It=>s.jsx(Cc,{command:It,isSelected:x===It.name,onSelect:()=>{S(It.name),a?.()},onReset:()=>Z(It),onDuplicate:()=>xe(It),isMenuOpen:b===It.name,onMenuOpenChange:os=>j(os?It.name:null)},It.name))]}),ft.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")}),[...ft].sort(rb).map(It=>s.jsx(Cc,{command:It,isSelected:x===It.name,onSelect:()=>{S(It.name),a?.()},onRename:()=>be(It),onDelete:()=>H(It),onDuplicate:()=>xe(It),isMenuOpen:b===It.name,onMenuOpenChange:os=>j(os?It.name:null)},It.name))]})]}),e[50]=_,e[51]=L,e[52]=H,e[53]=xe,e[54]=a,e[55]=b,e[56]=o,e[57]=x,e[58]=S,e[59]=n,e[60]=se,e[61]=ge,e[62]=ne,e[63]=Se,e[64]=ke,e[65]=Te}else se=e[60],ge=e[61],ne=e[62],Se=e[63],ke=e[64],Te=e[65];let Ee;e[92]!==se||e[93]!==ge||e[94]!==ne||e[95]!==Se?(Ee=s.jsx(se,{outerClassName:ge,className:ne,children:Se}),e[92]=se,e[93]=ge,e[94]=ne,e[95]=Se,e[96]=Ee):Ee=e[96];const Le=c!==null&&p!==null;let ce;e[97]!==h?(ce=Ye=>{!Ye&&!h&&J()},e[97]=h,e[98]=ce):ce=e[98];let Me;e[99]!==p||e[100]!==n?(Me=n(p==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[99]=p,e[100]=n,e[101]=Me):Me=e[101];let Fe;e[102]!==Me?(Fe=s.jsx(Ut,{children:Me}),e[102]=Me,e[103]=Fe):Fe=e[103];let me;e[104]!==c?.name||e[105]!==p||e[106]!==n?(me=p==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[104]=c?.name,e[105]=p,e[106]=n,e[107]=me):me=e[107];let de;e[108]!==me?(de=s.jsx($t,{children:me}),e[108]=me,e[109]=de):de=e[109];let Pe;e[110]!==Fe||e[111]!==de?(Pe=s.jsxs(zt,{children:[Fe,de]}),e[110]=Fe,e[111]=de,e[112]=Pe):Pe=e[112];let he;e[113]!==n?(he=n("settings.common.actions.cancel"),e[113]=n,e[114]=he):he=e[114];let Ue;e[115]!==h||e[116]!==he?(Ue=s.jsx(q,{size:"sm",variant:"ghost",onClick:J,disabled:h,children:he}),e[115]=h,e[116]=he,e[117]=Ue):Ue=e[117];let Ae;e[118]!==p||e[119]!==n?(Ae=n(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[118]=p,e[119]=n,e[120]=Ae):Ae=e[120];let Re;e[121]!==pe||e[122]!==h||e[123]!==Ae?(Re=s.jsx(q,{size:"sm",onClick:pe,disabled:h,children:Ae}),e[121]=pe,e[122]=h,e[123]=Ae,e[124]=Re):Re=e[124];let $e;e[125]!==Ue||e[126]!==Re?($e=s.jsxs(Xt,{children:[Ue,Re]}),e[125]=Ue,e[126]=Re,e[127]=$e):$e=e[127];let nt;e[128]!==Pe||e[129]!==$e?(nt=s.jsxs(Lt,{className:"max-w-md",children:[Pe,$e]}),e[128]=Pe,e[129]=$e,e[130]=nt):nt=e[130];let pt;e[131]!==Le||e[132]!==ce||e[133]!==nt?(pt=s.jsx(Ft,{open:Le,onOpenChange:ce,children:nt}),e[131]=Le,e[132]=ce,e[133]=nt,e[134]=pt):pt=e[134];const kt=r!==null;let bt;e[135]===Symbol.for("react.memo_cache_sentinel")?(bt=Ye=>!Ye&&l(null),e[135]=bt):bt=e[135];let yt;e[136]!==n?(yt=n("settings.commands.sidebar.renameDialog.title"),e[136]=n,e[137]=yt):yt=e[137];let Je;e[138]!==yt?(Je=s.jsx(Ut,{children:yt}),e[138]=yt,e[139]=Je):Je=e[139];const ct=r?.name??"";let Qe;e[140]!==n||e[141]!==ct?(Qe=n("settings.commands.sidebar.renameDialog.description",{name:ct}),e[140]=n,e[141]=ct,e[142]=Qe):Qe=e[142];let it;e[143]!==Qe?(it=s.jsx($t,{children:Qe}),e[143]=Qe,e[144]=it):it=e[144];let dt;e[145]!==Je||e[146]!==it?(dt=s.jsxs(zt,{children:[Je,it]}),e[145]=Je,e[146]=it,e[147]=dt):dt=e[147];let qe;e[148]===Symbol.for("react.memo_cache_sentinel")?(qe=Ye=>m(Ye.target.value),e[148]=qe):qe=e[148];let lt;e[149]!==n?(lt=n("settings.commands.sidebar.renameDialog.placeholder"),e[149]=n,e[150]=lt):lt=e[150];let ae;e[151]!==ve?(ae=Ye=>{Ye.key==="Enter"&&ve()},e[151]=ve,e[152]=ae):ae=e[152];let fe;e[153]!==u||e[154]!==lt||e[155]!==ae?(fe=s.jsx(Be,{value:u,onChange:qe,placeholder:lt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ae}),e[153]=u,e[154]=lt,e[155]=ae,e[156]=fe):fe=e[156];let ye;e[157]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>l(null),e[157]=ye):ye=e[157];let we;e[158]!==n?(we=n("settings.common.actions.cancel"),e[158]=n,e[159]=we):we=e[159];let Ge;e[160]!==we?(Ge=s.jsx(q,{size:"sm",variant:"ghost",onClick:ye,children:we}),e[160]=we,e[161]=Ge):Ge=e[161];let et;e[162]!==n?(et=n("settings.common.actions.rename"),e[162]=n,e[163]=et):et=e[163];let mt;e[164]!==ve||e[165]!==et?(mt=s.jsx(q,{size:"sm",onClick:ve,children:et}),e[164]=ve,e[165]=et,e[166]=mt):mt=e[166];let jt;e[167]!==Ge||e[168]!==mt?(jt=s.jsxs(Xt,{children:[Ge,mt]}),e[167]=Ge,e[168]=mt,e[169]=jt):jt=e[169];let vt;e[170]!==dt||e[171]!==fe||e[172]!==jt?(vt=s.jsxs(Lt,{children:[dt,fe,jt]}),e[170]=dt,e[171]=fe,e[172]=jt,e[173]=vt):vt=e[173];let Ct;e[174]!==kt||e[175]!==vt?(Ct=s.jsx(Ft,{open:kt,onOpenChange:bt,children:vt}),e[174]=kt,e[175]=vt,e[176]=Ct):Ct=e[176];let Bt;return e[177]!==ke||e[178]!==Te||e[179]!==Ee||e[180]!==pt||e[181]!==Ct?(Bt=s.jsxs("div",{className:ke,children:[Te,Ee,pt,Ct]}),e[177]=ke,e[178]=Te,e[179]=Ee,e[180]=pt,e[181]=Ct,e[182]=Bt):Bt=e[182],Bt},Cc=t=>{const e=Ke.c(47),{command:a,isSelected:n,onSelect:o,onDelete:i,onReset:r,onRename:l,onDuplicate:u,isMenuOpen:m,onMenuOpenChange:c}=t,{t:f}=ze();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=xl(),e[0]=p):p=e[0];const g=p,[h,k]=d.useState(!1);let b;e[1]!==i||e[2]!==u||e[3]!==l||e[4]!==r||e[5]!==f?(b=_=>s.jsxs(s.Fragment,{children:[l&&s.jsxs(_,{onClick:B=>{B.stopPropagation(),l()},children:[s.jsx(Q,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(_,{onClick:B=>{B.stopPropagation(),u()},children:[s.jsx(Q,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),r&&s.jsxs(_,{onClick:B=>{B.stopPropagation(),r()},children:[s.jsx(Q,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),i&&s.jsxs(_,{onClick:B=>{B.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[1]=i,e[2]=u,e[3]=l,e[4]=r,e[5]=f,e[6]=b):b=e[6];const j=b,x=n?"bg-interactive-selection":"hover:bg-interactive-hover";let S;e[7]!==x?(S=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[7]=x,e[8]=S):S=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=g?void 0:_=>{_.preventDefault(),k(!0)},e[9]=v):v=e[9];let N;e[10]!==S?(N=s.jsx("div",{className:S,onContextMenu:v}),e[10]=S,e[11]=N):N=e[11];let y;e[12]!==a.name?(y=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=y):y=e[13];let I;e[14]!==a||e[15]!==f?(I=(a.scope||Ua(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Ua(a)?f("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=f,e[16]=I):I=e[16];let w;e[17]!==y||e[18]!==I?(w=s.jsxs("div",{className:"flex items-center gap-2",children:[y,I]}),e[17]=y,e[18]=I,e[19]=w):w=e[19];let D;e[20]!==a.description?(D=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=D):D=e[21];let C;e[22]!==o||e[23]!==D||e[24]!==w?(C=s.jsxs("button",{onClick:o,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:[w,D]}),e[22]=o,e[23]=D,e[24]=w,e[25]=C):C=e[25];let A;e[26]!==c?(A=_=>{_&&k(!1),c(_)},e[26]=c,e[27]=A):A=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(Wn,{asChild:!0,children:s.jsx(q,{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(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=T):T=e[28];let O;e[29]!==j?(O=s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:j(Fn)}),e[29]=j,e[30]=O):O=e[30];let z;e[31]!==m||e[32]!==A||e[33]!==O?(z=s.jsxs(Jn,{open:m,onOpenChange:A,children:[T,O]}),e[31]=m,e[32]=A,e[33]=O,e[34]=z):z=e[34];let M;e[35]!==C||e[36]!==z?(M=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,z]}),e[35]=C,e[36]=z,e[37]=M):M=e[37];let P;e[38]!==M||e[39]!==N?(P=s.jsx(Ja,{render:N,children:M}),e[38]=M,e[39]=N,e[40]=P):P=e[40];let R;e[41]!==j?(R=s.jsx(Ga,{className:"w-fit min-w-20",children:j(Wa)}),e[41]=j,e[42]=R):R=e[42];let F;return e[43]!==h||e[44]!==P||e[45]!==R?(F=s.jsxs(Qa,{open:h,onOpenChange:k,children:[P,R]}),e[43]=h,e[44]=P,e[45]=R,e[46]=F):F=e[46],F};function sb(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function nb(t){return t.loadSkills}function ab(t){return t.name}function ib(t){return!Ua(t)}function ob(t,e){return t.name.localeCompare(e.name)}function rb(t,e){return t.name.localeCompare(e.name)}const lb=()=>{const{t}=ze(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:o,commandDraft:i,setCommandDraft:r,setSelectedCommand:l}=Va(Ms($=>({selectedCommandName:$.selectedCommandName,getCommandByName:$.getCommandByName,createCommand:$.createCommand,updateCommand:$.updateCommand,commandDraft:$.commandDraft,setCommandDraft:$.setCommandDraft,setSelectedCommand:$.setSelectedCommand}))),u=Ks(),m=Va($=>Wd($,u)),c=e?a(e,u):null,f=!!(i&&i.name===e&&!c),[p,g]=d.useState(""),[h,k]=d.useState("user"),[b,j]=d.useState(""),[x,S]=d.useState(""),[v,N]=d.useState(""),[y,I]=d.useState(""),[w,D]=d.useState(!1),[C,A]=d.useState(""),[T,O]=d.useState(!1),z=d.useRef(null),M=JSON.stringify([u,e]),P=d.useRef(null),R=d.useRef(null);d.useEffect(()=>{const $=P.current===M;if(P.current=M,f&&i){const H=i.name||"",W=i.scope||"user",Z=i.description||"",te=i.agent||"",J=Ni(i.model),ie=J?`${J.providerID}/${J.modelID}`:"",pe=J?.variant||"",X=i.subagent===!0,xe=i.template||"";g(H),k(W),j(Z),S(te),N(ie),I(pe),D(X),A(xe),z.current={draftName:H,draftScope:W,description:Z,agent:te,model:ie,variant:pe,subagent:X,template:xe}}else if(c){const H=c.description||"",W=c.agent||"",Z=Ni(c.model),te=Z?`${Z.providerID}/${Z.modelID}`:"",J=Z?.variant||"",ie=c.subagent===!0,pe=c.template||"",X=R.current,xe=[z.current,X?.identity===M?X.form:null];if($&&xe.some(Y=>Y&&Y.description===H&&Y.agent===W&&Y.model===te&&Y.variant===J&&Y.subagent===ie&&Y.template===pe))return;j(H),S(W),N(te),I(J),D(ie),A(pe),z.current={draftName:"",draftScope:"user",description:H,agent:W,model:te,variant:J,subagent:ie,template:pe}}},[c,f,e,m,i,M]);const F=d.useCallback($=>{const H=x.trim(),W=Mn(v.trim()),Z=W?du({providerID:W.providerId,modelID:W.modelId,variant:y.trim()||void 0}):null;return{name:$,description:b.trim()||void 0,agent:H===""?null:H,model:Z,subagent:w,template:C.trim(),scope:f?h:void 0}},[x,b,h,f,v,w,C,y]),_=d.useCallback(async()=>{const $=z.current,H=e?.trim();if(f||!$||!H||b.trim()===$.description.trim()&&x.trim()===$.agent.trim()&&v.trim()===$.model.trim()&&y.trim()===$.variant.trim()&&w===$.subagent&&C.trim()===$.template.trim())return Ds;if(!C.trim())return gs(t("settings.commands.page.toast.templateRequired"));const Z=F(H),te=Ni(Z.model),J={identity:M,form:{...$,description:Z.description||"",agent:Z.agent||"",model:te?`${te.providerID}/${te.modelID}`:"",variant:te?.variant||"",subagent:Z.subagent===!0,template:Z.template||""}};R.current=J;try{return await o(H,Z,u)?(P.current===M&&(z.current=J.form),yn):gs(t("settings.commands.page.toast.updateFailed"))}finally{R.current===J&&(R.current=null)}},[x,F,b,M,f,v,e,u,w,t,C,o,y]),B=Xa(_),{requestSave:V}=B,ee=async()=>{const $=p.trim().replace(/\s+/g,"-");if(!$){G.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){G.error(t("settings.commands.page.toast.templateRequired"));return}if(m.some(H=>H.name===$)){G.error(t("settings.commands.sidebar.toast.commandExists"));return}O(!0);try{await n(F($),u)?(r(null),G.success(t("settings.commands.page.toast.created"))):G.error(t("settings.commands.page.toast.createFailed"))}catch(H){console.error("Error creating command:",H),G.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{O(!1)}},L=()=>{r(null),l(null)};return e?s.jsxs(Qt,{title:f?t("settings.commands.page.title.new"):`/${e}`,description:t(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),onBlurCapture:B.onBlurCapture,children:[!f&&c&&s.jsx(Ol,{legacy:c.legacy===!0,path:c.path}),s.jsxs(Ve,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[f&&s.jsxs(ht,{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:p,onChange:$=>g($.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Tt,{value:h,onValueChange:$=>k($),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[100px]",children:s.jsx(Kt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{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(Ns,{value:b,onChange:$=>j($.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(Ve,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(ht,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(jl,{agentName:x,onChange:$=>{S($),V()},className:en})}),s.jsx(ht,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ga,{providerId:Mn(v)?.providerId??"",modelId:Mn(v)?.modelId??"",onChange:($,H)=>{N($&&H?`${$}/${H}`:""),V()},className:en})}),s.jsx(ht,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(Be,{value:y,onChange:$=>I($.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!v&&!y,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(ht,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(fa,{checked:w,onCheckedChange:$=>{D($),V()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(Ve,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ns,{value:C,onChange:$=>A($.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),f&&s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(q,{onClick:()=>{ee()},disabled:T||!p.trim()||!C.trim(),size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(q,{variant:"ghost",onClick:L,disabled:T,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Q,{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")})]})})};function _s(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function pi(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function hn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Yi(t,e,a){const n=db(a),o=typeof a.url=="string"?a.url.trim():"",i=Ic(a,"env","environment"),r=Ic(a,"headers"),l=_s(a.oauth)?a.oauth:null,u=gi(l,"client_id","clientId"),m=gi(l,"client_secret","clientSecret"),c=gi(l,"scope"),f=gi(l,"redirect_uri","redirectUri"),p=cb(l,"callback_port","callbackPort"),g=gi(l,"auth_server_metadata_url","authServerMetadataUrl"),h=a.oauth===!1||a.oauth===null||a.oauth===void 0?!1:!!l&&!!(u||m||c||f||p||g),k=ub(a);return{ok:!0,name:t,type:e,command:n,url:o,environment:i,headers:r,oauthEnabled:h,oauthClientId:u,oauthClientSecret:m,oauthScope:c,oauthRedirectUri:f,oauthCallbackPort:p,oauthAuthServerMetadataUrl:g,timeoutStartup:k.startup,timeoutCatalog:k.catalog,timeoutExecution:k.execution,codemode:a.codemode===!0?"on":a.codemode===!1?"off":"default",disabled:mb(a),protocol:Qr.find(b=>b===a.protocol)??"legacy"}}function gi(t,...e){if(!t)return"";for(const a of e){const n=t[a];if(typeof n=="string"&&n.trim())return n.trim()}return""}function cb(t,...e){if(!t)return"";for(const a of e){const n=ji(t[a]);if(n)return n}return""}function ji(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return String(Math.floor(t));if(typeof t=="string"&&t.trim()){const e=Number(t);if(Number.isFinite(e)&&e>0)return String(Math.floor(e))}return""}function db(t){const e=t.command,a=t.args;if(pi(e)&&pi(a))return[...e,...a];if(pi(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return pi(a)?[...n,...a]:n}return pi(a)?a:[]}function Ic(t,...e){for(const a of e){const n=t[a];if(!_s(n))continue;const o=Object.entries(n).filter(([i,r])=>i&&typeof r=="string");if(o.length>0)return o.map(([i,r])=>({key:i,value:String(r)}))}return[]}function ub(t){return _s(t.timeout)?{startup:ji(t.timeout.startup),catalog:ji(t.timeout.catalog),execution:ji(t.timeout.execution)}:{startup:"",catalog:"",execution:ji(t.timeout)}}function mb(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function pb(t){const e=t.mcpServers;if(_s(e)){const n=Object.keys(e);if(n.length===1){const o=n[0],i=e[o];if(_s(i))return{name:o,entry:i}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const o=t[n];return n!=="mcpServers"&&_s(o)});if(a.length===1){const n=a[0],o=t[n];if(wu(o))return{name:n,entry:o}}return null}function wu(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function gb(t,e){let a;try{const u=t.trim();if(!u)return hn("No JSON content provided");a=JSON.parse(u)}catch(u){return hn(u instanceof Error?`Invalid JSON: ${u.message}`:"Invalid JSON")}if(!_s(a))return hn("Expected a JSON object, not an array or primitive");const n=a,o=n.mcpServers;if(_s(o)){const u=Object.keys(o);if(u.length===0)return hn("mcpServers object is empty",a);if(u.length>1)return hn("Paste one server at a time. Found "+u.length+" servers in mcpServers",a);const m=u[0],c=o[m];return _s(c)?Yi(m,Zi(c),c):hn("Server entry is not a valid object",a)}const i=n.mcp,r=_s(i)&&_s(i.servers)?i.servers:i;if(_s(r)){const u=Object.keys(r);if(u.length===0)return hn("mcp object is empty",a);if(u.length>1)return hn("Paste one server at a time. Found "+u.length+" servers in mcp",a);const m=u[0],c=r[m];return _s(c)?Yi(m,Zi(c),c):hn("Server entry in mcp is not a valid object",a)}const l=pb(n);if(l)return Yi(l.name,Zi(l.entry),l.entry);if(wu(n)){const u=Zi(n),m=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Yi(m,u,n)}return hn("No recognizable MCP server configuration found in JSON",a)}function Zi(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 fb(t,e,a){const n=a?.isNewServer??!1,o=t.name,i=n&&o?o:e.name??"";return{...e,name:i,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",oauthCallbackPort:t.type==="remote"?t.oauthCallbackPort:"",oauthAuthServerMetadataUrl:t.type==="remote"?t.oauthAuthServerMetadataUrl:"",timeoutStartup:t.type==="local"?t.timeoutStartup:"",timeoutCatalog:t.timeoutCatalog,timeoutExecution:t.timeoutExecution,codemode:t.codemode,disabled:t.disabled,protocol:t.protocol}}const hb=(t,e)=>!!e&&t!=="claude-code",bb=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,xb=t=>bb.exec(t)?.[0]??void 0,ei=t=>t.type!=="external",ca=t=>t.title??t.key,vb=(t,e)=>{if(e===void 0)return!1;const a=String(e),n=String(t.value);return t.op==="eq"?a===n:a!==n},yb=(t,e)=>ei(t)?(t.when??[]).every(a=>vb(a,e[a.key])):!0,Fl=(t,e)=>{const a={},n=[];for(const o of t){if(!yb(o,a))continue;n.push(o);const i=e[o.key];ei(o)&&i!==void 0&&(a[o.key]=i)}return n},Su=t=>{const e={};for(const a of t)switch(a.type){case"external":break;case"boolean":e[a.key]=a.default??!1;break;case"number":case"integer":typeof a.default=="number"&&(e[a.key]=a.default);break;case"multiselect":e[a.key]=a.default??[];break;case"string":e[a.key]=a.default??a.options?.[0]?.value??"";break}return e},Nu=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,Cu=(t,e)=>Fl(t,e).find(a=>ei(a)&&a.required===!0&&Nu(e[a.key]))??null,Iu=(t,e)=>{const a={};for(const n of Fl(t,e)){if(!ei(n))continue;const o=e[n.key];Nu(o)||o===void 0||(a[n.key]=typeof o=="string"?o.trim():o)}return a},Pc=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ac=t=>typeof t=="string"&&t.length>0?t:void 0,jb=(t,e,a)=>{const n=Pc(t)?t:{},o=Pc(n.data)?n.data:{};switch(n.name){case"IntegrationOauthAttemptMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"IntegrationOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"IntegrationOauthFailed":return e("settings.providers.page.auth.oauth.error.declined");case"IntegrationValidationFailed":return Ac(o.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return Ac(n.message)??e(a)}},Xi="\0typed",Pu=t=>{const e=Ke.c(12),{fields:a,values:n,onChange:o}=t,{t:i}=ze();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Set,e[0]=r):r=e[0];const[l,u]=d.useState(r);let m;e[1]!==o||e[2]!==i||e[3]!==l||e[4]!==n?(m=g=>{if(g.type==="external")return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:ca(g)}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(g.url)},children:i("settings.providers.page.actions.open")})]},g.key);const h=n[g.key],k=typeof h=="string"?h:"",b=N=>o(g.key,N),j=g.type==="string"||g.type==="multiselect"?g.options??[]:[],x=g.type==="string"&&g.custom===!0,S=x&&l.has(g.key),v=N=>u(y=>{const I=new Set(y);return N?I.add(g.key):I.delete(g.key),I});return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:ca(g)}),g.description&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.description}),j.length>0?s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:S?Xi:k,onValueChange:N=>{if(N===Xi){v(!0),b("");return}v(!1),b(N)},children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{children:N=>N===Xi?i("settings.providers.page.auth.field.other"):j.find(y=>y.value===N)?.label??null})}),s.jsxs(At,{children:[j.map(kb),x?s.jsx(at,{value:Xi,children:i("settings.providers.page.auth.field.other")}):null]})]}),S?s.jsx(Be,{value:k,onChange:N=>b(N.target.value),placeholder:g.placeholder??i("settings.providers.page.auth.field.otherPlaceholder"),"aria-label":ca(g),className:"max-w-[24rem] text-xs",autoFocus:!0}):null]}):g.type==="boolean"?s.jsx("input",{type:"checkbox",checked:h===!0,onChange:N=>b(N.target.checked),"aria-label":ca(g)}):s.jsx(Be,{value:k,onChange:N=>b(N.target.value),placeholder:g.type==="string"?g.placeholder:void 0,"aria-label":ca(g),className:"max-w-[24rem] text-xs"})]},g.key)},e[1]=o,e[2]=i,e[3]=l,e[4]=n,e[5]=m):m=e[5];const c=m;let f;e[6]!==a||e[7]!==c||e[8]!==n?(f=Fl(a,n).map(c),e[6]=a,e[7]=c,e[8]=n,e[9]=f):f=e[9];let p;return e[10]!==f?(p=s.jsx(s.Fragment,{children:f}),e[10]=f,e[11]=p):p=e[11],p};function kb(t){return s.jsx(at,{value:t.value,children:t.description?`${t.label} · ${t.description}`:t.label},t.value)}const Nr={phase:"idle"},wb=1500,ol=({integrationId:t,methods:e,onConnected:a,directory:n,className:o})=>{const{t:i}=ze(),r=d.useCallback(()=>n?Ls.getScopedSdkClient(n):Ls.getSdkClient(),[n]),[l,u]=d.useState(Nr),[m,c]=d.useState({}),[f,p]=d.useState(""),g=d.useRef(null),h=d.useCallback(T=>{g.current=null,r().integration.oauth.cancel({integrationID:t,attemptID:T}).catch(()=>{})},[t,r]);d.useEffect(()=>()=>{const T=g.current;T&&h(T)},[h]);const k=l.phase==="idle"?null:l.methodID,b=l.phase==="connecting"||l.phase==="waiting"||l.phase==="awaitingCode"&&l.submitting,j=async(T,O,z)=>{const M=await za(T);if(M.ok){G.success(i(O));return}console.error("Failed to copy OAuth value:",M.error),G.error(i(z))},x=async(T="settings.providers.page.toast.oauthCompleted")=>{g.current=null,u(Nr),G.success(i(T)),await a()},S=(T,O,z)=>{g.current=null,console.error("OAuth flow failed:",O),u({phase:"failed",methodID:T,message:jb(O,i,z)})},v=async(T,O)=>{const z=r();for(;g.current===O;){if(await new Promise(M=>setTimeout(M,wb)),g.current!==O)return;try{const{data:M}=await z.integration.oauth.status({integrationID:t,attemptID:O});if(g.current!==O)return;if(M.status==="complete"){await x();return}if(M.status==="failed"){u({phase:"failed",methodID:T,message:M.message}),g.current=null;return}}catch(M){if(g.current!==O)return;S(T,M,"settings.providers.page.toast.oauthCompleteFailed");return}}},N=async(T,O)=>{u({phase:"connecting",methodID:T});try{await r().integration.connect.external({integrationID:t,methodID:T,answer:Object.keys(O).length>0?O:void 0})}catch(z){S(T,z,"settings.providers.page.toast.externalConnectFailed");return}await x("settings.providers.page.toast.externalConnected")},y=async(T,O)=>{if(T.type==="external"){await N(T.id,O);return}u({phase:"connecting",methodID:T.id});let z;try{const{data:M}=await r().integration.oauth.connect({integrationID:t,methodID:T.id,...Object.keys(O).length>0?{answer:O}:{}});z={attemptID:M.attemptID,mode:M.mode,url:M.url,instructions:M.instructions}}catch(M){S(T.id,M,"settings.providers.page.toast.oauthStartFailed");return}if(g.current=z.attemptID,hb(t,z.url)&&Ss(z.url),z.mode==="code"){p(""),u({phase:"awaitingCode",methodID:T.id,attempt:z,submitting:!1});return}u({phase:"waiting",methodID:T.id,attempt:z}),await v(T.id,z.attemptID)},I=T=>{const O=(T.form??[]).filter(ei);if(O.length===0){y(T,{});return}c(Su(O)),u({phase:"prompting",methodID:T.id,fields:O,error:null})},w=T=>{if(l.phase!=="prompting")return;const O=Cu(l.fields,m);if(O){u({...l,error:i("settings.providers.page.auth.oauth.promptRequired",{field:ca(O)})});return}y(T,Iu(l.fields,m))},D=async()=>{if(l.phase!=="awaitingCode")return;const T=f.trim();if(!T)return;const{methodID:O,attempt:z}=l;u({...l,submitting:!0});try{await r().integration.oauth.complete({integrationID:t,attemptID:z.attemptID,code:T}),await x()}catch(M){S(O,M,"settings.providers.page.toast.oauthCompleteFailed")}},C=()=>{(l.phase==="waiting"||l.phase==="awaitingCode")&&h(l.attempt.attemptID),u(Nr)},A=T=>{const O=xb(T.instructions);return s.jsxs(s.Fragment,{children:[T.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:T.instructions}),O&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:O,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{j(O,"settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),T.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:T.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(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(T.url)},children:i("settings.providers.page.actions.open")}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{j(T.url,"settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]})};return s.jsx("div",{className:Ie("space-y-4",o),children:e.map(T=>{const O=k===T.id;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:T.label}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>I(T),disabled:b,children:i("settings.providers.page.actions.connect")})]}),O&&l.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[s.jsx(Pu,{fields:l.fields,values:m,onChange:(z,M)=>c(P=>({...P,[z]:M}))}),l.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(q,{size:"xs",className:"!font-normal",onClick:()=>w(T),children:i("settings.providers.page.actions.continue")}),s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:C,children:i("settings.providers.page.actions.cancel")})]})]}),O&&l.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(Q,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),T.type==="external"?i("settings.providers.page.auth.external.connecting"):i("settings.providers.page.auth.oauth.starting")]}),O&&l.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[A(l.attempt),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(Q,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:C,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),O&&l.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[A(l.attempt),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:f,onChange:z=>p(z.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:l.submitting}),s.jsx(q,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{D()},disabled:l.submitting||f.trim().length===0,children:l.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:C,disabled:l.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),O&&l.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l.message}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>I(T),children:i("settings.providers.page.actions.tryAgain")})]})]},T.id)})})},Sb=(t,e)=>t.find(a=>a.id.startsWith("mcp_")&&a.metadata?.source==="mcp"&&a.name===e),Nb=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Cb=({serverName:t,directory:e,onConnected:a})=>{const[n,o]=d.useState(null);d.useEffect(()=>{let r=!1;o(null);const l=e?Ls.getScopedSdkClient(e):Ls.getSdkClient();return(async()=>{try{const{data:m}=await l.integration.list();r||o(Sb(m,t)??null)}catch(m){console.error("Failed to load MCP integrations:",m)}})(),()=>{r=!0}},[e,t]);const i=Nb(n??void 0);return!n||i.length===0?null:s.jsx(ol,{integrationId:n.id,methods:i,directory:e,onConnected:a},n.id)},wo={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},Ib=t=>t===!1?{...wo,oauthEnabled:!1}:t?{oauthEnabled:!0,oauthClientId:t.client_id??"",oauthClientSecret:t.client_secret??"",oauthScope:t.scope??"",oauthRedirectUri:t.redirect_uri??"",oauthCallbackPort:t.callback_port===void 0?"":String(t.callback_port)}:wo,Tc=[],Ll=t=>{const e=Ke.c(5),[a,n]=d.useState(Tc);let o,i;e[0]!==t?(o=()=>{let l=!1;return n(Tc),Ls.getIntegrationPolicies(t).then(u=>{l||n(u)}).catch(Pb),()=>{l=!0}},i=[t],e[0]=t,e[1]=o,e[2]=i):(o=e[1],i=e[2]),d.useEffect(o,i);let r;return e[3]!==a?(r=l=>Tg(a,l),e[3]=a,e[4]=r):r=e[4],r};function Pb(t){console.warn("[settings] could not read OpenCode integration policies:",t instanceof Error?t.message:String(t))}const Fo="grid grid-cols-1 gap-3 @xl:grid-cols-2 @3xl:grid-cols-3",rl=Ie("group flex min-h-[132px] flex-col rounded-xl border p-4 text-left transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"),Ab={success:"bg-[var(--status-success)]/15 text-[var(--status-success)]",warning:"bg-[var(--status-warning)]/15 text-[var(--status-warning)]",error:"bg-[var(--status-error)]/15 text-[var(--status-error)]",info:"bg-[var(--status-info)]/15 text-[var(--status-info)]",neutral:"bg-[var(--surface-muted)] text-muted-foreground"},Xs=t=>{const e=Ke.c(5),{tone:a,children:n}=t,o=Ab[a];let i;e[0]!==o?(i=Ie("max-w-40 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",o),e[0]=o,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("span",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r},So=t=>{const e=Ke.c(2),{children:a}=t;let n;return e[0]!==a?(n=s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-px text-[10px] font-medium",children:a}),e[0]=a,e[1]=n):n=e[1],n},Au=t=>{const e=Ke.c(5),{action:a}=t;let n;e[0]!==a.icon?(n=a.icon?s.jsx(Q,{name:a.icon,className:"size-4"}):null,e[0]=a.icon,e[1]=n):n=e[1];let o;return e[2]!==a.label||e[3]!==n?(o=s.jsxs(s.Fragment,{children:[n,a.label]}),e[2]=a.label,e[3]=n,e[4]=o):o=e[4],o},qa=t=>{const e=Ke.c(60),{icon:a,title:n,subtitle:o,description:i,badges:r,footer:l,muted:u,onOpen:m,actions:c,actionsLabel:f}=t,p=(c?.length??0)>0,g=u&&"opacity-60";let h;e[0]!==g?(h=Ie("flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",g),e[0]=g,e[1]=h):h=e[1];let k;e[2]!==a||e[3]!==h?(k=s.jsx("span",{className:h,children:a}),e[2]=a,e[3]=h,e[4]=k):k=e[4];let b;e[5]!==r?(b=r?s.jsx("span",{className:"flex min-w-0 flex-wrap justify-end gap-1",children:r}):null,e[5]=r,e[6]=b):b=e[6];let j;e[7]!==k||e[8]!==b?(j=s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[k,b]}),e[7]=k,e[8]=b,e[9]=j):j=e[9];const x=u&&"opacity-60";let S;e[10]!==x?(S=Ie("mt-3 min-w-0",x),e[10]=x,e[11]=S):S=e[11];let v;e[12]!==n?(v=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",title:n,children:n}),e[12]=n,e[13]=v):v=e[13];let N;e[14]!==o?(N=o?s.jsx("div",{className:"mt-0.5 truncate font-mono typography-micro text-muted-foreground",title:o,children:o}):null,e[14]=o,e[15]=N):N=e[15];let y;e[16]!==i?(y=i?s.jsx("div",{className:"mt-1 line-clamp-2 typography-micro text-muted-foreground",children:i}):null,e[16]=i,e[17]=y):y=e[17];let I;e[18]!==y||e[19]!==S||e[20]!==v||e[21]!==N?(I=s.jsxs("div",{className:S,children:[v,N,y]}),e[18]=y,e[19]=S,e[20]=v,e[21]=N,e[22]=I):I=e[22];const w=p&&"pr-8";let D;e[23]!==w?(D=Ie("mt-auto flex min-w-0 items-center gap-2 pt-3 typography-micro text-muted-foreground",w),e[23]=w,e[24]=D):D=e[24];let C;e[25]!==p||e[26]!==m?(C=m&&!p?s.jsx(Q,{name:"arrow-right-s",className:"ml-auto size-4 shrink-0 opacity-0 transition-opacity duration-150 group-hover:opacity-70 group-focus-visible:opacity-70","aria-hidden":!0}):null,e[25]=p,e[26]=m,e[27]=C):C=e[27];let A;e[28]!==l||e[29]!==D||e[30]!==C?(A=s.jsxs("div",{className:D,children:[l,C]}),e[28]=l,e[29]=D,e[30]=C,e[31]=A):A=e[31];let T;e[32]!==I||e[33]!==A||e[34]!==j?(T=s.jsxs(s.Fragment,{children:[j,I,A]}),e[32]=I,e[33]=A,e[34]=j,e[35]=T):T=e[35];const O=T;let z;e[36]!==O||e[37]!==m?(z=m?s.jsx("button",{type:"button",onClick:m,className:Ie(rl,"h-full w-full border-[var(--interactive-border)] bg-[var(--surface-elevated)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--interactive-hover)]/50"),children:O}):s.jsx("div",{className:Ie(rl,"h-full border-[var(--interactive-border)] bg-[var(--surface-elevated)]"),children:O}),e[36]=O,e[37]=m,e[38]=z):z=e[38];const M=z;if(!p||!c)return M;let P;e[39]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("div",{className:"group relative"}),e[39]=P):P=e[39];let R;e[40]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Q,{name:"more-2",className:"size-4"}),e[40]=R):R=e[40];let F;e[41]!==f?(F=s.jsx(Wn,{asChild:!0,children:s.jsx(q,{variant:"ghost",size:"icon",className:"absolute bottom-3 right-3 h-7 w-7 text-muted-foreground opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100 md:focus-visible:opacity-100 data-[state=open]:opacity-100","aria-label":f,title:f,children:R})}),e[41]=f,e[42]=F):F=e[42];let _;e[43]!==c?(_=c.map(Tb),e[43]=c,e[44]=_):_=e[44];let B;e[45]!==_?(B=s.jsx(Gn,{align:"end",className:"w-fit min-w-32",children:_}),e[45]=_,e[46]=B):B=e[46];let V;e[47]!==F||e[48]!==B?(V=s.jsxs(Jn,{children:[F,B]}),e[47]=F,e[48]=B,e[49]=V):V=e[49];let ee;e[50]!==M||e[51]!==V?(ee=s.jsxs(Ja,{render:P,children:[M,V]}),e[50]=M,e[51]=V,e[52]=ee):ee=e[52];let L;e[53]!==c?(L=c.map(Eb),e[53]=c,e[54]=L):L=e[54];let $;e[55]!==L?($=s.jsx(Ga,{className:"w-fit min-w-32",children:L}),e[55]=L,e[56]=$):$=e[56];let H;return e[57]!==ee||e[58]!==$?(H=s.jsxs(Qa,{children:[ee,$]}),e[57]=ee,e[58]=$,e[59]=H):H=e[59],H},Lo=t=>{const e=Ke.c(11),{label:a,hint:n,onClick:o,settingsItem:i}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=Ie(rl,"items-center justify-center gap-2 text-center border-dashed border-[var(--interactive-border)] text-muted-foreground hover:bg-[var(--interactive-hover)]/50 hover:text-foreground"),e[0]=r):r=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"flex size-10 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Q,{name:"add",className:"size-5"})}),e[1]=l):l=e[1];let u;e[2]!==a?(u=s.jsx("span",{className:"typography-ui-label font-medium",children:a}),e[2]=a,e[3]=u):u=e[3];let m;e[4]!==n?(m=n?s.jsx("span",{className:"typography-micro",children:n}):null,e[4]=n,e[5]=m):m=e[5];let c;return e[6]!==o||e[7]!==i||e[8]!==u||e[9]!==m?(c=s.jsxs("button",{type:"button",onClick:o,"data-settings-item":i,className:r,children:[l,u,m]}),e[6]=o,e[7]=i,e[8]=u,e[9]=m,e[10]=c):c=e[10],c},Ko=t=>{const e=Ke.c(7),{value:a,onChange:n,placeholder:o}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Q,{name:"search",className:"pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),e[0]=i):i=e[0];let r;e[1]!==n?(r=u=>n(u.target.value),e[1]=n,e[2]=r):r=e[2];let l;return e[3]!==o||e[4]!==r||e[5]!==a?(l=s.jsxs("div",{className:"relative mb-4 max-w-[24rem]",children:[i,s.jsx(Be,{value:a,onChange:r,placeholder:o,"aria-label":o,className:"h-9 pl-8"})]}),e[3]=o,e[4]=r,e[5]=a,e[6]=l):l=e[6],l},No=t=>{const e=Ke.c(4),{label:a,onClick:n}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(Q,{name:"arrow-left-s",className:"size-4"}),e[0]=o):o=e[0];let i;return e[1]!==a||e[2]!==n?(i=s.jsx(q,{variant:"ghost",size:"icon",className:"-ml-2 h-7 w-7 shrink-0",onClick:n,"aria-label":a,title:a,children:o}),e[1]=a,e[2]=n,e[3]=i):i=e[3],i},ll=t=>{const e=Ke.c(2),{name:a}=t;let n;return e[0]!==a?(n=s.jsx(Q,{name:a,className:"size-5 text-muted-foreground"}),e[0]=a,e[1]=n):n=e[1],n};function Tb(t){return s.jsx(Fn,{variant:t.destructive?"destructive":"default",onClick:t.onSelect,children:s.jsx(Au,{action:t})},t.label)}function Eb(t){return s.jsx(Wa,{className:Ie(t.destructive&&"text-destructive focus:text-destructive"),onClick:t.onSelect,children:s.jsx(Au,{action:t})},t.label)}const Db=t=>{const e="new-mcp-server";let a=e,n=1;for(;t.some(o=>o.name===a);)a=`${e}-${n}`,n+=1;return a},Mb=t=>{const e=Ke.c(13),{status:a,enabled:n,blocked:o}=t,{t:i}=ze();if(o){let m;e[0]!==i?(m=i("settings.mcp.grid.status.blockedByPolicy"),e[0]=i,e[1]=m):m=e[1];let c;return e[2]!==m?(c=s.jsx(Xs,{tone:"warning",children:m}),e[2]=m,e[3]=c):c=e[3],c}if(!n){let m;e[4]!==i?(m=i("settings.mcp.grid.status.disabled"),e[4]=i,e[5]=m):m=e[5];let c;return e[6]!==m?(c=s.jsx(Xs,{tone:"neutral",children:m}),e[6]=m,e[7]=c):c=e[7],c}let r;e[8]!==a||e[9]!==i?(r=a==="connected"?{tone:"success",label:i("settings.mcp.page.status.label.connected")}:a==="failed"?{tone:"error",label:i("settings.mcp.page.status.label.failed")}:a==="needs_auth"?{tone:"warning",label:i("settings.mcp.page.status.label.needsAuth")}:a==="pending"?{tone:"neutral",label:i("settings.mcp.grid.status.pending")}:null,e[8]=a,e[9]=i,e[10]=r):r=e[10];const l=r;let u;return e[11]!==l?(u=l?s.jsx(Xs,{tone:l.tone,children:l.label}):null,e[11]=l,e[12]=u):u=e[12],u},Rb=()=>{const t=Ke.c(132),{t:e}=ze(),a=Ks(),{setSelectedMcp:n,setMcpDraft:o,loadMcpConfigs:i,deleteMcp:r}=Dn(Ms(Ob)),[l,u]=d.useState(null),[m,c]=d.useState(!1);let f;t[0]!==a?(f=Ee=>vl(Ee,a),t[0]=a,t[1]=f):f=t[1];const p=Dn(f);let g;t[2]!==a?(g=Ee=>Ee.getStatusForDirectory(a),t[2]=a,t[3]=g):g=t[3];const h=cn(g),k=Ll(a),b=cn(Fb),j=cn(Lb),[x,S]=d.useState(!1),[v,N]=d.useState("");let y,I;t[4]!==i||t[5]!==a?(y=()=>{i({directory:a})},I=[i,a],t[4]=i,t[5]=a,t[6]=y,t[7]=I):(y=t[6],I=t[7]),d.useEffect(y,I);let w;t[8]!==j||t[9]!==x||t[10]!==b||t[11]!==a?(w=()=>{if(x)return;S(!0);const Ee=new Promise(Kb);Promise.all([b({directory:a,silent:!0}),Ee]).then(()=>{const Le=j(a);Le&&G.error(Le)}).finally(()=>S(!1))},t[8]=j,t[9]=x,t[10]=b,t[11]=a,t[12]=w):w=t[12];const D=w;let C;t[13]!==p||t[14]!==o||t[15]!==n?(C=()=>{const Ee=Db(p),Le={name:Ee,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...wo,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1};o(Le),n(Ee)},t[13]=p,t[14]=o,t[15]=n,t[16]=C):C=t[16];const A=C;let T;t[17]!==r||t[18]!==l||t[19]!==a||t[20]!==e?(T=async()=>{if(!l)return;const Ee=l;c(!0);const Le=await r(Ee,a);Le.ok?(Le.reloadFailed?G.warning(Le.message||e("settings.mcp.page.toast.serverDeletedReloadFailed",{name:Ee}),{description:Le.warning||e("settings.mcp.page.toast.refreshListIfStale")}):G.success(Le.message||e("settings.mcp.page.toast.serverDeleted",{name:Ee})),u(null)):G.error(e("settings.mcp.page.toast.deleteFailed")),c(!1)},t[17]=r,t[18]=l,t[19]=a,t[20]=e,t[21]=T):T=t[21];const O=T;let z,M,P,R,F,_,B,V,ee;if(t[22]!==A||t[23]!==D||t[24]!==k||t[25]!==x||t[26]!==h||t[27]!==v||t[28]!==p||t[29]!==o||t[30]!==n||t[31]!==e){const Ee=Qn([...p],v,zb);let Le;t[41]!==v?(Le=v.trim(),t[41]=v,t[42]=Le):Le=t[42];const ce=Le.length>0;z=Qt,t[43]!==e?(M=e("settings.page.mcp.title"),t[43]=e,t[44]=M):M=t[44],t[45]!==e?(P=e("settings.mcp.grid.description"),t[45]=e,t[46]=P):P=t[46];let Me;t[47]===Symbol.for("react.memo_cache_sentinel")?(Me=s.jsx(Mi,{className:"min-w-0 flex-1 @xl:w-56 @xl:flex-none"}),t[47]=Me):Me=t[47];let Fe;t[48]!==e?(Fe=e("settings.mcp.sidebar.actions.refreshStatusAria"),t[48]=e,t[49]=Fe):Fe=t[49];let me;t[50]!==e?(me=e("settings.mcp.sidebar.actions.refreshStatusTitle"),t[50]=e,t[51]=me):me=t[51];const de=x&&"animate-spin";let Pe;t[52]!==de?(Pe=Ie("size-4",de),t[52]=de,t[53]=Pe):Pe=t[53];let he;t[54]!==Pe?(he=s.jsx(Q,{name:"refresh",className:Pe}),t[54]=Pe,t[55]=he):he=t[55],t[56]!==D||t[57]!==x||t[58]!==Fe||t[59]!==me||t[60]!==he?(R=s.jsxs("div",{className:"flex w-full items-center gap-2 @xl:w-auto",children:[Me,s.jsx(q,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",disabled:x,onClick:D,"aria-label":Fe,title:me,children:he})]}),t[56]=D,t[57]=x,t[58]=Fe,t[59]=me,t[60]=he,t[61]=R):R=t[61],t[62]!==v||t[63]!==p.length||t[64]!==e?(F=p.length>0?s.jsx(Ko,{value:v,onChange:N,placeholder:e("settings.mcp.grid.searchPlaceholder")}):null,t[62]=v,t[63]=p.length,t[64]=e,t[65]=F):F=t[65],_=p.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.empty")}):Ee.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.noMatches",{query:v.trim()})}):null,B=Fo,t[66]!==A||t[67]!==ce||t[68]!==e?(V=ce?null:s.jsx(Lo,{label:e("settings.mcp.sidebar.actions.addServerTitle"),hint:e("settings.mcp.grid.addHint"),onClick:A,settingsItem:"mcp.create"}),t[66]=A,t[67]=ce,t[68]=e,t[69]=V):V=t[69];let Ue;t[70]!==k||t[71]!==h||t[72]!==o||t[73]!==n||t[74]!==e?(Ue=Ae=>{const Re=Ae.disabled!==!0,$e=k(`mcp:${Ae.name}`),nt=Ae.type==="local"?Ae.command?.join(" "):Ae.url;return s.jsx(qa,{icon:s.jsx(ll,{name:Ae.type==="local"?"server":"global"}),title:Ae.name,subtitle:nt||void 0,badges:s.jsx(Mb,{status:h[Ae.name]?.status.status,enabled:Re,blocked:$e}),muted:!Re||$e,footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ae.type==="local"?e("settings.mcp.sidebar.serverType.localTitle"):e("settings.mcp.sidebar.serverType.remoteTitle")}),Ae.scope==="project"?s.jsx(So,{children:e("settings.mcp.grid.scope.project")}):null]}),onOpen:()=>{o(null),n(Ae.name)},actionsLabel:e("settings.mcp.grid.actionsAria",{name:Ae.name}),actions:[{label:e("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>u(Ae.name)}]},Ae.name)},t[70]=k,t[71]=h,t[72]=o,t[73]=n,t[74]=e,t[75]=Ue):Ue=t[75],ee=Ee.map(Ue),t[22]=A,t[23]=D,t[24]=k,t[25]=x,t[26]=h,t[27]=v,t[28]=p,t[29]=o,t[30]=n,t[31]=e,t[32]=z,t[33]=M,t[34]=P,t[35]=R,t[36]=F,t[37]=_,t[38]=B,t[39]=V,t[40]=ee}else z=t[32],M=t[33],P=t[34],R=t[35],F=t[36],_=t[37],B=t[38],V=t[39],ee=t[40];let L;t[76]!==B||t[77]!==V||t[78]!==ee?(L=s.jsxs("div",{className:B,children:[V,ee]}),t[76]=B,t[77]=V,t[78]=ee,t[79]=L):L=t[79];const $=l!==null;let H;t[80]!==m?(H=Ee=>{!Ee&&!m&&u(null)},t[80]=m,t[81]=H):H=t[81];const W=l??"";let Z;t[82]!==e||t[83]!==W?(Z=e("settings.mcp.page.deleteDialog.title",{name:W}),t[82]=e,t[83]=W,t[84]=Z):Z=t[84];let te;t[85]!==Z?(te=s.jsx(Ut,{children:Z}),t[85]=Z,t[86]=te):te=t[86];let J;t[87]!==e?(J=e("settings.mcp.page.deleteDialog.descriptionPrefix"),t[87]=e,t[88]=J):J=t[88];let ie;t[89]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),t[89]=ie):ie=t[89];let pe;t[90]!==e?(pe=e("settings.mcp.page.deleteDialog.descriptionSuffix"),t[90]=e,t[91]=pe):pe=t[91];let X;t[92]!==J||t[93]!==pe?(X=s.jsxs($t,{children:[J," ",ie,"."," ",pe]}),t[92]=J,t[93]=pe,t[94]=X):X=t[94];let xe;t[95]!==te||t[96]!==X?(xe=s.jsxs(zt,{children:[te,X]}),t[95]=te,t[96]=X,t[97]=xe):xe=t[97];let Y;t[98]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>u(null),t[98]=Y):Y=t[98];let be;t[99]!==e?(be=e("settings.common.actions.cancel"),t[99]=e,t[100]=be):be=t[100];let De;t[101]!==m||t[102]!==be?(De=s.jsx(q,{variant:"outline",size:"sm",onClick:Y,disabled:m,children:be}),t[101]=m,t[102]=be,t[103]=De):De=t[103];let ve;t[104]!==O?(ve=()=>{O()},t[104]=O,t[105]=ve):ve=t[105];let se;t[106]!==m||t[107]!==e?(se=e(m?"settings.mcp.page.actions.deleting":"settings.common.actions.delete"),t[106]=m,t[107]=e,t[108]=se):se=t[108];let ge;t[109]!==m||t[110]!==ve||t[111]!==se?(ge=s.jsx(q,{variant:"destructive",size:"sm",onClick:ve,disabled:m,children:se}),t[109]=m,t[110]=ve,t[111]=se,t[112]=ge):ge=t[112];let ne;t[113]!==De||t[114]!==ge?(ne=s.jsxs(Xt,{children:[De,ge]}),t[113]=De,t[114]=ge,t[115]=ne):ne=t[115];let Se;t[116]!==xe||t[117]!==ne?(Se=s.jsxs(Lt,{className:"max-w-md",children:[xe,ne]}),t[116]=xe,t[117]=ne,t[118]=Se):Se=t[118];let ke;t[119]!==$||t[120]!==H||t[121]!==Se?(ke=s.jsx(Ft,{open:$,onOpenChange:H,children:Se}),t[119]=$,t[120]=H,t[121]=Se,t[122]=ke):ke=t[122];let Te;return t[123]!==z||t[124]!==M||t[125]!==P||t[126]!==R||t[127]!==F||t[128]!==_||t[129]!==L||t[130]!==ke?(Te=s.jsxs(z,{title:M,description:P,headerEnd:R,children:[F,_,L,ke]}),t[123]=z,t[124]=M,t[125]=P,t[126]=R,t[127]=F,t[128]=_,t[129]=L,t[130]=ke,t[131]=Te):Te=t[131],Te};function Ob(t){return{setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Fb(t){return t.refresh}function Lb(t){return t.getErrorForDirectory}function Kb(t){return setTimeout(t,500)}function zb(t){return[t.name,t.type==="local"?t.command?.join(" ")??"":t.url??""]}const Cr=t=>t===void 0?"":String(t),Ir=t=>{const e=t.trim();if(!e)return null;const a=Number(e);return!Number.isFinite(a)||a<=0?null:a%1e3===0?`${a/1e3}s`:`${a}ms`},Pr={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},Ec={default:"settings.mcp.page.advanced.codemodeOption.default",on:"settings.mcp.page.advanced.codemodeOption.on",off:"settings.mcp.page.advanced.codemodeOption.off"},Ub=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},fi=t=>t?.status.status,Ar=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function Tu(t){const e=[];let a="",n=!1,o=!1;for(let i=0;i<t.length;i++){const r=t[i];if(r==="'"&&!o){n=!n;continue}if(r==='"'&&!n){o=!o;continue}if((r===" "||r===" ")&&!n&&!o){a&&(e.push(a),a="");continue}a+=r}return a&&e.push(a),e}const $b=t=>{const e=Ke.c(27),{value:a,onChange:n,preview:o,onDetectUrl:i}=t;let r;e[0]!==a?(r=()=>a.join(`
5
+ `),e[0]=a,e[1]=r):r=e[1];const[l,u]=d.useState(r),m=d.useRef(a);let c,f;e[2]!==a?(c=()=>{JSON.stringify(m.current)!==JSON.stringify(a)&&(m.current=a,u(a.join(`
6
+ `)))},f=[a],e[2]=a,e[3]=c,e[4]=f):(c=e[3],f=e[4]),d.useEffect(c,f);let p;e[5]!==n||e[6]!==i?(p=y=>{const I=y.split(`
7
+ `).filter(Wb);if(i&&I.length===1&&/^https?:\/\/\S+$/i.test(I[0].trim())){i(I[0].trim());return}n(I)},e[5]=n,e[6]=i,e[7]=p):p=e[7];const g=p;let h;e[8]!==n?(h=y=>{const w=y.clipboardData.getData("text").trim();if(!w||w.includes(`
8
+ `)||!/\s/.test(w))return;const D=y.currentTarget;if(D.selectionStart!==0||D.selectionEnd!==D.value.length)return;y.preventDefault();const C=Tu(w);u(C.join(`
9
+ `)),n(C)},e[8]=n,e[9]=h):h=e[9];const k=h;let b;e[10]!==g?(b=y=>{u(y.target.value),g(y.target.value)},e[10]=g,e[11]=b):b=e[11];let j;e[12]!==g||e[13]!==l?(j=()=>{const y=l.split(`
10
+ `).map(Jb).join(`
11
+ `);u(y),g(y)},e[12]=g,e[13]=l,e[14]=j):j=e[14];const x=Math.max(4,a.length+1);let S;e[15]!==k||e[16]!==b||e[17]!==j||e[18]!==x||e[19]!==l?(S=s.jsx(Ns,{onPaste:k,value:l,onChange:b,onBlur:j,placeholder:`npx
12
+ -y
13
+ @modelcontextprotocol/server-postgres
14
+ postgresql://user:pass@host/db`,rows:x,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=k,e[16]=b,e[17]=j,e[18]=x,e[19]=l,e[20]=S):S=e[20];let v;e[21]!==o||e[22]!==a?(v=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:o(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(Qb)})})]}),e[21]=o,e[22]=a,e[23]=v):v=e[23];let N;return e[24]!==v||e[25]!==S?(N=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[S,v]}),e[24]=v,e[25]=S,e[26]=N):N=e[26],N},_b=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Dc=({value:t,onChange:e,onCommit:a,keyTransform:n=_b,keyPlaceholder:o="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:u,importSuccess:m,clipboardReadFailed:c,keyLabel:f,valueLabel:p,valuePlaceholder:g,hideValueTitle:h,showValueTitle:k,addVariable:b,plainTextWarning:j,removeVariableAria:x})=>{const[S,v]=d.useState(new Set),N=()=>e([...t,{key:"",value:""}]),y=A=>{e(t.filter((T,O)=>O!==A)),a?.(),v(T=>{const O=new Set(T);return O.delete(A),O})},I=(A,T,O)=>{const z=[...t];z[A]={...z[A],[T]:O},e(z)},w=A=>{v(T=>{const O=new Set(T);return O.has(A)?O.delete(A):O.add(A),O})},D=async()=>{try{const A=await navigator.clipboard.readText(),T=[];for(const z of A.split(`
15
+ `)){const M=z.trim();if(!M||M.startsWith("#"))continue;const P=M.indexOf("=");if(P===-1)continue;const R=M.slice(0,P).trim();let F=M.slice(P+1).trim();(F.startsWith('"')&&F.endsWith('"')||F.startsWith("'")&&F.endsWith("'"))&&(F=F.slice(1,-1)),R&&T.push({key:R,value:F})}if(T.length===0){G.error(u);return}const O=[...t];for(const z of T){const M=O.findIndex(P=>P.key===z.key);M!==-1?O[M]=z:O.push(z)}e(O),a?.(),G.success(m(T.length))}catch{G.error(c)}},C=t.some(A=>A.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:f}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),s.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:D,type:"button",title:l,children:[s.jsx(Q,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((A,T)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:A.key,onChange:O=>I(T,"key",n(O.target.value)),placeholder:o,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:S.has(T)?"text":"password",value:A.value,onChange:O=>I(T,"value",O.target.value),placeholder:g,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>w(T),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:S.has(T)?h:k,children:S.has(T)?s.jsx(Q,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(q,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(T),"aria-label":x,children:s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},T))}),s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:N,type:"button",children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),b]}),C&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:j})]})},Mc=t=>{const e=Ke.c(14),{status:a,enabled:n,getStatusLabel:o,variant:i}=t,r=i===void 0?"compact":i;if(!n||!a)return null;let l,u;if(e[0]!==o||e[1]!==a||e[2]!==r){u=Symbol.for("react.early_return_sentinel");e:{const p={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},blocked:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(r==="pill"){const g=Ie("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let h;e[5]!==o||e[6]!==a?(h=o(a),e[5]=o,e[6]=a,e[7]=h):h=e[7],u=s.jsxs("span",{className:g,children:["● ",h]});break e}l=Ie("typography-micro font-medium",p.text)}e[0]=o,e[1]=a,e[2]=r,e[3]=l,e[4]=u}else l=e[3],u=e[4];if(u!==Symbol.for("react.early_return_sentinel"))return u;let m;e[8]!==o||e[9]!==a?(m=o(a),e[8]=o,e[9]=a,e[10]=m):m=e[10];let c;return e[11]!==l||e[12]!==m?(c=s.jsxs("span",{className:l,children:["● ",m]}),e[11]=l,e[12]=m,e[13]=c):c=e[13],c},Bb=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return a?.trim()||e("settings.mcp.page.status.description.needsAuth");case"disabled":return e("settings.mcp.page.status.description.disabled");case"blocked":return e("settings.mcp.page.status.description.blockedByPolicy");default:return e("settings.mcp.page.status.description.default")}},Vb=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"blocked":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Hb=t=>t==="failed"||t==="needs_auth"||t==="blocked",qb=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Gb=()=>{const{t}=ze(),e=d.useCallback((le,Oe)=>t(le,Oe),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:o,setSelectedMcp:i,getMcpByName:r,createMcp:l,updateMcp:u,deleteMcp:m}=Dn(Ms(le=>({selectedMcpName:le.selectedMcpName,mcpDraft:le.mcpDraft,setMcpDraft:le.setMcpDraft,setSelectedMcp:le.setSelectedMcp,getMcpByName:le.getMcpByName,createMcp:le.createMcp,updateMcp:le.updateMcp,deleteMcp:le.deleteMcp}))),c=Ks(),f=Ll(c);d.useEffect(()=>()=>{const le=Dn.getState();le.setSelectedMcp(null),le.setMcpDraft(null)},[]);const p=cn(le=>le.getStatusForDirectory(c)),g=cn(le=>le.getDiagnosticForDirectory(c)),h=cn(le=>le.refresh),k=cn(le=>le.connect),b=cn(le=>le.disconnect),j=cn(le=>le.testConnection),x=Dn(le=>vl(le,c)),S=a?r(a,c):null,v=!!(n&&n.name===a&&!S),[N,y]=d.useState(""),[I,w]=d.useState("user"),[D,C]=d.useState("local"),[A,T]=d.useState([]),[O,z]=d.useState(""),[M,P]=d.useState([]),[R,F]=d.useState([]),[_,B]=d.useState(""),[V,ee]=d.useState(""),[L,$]=d.useState(""),[H,W]=d.useState("default"),[Z,te]=d.useState("legacy"),[J,ie]=d.useState(""),[pe,X]=d.useState(wo),[xe,Y]=d.useState(!0),[be,De]=d.useState(!1),[ve,se]=d.useState(!1),[ge,ne]=d.useState(!1),[Se,ke]=d.useState(!1),[Te,Ee]=d.useState(!1),[Le,ce]=d.useState(!1),[Me,Fe]=d.useState(!1),[me,de]=d.useState(""),[Pe,he]=d.useState(null),Ue=d.useMemo(()=>qb(a,c),[c,a]),Ae=d.useRef(Ue),Re=d.useRef(null),$e=JSON.stringify([a,c,v]),nt=d.useRef($e);nt.current=$e;const pt=d.useRef(null),kt={mcpType:D,command:A,url:O,envEntries:M,headerEntries:R,timeoutStartup:_,timeoutCatalog:V,timeoutExecution:L,codemode:H,protocol:Z,oauthAuthServerMetadataUrl:D==="remote"?J:"",enabled:xe},bt=d.useRef(kt);bt.current=kt;const yt=d.useCallback(()=>{de(""),he(null),Fe(!0)},[]),Je=d.useCallback(async()=>{try{const le=await navigator.clipboard.readText();de(le),he(null)}catch{G.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ct=d.useCallback(()=>{const le=gb(me,{fallbackName:N});if(!le.ok){he(le.error);return}const ot=fb(le,{name:N,scope:I,type:D,command:A,url:O,environment:M,headers:R,timeoutStartup:_,timeoutCatalog:V,timeoutExecution:L,codemode:H,disabled:!xe,protocol:Z,oauthAuthServerMetadataUrl:J},{isNewServer:v});y(ot.name),C(ot.type),T(ot.command??[]),z(ot.url??""),P(ot.environment??[]),F(ot.headers??[]),B(ot.timeoutStartup??""),ee(ot.timeoutCatalog??""),$(ot.timeoutExecution??""),W(ot.codemode??"default"),Y(ot.disabled!==!0),te(ot.protocol??"legacy"),ie(ot.oauthAuthServerMetadataUrl??""),Fe(!1),de(""),he(null),G.success(t("settings.mcp.page.toast.configImported"))},[me,N,I,D,A,O,M,R,Z,J,_,V,L,H,xe,v,t]);d.useEffect(()=>{if(v&&n){pt.current=null,y(n.name),w(n.scope||"user"),C(n.type),T(n.command),z(n.url),P(n.environment),F(n.headers),B(n.timeoutStartup),ee(n.timeoutCatalog),$(n.timeoutExecution),W(n.codemode),te(n.protocol),ie(n.oauthAuthServerMetadataUrl),X({oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,oauthCallbackPort:n.oauthCallbackPort}),Y(!n.disabled),ce(!1),Re.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,timeoutStartup:n.timeoutStartup,timeoutCatalog:n.timeoutCatalog,timeoutExecution:n.timeoutExecution,codemode:n.codemode,protocol:n.protocol,oauthAuthServerMetadataUrl:n.oauthAuthServerMetadataUrl,enabled:!n.disabled};return}if(S){w(S.scope==="project"?"project":"user");const le=Jl(S.environment),Oe=S.type==="remote"?S:null,ot=Jl(Oe?.headers),Rt=S.type,It=Rt==="local"?S.command??[]:[],os=Oe?.url??"",Xe=Cr(S.timeout?.startup),tt=Cr(S.timeout?.catalog),qt=Cr(S.timeout?.execution),ss=Zm(S.codemode),fs=S.protocol??"legacy",Jt=Ib(Oe?.oauth),Cs=Oe&&Oe.oauth?Oe.oauth.auth_server_metadata_url??"":"",kn=S.disabled!==!0;X(Jt);const Yn=Re.current!==null&&JSON.stringify(Re.current)!==JSON.stringify(bt.current);if(pt.current===$e&&Yn)return;pt.current=$e,C(Rt),T(It),z(os),P(le),F(ot),B(Xe),ee(tt),$(qt),W(ss),te(fs),ie(Cs),Y(kn),ce(!1),Re.current={mcpType:Rt,command:It,url:os,envEntries:le,headerEntries:ot,timeoutStartup:Xe,timeoutCatalog:tt,timeoutExecution:qt,codemode:ss,protocol:fs,oauthAuthServerMetadataUrl:Cs,enabled:kn}}},[S,a,c,v,n,$e]);const Qe=d.useMemo(()=>{const le=J.trim();return!le||Ub(le)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[J,t]),it=d.useMemo(()=>{const le=[];D==="remote"&&R.length>0&&le.push(`${R.length} ${t("settings.mcp.page.advanced.headers")}`);const Oe=D==="local"?Ir(_):null;Oe&&le.push(t("settings.mcp.page.advanced.summary.startup",{value:Oe}));const ot=Ir(V);ot&&le.push(t("settings.mcp.page.advanced.summary.catalog",{value:ot}));const Rt=Ir(L);return Rt&&le.push(t("settings.mcp.page.advanced.summary.execution",{value:Rt})),H==="on"&&le.push(t("settings.mcp.page.advanced.summary.codemodeOn")),H==="off"&&le.push(t("settings.mcp.page.advanced.summary.codemodeOff")),Z!=="legacy"&&le.push(t(Pr[Z])),le.join(" · ")},[H,R.length,D,Z,t,V,L,_]),dt=d.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(Q,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(Q,{name:"global",className:"h-3.5 w-3.5"})}],[t]),qe=d.useCallback(le=>{C("remote"),z(le),T([])},[]),lt=d.useCallback(le=>{z(le);const Oe=le.trim();Oe&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(Oe)&&/\s/.test(Oe)&&(C("local"),T(Tu(Oe)),z(""))},[]),ae=le=>({name:le,scope:I,type:D,command:A,url:O,environment:M,headers:R,...pe,oauthAuthServerMetadataUrl:D==="remote"?J:"",protocol:Z,timeoutStartup:_,timeoutCatalog:V,timeoutExecution:L,codemode:H,disabled:!xe}),ye=Xa(async()=>{const le=Re.current;if(v||!le||!a||JSON.stringify(le)===JSON.stringify({mcpType:D,command:A,url:O,envEntries:M,headerEntries:R,timeoutStartup:_,timeoutCatalog:V,timeoutExecution:L,codemode:H,protocol:Z,oauthAuthServerMetadataUrl:D==="remote"?J:"",enabled:xe}))return Ds;if(D==="local"&&A.filter(Boolean).length===0)return gs(t("settings.mcp.page.toast.localCommandRequired"));if(D==="remote"&&!O.trim())return gs(t("settings.mcp.page.toast.remoteUrlRequired"));if(D==="remote"&&Qe)return gs(Qe);const Oe=await u(a,ae(a),c);return Oe.ok?nt.current!==$e?yn:(Re.current={mcpType:D,command:A,url:O,envEntries:M,headerEntries:R,timeoutStartup:_,timeoutCatalog:V,timeoutExecution:L,codemode:H,protocol:Z,oauthAuthServerMetadataUrl:D==="remote"?J:"",enabled:xe},await h({directory:c,silent:!0}),Oe.reloadFailed?gs(Oe.warning||Oe.message||t("settings.mcp.page.toast.savedReloadFailed")):yn):gs(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:we}=ye,Ge=async()=>{const le=N.trim();if(!le){G.error(t("settings.mcp.page.toast.nameRequired"));return}if(x.some(Oe=>Oe.name===le)){G.error(t("settings.mcp.page.toast.serverNameExists"));return}if(D==="local"&&A.filter(Boolean).length===0){G.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(D==="remote"&&!O.trim()){G.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(D==="remote"&&Qe){G.error(Qe);return}De(!0);try{const Oe=await l(ae(le),c);Oe.ok?(o(null),i(le),await h({directory:c,silent:!0}),Oe.reloadFailed?G.warning(Oe.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:Oe.warning||t("settings.mcp.page.toast.retryRefreshHint")}):G.success(Oe.message||t("settings.mcp.page.toast.serverCreatedReloading"))):G.error(t("settings.mcp.page.toast.saveFailed"))}catch(Oe){G.error(Oe instanceof Error?Oe.message:t("settings.mcp.page.toast.unexpectedError"))}finally{De(!1)}},et=()=>{o(null),i(null)},mt=async()=>{if(!a)return;ne(!0);const le=await m(a,c);le.ok?(le.reloadFailed?G.warning(le.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:le.warning||t("settings.mcp.page.toast.refreshListIfStale")}):G.success(le.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),se(!1)):G.error(t("settings.mcp.page.toast.deleteFailed")),ne(!1)},jt=async()=>{if(a)try{await k(a,c),G.success(t("settings.mcp.page.toast.connected"))}catch(le){G.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionTestFailed"))}},vt=async()=>{if(a){ke(!0);try{if(fi(p[a])==="connected")await b(a,c),G.success(t("settings.mcp.page.toast.disconnected"));else{await k(a,c),await h({directory:c,silent:!0});const Oe=cn.getState().getStatusForDirectory(c)[a],ot=fi(Oe);ot==="connected"?G.success(t("settings.mcp.page.toast.connected")):ot==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ot==="failed"?G.error(Ar(Oe)||t("settings.mcp.page.toast.connectionFailed")):G.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await h({directory:c,silent:!0})}catch(le){G.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ke(!1)}}},Ct=d.useCallback(()=>v?(G.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[v,t]),Bt=d.useCallback(async(le=!1)=>{try{await h({directory:c,silent:le})}catch(Oe){le||G.error(Oe instanceof Error?Oe.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[c,h,t]);d.useEffect(()=>{Bt(!0)},[Bt]),d.useEffect(()=>{Ae.current=Ue,ke(!1),Ee(!1)},[Ue]);const Ye=d.useCallback(async()=>{if(!(!a||!Ct())){if(!xe){G.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Ee(!0);try{const le=await j(a,c),Oe=fi(le.status);le.warning?G.warning(le.warning):Oe==="connected"?G.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Oe==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Oe==="failed"?G.error(Ar(le.status)||le.error||t("settings.mcp.page.toast.connectionTestFailed")):le.error?G.error(le.error):G.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(le){G.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Ee(!1)}}},[c,xe,Ct,a,t,j]);if(!a)return s.jsx(Rb,{});const Ze=p[a],ut=a?g[a]:void 0,ft=a?f(`mcp:${a}`):!1,K=ft?"blocked":Ze?fi(Ze):ut?.status,ue=Ze?Ar(Ze):ut?.error,Ne=fi(Ze)==="connected",Ce=Bb(K,e,ue),He=le=>{switch(le){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"blocked":return t("settings.mcp.grid.status.blockedByPolicy");default:return le}};return s.jsxs(s.Fragment,{children:[s.jsxs(Qt,{title:v?t("settings.mcp.page.header.newServer"):a,titleLeading:s.jsx(No,{label:t("settings.mcp.page.back"),onClick:()=>{o(null),i(null)}}),titleAccessory:v?void 0:s.jsx(Mc,{status:K,enabled:xe,getStatusLabel:He,variant:"pill"}),description:v?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:v?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(q,{variant:Ne?"outline":"default",size:"xs",className:"!font-normal",onClick:vt,disabled:Se||!xe||ft,children:t(Se?"settings.mcp.page.actions.working":Ne?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),Ne&&s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Ye()},disabled:Te||!xe,children:t(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:ye.onBlurCapture,children:[!v&&S&&s.jsx(Ol,{legacy:S.legacy===!0,path:S.path}),!v&&Hb(K)&&s.jsx(Ve,{divider:!1,children:s.jsx("div",{className:Ie("rounded-lg border p-3",Vb(K)),children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Mc,{status:K,enabled:xe,getStatusLabel:He})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ce}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:I==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:c??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),K==="needs_auth"&&a&&s.jsx(Cb,{serverName:a,directory:c,onConnected:jt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ne&&s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ye()},disabled:Te||!xe||ft,children:t(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(Ve,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:v?s.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:yt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(Q,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[v&&s.jsxs(ht,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Be,{value:N,onChange:le=>y(le.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:I,onValueChange:le=>w(le),children:[s.jsxs(Pt,{size:_t,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(Q,{name:I==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(I==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(st,{checked:xe,onChange:le=>{Y(le),we()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Ve,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(kl,{items:dt,activeId:D,onSelect:le=>{C(le),we()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),D==="local"?s.jsx($b,{value:A,onChange:T,preview:le=>t("settings.mcp.page.connection.previewArgs",{count:le}),onDetectUrl:qe}):s.jsx(Be,{value:O,onChange:le=>lt(le.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")})]}),s.jsx(Ve,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Gs,{open:Le,onOpenChange:ce,children:[s.jsxs(Ws,{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")}),it&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",it,")"]})]}),Le?s.jsx(Q,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Q,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Js,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Tt,{value:Z,onValueChange:le=>{const Oe=Qr.find(ot=>ot===le);Oe&&(te(Oe),we())},children:[s.jsx(Pt,{size:_t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.protocol"),children:s.jsx("span",{className:"truncate",children:t(Pr[Z])})}),s.jsx(At,{children:Qr.map(le=>s.jsx(at,{value:le,children:t(Pr[le])},le))})]})]}),s.jsxs("div",{className:"space-y-2",children:[D==="local"&&s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(Be,{type:"number",min:"1",step:"1",value:_,onChange:le=>B(le.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(Be,{type:"number",min:"1",step:"1",value:V,onChange:le=>ee(le.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(Be,{type:"number",min:"1",step:"1",value:L,onChange:le=>$(le.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.codemode")}),s.jsxs(Gt,{children:[t("settings.mcp.page.advanced.codemodeHint")," ",t("settings.mcp.page.advanced.codemodeDefaultHint")]})]}),s.jsxs(Tt,{value:H,onValueChange:le=>{const Oe=Ql.find(ot=>ot===le);Oe&&(W(Oe),we())},children:[s.jsx(Pt,{size:_t,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.codemode"),children:s.jsx("span",{className:"truncate",children:t(Ec[H])})}),s.jsx(At,{children:Ql.map(le=>s.jsx(at,{value:le,children:t(Ec[le])},le))})]})]}),D==="remote"&&s.jsxs("div",{children:[s.jsxs(Ln,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),R.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",R.length,")"]})]}),s.jsx(Dc,{value:R,onChange:F,onCommit:we,keyTransform:le=>le.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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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")})]}),D==="remote"&&s.jsxs("div",{children:[s.jsx(Ln,{as:"div",className:"mb-2",children:t("settings.mcp.page.advanced.oauth")}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Nt,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.oauthMetadataUrlHint")})]}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx(Be,{type:"url",value:J,onChange:le=>ie(le.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":Qe?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),Qe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Qe})]})]})]})]})})]})}),s.jsx(Ve,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:M.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",M.length,")"]}):null,settingsItem:"mcp.environment",children:M.length===0?s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>P([{key:"",value:""}]),children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Dc,{value:M,onChange:P,onCommit:we,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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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:[v&&s.jsxs(s.Fragment,{children:[s.jsx(q,{onClick:()=>{Ge()},disabled:be||!N.trim(),size:"xs",className:"!font-normal",children:t(be?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(q,{variant:"ghost",onClick:et,disabled:be,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!v&&s.jsx(q,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>se(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Ft,{open:Me,onOpenChange:le=>{le||(Fe(!1),de(""),he(null))},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.mcp.page.importDialog.title")}),s.jsx($t,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ns,{value:me,onChange:le=>{de(le.target.value),he(null)},placeholder:`{
16
+ "mcpServers": {
17
+ "postgres": {
18
+ "command": "npx",
19
+ "args": ["-y", "@modelcontextprotocol/server-postgres"]
20
+ }
21
+ }
22
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Pe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Pe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Je,type:"button",children:[s.jsx(Q,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Xt,{children:[s.jsx(q,{variant:"outline",onClick:()=>{Fe(!1),de(""),he(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(q,{onClick:ct,disabled:!me.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Ft,{open:ve,onOpenChange:le=>{!le&&!ge&&se(!1)},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs($t,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Xt,{children:[s.jsx(q,{variant:"outline",onClick:()=>se(!1),disabled:ge,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(q,{variant:"destructive",size:"sm",onClick:mt,disabled:ge,children:t(ge?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Wb(t){return t.trim().length>0}function Jb(t){return t.trimEnd()}function Qb(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 Yb=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Zb(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 Xb=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=ze(),o=Ot(M=>M.createEntry),i=Ot(M=>M.createFile),[r,l]=d.useState("npm"),[u,m]=d.useState(""),[c,f]=d.useState(""),[p,g]=d.useState(""),[h,k]=d.useState(""),[b,j]=d.useState(a),[x,S]=d.useState(!1),v=d.useCallback(()=>{m(""),f(""),g(""),k(""),j(a)},[a]);d.useEffect(()=>{t&&(l("npm"),v())},[t,v]);const N=M=>{M!==r&&(l(M),v())},y=d.useMemo(()=>Zb(c),[c]),I=!y.ok,w=r==="file"&&p.trim()!==""&&!Yb.test(p.trim()),D=(r==="npm"||r==="path")&&u.trim()==="",C=r==="file"&&h.trim()==="",A=r==="file"&&p.trim()==="",T=x||I||r==="npm"&&D||r==="path"&&D||r==="file"&&(A||w||C),O=async()=>{if(!T){S(!0);try{let M;r==="file"?M=await i({fileName:p.trim(),content:h,scope:b}):M=await o({spec:u.trim(),options:y.ok?y.value:void 0,scope:b}),M.ok?(G.success(M.message||n("settings.plugins.toast.created")),M.reloadFailed&&G.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):G.error(M.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{S(!1)}}},z=d.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(Ft,{open:t,onOpenChange:M=>{!M&&x||e(M)},children:s.jsxs(Lt,{className:"max-w-xl",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:n("settings.plugins.dialog.add.title")}),s.jsx($t,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(kl,{items:z,activeId:r,onSelect:M=>N(M),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(r==="npm"||r==="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:u,onChange:M=>m(M.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":D?!1:void 0,disabled:x}),D&&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(Ns,{id:"plugin-options",value:c,onChange:M=>f(M.target.value),rows:5,className:"font-mono",hasError:I,disabled:x}),I&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),r==="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:p,onChange:M=>g(M.target.value),placeholder:"my-plugin.ts","aria-invalid":w||void 0,disabled:x}),w&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ns,{id:"plugin-content",value:h,onChange:M=>k(M.target.value),rows:16,className:"font-mono",disabled:x})]})]}),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(M=>{const P=b===M,R=n(M==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>j(M),disabled:x,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(wl,{checked:P,onChange:()=>j(M),ariaLabel:R}),s.jsx("span",{className:Ie("typography-ui-label font-normal",P?"text-foreground":"text-foreground/60"),children:R})]},M)})})]})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:x,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(q,{size:"sm",onClick:()=>{O()},disabled:T,children:[x?s.jsx(Q,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},ex=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),_a=t=>{const e=t.replace(/\\/g,"/"),a=[],[n,...o]=e.split("/");for(const r of o)if(!(r===""||r===".")){if(r===".."){a.pop();continue}a.push(r)}return`${/^[A-Za-z]:$/.test(n)?`${n.toUpperCase()}/`:"/"}${a.join("/")}`},tx=t=>_a(`${t.replace(/\\/g,"/")}/..`),sx=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function Eu(t,e){if(t.startsWith("file://")){const a=sx(t);return a?{kind:"local",path:_a(a)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:_a(`${tx(e)}/${t}`)}:null:ex(t)?{kind:"local",path:_a(t)}:{kind:"package",target:t}}function Du(t){return t?{kind:"local",path:_a(t)}:null}const nx=(t,e)=>{if(t.kind==="package")return e.source.kind==="package"&&e.source.target===t.target;if(e.source.kind!=="local")return!1;const a=_a(e.source.path);return a===t.path||a.startsWith(`${t.path}/`)};function Mu(t,e){return e.filter(a=>nx(t,a))}function ax(t){const e=t.find(n=>n.state.kind==="failed");if(e&&e.state.kind==="failed")return{kind:"failed",error:e.state.error,ref:e.state.ref};const a=t[0];return a?{kind:"active",version:a.source.kind==="package"?a.source.version:null}:{kind:"notReported"}}function Ru(t){const e=t.flatMap(a=>a.source.kind==="package"?[a.source]:[]);return e.some(a=>a.updating)?"updating":e.some(a=>a.outdated)?"available":"none"}function Ou(t){const e=Ke.c(12),a=Ot(ix),n=Sl(da());let o;e:{if(a.kind==="idle"||a.scope!==n){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={kind:"loading"},e[0]=m):m=e[0],o=m;break e}if(a.kind==="failed"||!t){let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m={kind:"unknown"},e[1]=m):m=e[1],o=m;break e}let i,r,l;if(e[2]!==a.plugins||e[3]!==t){const m=Mu(t,a.plugins);i="known",r=ax(m),l=Ru(m),e[2]=a.plugins,e[3]=t,e[4]=i,e[5]=r,e[6]=l}else i=e[4],r=e[5],l=e[6];let u;e[7]!==i||e[8]!==r||e[9]!==l||e[10]!==t?(u={kind:i,load:r,update:l,target:t},e[7]=i,e[8]=r,e[9]=l,e[10]=t,e[11]=u):u=e[11],o=u}return o}function ix(t){return t.runtime}function Fu(t){const e=Ke.c(4);let a;if(e[0]!==t){const i=Sl(da());a=t?.kind==="package"?Jd(i,t.target):null,e[0]=t,e[1]=a}else a=e[1];const n=a;let o;return e[2]!==n?(o=i=>n?i.packageUpdates[n]??null:null,e[2]=n,e[3]=o):o=e[3],Ot(o)}const Rc=t=>{const e=Ke.c(18),{target:a,spec:n}=t,{t:o}=ze(),i=Ou(a),r=Fu(a);let l;e[0]!==n?(l=b=>n?b.registryInfo[n]:void 0,e[0]=n,e[1]=l):l=e[1];const u=Ot(l),m=u?.kind==="npm-missing-package"||u?.kind==="npm-missing-version"||u?.kind==="npm-malformed"||u?.kind==="path-missing"||u?.kind==="path-unreadable",c=i.kind==="known"&&(i.update==="updating"||r?.kind==="running"),f=!c&&(u?.kind==="npm-ok"&&u.hasUpdate||i.kind==="known"&&i.update==="available");let p;e[2]!==m||e[3]!==o?(p=m?s.jsx(Xs,{tone:"error",children:o("settings.plugins.registry.banner.invalid.title")}):null,e[2]=m,e[3]=o,e[4]=p):p=e[4];let g;e[5]!==m||e[6]!==i.kind||e[7]!==i.load||e[8]!==o||e[9]!==c?(g=i.kind==="known"&&!m?c?s.jsx(Xs,{tone:"neutral",children:o("settings.plugins.update.running")}):i.load.kind==="failed"?s.jsx(Xs,{tone:"error",children:o("settings.plugins.status.failed.title")}):i.load.kind==="notReported"?s.jsx(Xs,{tone:"neutral",children:o("settings.plugins.status.notReported.title")}):s.jsx(Xs,{tone:"success",children:o("settings.plugins.status.loaded")}):null,e[5]=m,e[6]=i.kind,e[7]=i.load,e[8]=o,e[9]=c,e[10]=g):g=e[10];let h;e[11]!==o||e[12]!==f?(h=f?s.jsx(Xs,{tone:"info",children:o("settings.plugins.update.available.title")}):null,e[11]=o,e[12]=f,e[13]=h):h=e[13];let k;return e[14]!==p||e[15]!==g||e[16]!==h?(k=s.jsxs(s.Fragment,{children:[p,g,h]}),e[14]=p,e[15]=g,e[16]=h,e[17]=k):k=e[17],k},ox=t=>{const e=Ke.c(54),{onAdd:a,onDelete:n}=t,{t:o}=ze(),{entries:i,files:r,setSelected:l,loadPlugins:u}=Ot(Ms(rx)),m=Ot(lx),c=Ot(cx),f=Ot(dx),p=Ot(ux),g=Ot(mx),h=Ot(px),k=Ot(gx),b=Ot(fx),j=Ot(hx),x=Sl(da()),S=g.kind==="failed"&&g.scope===x,v=g.kind==="ready"&&g.scope===x?g.plugins:null,[N,y]=d.useState("");let I,w;e[0]!==u?(I=()=>{u()},w=[u],e[0]=u,e[1]=I,e[2]=w):(I=e[1],w=e[2]),d.useEffect(I,w);let D;e[3]!==p||e[4]!==c||e[5]!==o?(D=async()=>{G.info(o("settings.plugins.toast.refreshing"));const[ge,ne]=await Promise.all([c({force:!0}),p()]);ge||G.error(o("settings.plugins.toast.refreshFailed")),ne||G.error(o("settings.plugins.toast.checkFailed"))},e[3]=p,e[4]=c,e[5]=o,e[6]=D):D=e[6];const C=D;let A;if(e[7]!==i||e[8]!==r){A=new Map;for(const ge of i)A.set(ge.id,Eu(ge.spec,ge.sourcePath));for(const ge of r)A.set(ge.id,Du(ge.absolutePath));e[7]=i,e[8]=r,e[9]=A}else A=e[9];const T=A,O=ge=>{const ne=T.get(ge);return!v||ne?.kind!=="package"||k[Jd(x,ne.target)]?.kind==="running"?null:Ru(Mu(ne,v))==="available"?ne.target:null},z=ge=>{const ne=[],Se=h[ge.spec],ke=O(ge.id);if(Se?.kind==="npm-ok"&&Se.hasUpdate&&Se.latestVersion){const Te=Se.latestVersion;ne.push({label:o("settings.plugins.registry.banner.updateAvailable.action",{latest:Te}),icon:"arrow-up-s",onSelect:()=>{b(ge.id).then(Ee=>{Ee.ok?G.success(o("settings.plugins.toast.updatedToLatest",{version:Te})):G.error(o("settings.plugins.toast.refreshFailed"))})}})}else ke&&ne.push({label:o("settings.plugins.update.action"),icon:"arrow-up-s",onSelect:()=>{j(ke).then(Te=>{Te?G.success(o("settings.plugins.update.toast.done",{name:ge.spec})):G.error(o("settings.plugins.update.toast.failed",{name:ge.spec}))})}});return ne.push({label:o("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>n({kind:"entry",id:ge.id,label:ge.spec})}),ne},M=[...i.map(bx),...r.map(xx)],P=Qn(M,N,vx);let R;e[10]!==N?(R=N.trim(),e[10]=N,e[11]=R):R=e[11];const F=R.length>0,_=m||f,B=Qt;let V;e[12]!==o?(V=o("settings.page.plugins.title"),e[12]=o,e[13]=V):V=e[13];let ee;e[14]!==o?(ee=o("settings.plugins.grid.description"),e[14]=o,e[15]=ee):ee=e[15];let L;e[16]!==S||e[17]!==o?(L=S?s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsx(Q,{name:"question",className:"size-3.5"}),o("settings.plugins.status.sidebar.unavailable")]}):null,e[16]=S,e[17]=o,e[18]=L):L=e[18];let $;e[19]!==C?($=()=>{C()},e[19]=C,e[20]=$):$=e[20];let H;e[21]!==o?(H=o("settings.plugins.sidebar.actions.refresh"),e[21]=o,e[22]=H):H=e[22];let W;e[23]!==o?(W=o("settings.plugins.sidebar.actions.refresh"),e[23]=o,e[24]=W):W=e[24];const Z=_&&"animate-spin";let te;e[25]!==Z?(te=Ie("size-4",Z),e[25]=Z,e[26]=te):te=e[26];let J;e[27]!==te?(J=s.jsx(Q,{name:"refresh",className:te}),e[27]=te,e[28]=J):J=e[28];let ie;e[29]!==_||e[30]!==W||e[31]!==J||e[32]!==$||e[33]!==H?(ie=s.jsx(q,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",onClick:$,disabled:_,"aria-label":H,title:W,children:J}),e[29]=_,e[30]=W,e[31]=J,e[32]=$,e[33]=H,e[34]=ie):ie=e[34];let pe;e[35]!==ie||e[36]!==L?(pe=s.jsxs("div",{className:"flex items-center gap-2",children:[L,ie]}),e[35]=ie,e[36]=L,e[37]=pe):pe=e[37];const X=M.length>0?s.jsx(Ko,{value:N,onChange:y,placeholder:o("settings.plugins.grid.searchPlaceholder")}):null,xe=M.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:o("settings.plugins.grid.empty")}):P.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:o("settings.plugins.grid.noMatches",{query:N.trim()})}):null,Y=Fo;let be;e[38]!==F||e[39]!==a||e[40]!==o?(be=F?null:s.jsx(Lo,{label:o("settings.plugins.sidebar.actions.addTitle"),hint:o("settings.plugins.grid.addHint"),onClick:a,settingsItem:"plugins.create"}),e[38]=F,e[39]=a,e[40]=o,e[41]=be):be=e[41];const De=P.map(ge=>{if(ge.kind==="entry"){const{entry:ke}=ge;return s.jsx(qa,{icon:s.jsx(ll,{name:ke.parsedKind==="npm"?"code-box":"folder"}),title:ke.spec,badges:s.jsx(Rc,{target:T.get(ke.id)??null,spec:ke.spec}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:ke.parsedKind==="npm"?o("settings.plugins.sidebar.kind.npm"):o("settings.plugins.sidebar.kind.path")}),ke.scope==="project"?s.jsx(So,{children:o("settings.plugins.grid.scope.project")}):null]}),onOpen:()=>l(ke.id),actionsLabel:o("settings.plugins.grid.actionsAria",{name:ke.spec}),actions:z(ke)},ke.id)}const{file:ne}=ge,Se=ne.kind==="package";return s.jsx(qa,{icon:s.jsx(ll,{name:Se?"folder":"file-text"}),title:ne.fileName,badges:s.jsx(Rc,{target:T.get(ne.id)??null}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:o(Se?"settings.plugins.sidebar.kind.package":"settings.plugins.sidebar.kind.file")}),ne.scope==="project"?s.jsx(So,{children:o("settings.plugins.grid.scope.project")}):null]}),onOpen:Se?void 0:()=>l(ne.id),actionsLabel:o("settings.plugins.grid.actionsAria",{name:ne.fileName}),actions:Se?void 0:[{label:o("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>n({kind:"file",id:ne.id,label:ne.fileName})}]},ne.id)});let ve;e[42]!==Y||e[43]!==be||e[44]!==De?(ve=s.jsxs("div",{className:Y,children:[be,De]}),e[42]=Y,e[43]=be,e[44]=De,e[45]=ve):ve=e[45];let se;return e[46]!==B||e[47]!==pe||e[48]!==X||e[49]!==xe||e[50]!==ve||e[51]!==V||e[52]!==ee?(se=s.jsxs(B,{title:V,description:ee,headerEnd:pe,children:[X,xe,ve]}),e[46]=B,e[47]=pe,e[48]=X,e[49]=xe,e[50]=ve,e[51]=V,e[52]=ee,e[53]=se):se=e[53],se};function rx(t){return{entries:t.entries,files:t.files,setSelected:t.setSelected,loadPlugins:t.loadPlugins}}function lx(t){return t.isLoadingRegistry}function cx(t){return t.loadRegistryInfo}function dx(t){return t.isCheckingUpdates}function ux(t){return t.checkUpdates}function mx(t){return t.runtime}function px(t){return t.registryInfo}function gx(t){return t.packageUpdates}function fx(t){return t.updateToLatest}function hx(t){return t.updatePackage}function bx(t){return{kind:"entry",entry:t}}function xx(t){return{kind:"file",file:t}}function vx(t){return t.kind==="entry"?[t.entry.spec]:[t.file.fileName,t.file.absolutePath??""]}const yx=({entryId:t,spec:e})=>{const{t:a}=ze(),n=Ot(f=>f.registryInfo[e]),o=Ot(f=>f.updateToLatest),[i,r]=d.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const f=n.latestVersion,p=n.currentVersion??"",g=async()=>{r(!0);try{(await o(t)).ok?G.success(a("settings.plugins.toast.updatedToLatest",{version:f})):G.error(a("settings.plugins.toast.refreshFailed"))}finally{r(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(Q,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:f})})]}),s.jsx(q,{variant:"default",size:"sm",onClick:()=>{g()},disabled:i,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:f})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(Q,{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 l=n.kind==="path-unreadable",u=l?"var(--status-warning)":"var(--status-error)",m=l?"alert":"error-warning",c=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(Q,{name:m,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:u}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:u},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:c})]})]})},Oc=t=>{const e=Ke.c(68),{target:a,name:n}=t,{t:o}=ze(),i=Ou(a),r=Fu(a),l=Ot(jx),u=Ot(kx);if(i.kind==="loading")return null;if(i.kind==="unknown"){let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Q,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=v):v=e[0];let N;e[1]!==o?(N=o("settings.plugins.status.unknown.title"),e[1]=o,e[2]=N):N=e[2];let y;e[3]!==N?(y=s.jsx("p",{className:"typography-label text-foreground",children:N}),e[3]=N,e[4]=y):y=e[4];let I;e[5]!==o?(I=o("settings.plugins.status.unknown.description"),e[5]=o,e[6]=I):I=e[6];let w;e[7]!==I?(w=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:I}),e[7]=I,e[8]=w):w=e[8];let D;e[9]!==y||e[10]!==w?(D=s.jsxs("div",{className:"flex-1 min-w-0",children:[y,w]}),e[9]=y,e[10]=w,e[11]=D):D=e[11];let C;e[12]!==l?(C=()=>{l()},e[12]=l,e[13]=C):C=e[13];let A;e[14]!==o?(A=o("settings.plugins.status.retry"),e[14]=o,e[15]=A):A=e[15];let T;e[16]!==C||e[17]!==A?(T=s.jsx(q,{variant:"outline",size:"sm",onClick:C,children:A}),e[16]=C,e[17]=A,e[18]=T):T=e[18];let O;return e[19]!==D||e[20]!==T?(O=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[v,D,T]}),e[19]=D,e[20]=T,e[21]=O):O=e[21],O}const{load:m,update:c}=i,f=i.target.kind==="package"?i.target.target:null,p=c==="updating"||r?.kind==="running";let g;e[22]!==n||e[23]!==f||e[24]!==o||e[25]!==u?(g=async()=>{if(!f)return;await u(f)?G.success(o("settings.plugins.update.toast.done",{name:n})):G.error(o("settings.plugins.update.toast.failed",{name:n}))},e[22]=n,e[23]=f,e[24]=o,e[25]=u,e[26]=g):g=e[26];const h=g;let k;e:{switch(m.kind){case"active":{let v;e[27]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Q,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=v):v=e[27];let N;e[28]!==m.version||e[29]!==o?(N=m.version?o("settings.plugins.status.loadedVersion",{version:m.version}):o("settings.plugins.status.loaded"),e[28]=m.version,e[29]=o,e[30]=N):N=e[30];let y;e[31]!==N?(y=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[v,N]}),e[31]=N,e[32]=y):y=e[32],k=y;break e}case"notReported":{let v;e[33]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Q,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=v):v=e[33];let N;e[34]!==o?(N=o("settings.plugins.status.notReported.title"),e[34]=o,e[35]=N):N=e[35];let y;e[36]!==N?(y=s.jsx("p",{className:"typography-label text-foreground",children:N}),e[36]=N,e[37]=y):y=e[37];let I;e[38]!==o?(I=o("settings.plugins.status.notReported.description"),e[38]=o,e[39]=I):I=e[39];let w;e[40]!==I?(w=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:I}),e[40]=I,e[41]=w):w=e[41];let D;e[42]!==y||e[43]!==w?(D=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[v,s.jsxs("div",{className:"flex-1 min-w-0",children:[y,w]})]}),e[42]=y,e[43]=w,e[44]=D):D=e[44],k=D;break e}case"failed":{let v;e[45]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Q,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=v):v=e[45];let N;e[46]!==o?(N=o("settings.plugins.status.failed.title"),e[46]=o,e[47]=N):N=e[47];let y;e[48]!==N?(y=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:N}),e[48]=N,e[49]=y):y=e[49];let I;e[50]!==m.error?(I=s.jsx("p",{className:"typography-micro font-mono text-foreground mt-1 whitespace-pre-wrap break-words",children:m.error}),e[50]=m.error,e[51]=I):I=e[51];let w;e[52]!==m.ref||e[53]!==o?(w=m.ref?s.jsx("p",{className:"typography-micro text-muted-foreground mt-1",children:o("settings.plugins.status.failed.ref",{ref:m.ref})}):null,e[52]=m.ref,e[53]=o,e[54]=w):w=e[54];let D;e[55]!==y||e[56]!==I||e[57]!==w?(D=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[v,s.jsxs("div",{className:"flex-1 min-w-0",children:[y,I,w]})]}),e[55]=y,e[56]=I,e[57]=w,e[58]=D):D=e[58],k=D;break e}}k=void 0}const b=k,j=f!==null&&(c!=="none"||r!==null);let x;e[59]!==h||e[60]!==p||e[61]!==r||e[62]!==j||e[63]!==o?(x=j?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(Q,{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:o("settings.plugins.update.available.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:o("settings.plugins.update.available.description")}),r?.kind==="failed"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-micro text-[var(--status-error)] mt-2",children:o("settings.plugins.update.failed.title")}),s.jsx("p",{className:"typography-micro font-mono text-foreground mt-0.5 whitespace-pre-wrap break-words",children:r.error})]}):null]}),s.jsx(q,{variant:"default",size:"sm",onClick:()=>{h()},disabled:p,children:p?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"loader-4",className:"size-4 animate-spin"}),o("settings.plugins.update.running")]}):o("settings.plugins.update.action")})]}):null,e[59]=h,e[60]=p,e[61]=r,e[62]=j,e[63]=o,e[64]=x):x=e[64];let S;return e[65]!==b||e[66]!==x?(S=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,x]}),e[65]=b,e[66]=x,e[67]=S):S=e[67],S};function jx(t){return t.loadRuntime}function kx(t){return t.updatePackage}function Co(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 Io(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Fc(t,e){if(t.trim()===e.trim())return!0;const a=Co(t),n=Co(e);return a.ok&&n.ok&&Io(a.value)===Io(n.value)}function wx(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Io(t.options),fileName:"",content:""}}function Sx(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Lc=t=>{const e=Ke.c(4),{scope:a,label:n}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=Ie("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=o):o=e[0];let i;return e[1]!==n||e[2]!==a?(i=s.jsx("span",{className:o,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=i):i=e[3],i},Nx=()=>{const t=Ke.c(229),{t:e}=ze(),n=dn(Cx)?.trim()||da(),o=Ot(Ix),i=Ot(Px),r=o===n&&i===Yt(),l=Ot(Ax),u=Ot(Tx),m=Ot(Ex),c=Ot(Dx),f=Ot(Mx),p=Ot(Rx),g=Ot(Ox),h=Ot(Fx),k=Ot(Lx),b=Ot(Kx),j=Ot(zx),[x,S]=d.useState(!1),[v,N]=d.useState(null),[y,I]=d.useState(!1);let w;t[0]!==S?(w=()=>{const Je=()=>S(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Je),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Je)},t[0]=S,t[1]=w):w=t[1];let D;t[2]===Symbol.for("react.memo_cache_sentinel")?(D=[],t[2]=D):D=t[2],d.useEffect(w,D);let C;t[3]===Symbol.for("react.memo_cache_sentinel")?(C=[],t[3]=C):C=t[3],d.useEffect($x,C);let A;t[4]!==u||t[5]!==l?(A=l?u.find(Je=>Je.id===l)??null:null,t[4]=u,t[5]=l,t[6]=A):A=t[6];const T=A;let O;t[7]!==m||t[8]!==l?(O=l?m.find(Je=>Je.id===l)??null:null,t[7]=m,t[8]=l,t[9]=O):O=t[9];const z=O;let M;t[10]!==T?(M=T?Eu(T.spec,T.sourcePath):null,t[10]=T,t[11]=M):M=t[11];const P=M;let R;t[12]!==z?(R=z?Du(z.absolutePath):null,t[12]=z,t[13]=R):R=t[13];const F=R,[_,B]=d.useState(!1);let V;t[14]===Symbol.for("react.memo_cache_sentinel")?(V=new Map,t[14]=V):V=t[14];const ee=d.useRef(V),L=d.useRef(null),$=JSON.stringify([n,l]);let H;t[15]!==r||t[16]!==n||t[17]!==$||t[18]!==h||t[19]!==T||t[20]!==z||t[21]!==f||t[22]!==B?(H=()=>{let Je=!1;if(!r){L.current=null,f(null);return}const ct=(Qe,it)=>{if(Ot.getState().selectedId!==Qe||da()!==n)return;const dt=L.current,qe=Ot.getState().draft,lt=dt?.id===Qe&&dt.directory===n&&qe!==null&&(qe.spec!==dt.value.spec||!Fc(qe.optionsJson,dt.value.optionsJson)||qe.content!==dt.value.content);L.current={id:Qe,directory:n,value:it},lt||f(it)};return T?(ct(T.id,wx(T)),()=>{Je=!0}):z?(B(L.current?.id!==z.id||L.current.directory!==n),(async()=>{const Qe=await h(z.id);if(Je||da()!==n)return;B(!1);const it=Qe?.content??"";ee.current.set($,it),ct(z.id,Sx(z,it))})(),()=>{Je=!0}):(L.current=null,f(null),()=>{Je=!0})},t[15]=r,t[16]=n,t[17]=$,t[18]=h,t[19]=T,t[20]=z,t[21]=f,t[22]=B,t[23]=H):H=t[23];let W;t[24]!==r||t[25]!==n||t[26]!==$||t[27]!==h||t[28]!==T||t[29]!==z||t[30]!==f?(W=[T,z,h,f,r,n,$],t[24]=r,t[25]=n,t[26]=$,t[27]=h,t[28]=T,t[29]=z,t[30]=f,t[31]=W):W=t[31],d.useEffect(H,W);let Z;t[32]!==r||t[33]!==n||t[34]!==c||t[35]!==$||t[36]!==T||t[37]!==z||t[38]!==e||t[39]!==p||t[40]!==g?(Z=async()=>{if(!c||!r||da()!==n)return Ds;if(T&&c.mode==="entry"){const Je=c.spec.trim();if(Je===T.spec&&Fc(c.optionsJson,Io(T.options)))return Ds;if(!Je)return gs(e("settings.plugins.validation.specRequired"));const Qe=Co(c.optionsJson);if(!Qe.ok)return gs(e("settings.plugins.page.field.options.invalidJson"));const it=await p(T.id,{spec:Je,options:Qe.value});return it.ok?it.reloadFailed?gs(it.warning||it.message||e("settings.plugins.toast.reloadFailed")):yn:gs(it.message||e("settings.plugins.toast.reloadFailed"))}if(z&&c.mode==="file"){const Je=ee.current.get($)??"";if(c.content===Je)return Ds;const ct=await g(z.id,{content:c.content});return ct.ok?(ee.current.set($,c.content),ct.reloadFailed?gs(ct.warning||ct.message||e("settings.plugins.toast.reloadFailed")):yn):gs(ct.message||e("settings.plugins.toast.reloadFailed"))}return Ds},t[32]=r,t[33]=n,t[34]=c,t[35]=$,t[36]=T,t[37]=z,t[38]=e,t[39]=p,t[40]=g,t[41]=Z):Z=t[41];const J=Xa(Z);let ie;t[42]!==b||t[43]!==j||t[44]!==v||t[45]!==N||t[46]!==I||t[47]!==e?(ie=async()=>{if(!v)return;I(!0);const Je=v.kind==="entry"?await b(v.id):await j(v.id);Je.ok?G.success(Je.message||e("settings.plugins.sidebar.toast.deleted",{name:v.label})):G.error(e("settings.plugins.sidebar.toast.deleteFailed")),N(null),I(!1)},t[42]=b,t[43]=j,t[44]=v,t[45]=N,t[46]=I,t[47]=e,t[48]=ie):ie=t[48];const pe=ie;let X;t[49]!==x||t[50]!==S?(X=s.jsx(Xb,{open:x,onOpenChange:S}),t[49]=x,t[50]=S,t[51]=X):X=t[51];const xe=v!==null;let Y;t[52]!==y||t[53]!==N?(Y=Je=>{!Je&&!y&&N(null)},t[52]=y,t[53]=N,t[54]=Y):Y=t[54];let be;t[55]!==e?(be=e("settings.plugins.sidebar.deleteDialog.title"),t[55]=e,t[56]=be):be=t[56];let De;t[57]!==be?(De=s.jsx(Ut,{children:be}),t[57]=be,t[58]=De):De=t[58];const ve=v?.label??"";let se;t[59]!==e||t[60]!==ve?(se=e("settings.plugins.sidebar.deleteDialog.description",{name:ve}),t[59]=e,t[60]=ve,t[61]=se):se=t[61];let ge;t[62]!==se?(ge=s.jsx($t,{children:se}),t[62]=se,t[63]=ge):ge=t[63];let ne;t[64]!==De||t[65]!==ge?(ne=s.jsxs(zt,{children:[De,ge]}),t[64]=De,t[65]=ge,t[66]=ne):ne=t[66];let Se;t[67]!==N?(Se=()=>N(null),t[67]=N,t[68]=Se):Se=t[68];let ke;t[69]!==e?(ke=e("settings.common.actions.cancel"),t[69]=e,t[70]=ke):ke=t[70];let Te;t[71]!==y||t[72]!==Se||t[73]!==ke?(Te=s.jsx(q,{size:"sm",variant:"ghost",onClick:Se,disabled:y,children:ke}),t[71]=y,t[72]=Se,t[73]=ke,t[74]=Te):Te=t[74];let Ee;t[75]!==pe?(Ee=()=>{pe()},t[75]=pe,t[76]=Ee):Ee=t[76];let Le;t[77]!==y||t[78]!==e?(Le=e(y?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),t[77]=y,t[78]=e,t[79]=Le):Le=t[79];let ce;t[80]!==y||t[81]!==Ee||t[82]!==Le?(ce=s.jsx(q,{size:"sm",variant:"destructive",onClick:Ee,disabled:y,children:Le}),t[80]=y,t[81]=Ee,t[82]=Le,t[83]=ce):ce=t[83];let Me;t[84]!==Te||t[85]!==ce?(Me=s.jsxs(Xt,{children:[Te,ce]}),t[84]=Te,t[85]=ce,t[86]=Me):Me=t[86];let Fe;t[87]!==ne||t[88]!==Me?(Fe=s.jsxs(Lt,{className:"max-w-md",children:[ne,Me]}),t[87]=ne,t[88]=Me,t[89]=Fe):Fe=t[89];let me;t[90]!==xe||t[91]!==Y||t[92]!==Fe?(me=s.jsx(Ft,{open:xe,onOpenChange:Y,children:Fe}),t[90]=xe,t[91]=Y,t[92]=Fe,t[93]=me):me=t[93];let de;t[94]!==X||t[95]!==me?(de=s.jsxs(s.Fragment,{children:[X,me]}),t[94]=X,t[95]=me,t[96]=de):de=t[96];const Pe=de;if(!l){let Je;t[97]!==S?(Je=()=>S(!0),t[97]=S,t[98]=Je):Je=t[98];let ct;t[99]!==N||t[100]!==Je?(ct=s.jsx(ox,{onAdd:Je,onDelete:N}),t[99]=N,t[100]=Je,t[101]=ct):ct=t[101];let Qe;return t[102]!==Pe||t[103]!==ct?(Qe=s.jsxs(s.Fragment,{children:[ct,Pe]}),t[102]=Pe,t[103]=ct,t[104]=Qe):Qe=t[104],Qe}let he;t[105]!==e?(he=e("settings.plugins.page.back"),t[105]=e,t[106]=he):he=t[106];let Ue;t[107]!==k?(Ue=()=>k(null),t[107]=k,t[108]=Ue):Ue=t[108];let Ae;t[109]!==he||t[110]!==Ue?(Ae=s.jsx(No,{label:he,onClick:Ue}),t[109]=he,t[110]=Ue,t[111]=Ae):Ae=t[111];const Re=Ae;let $e;t[112]!==T||t[113]!==z||t[114]!==N?($e=()=>{T?N({kind:"entry",id:T.id,label:T.spec}):z&&N({kind:"file",id:z.id,label:z.fileName})},t[112]=T,t[113]=z,t[114]=N,t[115]=$e):$e=t[115];let nt;t[116]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(Q,{name:"delete-bin",className:"size-3.5"}),t[116]=nt):nt=t[116];let pt;t[117]!==e?(pt=e("settings.common.actions.delete"),t[117]=e,t[118]=pt):pt=t[118];let kt;t[119]!==$e||t[120]!==pt?(kt=s.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:$e,children:[nt,pt]}),t[119]=$e,t[120]=pt,t[121]=kt):kt=t[121];const bt=kt;if(T&&c&&c.mode==="entry"){let Je;t[122]!==c.optionsJson?(Je=Co(c.optionsJson),t[122]=c.optionsJson,t[123]=Je):Je=t[123];const Qe=Je.ok;let it;t[124]!==e?(it=e("settings.plugins.page.header.entry"),t[124]=e,t[125]=it):it=t[125];let dt;t[126]!==T.scope||t[127]!==e?(dt=T.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[126]=T.scope,t[127]=e,t[128]=dt):dt=t[128];let qe;t[129]!==T.scope||t[130]!==dt?(qe=s.jsx(Lc,{scope:T.scope,label:dt}),t[129]=T.scope,t[130]=dt,t[131]=qe):qe=t[131];const lt=J.onBlurCapture;let ae;t[132]!==T.spec||t[133]!==P?(ae=s.jsx(Oc,{target:P,name:T.spec}),t[132]=T.spec,t[133]=P,t[134]=ae):ae=t[134];let fe;t[135]!==T.id||t[136]!==T.spec?(fe=s.jsx(yx,{entryId:T.id,spec:T.spec}),t[135]=T.id,t[136]=T.spec,t[137]=fe):fe=t[137];let ye;t[138]!==ae||t[139]!==fe?(ye=s.jsx(Ve,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[ae,fe]})}),t[138]=ae,t[139]=fe,t[140]=ye):ye=t[140];let we;t[141]!==e?(we=e("settings.plugins.page.field.spec"),t[141]=e,t[142]=we):we=t[142];const Ge=c.spec;let et;t[143]!==c||t[144]!==f?(et=He=>f({...c,spec:He.target.value}),t[143]=c,t[144]=f,t[145]=et):et=t[145];let mt;t[146]!==e?(mt=e("settings.plugins.page.field.spec.placeholder"),t[146]=e,t[147]=mt):mt=t[147];let jt;t[148]!==c.spec||t[149]!==et||t[150]!==mt?(jt=s.jsx(Be,{value:Ge,onChange:et,placeholder:mt,className:"font-mono typography-meta",spellCheck:!1}),t[148]=c.spec,t[149]=et,t[150]=mt,t[151]=jt):jt=t[151];let vt;t[152]!==we||t[153]!==jt?(vt=s.jsx(Ve,{title:we,settingsItem:"plugins.spec",children:jt}),t[152]=we,t[153]=jt,t[154]=vt):vt=t[154];let Ct;t[155]!==e?(Ct=e("settings.plugins.page.field.options"),t[155]=e,t[156]=Ct):Ct=t[156];const Bt=c.optionsJson;let Ye;t[157]!==c||t[158]!==f?(Ye=He=>f({...c,optionsJson:He.target.value}),t[157]=c,t[158]=f,t[159]=Ye):Ye=t[159];const Ze=!Qe&&"border-[var(--status-error-border)]";let ut;t[160]!==Ze?(ut=Ie("font-mono typography-meta min-h-[200px]",Ze),t[160]=Ze,t[161]=ut):ut=t[161];let ft;t[162]!==c.optionsJson||t[163]!==Ye||t[164]!==ut?(ft=s.jsx(Ns,{value:Bt,onChange:Ye,rows:10,className:ut,spellCheck:!1,placeholder:"{ }"}),t[162]=c.optionsJson,t[163]=Ye,t[164]=ut,t[165]=ft):ft=t[165];let K;t[166]!==Qe||t[167]!==e?(K=!Qe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[166]=Qe,t[167]=e,t[168]=K):K=t[168];let ue;t[169]!==Ct||t[170]!==ft||t[171]!==K?(ue=s.jsxs(Ve,{title:Ct,settingsItem:"plugins.options",children:[ft,K]}),t[169]=Ct,t[170]=ft,t[171]=K,t[172]=ue):ue=t[172];let Ne;t[173]!==J.onBlurCapture||t[174]!==Re||t[175]!==bt||t[176]!==it||t[177]!==qe||t[178]!==ye||t[179]!==vt||t[180]!==ue?(Ne=s.jsxs(Qt,{title:it,titleLeading:Re,headerEnd:bt,titleAccessory:qe,onBlurCapture:lt,children:[ye,vt,ue]}),t[173]=J.onBlurCapture,t[174]=Re,t[175]=bt,t[176]=it,t[177]=qe,t[178]=ye,t[179]=vt,t[180]=ue,t[181]=Ne):Ne=t[181];let Ce;return t[182]!==Pe||t[183]!==Ne?(Ce=s.jsxs(s.Fragment,{children:[Ne,Pe]}),t[182]=Pe,t[183]=Ne,t[184]=Ce):Ce=t[184],Ce}if(z&&c&&c.mode==="file"){let Je;t[185]!==e?(Je=e("settings.plugins.page.header.file"),t[185]=e,t[186]=Je):Je=t[186];let ct;t[187]!==z.scope||t[188]!==e?(ct=z.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[187]=z.scope,t[188]=e,t[189]=ct):ct=t[189];let Qe;t[190]!==z.scope||t[191]!==ct?(Qe=s.jsx(Lc,{scope:z.scope,label:ct}),t[190]=z.scope,t[191]=ct,t[192]=Qe):Qe=t[192];let it;t[193]===Symbol.for("react.memo_cache_sentinel")?(it=Ie("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),t[193]=it):it=t[193];let dt;t[194]!==z.fileName?(dt=s.jsx("span",{className:it,children:z.fileName}),t[194]=z.fileName,t[195]=dt):dt=t[195];let qe;t[196]!==Qe||t[197]!==dt?(qe=s.jsxs(s.Fragment,{children:[Qe,dt]}),t[196]=Qe,t[197]=dt,t[198]=qe):qe=t[198];const lt=J.onBlurCapture;let ae;t[199]!==z.fileName||t[200]!==F?(ae=s.jsx(Ve,{divider:!1,children:s.jsx(Oc,{target:F,name:z.fileName})}),t[199]=z.fileName,t[200]=F,t[201]=ae):ae=t[201];let fe;t[202]!==e?(fe=e("settings.plugins.page.field.content"),t[202]=e,t[203]=fe):fe=t[203];let ye;t[204]!==c||t[205]!==f?(ye=vt=>f({...c,content:vt.target.value}),t[204]=c,t[205]=f,t[206]=ye):ye=t[206];let we;t[207]!==J?(we=vt=>{vt.key==="Enter"&&(vt.metaKey||vt.ctrlKey)&&(vt.preventDefault(),J.requestSave())},t[207]=J,t[208]=we):we=t[208];let Ge;t[209]!==c.content||t[210]!==_||t[211]!==ye||t[212]!==we?(Ge=s.jsx(Ns,{value:c.content,onChange:ye,onKeyDown:we,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:_}),t[209]=c.content,t[210]=_,t[211]=ye,t[212]=we,t[213]=Ge):Ge=t[213];let et;t[214]!==fe||t[215]!==Ge?(et=s.jsx(Ve,{title:fe,settingsItem:"plugins.content",children:Ge}),t[214]=fe,t[215]=Ge,t[216]=et):et=t[216];let mt;t[217]!==J.onBlurCapture||t[218]!==Re||t[219]!==bt||t[220]!==Je||t[221]!==qe||t[222]!==ae||t[223]!==et?(mt=s.jsxs(Qt,{title:Je,titleLeading:Re,headerEnd:bt,titleAccessory:qe,onBlurCapture:lt,children:[ae,et]}),t[217]=J.onBlurCapture,t[218]=Re,t[219]=bt,t[220]=Je,t[221]=qe,t[222]=ae,t[223]=et,t[224]=mt):mt=t[224];let jt;return t[225]!==Pe||t[226]!==mt?(jt=s.jsxs(s.Fragment,{children:[mt,Pe]}),t[225]=Pe,t[226]=mt,t[227]=jt):jt=t[227],jt}let yt;return t[228]===Symbol.for("react.memo_cache_sentinel")?(yt=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(Q,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[228]=yt):yt=t[228],yt};function Cx(t){return t.getActiveProject()?.path}function Ix(t){return t.loadedDirectory}function Px(t){return t.loadedRuntimeKey}function Ax(t){return t.selectedId}function Tx(t){return t.entries}function Ex(t){return t.files}function Dx(t){return t.draft}function Mx(t){return t.setDraft}function Rx(t){return t.updateEntry}function Ox(t){return t.updateFile}function Fx(t){return t.readFile}function Lx(t){return t.setSelected}function Kx(t){return t.deleteEntry}function zx(t){return t.deleteFile}function Ux(){Ot.getState().setSelected(null)}function $x(){return Ux}const _x="<built-in>",Ba=t=>t?.path===_x,cl=t=>!!t&&!Ba(t)&&t.renamable===!0,eo=t=>{if(Ba(t))return t.name;const e=t.path.split(/[\\/]/).filter(Boolean),a=e.at(-1)??"";return a==="SKILL.md"?e.at(-2)??t.name:a.endsWith(".md")?a.slice(0,-3):t.name},Bx=t=>{const e=Ke.c(167),{onItemSelect:a}=t,{t:n}=ze(),[o,i]=d.useState(""),[r,l]=d.useState(null),[u,m]=d.useState(""),[c,f]=d.useState(null),[p,g]=d.useState(!1),[h,k]=d.useState(null),{selectedSkillName:b,setSelectedSkill:j,setSkillDraft:x,deleteSkill:S,renameSkill:v,getSkillDetail:N}=Bs(Ms(Vx)),y=Ks();let I;e[0]!==y?(I=K=>yl(K,y),e[0]=y,e[1]=I):I=e[1];const w=Bs(I),D=Ll(y),C=Bs(Hx);let A,T;e[2]!==C||e[3]!==y?(A=()=>{C(y)},T=[C,y],e[2]=C,e[3]=y,e[4]=A,e[5]=T):(A=e[4],T=e[5]),d.useEffect(A,T);let O;e[6]!==a||e[7]!==j||e[8]!==x||e[9]!==w?(O=()=>{let K="new-skill",ue=1;for(;w.some(Ne=>Ne.name===K);)K=`new-skill-${ue}`,ue++;x({name:K,scope:"user",source:"opencode",description:""}),j(K),a?.()},e[6]=a,e[7]=j,e[8]=x,e[9]=w,e[10]=O):O=e[10];const z=O;let M;e[11]===Symbol.for("react.memo_cache_sentinel")?(M=async K=>{Ba(K)||f(K)},e[11]=M):M=e[11];const P=M;let R;e[12]!==c||e[13]!==S||e[14]!==y||e[15]!==n?(R=async()=>{if(!c)return;if(Ba(c)){f(null);return}g(!0),await S(c.name,y)?(G.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),f(null)):G.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),g(!1)},e[12]=c,e[13]=S,e[14]=y,e[15]=n,e[16]=R):R=e[16];const F=R;let _;e[17]!==N||e[18]!==j||e[19]!==x||e[20]!==y||e[21]!==w||e[22]!==n?(_=async K=>{if(Ba(K))return;const ue=K.name;let Ne=1,Ce=`${ue}-copy`;for(;w.some(le=>le.name===Ce);)Ne++,Ce=`${ue}-copy-${Ne}`;const He=await N(K.name,y);if(!He){G.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}x({name:Ce,scope:K.scope||"user",source:K.source||"opencode",description:(He.sources.md.fields.includes("description"),""),instructions:""}),j(Ce)},e[17]=N,e[18]=j,e[19]=x,e[20]=y,e[21]=w,e[22]=n,e[23]=_):_=e[23];const B=_;let V;e[24]===Symbol.for("react.memo_cache_sentinel")?(V=K=>{cl(K)&&(m(K.name),l(K))},e[24]=V):V=e[24];const ee=V;let L;e[25]!==r||e[26]!==u||e[27]!==v||e[28]!==j||e[29]!==y||e[30]!==w||e[31]!==n?(L=async()=>{if(!r)return;if(!cl(r)){l(null);return}const K=u.trim().replace(/\s+/g,"-").toLowerCase();if(!K){G.error(n("settings.skills.page.toast.skillNameRequired"));return}if(K===r.name){l(null);return}if(w.some(Ne=>Ne.name===K)){G.error(n("settings.skills.page.toast.skillExists"));return}await v(r.name,K,y)?(G.success(n("settings.skills.sidebar.toast.skillRenamed",{name:K})),j(K)):G.error(n("settings.skills.sidebar.toast.renameFailed")),l(null)},e[25]=r,e[26]=u,e[27]=v,e[28]=j,e[29]=y,e[30]=w,e[31]=n,e[32]=L):L=e[32];const $=L;let H,W,Z;if(e[33]!==o||e[34]!==w){let K;e[38]!==o?(K=ue=>Ii([ue.name,ue.description],o),e[38]=o,e[39]=K):K=e[39],W=w.filter(K),H=W.filter(qx),Z=W.filter(Gx),e[33]=o,e[34]=w,e[35]=H,e[36]=W,e[37]=Z}else H=e[35],W=e[36],Z=e[37];const te=Z;let J;e[40]===Symbol.for("react.memo_cache_sentinel")?(J=function(ue){const Ne={},Ce=[];for(const le of ue)le.group?(Ne[le.group]||(Ne[le.group]=[]),Ne[le.group].push(le)):Ce.push(le);const He=Object.keys(Ne).sort(Wx).map(le=>({name:le,skills:[...Ne[le]].sort(Jx)}));return Ce.sort(Qx),{sortedGroups:He,ungrouped:Ce}},e[40]=J):J=e[40];const ie=J;let pe;e[41]!==H?(pe=ie(H),e[41]=H,e[42]=pe):pe=e[42];const X=pe;let xe;e[43]!==te?(xe=ie(te),e[43]=te,e[44]=xe):xe=e[44];const Y=xe;let be;e[45]===Symbol.for("react.memo_cache_sentinel")?(be=Ie("flex h-full flex-col","bg-background"),e[45]=be):be=e[45];let De;e[46]!==n?(De=n("settings.skills.sidebar.title"),e[46]=n,e[47]=De):De=e[47];let ve;e[48]!==De?(ve=s.jsx("h2",{className:`${zn} mb-3`,children:De}),e[48]=De,e[49]=ve):ve=e[49];let se;e[50]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Mi,{className:"mb-3"}),e[50]=se):se=e[50];let ge;e[51]!==w.length||e[52]!==n?(ge=n("settings.skills.sidebar.total",{count:w.length}),e[51]=w.length,e[52]=n,e[53]=ge):ge=e[53];let ne;e[54]!==ge?(ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ge}),e[54]=ge,e[55]=ne):ne=e[55];let Se;e[56]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),e[56]=Se):Se=e[56];let ke;e[57]!==z?(ke=s.jsx(q,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:z,children:Se}),e[57]=z,e[58]=ke):ke=e[58];let Te;e[59]!==ne||e[60]!==ke?(Te=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ne,ke]}),e[59]=ne,e[60]=ke,e[61]=Te):Te=e[61];let Ee;e[62]!==o||e[63]!==w.length?(Ee=w.length>0?s.jsx(Ml,{value:o,onChange:i}):null,e[62]=o,e[63]=w.length,e[64]=Ee):Ee=e[64];let Le;e[65]!==ve||e[66]!==Te||e[67]!==Ee?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,se,Te,Ee]}),e[65]=ve,e[66]=Te,e[67]=Ee,e[68]=Le):Le=e[68];let ce;e[69]!==X||e[70]!==Y||e[71]!==B||e[72]!==D||e[73]!==a||e[74]!==h||e[75]!==H||e[76]!==o||e[77]!==b||e[78]!==j||e[79]!==W||e[80]!==w.length||e[81]!==n||e[82]!==te?(ce=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Q,{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")})]}):W.length===0?s.jsx(Rl,{query:o}):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:n("settings.skills.sidebar.section.project")}),X.sortedGroups.map(K=>{const{name:ue,skills:Ne}=K;return s.jsx(al,{label:ue,count:Ne.length,storageKey:"project-skills",children:Ne.map(Ce=>s.jsx(to,{skill:Ce,blocked:D(`skill:${eo(Ce)}`),isSelected:b===Ce.name,onSelect:()=>{j(Ce.name),a?.()},onRename:()=>ee(Ce),onDelete:()=>P(Ce),onDuplicate:()=>B(Ce),isMenuOpen:h===Ce.name,onMenuOpenChange:He=>k(He?Ce.name:null)},Ce.name))},ue)}),X.ungrouped.map(K=>s.jsx(to,{skill:K,blocked:D(`skill:${eo(K)}`),isSelected:b===K.name,onSelect:()=>{j(K.name),a?.()},onRename:()=>ee(K),onDelete:()=>P(K),onDuplicate:()=>B(K),isMenuOpen:h===K.name,onMenuOpenChange:ue=>k(ue?K.name:null)},K.name))]}),te.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")}),Y.sortedGroups.map(K=>{const{name:ue,skills:Ne}=K;return s.jsx(al,{label:ue,count:Ne.length,storageKey:"user-skills",children:Ne.map(Ce=>s.jsx(to,{skill:Ce,blocked:D(`skill:${eo(Ce)}`),isSelected:b===Ce.name,onSelect:()=>{j(Ce.name),a?.()},onRename:()=>ee(Ce),onDelete:()=>P(Ce),onDuplicate:()=>B(Ce),isMenuOpen:h===Ce.name,onMenuOpenChange:He=>k(He?Ce.name:null)},Ce.name))},ue)}),Y.ungrouped.map(K=>s.jsx(to,{skill:K,blocked:D(`skill:${eo(K)}`),isSelected:b===K.name,onSelect:()=>{j(K.name),a?.()},onRename:()=>ee(K),onDelete:()=>P(K),onDuplicate:()=>B(K),isMenuOpen:h===K.name,onMenuOpenChange:ue=>k(ue?K.name:null)},K.name))]})]})}),e[69]=X,e[70]=Y,e[71]=B,e[72]=D,e[73]=a,e[74]=h,e[75]=H,e[76]=o,e[77]=b,e[78]=j,e[79]=W,e[80]=w.length,e[81]=n,e[82]=te,e[83]=ce):ce=e[83];const Me=c!==null;let Fe;e[84]!==p?(Fe=K=>{!K&&!p&&f(null)},e[84]=p,e[85]=Fe):Fe=e[85];let me;e[86]!==n?(me=n("settings.skills.sidebar.deleteDialog.title"),e[86]=n,e[87]=me):me=e[87];let de;e[88]!==me?(de=s.jsx(Ut,{children:me}),e[88]=me,e[89]=de):de=e[89];const Pe=c?.name??"";let he;e[90]!==n||e[91]!==Pe?(he=n("settings.skills.sidebar.deleteDialog.description",{name:Pe}),e[90]=n,e[91]=Pe,e[92]=he):he=e[92];let Ue;e[93]!==he?(Ue=s.jsx($t,{children:he}),e[93]=he,e[94]=Ue):Ue=e[94];let Ae;e[95]!==de||e[96]!==Ue?(Ae=s.jsxs(zt,{children:[de,Ue]}),e[95]=de,e[96]=Ue,e[97]=Ae):Ae=e[97];let Re;e[98]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>f(null),e[98]=Re):Re=e[98];let $e;e[99]!==n?($e=n("settings.common.actions.cancel"),e[99]=n,e[100]=$e):$e=e[100];let nt;e[101]!==p||e[102]!==$e?(nt=s.jsx(q,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,disabled:p,children:$e}),e[101]=p,e[102]=$e,e[103]=nt):nt=e[103];let pt;e[104]!==n?(pt=n("settings.common.actions.delete"),e[104]=n,e[105]=pt):pt=e[105];let kt;e[106]!==F||e[107]!==p||e[108]!==pt?(kt=s.jsx(q,{size:"sm",onClick:F,disabled:p,children:pt}),e[106]=F,e[107]=p,e[108]=pt,e[109]=kt):kt=e[109];let bt;e[110]!==nt||e[111]!==kt?(bt=s.jsxs(Xt,{children:[nt,kt]}),e[110]=nt,e[111]=kt,e[112]=bt):bt=e[112];let yt;e[113]!==Ae||e[114]!==bt?(yt=s.jsxs(Lt,{className:"max-w-md",children:[Ae,bt]}),e[113]=Ae,e[114]=bt,e[115]=yt):yt=e[115];let Je;e[116]!==Me||e[117]!==Fe||e[118]!==yt?(Je=s.jsx(Ft,{open:Me,onOpenChange:Fe,children:yt}),e[116]=Me,e[117]=Fe,e[118]=yt,e[119]=Je):Je=e[119];const ct=r!==null;let Qe;e[120]===Symbol.for("react.memo_cache_sentinel")?(Qe=K=>!K&&l(null),e[120]=Qe):Qe=e[120];let it;e[121]!==n?(it=n("settings.skills.sidebar.renameDialog.title"),e[121]=n,e[122]=it):it=e[122];let dt;e[123]!==it?(dt=s.jsx(Ut,{children:it}),e[123]=it,e[124]=dt):dt=e[124];const qe=r?.name??"";let lt;e[125]!==n||e[126]!==qe?(lt=n("settings.skills.sidebar.renameDialog.description",{name:qe}),e[125]=n,e[126]=qe,e[127]=lt):lt=e[127];let ae;e[128]!==lt?(ae=s.jsx($t,{children:lt}),e[128]=lt,e[129]=ae):ae=e[129];let fe;e[130]!==dt||e[131]!==ae?(fe=s.jsxs(zt,{children:[dt,ae]}),e[130]=dt,e[131]=ae,e[132]=fe):fe=e[132];let ye;e[133]===Symbol.for("react.memo_cache_sentinel")?(ye=K=>m(K.target.value),e[133]=ye):ye=e[133];let we;e[134]!==n?(we=n("settings.skills.sidebar.renameDialog.placeholder"),e[134]=n,e[135]=we):we=e[135];let Ge;e[136]!==$?(Ge=K=>{K.key==="Enter"&&$()},e[136]=$,e[137]=Ge):Ge=e[137];let et;e[138]!==u||e[139]!==we||e[140]!==Ge?(et=s.jsx(Be,{value:u,onChange:ye,placeholder:we,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ge}),e[138]=u,e[139]=we,e[140]=Ge,e[141]=et):et=e[141];let mt;e[142]===Symbol.for("react.memo_cache_sentinel")?(mt=()=>l(null),e[142]=mt):mt=e[142];let jt;e[143]!==n?(jt=n("settings.common.actions.cancel"),e[143]=n,e[144]=jt):jt=e[144];let vt;e[145]!==jt?(vt=s.jsx(q,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:mt,children:jt}),e[145]=jt,e[146]=vt):vt=e[146];let Ct;e[147]!==n?(Ct=n("settings.common.actions.rename"),e[147]=n,e[148]=Ct):Ct=e[148];let Bt;e[149]!==$||e[150]!==Ct?(Bt=s.jsx(q,{size:"sm",onClick:$,children:Ct}),e[149]=$,e[150]=Ct,e[151]=Bt):Bt=e[151];let Ye;e[152]!==vt||e[153]!==Bt?(Ye=s.jsxs(Xt,{children:[vt,Bt]}),e[152]=vt,e[153]=Bt,e[154]=Ye):Ye=e[154];let Ze;e[155]!==fe||e[156]!==et||e[157]!==Ye?(Ze=s.jsxs(Lt,{children:[fe,et,Ye]}),e[155]=fe,e[156]=et,e[157]=Ye,e[158]=Ze):Ze=e[158];let ut;e[159]!==ct||e[160]!==Ze?(ut=s.jsx(Ft,{open:ct,onOpenChange:Qe,children:Ze}),e[159]=ct,e[160]=Ze,e[161]=ut):ut=e[161];let ft;return e[162]!==Le||e[163]!==ce||e[164]!==Je||e[165]!==ut?(ft=s.jsxs("div",{className:be,children:[Le,ce,Je,ut]}),e[162]=Le,e[163]=ce,e[164]=Je,e[165]=ut,e[166]=ft):ft=e[166],ft},to=t=>{const e=Ke.c(50),{skill:a,blocked:n,isSelected:o,onSelect:i,onDelete:r,onRename:l,onDuplicate:u,isMenuOpen:m,onMenuOpenChange:c}=t,{t:f}=ze();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=xl(),e[0]=p):p=e[0];const g=p;let h;e[1]!==a?(h=Ba(a),e[1]=a,e[2]=h):h=e[2];const k=h;let b;e[3]!==a?(b=cl(a),e[3]=a,e[4]=b):b=e[4];const j=b,[x,S]=d.useState(!1);let v;e[5]!==j||e[6]!==r||e[7]!==u||e[8]!==l||e[9]!==f?(v=ee=>s.jsxs(s.Fragment,{children:[j?s.jsxs(ee,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(Q,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}):null,s.jsxs(ee,{onClick:L=>{L.stopPropagation(),u()},children:[s.jsx(Q,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),s.jsxs(ee,{onClick:L=>{L.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[5]=j,e[6]=r,e[7]=u,e[8]=l,e[9]=f,e[10]=v):v=e[10];const N=v,y=!k&&x,I=o?"bg-interactive-selection":"hover:bg-interactive-hover";let w;e[11]!==I?(w=Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",I),e[11]=I,e[12]=w):w=e[12];let D;e[13]!==k?(D=!g&&!k?ee=>{ee.preventDefault(),S(!0)}:void 0,e[13]=k,e[14]=D):D=e[14];let C;e[15]!==w||e[16]!==D?(C=s.jsx("div",{className:w,onContextMenu:D}),e[15]=w,e[16]=D,e[17]=C):C=e[17];const A=n?"text-muted-foreground":"text-foreground";let T;e[18]!==A?(T=Ie("typography-ui-label font-normal truncate",A),e[18]=A,e[19]=T):T=e[19];let O;e[20]!==a.name||e[21]!==T?(O=s.jsx("span",{className:T,children:a.name}),e[20]=a.name,e[21]=T,e[22]=O):O=e[22];let z;e[23]!==n||e[24]!==f?(z=n?s.jsx("span",{className:"typography-micro shrink-0 text-[var(--status-warning)]",title:f("settings.skills.sidebar.blockedByPolicyHint"),children:f("settings.skills.sidebar.blockedByPolicy")}):null,e[23]=n,e[24]=f,e[25]=z):z=e[25];let M;e[26]!==O||e[27]!==z?(M=s.jsxs("div",{className:"flex items-center gap-1.5",children:[O,z]}),e[26]=O,e[27]=z,e[28]=M):M=e[28];let P;e[29]!==i||e[30]!==M?(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:M}),e[29]=i,e[30]=M,e[31]=P):P=e[31];let R;e[32]!==k||e[33]!==m||e[34]!==c||e[35]!==N?(R=k?null:s.jsxs(Jn,{open:m,onOpenChange:ee=>{ee&&S(!1),c(ee)},children:[s.jsx(Wn,{asChild:!0,children:s.jsx(q,{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(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:N(Fn)})]}),e[32]=k,e[33]=m,e[34]=c,e[35]=N,e[36]=R):R=e[36];let F;e[37]!==P||e[38]!==R?(F=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,R]}),e[37]=P,e[38]=R,e[39]=F):F=e[39];let _;e[40]!==F||e[41]!==C?(_=s.jsx(Ja,{render:C,children:F}),e[40]=F,e[41]=C,e[42]=_):_=e[42];let B;e[43]!==k||e[44]!==N?(B=k?null:s.jsx(Ga,{className:"w-fit min-w-20",children:N(Wa)}),e[43]=k,e[44]=N,e[45]=B):B=e[45];let V;return e[46]!==_||e[47]!==B||e[48]!==y?(V=s.jsxs(Qa,{open:y,onOpenChange:S,children:[_,B]}),e[46]=_,e[47]=B,e[48]=y,e[49]=V):V=e[49],V};function Vx(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Hx(t){return t.loadSkills}function qx(t){return t.scope==="project"}function Gx(t){return t.scope==="user"}function Wx(t,e){return t.localeCompare(e)}function Jx(t,e){return t.name.localeCompare(e.name)}function Qx(t,e){return t.name.localeCompare(e.name)}const Yx=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Zx=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},Xx=t=>t.transport==="account"&&!!t.account||t.transport==="ssh"&&!!t.sshCredentialId,ev=({open:t,onOpenChange:e,catalogId:a=null})=>{const{t:n}=ze(),o=bn(F=>F.scanRepo),i=bn(F=>F.loadCatalog),r=bn(F=>F.loadSource),l=bn(F=>F.setSelectedSource),u=bn(F=>F.isScanning),m=ma(F=>F.profiles),c=ma(F=>F.loadProfiles),[f,p]=d.useState(""),[g,h]=d.useState(""),[k,b]=d.useState(""),[j,x]=d.useState(null),[S,v]=d.useState(null),[N,y]=d.useState(!1),[I,w]=d.useState(null),D=d.useRef(0),C=d.useRef(0),A=d.useCallback(()=>{D.current+=1,y(!1),v(null)},[]);d.useEffect(()=>{if(!t)return;const F=++C.current;return D.current+=1,p(""),h(""),b(""),v(null),y(!1),w(null),c(),x(null),(async()=>{const _=await jn();if(C.current!==F)return;const B=_?_.skillCatalogs??[]:null;if(x(B),!B||!a)return;const V=B.find(ee=>ee.id===a);V&&(p(V.label),h(V.source),b(V.subpath??""),w(V.gitIdentityId??null),y(!1))})(),()=>{C.current+=1,D.current+=1}},[t,a,c]);const T=d.useMemo(()=>m.filter(Xx),[m]),O=!I||I===Xm||m.some(F=>F.id===I&&Eg(F)==="system")?"none":I,z=m.find(F=>F.id===O),M=d.useMemo(()=>{const F=g.trim(),_=k.trim();return(j??[]).some(B=>{if(B.id===a)return!1;const V=(B.source||"").trim(),ee=(B.subpath||"").trim();return V===F&&ee===_})},[a,j,g,k]),P=async()=>{const F=g.trim();if(!F){G.error(n("settings.skills.catalog.add.toast.repositoryRequired"));return}f.trim()||p(Zx(F)),y(!1),v(null);const _=D.current+1;D.current=_;const B=await o({source:F,subpath:k.trim()||void 0,gitIdentityId:I||void 0});if(D.current!==_)return;if(!B.ok){if(B.error?.kind==="authRequired"){if(is()){G.error(n("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}G.error(n("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}G.error(B.error?.message||n("settings.skills.catalog.add.toast.scanFailed"));return}const V=B.items?.length||0;if(v(V),V===0){G.error(n("settings.skills.catalog.add.toast.noSkillsFound")),y(!1);return}y(!0),G.success(n("settings.skills.catalog.shared.toast.foundSkills",{count:V}))},R=async()=>{const F=f.trim(),_=g.trim(),B=k.trim();if(!F){G.error(n("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!_){G.error(n("settings.skills.catalog.add.toast.repositoryRequired"));return}const V=j?.find(H=>H.id===a);if((!a||!V||V.source!==_||(V.subpath??"")!==B||(V.gitIdentityId??null)!==I)&&!N){G.error(n("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(M){G.error(n("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const L={id:a??Yx(),label:F,source:_};if(B&&(L.subpath=B),I&&(L.gitIdentityId=I),j===null){G.error(n("settings.skills.catalog.add.toast.saveFailed"));return}if(a&&!V){G.error(n("settings.skills.catalog.add.toast.saveFailed"));return}const $=a?j.map(H=>H.id===a?L:H):[...j,L];try{if(!(await gt({skillCatalogs:$})).ok)throw new Error(n("settings.skills.catalog.add.toast.saveFailed"));x($),await i({refresh:!0})&&await r(L.id,{refresh:!0}),l(L.id),e(!1)}catch(H){G.error(H instanceof Error?H.message:n("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(Ft,{open:t,onOpenChange:e,children:s.jsxs(Lt,{className:"max-w-xl",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:n(a?"settings.skills.catalog.edit.title":"settings.skills.catalog.add.title")}),s.jsxs($t,{children:[n("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),n("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:n("settings.skills.catalog.add.field.catalogName")}),s.jsx(Be,{value:f,onChange:F=>p(F.target.value),placeholder:n("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:n("settings.skills.catalog.add.field.repository")}),s.jsx(Gt,{children:n("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(Be,{value:g,onChange:F=>{h(F.target.value),A()},placeholder:n("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:n("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(Be,{value:k,onChange:F=>{b(F.target.value),A()},placeholder:n("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),(T.length>0||O!=="none")&&!is()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.skills.catalog.shared.auth.description")}),s.jsx(Gt,{children:n("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Tt,{value:O,onValueChange:F=>{w(F==="none"?null:F),A()},children:[s.jsx(Pt,{className:"w-fit","aria-label":n("settings.skills.catalog.shared.auth.description"),children:s.jsx("span",{children:O==="none"?n("settings.skills.catalog.shared.auth.default"):z?.name??O})}),s.jsxs(At,{align:"start",className:"max-w-80",portalToBody:!0,children:[s.jsxs(at,{value:"none",children:[s.jsx(Q,{name:"terminal-box",className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.skills.catalog.shared.auth.default")}),s.jsx("span",{className:"typography-meta text-muted-foreground whitespace-normal",children:n("settings.skills.catalog.shared.auth.defaultHint")})]})]}),O!=="none"&&!T.some(F=>F.id===O)&&s.jsx(at,{value:O,disabled:!0,children:z?.name??O}),T.map(F=>s.jsxs(at,{value:F.id,children:[s.jsx(Q,{name:F.transport==="ssh"?"key":F.account?.provider==="gitlab"?"gitlab":"github",className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:F.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:F.transport==="ssh"?n("settings.skills.catalog.shared.auth.sshHint"):n("settings.skills.catalog.shared.auth.accountHint")})]})]},F.id))]})]})]}):null,S!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:n("settings.skills.catalog.add.scanResult",{count:S})}):null,M?s.jsx("div",{className:"typography-meta text-muted-foreground",children:n("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:n("settings.common.actions.cancel")}),s.jsxs(q,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{P()},disabled:u||!g.trim(),children:[s.jsx(Q,{name:"git-repository",className:"h-4 w-4"}),n(u?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(q,{size:"sm",onClick:()=>{R()},disabled:M||j===null||!f.trim()||!g.trim()||(!a||!j.some(F=>F.id===a&&F.source===g.trim()&&(F.subpath??"")===k.trim()&&(F.gitIdentityId??null)===I))&&!N,children:n(a?"settings.skills.catalog.edit.actions.save":"settings.skills.catalog.add.actions.addCatalog")})]})]})})},tv=t=>{const e=Ke.c(85),{open:a,onOpenChange:n,conflicts:o,onConfirm:i}=t,{t:r}=ze();let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={},e[0]=l):l=e[0];const[u,m]=d.useState(l);let c,f;e[1]!==o||e[2]!==a?(c=()=>{if(!a)return;const te={};for(const J of o)te[J.skillName]="skip";m(te)},f=[a,o],e[1]=o,e[2]=a,e[3]=c,e[4]=f):(c=e[3],f=e[4]),d.useEffect(c,f);let p;e[5]!==o?(p=te=>{const J={};for(const ie of o)J[ie.skillName]=te;m(J)},e[5]=o,e[6]=p):p=e[6];const g=p;let h;e[7]!==o||e[8]!==u?(h=o.length>0&&o.every(te=>u[te.skillName]),e[7]=o,e[8]=u,e[9]=h):h=e[9];const k=h;let b;e[10]!==r?(b=r("settings.skills.catalog.conflicts.title"),e[10]=r,e[11]=b):b=e[11];let j;e[12]!==b?(j=s.jsx(Ut,{children:b}),e[12]=b,e[13]=j):j=e[13];let x;e[14]!==r?(x=r("settings.skills.catalog.conflicts.description"),e[14]=r,e[15]=x):x=e[15];let S;e[16]!==x?(S=s.jsx($t,{children:x}),e[16]=x,e[17]=S):S=e[17];let v;e[18]!==j||e[19]!==S?(v=s.jsxs(zt,{children:[j,S]}),e[18]=j,e[19]=S,e[20]=v):v=e[20];let N;e[21]!==o.length||e[22]!==r?(N=r("settings.skills.catalog.conflicts.count",{count:o.length}),e[21]=o.length,e[22]=r,e[23]=N):N=e[23];let y;e[24]!==N?(y=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[24]=N,e[25]=y):y=e[25];let I;e[26]!==g?(I=()=>g("skip"),e[26]=g,e[27]=I):I=e[27];let w;e[28]!==r?(w=r("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=r,e[29]=w):w=e[29];let D;e[30]!==I||e[31]!==w?(D=s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:I,children:w}),e[30]=I,e[31]=w,e[32]=D):D=e[32];let C;e[33]!==g?(C=()=>g("overwrite"),e[33]=g,e[34]=C):C=e[34];let A;e[35]!==r?(A=r("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=r,e[36]=A):A=e[36];let T;e[37]!==C||e[38]!==A?(T=s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:A}),e[37]=C,e[38]=A,e[39]=T):T=e[39];let O;e[40]!==D||e[41]!==T?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[D,T]}),e[40]=D,e[41]=T,e[42]=O):O=e[42];let z;e[43]!==y||e[44]!==O?(z=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y,O]}),e[43]=y,e[44]=O,e[45]=z):z=e[45];let M;if(e[46]!==o||e[47]!==u||e[48]!==r){let te;e[50]!==u||e[51]!==r?(te=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:r("settings.skills.catalog.conflicts.installedIn",{scope:J.scope==="project"?r("settings.skills.catalog.conflicts.scope.project"):r("settings.skills.catalog.conflicts.scope.user"),source:J.source==="agents"?r("settings.skills.catalog.conflicts.source.agents"):r("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Tt,{value:u[J.skillName]||"skip",onValueChange:ie=>m(pe=>({...pe,[J.skillName]:ie})),children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(u[J.skillName]||"skip")==="overwrite"?r("settings.skills.catalog.conflicts.decision.overwrite"):r("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(at,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(at,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},J.skillName),e[50]=u,e[51]=r,e[52]=te):te=e[52],M=o.map(te),e[46]=o,e[47]=u,e[48]=r,e[49]=M}else M=e[49];let P;e[53]!==M?(P=s.jsx("div",{className:"space-y-2",children:M}),e[53]=M,e[54]=P):P=e[54];let R;e[55]!==z||e[56]!==P?(R=s.jsxs("div",{className:"space-y-3",children:[z,P]}),e[55]=z,e[56]=P,e[57]=R):R=e[57];let F;e[58]!==n?(F=()=>n(!1),e[58]=n,e[59]=F):F=e[59];let _;e[60]!==r?(_=r("settings.common.actions.cancel"),e[60]=r,e[61]=_):_=e[61];let B;e[62]!==F||e[63]!==_?(B=s.jsx(q,{size:"sm",variant:"ghost",onClick:F,children:_}),e[62]=F,e[63]=_,e[64]=B):B=e[64];let V;e[65]!==u||e[66]!==i?(V=()=>i(u),e[65]=u,e[66]=i,e[67]=V):V=e[67];const ee=!k;let L;e[68]!==r?(L=r("settings.skills.catalog.conflicts.actions.continue"),e[68]=r,e[69]=L):L=e[69];let $;e[70]!==V||e[71]!==ee||e[72]!==L?($=s.jsx(q,{size:"sm",onClick:V,disabled:ee,children:L}),e[70]=V,e[71]=ee,e[72]=L,e[73]=$):$=e[73];let H;e[74]!==B||e[75]!==$?(H=s.jsxs(Xt,{children:[B,$]}),e[74]=B,e[75]=$,e[76]=H):H=e[76];let W;e[77]!==v||e[78]!==R||e[79]!==H?(W=s.jsxs(Lt,{className:"max-w-2xl",children:[v,R,H]}),e[77]=v,e[78]=R,e[79]=H,e[80]=W):W=e[80];let Z;return e[81]!==n||e[82]!==a||e[83]!==W?(Z=s.jsx(Ft,{open:a,onOpenChange:n,children:W}),e[81]=n,e[82]=a,e[83]=W,e[84]=Z):Z=e[84],Z},Po=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function Ci(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Lu(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Po.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const sv=t=>{const e=Ke.c(125),{open:a,onOpenChange:n,items:o}=t,{t:i}=ze(),r=bn(nv),l=bn(av),u=bn(iv),[m,c]=d.useState("user"),[f,p]=d.useState("opencode"),g=dn(ov),h=dn(rv),[k,b]=d.useState(null),[j,x]=d.useState(!1);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[0]=S):S=e[0];const[v,N]=d.useState(S),[y,I]=d.useState(null);let w,D;e[1]!==h||e[2]!==a?(w=()=>{a&&(c("user"),p("opencode"),b(h),x(!1),N([]),I(null))},D=[a,h],e[1]=h,e[2]=a,e[3]=w,e[4]=D):(w=e[3],D=e[4]),d.useEffect(w,D);let C;e[5]!==i?(C=Ae=>{switch(Ae){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=C):C=e[6];const A=C;let T;e[7]!==i?(T=Ae=>{switch(Ae){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=T):T=e[8];const O=T;let z;e:{if(g.length===0){z=null;break e}if(k&&g.some(Ae=>Ae.id===k)){z=k;break e}if(h&&g.some(Ae=>Ae.id===h)){z=h;break e}z=g[0]?.id??null}const M=z;let P;e:{if(m!=="project"){P=null;break e}const Ae=M;if(!Ae){P=null;break e}let Re;if(e[9]!==Ae||e[10]!==g){let nt;e[12]!==Ae?(nt=pt=>pt.id===Ae,e[12]=Ae,e[13]=nt):nt=e[13],Re=g.find(nt),e[9]=Ae,e[10]=g,e[11]=Re}else Re=e[11];P=Re?.path??null}const R=P;let F;e[14]!==r||e[15]!==o||e[16]!==l||e[17]!==n||e[18]!==i?(F=async Ae=>{const Re=await r({source:Ae.source,subpath:Ae.subpath,gitIdentityId:o[0]?.gitIdentityId,scope:Ae.scope,targetSource:Ae.targetSource,selections:Ae.skillDirs.map(lv),conflictPolicy:"prompt",conflictDecisions:Ae.conflictDecisions},{directory:Ae.directoryOverride??null});if(Re.ok){const $e=Re.skipped??[];$e.length>0?G.warning(i("settings.skills.catalog.installSkill.toast.skipped",{skills:$e.map(cv).join(", ")})):G.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1),await Promise.all([...new Set(o.map(dv))].map(nt=>l(nt,{refresh:!0})));return}if(Re.error?.kind==="conflicts"){I({source:Ae.source,subpath:Ae.subpath,scope:Ae.scope,targetSource:Ae.targetSource,skillDirs:Ae.skillDirs,directoryOverride:Ae.directoryOverride??null}),N(Re.error.conflicts),x(!0);return}if(Re.error?.kind==="authRequired"){G.error(Re.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}G.error(Re.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=r,e[15]=o,e[16]=l,e[17]=n,e[18]=i,e[19]=F):F=e[19];const _=F;if(o.length===0)return null;let B;e[20]!==o.length||e[21]!==i?(B=o.length===1?i("settings.skills.catalog.installSkill.title"):i("settings.skills.catalog.installFromRepo.title"),e[20]=o.length,e[21]=i,e[22]=B):B=e[22];let V;e[23]!==B?(V=s.jsx(Ut,{children:B}),e[23]=B,e[24]=V):V=e[24];let ee;e[25]!==o[0].skillName||e[26]!==o.length||e[27]!==i?(ee=o.length===1?s.jsxs(s.Fragment,{children:[i("settings.skills.catalog.installSkill.descriptionPrefix")," ",s.jsx("span",{className:"font-semibold text-foreground",children:o[0].skillName})," ",i("settings.skills.catalog.installSkill.descriptionSuffix")]}):i("settings.skills.catalog.installFromRepo.selectedCount",{selected:o.length,total:o.length}),e[25]=o[0].skillName,e[26]=o.length,e[27]=i,e[28]=ee):ee=e[28];let L;e[29]!==ee?(L=s.jsx($t,{children:ee}),e[29]=ee,e[30]=L):L=e[30];let $;e[31]!==V||e[32]!==L?($=s.jsxs(zt,{children:[V,L]}),e[31]=V,e[32]=L,e[33]=$):$=e[33];let H;e[34]!==i?(H=i("settings.skills.catalog.installSkill.field.destination"),e[34]=i,e[35]=H):H=e[35];let W;e[36]!==H?(W=s.jsx("span",{className:"typography-ui-label text-foreground",children:H}),e[36]=H,e[37]=W):W=e[37];let Z;e[38]!==m||e[39]!==f?(Z=Ci(m,f),e[38]=m,e[39]=f,e[40]=Z):Z=e[40];let te;e[41]===Symbol.for("react.memo_cache_sentinel")?(te=Ae=>{const Re=Po.find(nt=>nt.value===Ae);if(!Re)return;const $e=Lu(Re.value);c($e.scope),p($e.source==="agents"?"agents":"opencode")},e[41]=te):te=e[41];let J;e[42]!==m?(J=m==="user"?s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),e[42]=m,e[43]=J):J=e[43];let ie;e[44]!==f?(ie=f==="agents"?s.jsx(Q,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[44]=f,e[45]=ie):ie=e[45];let pe;e[46]!==A||e[47]!==m||e[48]!==f?(pe=A(Ci(m,f)),e[46]=A,e[47]=m,e[48]=f,e[49]=pe):pe=e[49];let X;e[50]!==pe?(X=s.jsx("span",{children:pe}),e[50]=pe,e[51]=X):X=e[51];let xe;e[52]!==J||e[53]!==ie||e[54]!==X?(xe=s.jsxs(Pt,{className:"w-fit gap-1.5",children:[J,ie,X]}),e[52]=J,e[53]=ie,e[54]=X,e[55]=xe):xe=e[55];let Y;e[56]!==O||e[57]!==A?(Y=Po.map(Ae=>s.jsx(at,{value:Ae.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:[Ae.scope==="user"?s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),Ae.source==="agents"?s.jsx(Q,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:A(Ae.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:O(Ae.value)})]})},Ae.value)),e[56]=O,e[57]=A,e[58]=Y):Y=e[58];let be;e[59]!==Y?(be=s.jsx(At,{align:"start",portalToBody:!0,children:Y}),e[59]=Y,e[60]=be):be=e[60];let De;e[61]!==Z||e[62]!==xe||e[63]!==be?(De=s.jsxs(Tt,{value:Z,onValueChange:te,children:[xe,be]}),e[61]=Z,e[62]=xe,e[63]=be,e[64]=De):De=e[64];let ve;e[65]!==W||e[66]!==De?(ve=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[W,De]}),e[65]=W,e[66]=De,e[67]=ve):ve=e[67];let se;e[68]!==g||e[69]!==M||e[70]!==m||e[71]!==i?(se=m==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),g.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Tt,{value:M??"",onValueChange:Ae=>b(Ae),disabled:g.length===1,children:[s.jsx(Pt,{className:"w-fit",children:s.jsx(Kt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",portalToBody:!0,children:g.map(uv)})]})]}),e[68]=g,e[69]=M,e[70]=m,e[71]=i,e[72]=se):se=e[72];let ge;e[73]!==o?(ge=o.flatMap(mv).length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:o.flatMap(pv).join(" · ")}):null,e[73]=o,e[74]=ge):ge=e[74];let ne;e[75]!==ve||e[76]!==se||e[77]!==ge?(ne=s.jsxs("div",{className:"mt-2 space-y-3",children:[ve,se,ge]}),e[75]=ve,e[76]=se,e[77]=ge,e[78]=ne):ne=e[78];let Se;e[79]!==n?(Se=()=>n(!1),e[79]=n,e[80]=Se):Se=e[80];let ke;e[81]!==i?(ke=i("settings.common.actions.cancel"),e[81]=i,e[82]=ke):ke=e[82];let Te;e[83]!==Se||e[84]!==ke?(Te=s.jsx(q,{size:"sm",variant:"ghost",onClick:Se,children:ke}),e[83]=Se,e[84]=ke,e[85]=Te):Te=e[85];let Ee;e[86]!==R||e[87]!==u||e[88]!==o||e[89]!==m?(Ee=u||o.some(gv)||m==="project"&&!R,e[86]=R,e[87]=u,e[88]=o,e[89]=m,e[90]=Ee):Ee=e[90];let Le;e[91]!==R||e[92]!==_||e[93]!==o||e[94]!==m||e[95]!==f?(Le=()=>{_({source:o[0].repoSource,subpath:o[0].repoSubpath,scope:m,targetSource:f,skillDirs:o.map(fv),directoryOverride:R})},e[91]=R,e[92]=_,e[93]=o,e[94]=m,e[95]=f,e[96]=Le):Le=e[96];let ce;e[97]!==u||e[98]!==i?(ce=i(u?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[97]=u,e[98]=i,e[99]=ce):ce=e[99];let Me;e[100]!==Ee||e[101]!==Le||e[102]!==ce?(Me=s.jsx(q,{size:"sm",disabled:Ee,onClick:Le,children:ce}),e[100]=Ee,e[101]=Le,e[102]=ce,e[103]=Me):Me=e[103];let Fe;e[104]!==Te||e[105]!==Me?(Fe=s.jsxs(Xt,{children:[Te,Me]}),e[104]=Te,e[105]=Me,e[106]=Fe):Fe=e[106];let me;e[107]!==$||e[108]!==ne||e[109]!==Fe?(me=s.jsxs(Lt,{className:"max-w-md",children:[$,ne,Fe]}),e[107]=$,e[108]=ne,e[109]=Fe,e[110]=me):me=e[110];let de;e[111]!==n||e[112]!==a||e[113]!==me?(de=s.jsx(Ft,{open:a,onOpenChange:n,children:me}),e[111]=n,e[112]=a,e[113]=me,e[114]=de):de=e[114];let Pe;e[115]!==y||e[116]!==_?(Pe=Ae=>{y&&(_({source:y.source,subpath:y.subpath,scope:y.scope,targetSource:y.targetSource,skillDirs:y.skillDirs,conflictDecisions:Ae,directoryOverride:y.directoryOverride??null}),x(!1))},e[115]=y,e[116]=_,e[117]=Pe):Pe=e[117];let he;e[118]!==v||e[119]!==j||e[120]!==Pe?(he=s.jsx(tv,{open:j,onOpenChange:x,conflicts:v,onConfirm:Pe}),e[118]=v,e[119]=j,e[120]=Pe,e[121]=he):he=e[121];let Ue;return e[122]!==de||e[123]!==he?(Ue=s.jsxs(s.Fragment,{children:[de,he]}),e[122]=de,e[123]=he,e[124]=Ue):Ue=e[124],Ue};function nv(t){return t.installSkills}function av(t){return t.loadSource}function iv(t){return t.isInstalling}function ov(t){return t.projects}function rv(t){return t.activeProjectId}function lv(t){return{skillDir:t}}function cv(t){return`${t.skillName} (${t.reason})`}function dv(t){return t.sourceId}function uv(t){return s.jsx(at,{value:t.id,children:t.label||t.path},t.id)}function mv(t){return t.warnings??[]}function pv(t){return t.warnings??[]}function gv(t){return!t.installable}function fv(t){return t.skillDir}const hv=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,bv=t=>{const e=t.trim();return hv.test(e)?`https://github.com/${e}`:null},xv=t=>{const e=bv(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let so=null;const vv=t=>{const e=Nl();return(!so||so.locale!==e)&&(so={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),so.formatter.format(t)},yv=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 o=Math.floor(n/60);if(o<24)return{key:"common.relative.hoursAgoShort",count:o};const i=Math.floor(o/24);if(i<7)return{key:"common.relative.daysAgoShort",count:i};const r=Math.floor(i/7);return r<52?{key:"common.relative.weeksAgoShort",count:r}:{key:"common.relative.yearsAgoShort",count:Math.floor(i/365)}},jv=t=>{const e=Ke.c(50),{source:a,isActive:n,isLoading:o,skillsCount:i,onSelect:r,t:l}=t,u=a.stars??null;let m,c,f,p,g,h,k,b,j,x;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==u||e[8]!==l){const y=a.repoUpdatedAt?yv(a.repoUpdatedAt):null;b="button",j=r,x=n;const I=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==I?(c=Ie("oc-surface-elevated w-full min-h-24 text-left rounded-lg border bg-surface-elevated p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",I),e[19]=I,e[20]=c):c=e[20],g="min-w-0 flex-1 block";let w;e[21]!==a.label?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=w):w=e[22];let D;e[23]!==o||e[24]!==i||e[25]!==l?(D=o?s.jsx(Q,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:l("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=o,e[24]=i,e[25]=l,e[26]=D):D=e[26],e[27]!==w||e[28]!==D?(h=s.jsxs("span",{className:"flex items-center gap-2",children:[w,D]}),e[27]=w,e[28]=D,e[29]=h):h=e[29],e[30]!==a.source?(k=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]=k):k=e[31],m="flex items-center gap-3 mt-1",e[32]!==u||e[33]!==l?(f=u!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:l("settings.skills.catalog.page.source.stars",{count:u}),children:[s.jsx(Q,{name:"star",className:"h-3 w-3"}),vv(u)]}),e[32]=u,e[33]=l,e[34]=f):f=e[34],p=y&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:y.key==="common.relative.justNow"?l(y.key):l("settings.skills.catalog.page.source.updated",{time:l(y.key,{count:y.count})})}),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=u,e[8]=l,e[9]=m,e[10]=c,e[11]=f,e[12]=p,e[13]=g,e[14]=h,e[15]=k,e[16]=b,e[17]=j,e[18]=x}else m=e[9],c=e[10],f=e[11],p=e[12],g=e[13],h=e[14],k=e[15],b=e[16],j=e[17],x=e[18];let S;e[35]!==m||e[36]!==f||e[37]!==p?(S=s.jsxs("span",{className:m,children:[f,p]}),e[35]=m,e[36]=f,e[37]=p,e[38]=S):S=e[38];let v;e[39]!==S||e[40]!==g||e[41]!==h||e[42]!==k?(v=s.jsxs("span",{className:g,children:[h,k,S]}),e[39]=S,e[40]=g,e[41]=h,e[42]=k,e[43]=v):v=e[43];let N;return e[44]!==c||e[45]!==v||e[46]!==b||e[47]!==j||e[48]!==x?(N=s.jsx("button",{type:b,onClick:j,"aria-pressed":x,className:c,children:v}),e[44]=c,e[45]=v,e[46]=b,e[47]=j,e[48]=x,e[49]=N):N=e[49],N},kv=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=ze(),{sources:o,itemsBySource:i,selectedSourceId:r,setSelectedSource:l,loadCatalog:u,loadSource:m,isLoadingCatalog:c,isLoadingSource:f,loadedSourceIds:p,lastCatalogError:g}=bn(Ms(ne=>({sources:ne.sources,itemsBySource:ne.itemsBySource,selectedSourceId:ne.selectedSourceId,setSelectedSource:ne.setSelectedSource,loadCatalog:ne.loadCatalog,loadSource:ne.loadSource,isLoadingCatalog:ne.isLoadingCatalog,isLoadingSource:ne.isLoadingSource,loadedSourceIds:ne.loadedSourceIds,lastCatalogError:ne.lastCatalogError}))),[h,k]=d.useState(""),[b,j]=d.useState(!1),[x,S]=d.useState(null),[v,N]=d.useState(!1),[y,I]=d.useState([]),[w,D]=d.useState(new Set),[C,A]=d.useState([]),[T,O]=d.useState(!1),[z,M]=d.useState(!1),[P,R]=d.useState(!1),F=d.useRef(null),_=Bs(ne=>ne.deleteSkill),B=Ks();d.useEffect(()=>{u()},[u]),d.useEffect(()=>{const ne=o.filter(Te=>!p[Te.id]);if(ne.length===0)return;let Se=!1;return(async()=>{for(const Te of ne){if(Se)return;await m(Te.id)}})(),()=>{Se=!0}},[o,p,m]),d.useEffect(()=>{!r||p[r]||m(r)},[r,p,m]),d.useEffect(()=>{const ne=Se=>{(Se.metaKey||Se.ctrlKey)&&Se.key.toLowerCase()==="k"&&(Se.preventDefault(),F.current?.focus())};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[]);const V=h.trim().length>0,ee=d.useMemo(()=>V?Qn(o.flatMap(ne=>i[ne.id]||[]),h,ne=>[ne.skillName,ne.frontmatterName,ne.description]):r?i[r]||[]:[],[o,i,r,h,V]),L=d.useMemo(()=>o.find(ne=>ne.id===r)||null,[o,r]),$=!!(r&&r.startsWith("custom:")),H=d.useCallback(ne=>`${ne.sourceId}:${ne.skillDir}`,[]),W=d.useMemo(()=>ee.filter(ne=>w.has(H(ne))),[ee,H,w]),Z=W[0]?.sourceId??(V?ee.find(ne=>ne.installable||ne.installed?.isInstalled)?.sourceId:r),te=W.filter(ne=>!ne.installed?.isInstalled),J=W.filter(ne=>ne.installed?.isInstalled),ie=ee.filter(ne=>(ne.installable||ne.installed?.isInstalled)&&ne.sourceId===Z),pe=o.find(ne=>ne.id===Z)?.label,X=ie.length>0&&ie.every(ne=>w.has(H(ne)));d.useEffect(()=>{const ne=new Set(ee.filter(Se=>Se.installable||Se.installed?.isInstalled).map(H));D(Se=>new Set([...Se].filter(ke=>ne.has(ke))))},[ee,H]);const xe=(ne,Se)=>{const ke=H(ne);D(Te=>{const Ee=ee.find(ce=>Te.has(H(ce)));if(Se&&Ee&&Ee.sourceId!==ne.sourceId)return Te;const Le=new Set(Te);return Se?Le.add(ke):Le.delete(ke),Le})},Y=ne=>{D(Se=>{const ke=new Set(Se);for(const Te of ie)ne?ke.add(H(Te)):ke.delete(H(Te));return ke})},be=ne=>{ne.length!==0&&(I(ne),N(!0))},De=async()=>{if(C.length===0)return;O(!0);const ne=[],Se=new Set;for(const ke of C){const Te=ke.installed?.scope==="project"?B:null;(ke.installed?.scope!=="project"||!!Te)&&await _(ke.skillName,Te)?(Se.add(ke.sourceId),D(Le=>{const ce=new Set(Le);return ce.delete(H(ke)),ce})):ne.push(ke)}A(ne),await Promise.all([...Se].map(ke=>m(ke,{refresh:!0}))),ne.length>0?G.error(n("settings.skills.sidebar.toast.deleteSkillFailed")):C.length===1?G.success(n("settings.skills.sidebar.toast.skillDeleted",{name:C[0].skillName})):G.success(n("settings.skills.catalog.page.toast.deleted",{count:C.length})),O(!1)},ve=async()=>{if(!(!r||!$)){M(!0);try{const ne=await jn();if(!ne){G.error(n("settings.skills.catalog.add.toast.saveFailed"));return}const ke=(ne.skillCatalogs??[]).filter(Ee=>Ee.id!==r);if(!(await gt({skillCatalogs:ke})).ok){G.error(n("settings.skills.catalog.add.toast.saveFailed"));return}if(!await u({refresh:!0})){G.error(n("settings.skills.catalog.add.toast.saveFailed"));return}R(!1)}catch{G.error(n("settings.skills.catalog.add.toast.saveFailed"))}finally{M(!1)}}},se=V?n("settings.skills.catalog.page.list.searchTitle"):L?.label??"",ge=!V&&r!==null&&!p[r]&&(f||c);return s.jsxs(s.Fragment,{children:[s.jsxs(Qt,{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(kl,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:ne=>{(ne==="manual"||ne==="external")&&e(ne)},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(Q,{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:F,value:h,onChange:ne=>k(ne.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:Ie("h-8 pl-8 w-full",h&&"pr-8")}),h&&s.jsx("button",{type:"button",onClick:()=>{k(""),F.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(Q,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(Ve,{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:[o.map(ne=>s.jsx(jv,{source:ne,isActive:ne.id===r,isLoading:f&&!p[ne.id],skillsCount:p[ne.id]?(i[ne.id]||[]).length:null,onSelect:()=>l(ne.id),t:n},ne.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>{S(null),j(!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(Q,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),g&&s.jsx(Ve,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:g.message}),g.kind==="authRequired"&&$&&s.jsx(q,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>{S(r),j(!0)},children:n("settings.skills.catalog.page.actions.editCatalog")})]})}),s.jsxs(Ve,{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:se}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:ee.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{r&&!V?m(r,{refresh:!0}):u({refresh:!0})},disabled:c||f,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(Q,{name:"refresh",className:Ie("h-3.5 w-3.5",(c||f)&&"animate-spin")})}),$&&!V&&s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{S(r),j(!0)},title:n("settings.skills.catalog.page.actions.editCatalog"),children:s.jsx(Q,{name:"edit",className:"h-3.5 w-3.5"})}),$&&!V&&s.jsx(q,{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:z,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),ie.length>0&&s.jsxs("div",{className:"flex items-center justify-between gap-3 pb-2 min-h-8",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(Ai,{checked:X,indeterminate:W.length>0&&!X,onChange:ne=>Y(ne),ariaLabel:n(X?"settings.skills.catalog.page.actions.deselectAll":"settings.skills.catalog.installFromRepo.actions.selectAll")}),s.jsxs("span",{children:[n(X?"settings.skills.catalog.page.actions.deselectAll":"settings.skills.catalog.installFromRepo.actions.selectAll"),V&&pe?` · ${pe}`:""]})]}),W.length>0&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:n("settings.skills.catalog.installFromRepo.selectedCount",{selected:W.length,total:ie.length})}),te.length>0&&s.jsx(q,{size:"xs",onClick:()=>be(te),children:n("settings.skills.catalog.installFromRepo.actions.installSelected")}),J.length>0&&s.jsx(q,{size:"xs",variant:"destructive",onClick:()=>A(J),children:n("settings.skills.catalog.page.actions.delete")})]})]}),ge||f&&ee.length===0||c&&o.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(Q,{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")})]}):ee.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:ee.map(ne=>{const Se=ne.installed?.isInstalled,ke=ne.installed?.scope,Te=xv(ne);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(Ai,{checked:w.has(H(ne)),onChange:Ee=>xe(ne,Ee),disabled:!Se&&!ne.installable||W.length>0&&Z!==ne.sourceId,ariaLabel:`${n(Se?"settings.skills.catalog.page.actions.delete":"settings.skills.catalog.shared.actions.install")} ${ne.skillName}`}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:ne.skillName}),Se&&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:ke||n("settings.skills.catalog.page.badge.unknown")})}),!ne.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")})]}),ne.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:ne.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:[Te?s.jsxs("a",{href:Te,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(Q,{name:"github",className:"h-3 w-3 shrink-0"}),ne.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:ne.repoSource}),ne.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:ne.skillDir})]})]}),ne.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:ne.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[Te&&s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(Te,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(Q,{name:"external-link",className:"h-3.5 w-3.5"})}),Se?s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-[var(--status-success)] hover:text-[var(--status-error)]",onClick:()=>A([ne]),title:n("settings.skills.sidebar.deleteDialog.title"),children:s.jsx(Q,{name:"check",className:"h-4 w-4"})}):s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",disabled:!ne.installable,onClick:()=>{be([ne])},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${ne.sourceId}:${ne.skillDir}`)})})]})]}),s.jsx(ev,{open:b,onOpenChange:j,catalogId:x}),s.jsx(sv,{open:v,onOpenChange:N,items:y}),s.jsx(Ft,{open:C.length>0,onOpenChange:ne=>!ne&&!T&&A([]),children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:n("settings.skills.sidebar.deleteDialog.title")}),s.jsx($t,{children:C.length===1?n("settings.skills.sidebar.deleteDialog.description",{name:C[0].skillName}):C.map(ne=>ne.skillName).join(", ")})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>A([]),disabled:T,children:n("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",variant:"destructive",onClick:()=>{De()},disabled:T,children:n("settings.common.actions.delete")})]})]})}),s.jsx(Ft,{open:P,onOpenChange:ne=>{z||R(ne)},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>R(!1),disabled:z,children:n("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",variant:"destructive",onClick:()=>{ve()},disabled:z,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},wv=()=>{const t=Ke.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(kv,{mode:"external",onModeChange:Av,showModeTabs:!1}),t[0]=e):e=t[0],e},Sv="SKILL.md",Nv="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",po=(t,e)=>{const a=Mf({description:t}).trimEnd(),n=e.trimStart();return`---
23
+ ${a}
24
+ ---${n?`
25
+
26
+ ${n}`:`
27
+ `}`},Cv=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ku=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=Rf(e[1]);if(Cv(n)){const o=n.description;typeof o=="string"&&(a=o)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Iv=(t,e)=>{const a=Ku(t);return po(e,a.instructions)},Pv=()=>{const{t}=ze(),{currentTheme:e}=xa(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:o,createSkill:i,updateSkill:r,skillDraft:l,setSkillDraft:u,setSelectedSkill:m}=Bs(Ms(fe=>({selectedSkillName:fe.selectedSkillName,getSkillByName:fe.getSkillByName,getSkillDetail:fe.getSkillDetail,createSkill:fe.createSkill,updateSkill:fe.updateSkill,skillDraft:fe.skillDraft,setSkillDraft:fe.setSkillDraft,setSelectedSkill:fe.setSelectedSkill}))),c=Ks(),f=Bs(fe=>yl(fe,c)),p=a?n(a,c):null,g=!!(l&&l.name===a&&!p),h=!!(a&&!p&&!l),k=p?.path==="<built-in>";d.useEffect(()=>{h&&m(null)},[h,m]);const[b,j]=d.useState(""),[x,S]=d.useState("user"),[v,N]=d.useState("opencode"),[y,I]=d.useState(""),[w,D]=d.useState(""),[C,A]=d.useState(!1),[T,O]=d.useState(()=>po("","")),[z,M]=d.useState("edit"),[P,R]=d.useState([]),[F,_]=d.useState([]),[B,V]=d.useState(!1),[ee,L]=d.useState(!1),[$,H]=d.useState(""),[W,Z]=d.useState(""),[te,J]=d.useState(!1),[ie,pe]=d.useState(!1),[X,xe]=d.useState(""),[Y,be]=d.useState(""),[De,ve]=d.useState(null),[se,ge]=d.useState(!1),[ne,Se]=d.useState(""),[ke,Te]=d.useState(null),[Ee,Le]=d.useState(!1),ce=De?Y!==ne:X.trim()!=="",Me=d.useCallback(fe=>{switch(fe){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]),Fe=d.useCallback(fe=>{switch(fe){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]),me=JSON.stringify([c,a,p?.path,g]),de=d.useRef(null),Pe=d.useRef({key:me,markdown:T,disableModelInvocation:C});Pe.current={key:me,markdown:T,disableModelInvocation:C};const he=d.useRef(""),Ue=d.useRef(!1);d.useEffect(()=>{let fe=!1;const ye=(Ge,et,mt)=>{if(Pe.current.key!==me)return;const jt=po(Ge,et),vt=de.current===me,Ct=vt&&Pe.current.markdown!==he.current,Bt=vt&&Pe.current.disableModelInvocation!==Ue.current;de.current=me,he.current=jt,Ue.current=mt,Ct||(I(Ge),D(et),O(jt)),Bt||A(mt)};return(async()=>{if(g&&l){L(!1);const Ge=l.description||"",et=l.instructions||"";j(l.name||""),S(l.scope||"user"),N(l.source==="agents"?"agents":"opencode"),ye(Ge,et,!1),H(""),Z(""),J(!1),R([]),_(l.pendingFiles||[])}else if(a&&p){L(de.current!==me);try{const Ge=await o(a,c);if(!fe&&Pe.current.key===me&&Ge){const et=Ge.sources.md,mt=et.description||"",jt=et.instructions||"",vt=et.disableModelInvocation===!0;ye(mt,jt,vt),H(mt),Z(jt),J(vt),R(et.supportingFiles||[])}}catch(Ge){console.error("Failed to load skill details:",Ge)}finally{fe||L(!1)}}})(),()=>{fe=!0}},[p,g,a,c,f,l,o,me]);const Ae=re(fe=>fe.editorFontSize),Re=d.useMemo(()=>{const fe=[hc(e,{fontSize:Ae})],ye=Yl(Sv);return ye&&fe.push(ye),fe.push(xc.lineWrapping),fe},[e,Ae]),$e=d.useMemo(()=>{const fe=X.trim()||"supporting-file.md",ye=ep(fe),we=!!ye&&ye!=="markdown",Ge=[hc(e,we?{syntaxColors:!1,fontSize:Ae}:{fontSize:Ae})],et=Yl(fe);return et&&Ge.push(et),we&&ye&&Ge.push(Of({language:ye,themeName:e.metadata.id,theme:Kf(e)})),Ge.push(xc.lineWrapping),Ge},[e,X,Ae]),nt=d.useCallback(fe=>{I(fe),O(ye=>Iv(ye,fe))},[]),pt=d.useCallback(fe=>{O(fe);const ye=Ku(fe);I(ye.description??""),D(ye.instructions)},[]),kt=fe=>fe?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(fe)||fe.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),bt=d.useCallback(async()=>{const fe=a?.trim();return g||k||!fe||y===$&&w===W&&C===te?Ds:y.trim()?await r(fe,{name:fe,description:y.trim(),instructions:w.trim()||void 0,targetPath:p?.path,disableModelInvocation:C},c)?(Pe.current.key===me&&(he.current=po(y,w),Ue.current=C,H(y),Z(w),J(C)),yn):gs(t("settings.skills.page.toast.updateSkillFailed")):gs(t("settings.skills.page.toast.descriptionRequired"))},[y,w,C,g,k,$,W,te,p?.path,a,c,me,t,r]),yt=Xa(bt),Je=fe=>{A(fe),g||yt.requestSave()},ct=async()=>{const fe=b.trim().replace(/\s+/g,"-").toLowerCase(),ye=kt(fe);if(ye){G.error(ye);return}if(!y.trim()){G.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f.some(we=>we.name===fe)){G.error(t("settings.skills.page.toast.skillExists"));return}V(!0);try{const we={name:fe,description:y.trim(),instructions:w.trim()||void 0,scope:x,source:v,supportingFiles:F.length>0?F:void 0,disableModelInvocation:C};await i(we,c)?(u(null),_([]),m(fe),G.success(t("settings.skills.page.toast.skillCreated"))):G.error(t("settings.skills.page.toast.createSkillFailed"))}catch(we){console.error("Error creating skill:",we),G.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{V(!1)}},Qe=()=>{u(null),m(null)},it=()=>{ve(null),xe(""),be(""),Se(""),pe(!0)},dt=async fe=>{if(ve(fe),xe(fe),g){const we=F.find(Ge=>Ge.path===fe)?.content||"";be(we),Se(we),pe(!0);return}if(a){ge(!0),pe(!0);try{const{readSupportingFile:ye}=Bs.getState(),we=await ye(a,fe,c);be(we||""),Se(we||"")}catch{G.error(t("settings.skills.page.toast.loadFileContentFailed")),be(""),Se("")}finally{ge(!1)}}},qe=async()=>{if(!X.trim()){G.error(t("settings.skills.page.toast.fileNameRequired"));return}const fe=X.trim(),ye=De!==null;if(g){if(ye)_(et=>et.map(mt=>mt.path===De?{path:fe,content:Y}:mt)),G.success(t("settings.skills.page.toast.fileUpdated",{path:fe}));else{if(F.some(et=>et.path===fe)){G.error(t("settings.skills.page.toast.fileExists"));return}_(et=>[...et,{path:fe,content:Y}]),G.success(t("settings.skills.page.toast.fileAdded",{path:fe}))}pe(!1),ve(null);return}if(!a){G.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:we}=Bs.getState();if(await we(a,fe,Y,c)){G.success(ye?t("settings.skills.page.toast.fileUpdated",{path:fe}):t("settings.skills.page.toast.fileCreated",{path:fe})),pe(!1),ve(null);const et=await o(a,c);et&&R(et.sources.md.supportingFiles||[])}else G.error(t(ye?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},lt=fe=>{if(g){_(ye=>ye.filter(we=>we.path!==fe)),G.success(t("settings.skills.page.toast.fileRemoved",{path:fe}));return}a&&Te(fe)},ae=async()=>{if(!ke||!a)return;Le(!0);const{deleteSupportingFile:fe}=Bs.getState();if(await fe(a,ke,c)){G.success(t("settings.skills.page.toast.fileDeleted",{path:ke}));const we=await o(a,c);we&&R(we.sources.md.supportingFiles||[]),Te(null)}else G.error(t("settings.skills.page.toast.deleteFileFailed"));Le(!1)};return!a&&!l||h?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(Q,{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(Qt,{title:g?t("settings.skills.page.title.newSkill"):a,description:p?t("settings.skills.page.subtitle.skillLocation",{location:Me(Ci(p.scope,p.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:yt.onBlurCapture,children:[s.jsxs(Ve,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[g&&s.jsxs(ht,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Be,{value:b,onChange:fe=>j(fe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Tt,{value:Ci(x,v),onValueChange:fe=>{const ye=Lu(fe);S(ye.scope),N(ye.source==="agents"?"agents":"opencode")},children:[s.jsxs(Pt,{size:_t,className:"w-fit gap-1.5",children:[x==="user"?s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),v==="agents"?s.jsx(Q,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(Ci(x,v))})]}),s.jsx(At,{align:"start",children:Po.map(fe=>s.jsx(at,{value:fe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[fe.scope==="user"?s.jsx(Q,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"folder",className:"h-3.5 w-3.5"}),fe.source==="agents"?s.jsx(Q,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(fe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Fe(fe.value)})]})},fe.value))})]})]}),s.jsx(Et,{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(Ns,{value:y,onChange:fe=>nt(fe.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:k})}),s.jsx(st,{checked:C,onChange:Je,label:t("settings.skills.page.field.disableModelInvocation"),info:t("settings.skills.page.field.disableModelInvocationHint"),disabled:k,className:"pt-2"})]}),s.jsx(Ve,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Ff,{currentMode:z==="preview"?"preview":"edit",onToggle:()=>M(fe=>fe==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:Ie("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Nv),onKeyDown:fe=>{fe.key==="Enter"&&(fe.metaKey||fe.ctrlKey)&&(fe.preventDefault(),yt.requestSave())},children:z==="preview"?s.jsx(Ps,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(tp,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(bc,{value:T,onChange:pt,readOnly:k,extensions:Re,className:"h-full",enableSearch:!0})})}),s.jsx(Ve,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:it,disabled:k,children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const fe=g?F:P;return fe.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:fe.map(ye=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>dt(ye.path),children:[s.jsx(Q,{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:ye.path}),g&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!k&&s.jsx(q,{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:we=>{we.stopPropagation(),lt(ye.path)},children:s.jsx(Q,{name:"delete-bin",className:"h-3 w-3"})})]},ye.path))})})()}),g&&s.jsx(Ve,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(q,{onClick:()=>{ct()},disabled:B||!b.trim()||!y.trim(),size:"xs",className:"!font-normal",children:t(B?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(q,{variant:"ghost",onClick:Qe,disabled:B,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(Ft,{open:ke!==null,onOpenChange:fe=>{!fe&&!Ee&&Te(null)},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.description",{path:ke??""})})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>Te(null),disabled:Ee,children:t("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",variant:"destructive",onClick:ae,disabled:Ee,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Ft,{open:ie,onOpenChange:fe=>{if(fe){pe(!0);return}if(De!==null&&Y!==ne){qe();return}pe(!1),ve(null)},children:s.jsxs(Lt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(zt,{className:"flex-shrink-0",children:[s.jsx(Ut,{children:t(De?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx($t,{children:t(De?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),se?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Nt,children:t("settings.skills.page.fileDialog.field.filePath")}),!De&&s.jsx(Gt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Be,{value:X,onChange:fe=>xe(fe.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:De!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Nt} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(bc,{value:Y,onChange:be,extensions:$e,className:"h-full",enableSearch:!0})})]})]}),s.jsx(Xt,{className:"mt-4",children:De?s.jsx(q,{size:"sm",onClick:()=>{qe()},disabled:se,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>{pe(!1),ve(null)},children:t("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",onClick:()=>{qe()},disabled:se||!ce,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},Kc=t=>{const e=Ke.c(2),{view:a}=t,n=a===void 0?"installed":a;let o;return e[0]!==n?(o=n==="catalog"?s.jsx(wv,{}):s.jsx(Pv,{}),e[0]=n,e[1]=o):o=e[1],o};function Av(){}const Tv=t=>{const e=Ke.c(26),{header:a,footer:n,children:o,className:i,variant:r}=t,l=r===void 0?"sidebar":r,u=is(),m=d.useRef(null),[c,f]=d.useState(!1),[p,g]=d.useState(!1),h=l==="background"||u?"bg-background":"bg-sidebar",k=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const T=m.current;if(!T){f(!1),g(!1);return}if(!(T.scrollHeight>T.clientHeight+1)){f(!1),g(!1);return}f(T.scrollTop>1),g(T.scrollTop+T.clientHeight<T.scrollHeight-1)},e[0]=b):b=e[0];const j=b;let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{j()},e[1]=x):x=e[1];let S;e[2]!==o?(S=[o,j],e[2]=o,e[3]=S):S=e[3],d.useEffect(x,S);let v,N;e[4]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const T=m.current;if(!T)return;const O=()=>j();return T.addEventListener("scroll",O,{passive:!0}),()=>T.removeEventListener("scroll",O)},N=[j],e[4]=v,e[5]=N):(v=e[4],N=e[5]),d.useEffect(v,N);let y;e[6]!==h||e[7]!==i?(y=Ie("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=y):y=e[8];let I;e[9]!==o?(I=s.jsx(Ps,{ref:m,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:o}),e[9]=o,e[10]=I):I=e[10];let w;e[11]!==k||e[12]!==c?(w=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${k} 0%, transparent 100%)`}}),e[11]=k,e[12]=c,e[13]=w):w=e[13];let D;e[14]!==k||e[15]!==p?(D=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${k} 0%, transparent 100%)`}}),e[14]=k,e[15]=p,e[16]=D):D=e[16];let C;e[17]!==D||e[18]!==I||e[19]!==w?(C=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[I,w,D]}),e[17]=D,e[18]=I,e[19]=w,e[20]=C):C=e[20];let A;return e[21]!==n||e[22]!==a||e[23]!==C||e[24]!==y?(A=s.jsxs("div",{className:y,children:[a,C,n]}),e[21]=n,e[22]=a,e[23]=C,e[24]=y,e[25]=A):A=e[25],A},Ev=t=>{const e=Ke.c(23),{title:a,metadata:n,selected:o,onSelect:i,icon:r,actions:l,className:u}=t,m=o===void 0?!1:o,c=l&&l.length>0,f=m?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==u||e[1]!==f?(p=Ie("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",f,u),e[0]=u,e[1]=f,e[2]=p):p=e[2];let g;e[3]!==a?(g=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=g):g=e[4];let h;e[5]!==r||e[6]!==g?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[r,g]}),e[5]=r,e[6]=g,e[7]=h):h=e[7];let k;e[8]!==n?(k=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=k):k=e[9];let b;e[10]!==i||e[11]!==h||e[12]!==k?(b=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[h,k]}),e[10]=i,e[11]=h,e[12]=k,e[13]=b):b=e[13];let j;e[14]!==l||e[15]!==c?(j=c&&s.jsxs(Jn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsx(q,{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(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:l.map(Dv)})]}),e[14]=l,e[15]=c,e[16]=j):j=e[16];let x;e[17]!==b||e[18]!==j?(x=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,j]}),e[17]=b,e[18]=j,e[19]=x):x=e[19];let S;return e[20]!==p||e[21]!==x?(S=s.jsx("div",{className:p,children:x}),e[20]=p,e[21]=x,e[22]=S):S=e[22],S};function Dv(t){const e=t.icon;return s.jsxs(Fn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:Ie(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(Q,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Mv=t=>{const e=Ke.c(38),{onItemSelect:a}=t,{t:n}=ze(),o=dn(Rv),i=re(Ov),r=re(Fv),{currentTheme:l}=xa();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=is(),e[0]=u):u=e[0];const m=u,c=Lv;let f,p;e[1]!==o||e[2]!==i||e[3]!==r?(f=()=>{if(o.length===0){i!==null&&r(null);return}i&&o.some(I=>I.id===i)||r(o[0].id)},p=[o,i,r],e[1]=o,e[2]=i,e[3]=r,e[4]=f,e[5]=p):(f=e[4],p=e[5]),d.useEffect(f,p);let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=Ie("border-b px-3","pt-4 pb-3"),e[6]=g):g=e[6];let h;e[7]!==n?(h=n("settings.page.projects.title"),e[7]=n,e[8]=h):h=e[8];let k;e[9]!==h?(k=s.jsx("h2",{className:`${zn} mb-3`,children:h}),e[9]=h,e[10]=k):k=e[10];let b;e[11]!==o.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:o.length}),e[11]=o.length,e[12]=n,e[13]=b):b=e[13];let j;e[14]!==b?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=j):j=e[15];let x;e[16]!==n?(x=!m&&s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:c,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(Q,{name:"add",className:"size-4"})}),e[16]=n,e[17]=x):x=e[17];let S;e[18]!==j||e[19]!==x?(S=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,x]}),e[18]=j,e[19]=x,e[20]=S):S=e[20];let v;e[21]!==S||e[22]!==k?(v=s.jsxs("div",{className:g,children:[k,S]}),e[21]=S,e[22]=k,e[23]=v):v=e[23];let N;if(e[24]!==l||e[25]!==a||e[26]!==o||e[27]!==i||e[28]!==r){let I;e[30]!==l||e[31]!==a||e[32]!==i||e[33]!==r?(I=w=>{const D=w.id===i,C=w.icon?np[w.icon]:null,A=w.color?ap[w.color]??null:null,T=C?s.jsx(Q,{name:C,className:Ie("h-4 w-4",D?"text-foreground":"text-muted-foreground/70"),style:A?{color:A}:void 0}):s.jsx(Q,{name:"folder",className:Ie("h-4 w-4",D?"text-foreground":"text-muted-foreground/70"),style:A?{color:A}:void 0}),O=w.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:w.iconBackground?{backgroundColor:w.iconBackground}:void 0,children:s.jsx(ip,{project:w,options:{themeVariant:l.metadata.variant,iconColor:l.colors.surface.foreground},className:"h-full w-full object-contain",fallback:T})}):T;return s.jsx(Ev,{title:w.label||w.path,icon:O,selected:D,onSelect:()=>{r(w.id),a?.()}},w.id)},e[30]=l,e[31]=a,e[32]=i,e[33]=r,e[34]=I):I=e[34],N=o.map(I),e[24]=l,e[25]=a,e[26]=o,e[27]=i,e[28]=r,e[29]=N}else N=e[29];let y;return e[35]!==v||e[36]!==N?(y=s.jsx(Tv,{variant:"background",header:v,children:N}),e[35]=v,e[36]=N,e[37]=y):y=e[37],y};function Rv(t){return t.projects}function Ov(t){return t.settingsProjectsSelectedId}function Fv(t){return t.setSettingsProjectsSelectedId}function Lv(){sp.requestDirectoryDialog()}const Kv=()=>{const t=Ke.c(30),{t:e}=ze(),a=dn(zv),n=dn(Uv),o=re($v),i=re(_v);let r;e:{if(!o){r=null;break e}let b;t[0]!==a||t[1]!==o?(b=a.find(j=>j.id===o)??null,t[0]=a,t[1]=o,t[2]=b):b=t[2],r=b}const l=r;let u,m;t[3]!==a||t[4]!==o||t[5]!==i?(u=()=>{if(a.length===0){i(null);return}o&&a.some(b=>b.id===o)||i(a[0].id)},m=[a,o,i],t[3]=a,t[4]=o,t[5]=i,t[6]=u,t[7]=m):(u=t[6],m=t[7]),d.useEffect(u,m);let c;t[8]!==l||t[9]!==n?(c=async b=>{l&&n(l.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]=l,t[9]=n,t[10]=c):c=t[10];const f=c;if(!l){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let j;t[13]!==e?(j=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=j):j=t[14];let x;t[15]!==j?(x=s.jsx("p",{className:"typography-meta text-muted-foreground",children:j}),t[15]=j,t[16]=x):x=t[16];let S;return t[17]!==b||t[18]!==x?(S=s.jsx(Qt,{title:b,showSaveStatus:!0,children:x}),t[17]=b,t[18]=x,t[19]=S):S=t[19],S}let p;t[20]!==l.label||t[21]!==e?(p=l.label??e("settings.projects.page.title.default"),t[20]=l.label,t[21]=e,t[22]=p):p=t[22];const g=p;let h;t[23]!==f||t[24]!==l?(h=s.jsx(jf,{project:l,onIdentitySave:f}),t[23]=f,t[24]=l,t[25]=h):h=t[25];let k;return t[26]!==g||t[27]!==l.path||t[28]!==h?(k=s.jsx(Qt,{title:g,description:l.path,showSaveStatus:!0,outerClassName:"bg-background",children:h}),t[26]=g,t[27]=l.path,t[28]=h,t[29]=k):k=t[29],k};function zv(t){return t.projects}function Uv(t){return t.updateProjectMeta}function $v(t){return t.settingsProjectsSelectedId}function _v(t){return t.setSettingsProjectsSelectedId}const Bv=ts({clientToken:wt().trim().min(1)}),Vv=ts({error:ff("Invalid or expired pairing session")}),Hv=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&Vv.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const a=Bv.safeParse(e);return a.success?{kind:"success",token:a.data.clientToken}:{kind:"invalid-response"}};function qv(t){const e=Ke.c(42),{t:a}=ze(),[n,o]=_e.useState(null),i=_e.useRef(null),r=_e.useRef(null);let l,u;e[0]!==t?(l=()=>(r.current=t,o(null),()=>{r.current=null;const M=i.current;i.current=null,M?.(null)}),u=[t],e[0]=t,e[1]=l,e[2]=u):(l=e[1],u=e[2]),_e.useEffect(l,u);let m;e[3]!==t?(m=(M,P)=>{const R=P===void 0?"settings.common.actions.saveChanges":P;return!t||r.current!==t||i.current?Promise.resolve(null):new Promise(F=>{i.current=F,o({messageKey:M,actionKey:R})})},e[3]=t,e[4]=m):m=e[4];const c=m;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=M=>{const P=i.current;i.current=null,o(null),P?.(M)},e[5]=f):f=e[5];const p=f,g=n!==null;let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=M=>{M||p(!1)},e[6]=h):h=e[6];let k;e[7]!==a?(k=a("settings.remoteInstances.page.title"),e[7]=a,e[8]=k):k=e[8];let b;e[9]!==k?(b=s.jsx(Ut,{children:k}),e[9]=k,e[10]=b):b=e[10];let j;e[11]!==n||e[12]!==a?(j=n?a(n.messageKey):null,e[11]=n,e[12]=a,e[13]=j):j=e[13];let x;e[14]!==j?(x=s.jsx($t,{children:j}),e[14]=j,e[15]=x):x=e[15];let S;e[16]!==b||e[17]!==x?(S=s.jsxs(zt,{children:[b,x]}),e[16]=b,e[17]=x,e[18]=S):S=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=()=>p(!1),e[19]=v):v=e[19];let N;e[20]!==a?(N=a("settings.common.actions.cancel"),e[20]=a,e[21]=N):N=e[21];let y;e[22]!==N?(y=s.jsx(q,{variant:"outline",autoFocus:!0,onClick:v,children:N}),e[22]=N,e[23]=y):y=e[23];let I;e[24]===Symbol.for("react.memo_cache_sentinel")?(I=()=>p(!0),e[24]=I):I=e[24];let w;e[25]!==n||e[26]!==a?(w=n?a(n.actionKey):null,e[25]=n,e[26]=a,e[27]=w):w=e[27];let D;e[28]!==w?(D=s.jsx(q,{onClick:I,children:w}),e[28]=w,e[29]=D):D=e[29];let C;e[30]!==y||e[31]!==D?(C=s.jsxs(Xt,{children:[y,D]}),e[30]=y,e[31]=D,e[32]=C):C=e[32];let A;e[33]!==S||e[34]!==C?(A=s.jsxs(Lt,{children:[S,C]}),e[33]=S,e[34]=C,e[35]=A):A=e[35];let T;e[36]!==A||e[37]!==g?(T=s.jsx(Ft,{open:g,onOpenChange:h,children:A}),e[36]=A,e[37]=g,e[38]=T):T=e[38];const O=T;let z;return e[39]!==c||e[40]!==O?(z={confirm:c,dialog:O},e[39]=c,e[40]=O,e[41]=z):z=e[41],z}const go=()=>Math.floor(2e4+Math.random()*3e4),Gv=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")},Wv=()=>{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"},zc=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}},Uc=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"}},Jv=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Kl=t=>!!(t&&Jv.has(t)),$c=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Kl(t)?"connecting":"idle",_c=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"}},Qv=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},Bc={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Yv=t=>t==="noRuntime"?Bc.noRuntime:t==="noOpencode"?Bc.noOpencode:null,Vc=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Kl(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Zv=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}`,Xv=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:go(),remoteHost:"127.0.0.1",remotePort:80}),ey=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Ys=t=>{const e=Ke.c(7),{label:a,hint:n}=t;let o;e[0]!==a?(o=s.jsx("span",{children:a}),e[0]=a,e[1]=o):o=e[1];let i;e[2]!==n?(i=s.jsx(Gt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=i):i=e[3];let r;return e[4]!==o||e[5]!==i?(r=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Nt}`,children:[o,i]}),e[4]=o,e[5]=i,e[6]=r):r=e[6],r},ty=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"}},Hc=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},sy=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},ny=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],o=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${n}] [${o}] ${i}`},dl=(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}),ay=t=>t.trim().toLowerCase()==="authorization",Tr=t=>{const e={};for(const a of t){const n=a.name.trim(),o=a.value.trim();n&&o&&!ay(n)&&(e[n]=o)}return Object.keys(e).length>0?e:void 0},iy=t=>Object.entries(t||{}).map(([e,a])=>dl(e,a)),zu=()=>{if(typeof window>"u")return null;const e=Ei()||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}},qc=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},oy=async()=>{const t=la(Ei())||window.location.origin;if(!rs()||!Za()||(await jn())?.desktopLanAccessActive!==!0)return t;const a=await uu(),n=zu();return!a||!n?t:`http://${a}:${n}`},Gc=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},ry=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(o=>({...o,localHost:o.localHost?.trim()||"127.0.0.1",localPort:typeof o.localPort=="number"?Math.max(1,Math.min(65535,Math.round(o.localPort))):void 0,remoteHost:o.remoteHost?.trim(),remotePort:typeof o.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(o.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}},ly=()=>{const{t}=ze(),e=re(U=>U.timeFormatPreference),{clientAuth:a}=Ya(),n=rs(),o=Is(U=>U.instances),i=Is(U=>U.statusesById),r=Is(U=>U.importCandidates),l=Is(U=>U.isLoading),u=Is(U=>U.isImportsLoading),m=Is(U=>U.isSaving),c=Is(U=>U.error),f=Is(U=>U.load),p=Is(U=>U.loadImports),g=Is(U=>U.refreshStatuses),h=Is(U=>U.upsertInstance),k=Is(U=>U.createFromCommand),b=Is(U=>U.removeInstance),j=Is(U=>U.connect),x=Is(U=>U.disconnect),S=Is(U=>U.retry),v=re(U=>U.settingsRemoteInstancesSelectedId),N=re(U=>U.setSettingsRemoteInstancesSelectedId),y=re(U=>U.setSettingsDialogOpen),{confirm:I,dialog:w}=qv(v),D=d.useMemo(()=>v&&o.find(U=>U.id===v)||null,[o,v]),[C,A]=d.useState(null),[T,O]=d.useState(!1),[z,M]=d.useState(!1),[P,R]=d.useState(null),[F,_]=d.useState([]),[B,V]=d.useState(null),[ee,L]=d.useState(""),[$,H]=d.useState(!1),[W,Z]=d.useState({}),[te,J]=d.useState(!1),[ie,pe]=d.useState(!1),[X,xe]=d.useState(()=>Date.now()),[Y,be]=d.useState([]),[De,ve]=d.useState({}),[se,ge]=d.useState("local"),[ne,Se]=d.useState(!1),[ke,Te]=d.useState(!1),[Ee,Le]=d.useState(""),[ce,Me]=d.useState(""),[Fe,me]=d.useState(""),[de,Pe]=d.useState([]),[he,Ue]=d.useState(""),[Ae,Re]=d.useState(null),[$e,nt]=d.useState(!1),[pt,kt]=d.useState(!1),[bt,yt]=d.useState(!1),[Je,ct]=d.useState(null),[Qe,it]=d.useState(""),[dt,qe]=d.useState(""),[lt,ae]=d.useState(""),[fe,ye]=d.useState([]),[we,Ge]=d.useState([]),[et,mt]=d.useState([]),[jt,vt]=d.useState(!1),[Ct,Bt]=d.useState(""),[Ye,Ze]=d.useState(null),[ut,ft]=d.useState(null),[K,ue]=d.useState(null),[Ne,Ce]=d.useState(null),[He,le]=d.useState(!1),[Oe,ot]=d.useState(!1),[Rt,It]=d.useState("configure"),[os,Xe]=d.useState(!1),[tt,qt]=d.useState("relay"),[ss,fs]=d.useState(!0),[Jt,Cs]=d.useState(null),kn=Ti(U=>U.networkAccessBlocked),Yn=!Jt||Jt.lanUrl?t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"):rs()?Za()?t(kn?"settings.openchamber.desktopNetwork.field.enterpriseBlocked":"settings.remoteInstances.clientAuth.addDevice.transport.lanUnavailableDesktopHint"):t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"):t("settings.remoteInstances.clientAuth.addDevice.transport.lanUnavailableServerHint"),Oi=d.useMemo(()=>we.filter(U=>!!U.revokedAt).length,[we]),[ti,$n]=d.useState(!1),[Fi,si]=d.useState("saved"),[ni,Li]=d.useState(""),[va,ai]=d.useState(""),[ii,oi]=d.useState(""),[ri,wn]=d.useState(!1);d.useEffect(()=>{f(),p()},[f,p]);const li=d.useCallback(async()=>{Se(!0),Re(null);try{const U=await yr();be(U.hosts||[]),ge(U.defaultHostId||"local")}catch(U){Re(U instanceof Error?U.message:String(U))}finally{Se(!1)}},[]);d.useEffect(()=>{li()},[li]);const zs=d.useCallback(async(U,je=se)=>{Te(!0),Re(null);try{return await ic({hosts:U,defaultHostId:je,initialHostChoiceCompleted:!0}),be(U),ge(je),!0}catch(We){return Re(We instanceof Error?We.message:String(We)),!1}finally{Te(!1)}},[se]),_o=d.useCallback(async()=>{const U=oc(ce);if(!U){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const je=U.persistedUrl,oe={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ee.trim()||mi(je),url:je,apiUrl:je,...Fe.trim()?{clientToken:Fe.trim()}:{},...Tr(de)?{requestHeaders:Tr(de)}:{}};await zs([oe,...Y],se)&&(Le(""),Me(""),me(""),Pe([]),nt(!1),U.redeemUrl&&Gc(U.redeemUrl))},[se,de,Y,Ee,Fe,ce,zs,t]),Bo=d.useCallback(async()=>{Re(null);const U=Dg(he);if(!U){Re(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const je=await Mg().catch(()=>""),We=JSON.stringify({pairingId:U.pairingId,secret:U.secret,clientLabel:U.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Wv(),...je?{dedupeKey:`desktop:${je}`}:{}}),oe={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:We};let St=null;const hs=async Ht=>{const cs=await Hv(Ht);switch(cs.kind){case"success":return cs.token;case"rejected":St=t("desktopHostSwitcher.error.pairingRejected");break;case"http-error":St??=t("desktopHostSwitcher.error.pairingFailed",{status:cs.status});break;case"invalid-response":St??=t("desktopHostSwitcher.error.pairingInvalidResponse");break}return null},an=[...U.candidates].sort((Ht,cs)=>(Ht.type==="relay"?1:0)-(cs.type==="relay"?1:0));let ms=null;for(const Ht of an){if(Ht.type==="relay"){const rn=Rg({relayUrl:Ht.relayUrl,serverId:Ht.serverId,hostEncPubJwk:Ht.hostEncPubJwk,...Ht.grant?{grant:Ht.grant}:{}});try{const Cn=await rn.fetch("/api/client-auth/pairing/redeem",{...oe,signal:AbortSignal.timeout(15e3)}),Ta=await hs(Cn);if(Ta){ms={kind:"relay",relay:{relayUrl:Ht.relayUrl,serverId:Ht.serverId,hostEncPubJwk:Ht.hostEncPubJwk},token:Ta};break}}catch{}finally{rn.close()}continue}const cs=la(Ht.url);if(cs)try{const rn=await fetch(`${cs}/api/client-auth/pairing/redeem`,{...oe,signal:AbortSignal.timeout(15e3)}),Cn=await hs(rn);if(Cn){ms={kind:"direct",url:cs,token:Cn};break}}catch{}}if(!ms){Re(St||t("mobile.connect.error.unreachable"));return}const As=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,gn=U.candidates.find(Ht=>Ht.type==="relay"),on=ms.kind==="relay"?ms.relay:gn?{relayUrl:gn.relayUrl,serverId:gn.serverId,hostEncPubJwk:gn.hostEncPubJwk}:void 0,Aa=U.candidates.filter(Ht=>Ht.type!=="relay").map(Ht=>la(Ht.url)).find(Ht=>!!Ht),Sn=ms.kind==="direct"?ms.url:Aa,{token:Vt}=ms,es=Sn||(on?Og(on.serverId):null);if(!es){Re(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ta={url:es,apiUrl:Sn||void 0,clientToken:Vt,...on?{relay:on}:{}},Nn=Y.find(Ht=>on?Ht.relay?.serverId===on.serverId:!Ht.relay&&la(Ht.apiUrl||Ht.url)===es);if(Nn){const Ht=Y.map(cs=>cs.id===Nn.id?{...cs,label:U.label||cs.label,...ta}:cs);if(!await zs(Ht,se))return}else if(!await zs([{id:As(),label:U.label||mi(es),...ta},...Y],se))return;Ue(""),Re(null),kt(!1)},[he,se,Y,zs,t]),ya=d.useCallback(async U=>{const je=Y.filter(oe=>oe.id!==U);await zs(je,se===U?"local":se)&&Je===U&&ct(null)},[se,Je,Y,zs]),Vo=d.useCallback(U=>{ct(U.id),it(U.label),qe(U.apiUrl||U.url),ae(U.clientToken||""),ye(iy(U.requestHeaders)),Re(null)},[]),Ho=d.useCallback(async()=>{if(!Je)return;const U=oc(dt);if(!U){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const je=U.persistedUrl,We=Y.map(oe=>oe.id===Je?{...oe,label:Qe.trim()||mi(je),url:je,apiUrl:je,clientToken:lt.trim()||void 0,requestHeaders:Tr(fe)}:oe);await zs(We,se)&&(ct(null),U.redeemUrl&&Gc(U.redeemUrl))},[se,fe,Qe,lt,dt,Je,Y,zs,t]),Ki=d.useCallback(async()=>{const U=va.trim();if(!U){G.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const je=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await k(je,U,ii.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),N(je),$n(!1),ai(""),oi(""),G.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(We){G.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:We instanceof Error?We.message:String(We)})}},[k,N,va,ii,t]),zi=d.useCallback(()=>{Li(""),si(r.length>0?"saved":"manual"),$n(!0)},[r.length]),qo=d.useCallback(async U=>{await zs(Y,U)},[Y,zs]);d.useEffect(()=>{if(!n||Y.length===0)return;let U=!1;return Promise.all(Y.map(async je=>{const We=()=>Ug(je.relay,{clientToken:je.clientToken||null,requestHeaders:je.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(je.relay&&!je.apiUrl)return[je.id,await We()];const oe=la(rc(je));if(!oe)return[je.id,je.relay?await We():{status:"unreachable",latencyMs:0}];const St=await Fg(oe,{clientToken:je.clientToken||null,requestHeaders:je.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(St.status==="unreachable"&&je.relay){const hs=await We();if(hs.status==="ok")return[je.id,hs]}return[je.id,St]})).then(je=>{U||ve(Object.fromEntries(je))}),()=>{U=!0}},[Y,n]);const Us=d.useCallback(async U=>{if(a){U?.silent||vt(!0),U?.silent||Ze(null);try{const[je,We]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);Ge(je),We&&mt(We)}catch(je){U?.silent||Ze(je instanceof Error?je.message:String(je))}finally{U?.silent||vt(!1)}}},[a]),Zn=d.useRef(!1);d.useEffect(()=>{if(!(!Oe||Rt!=="result"||!K)){if(et.some(U=>U.id===K)){Zn.current=!0;return}Zn.current&&(ue(null),ot(!1),we.some(U=>U.pairingId===K)&&G.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Oe,Rt,K,et,we,t]);const ci=d.useCallback(async U=>{if(a)try{await a.cancelPairing(U),mt(je=>je.filter(We=>We.id!==U)),await Us({silent:!0})}catch(je){Ze(je instanceof Error?je.message:String(je))}},[a,Us]);d.useEffect(()=>{if(!a)return;Us();const U=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Us({silent:!0})},5e3);return()=>window.clearInterval(U)},[a,Us]);const Ui=d.useCallback(async()=>{if(a?.getPairingTransports)try{const oe=await a.getPairingTransports();return{localUrl:oe.local,lanUrl:oe.lan,relayAvailable:oe.relayAvailable}}catch{}const U=zu(),je=U?`http://127.0.0.1:${U}`:qc(window.location.origin)?window.location.origin:null;let We=null;try{const oe=la(await oy());We=oe&&!qc(oe)?oe:null}catch{}return{localUrl:je,lanUrl:We,relayAvailable:!0}},[a]),Go=d.useCallback(async()=>{Ze(null),ft(null),Ce(null),le(!1),ue(null),It("configure"),fs(!0),ot(!0);const U=await Ui();Cs(U),qt(U.relayAvailable?"relay":U.lanUrl?"lan":"local")},[Ui]),Wo=d.useCallback(async()=>{if(!(!a?.createPairingSession||!Jt)){Ze(null),Xe(!0);try{const U=Ct.trim()||void 0;let je,We,oe=!0;tt==="local"?(je=Jt.localUrl??void 0,We=!1):tt==="lan"?(je=Jt.lanUrl??void 0,We=ss):ss&&Jt.lanUrl?(je=Jt.lanUrl,We=!0):(oe=!1,We=!0);const{pairing:St,server:hs}=await a.createPairingSession({label:U,allowedClientKinds:["mobile","desktop"],serverUrl:je,includeRelay:We,includeDirect:oe}),an=Lg({pairingId:St.id,secret:St.secret,label:hs.label,fingerprint:St.fingerprint??void 0,expiresAt:St.expiresAt,candidates:hs.candidates}),ms=Kg(an);ft(ms),Ce(await vu.toDataURL(ms,{width:1024,margin:2,errorCorrectionLevel:"L"})),le(!1),Zn.current=!1,ue(St.id),It("result"),await Us({silent:!0})}catch(U){Ze(U instanceof Error?U.message:String(U))}finally{Xe(!1)}}},[a,Jt,tt,ss,Ct,Us]),Jo=d.useCallback(()=>{ut&&za(ut).then(U=>{U.ok&&(le(!0),window.setTimeout(()=>le(!1),2e3))})},[ut]),Qo=d.useCallback(async U=>{if(!a)return;const je=U.clientKind==="desktop-local";Ze(null);try{if(await a.revokeClient(U.id),je&&rs()){const We=await yr();await ic({hosts:We.hosts,defaultHostId:We.defaultHostId,initialHostChoiceCompleted:We.initialHostChoiceCompleted,localClientToken:null}),Ge(oe=>oe.map(St=>St.id===U.id?{...St,revokedAt:new Date().toISOString()}:St)),lc({apiBaseUrl:Ei(),clientToken:null,runtimeKey:"local"});return}await Us()}catch(We){Ze(We instanceof Error?We.message:String(We))}},[a,Us]),Yo=d.useCallback(async()=>{if(a){Ze(null);try{await a.purgeRevokedClients(),await Us()}catch(U){Ze(U instanceof Error?U.message:String(U))}}},[a,Us]);d.useEffect(()=>{A(D)},[D]),d.useEffect(()=>{wn(!1)},[v]),d.useEffect(()=>{if(!v)return;const U=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||g()},2e3);return()=>{window.clearInterval(U)}},[g,v]),d.useEffect(()=>{let U=null,je=Date.now();const We=()=>{const St=Date.now();St-je>=1e3&&(xe(St),je=St),U=requestAnimationFrame(We)};(typeof document>"u"||document.visibilityState==="visible")&&(U=requestAnimationFrame(We));const oe=()=>{document.visibilityState==="visible"&&U===null?U=requestAnimationFrame(We):document.visibilityState!=="visible"&&U!==null&&(cancelAnimationFrame(U),U=null)};return document.addEventListener("visibilitychange",oe),()=>{document.removeEventListener("visibilitychange",oe),U!==null&&cancelAnimationFrame(U)}},[]);const Rs=v?i[v]:null,Qs=Rs?.phase,ja=Qs==="ready",un=Qs==="degraded",_n=Kl(Qs),mn=ja||(_n||un),$i=Rs?Math.max(0,X-Rs.updatedAtMs):0,ka=un&&$i>12e3,wa=$c(Qs),Xn=wa==="error"?Qv(Rs?.detail):null,di=Yv(Xn),_i=d.useMemo(()=>!C||!D?!1:JSON.stringify(C)!==JSON.stringify(D),[C,D]),us=d.useCallback(U=>{A(je=>je&&U(je))},[]),Zo=d.useCallback(async()=>{if(!C)return;const U=ry(C);if(!U.sshCommand.trim()){G.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(U.remoteOpenchamber.mode==="external"&&!U.remoteOpenchamber.preferredPort){G.error(t("settings.remoteInstances.page.validation.externalPortRequired")),wn(!0);return}if(U.remoteOpenchamber.mode==="managed"&&U.remoteOpenchamber.bindHost==="0.0.0.0"&&!U.auth.openchamberPassword?.value?.trim()){G.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),wn(!0),window.setTimeout(()=>Ca.current?.focus(),0);return}if(!(U.localForward.bindHost==="0.0.0.0"&&!await I("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(U.auth.sshPassword?.enabled&&U.auth.sshPassword.value?.trim()&&U.auth.sshPassword.store!=="settings"){const je=await I("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext");if(je===null)return;U.auth.sshPassword.store=je?"settings":"never",je||(U.auth.sshPassword.value=void 0)}if(U.auth.openchamberPassword?.enabled&&U.auth.openchamberPassword.value?.trim()&&U.auth.openchamberPassword.store!=="settings"){const je=await I("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext");if(je===null)return;U.auth.openchamberPassword.store=je?"settings":"never",je||(U.auth.openchamberPassword.value=void 0)}try{await h(U),G.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(je){G.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:je instanceof Error?je.message:String(je)})}}},[I,C,t,h]),Sa=d.useCallback(async(U,je)=>{const We=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await k(We,`ssh ${je}`,U),N(We),G.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(oe){return G.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:oe instanceof Error?oe.message:String(oe)}),!1}},[k,N,t]),Na=d.useCallback(()=>{$||(V(null),L(""))},[$]),Xo=d.useCallback((U,je)=>{if($n(!1),je){V(U),L(ey(U));return}Sa(U,U)},[Sa]),Bi=d.useMemo(()=>Qn(r,ni,U=>[U.host,U.sshCommand]),[r,ni]),Vi=d.useCallback(async U=>{const We=(await yr().catch(()=>null))?.hosts.find(St=>St.id===U),oe=We?la(rc(We)):null;if(!We||!oe){G.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}lc({apiBaseUrl:oe,clientToken:We.clientToken||null,requestHeaders:We.requestHeaders||null,runtimeKey:zg(We)}),y(!1)},[y,t]),Hi=d.useCallback(async()=>{const U=B,je=ee.trim();if(U){if(!je){G.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}H(!0);try{await Sa(U,je)&&(V(null),L(""))}finally{H(!1)}}},[Sa,ee,B,t]),ea=d.useCallback(async()=>{if(D)try{await j(D.id);return}catch(U){if(!Gv(U)||!await I("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw U;const We={...D,localForward:{...D.localForward,preferredLocalPort:go()}};await h(We),await j(We.id),G.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[I,j,D,t,h]),Ca=d.useRef(null),qi=d.useRef(null),er=d.useCallback(async U=>{if(D){if(U==="localPort"){const je={...D,localForward:{...D.localForward,preferredLocalPort:go()}};try{await h(je),await j(je.id),G.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(We){G.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:We instanceof Error?We.message:String(We)})}return}wn(!0),window.setTimeout(()=>{if(U==="uiPassword"){Ca.current?.focus();return}qi.current?.scrollIntoView({block:"center"})},0)}},[j,D,t,h]),Ia=d.useCallback(async U=>(await op(U,600)).map(We=>ny(We)),[]),tr=d.useCallback(async()=>{if(C){O(!0),M(!0),R(null);try{const U=await Ia(C.id);_(U)}catch(U){_([]),R(U instanceof Error?U.message:String(U))}finally{M(!1)}}},[C,Ia]);d.useEffect(()=>{if(!T||!C)return;let U=!1;const je=async()=>{try{const oe=await Ia(C.id);U||(_(oe),R(null))}catch(oe){U||R(oe instanceof Error?oe.message:String(oe))}};je();const We=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||je()},1e3);return()=>{U=!0,window.clearInterval(We)}},[C,T,Ia]);const Pa=d.useMemo(()=>F.join(`
28
+ `),[F]),sr=d.useCallback(()=>{if(!Pa.trim()){G.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}za(Pa).then(U=>{U.ok&&G.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Pa,t]),nr=d.useCallback(async()=>{if(C)try{await rp(C.id),_([]),G.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(U){G.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:U instanceof Error?U.message:String(U)})}},[C,t]),ar=d.useCallback(()=>{if(!C)return;if(!mn&&C.remoteOpenchamber.mode==="external"&&!C.remoteOpenchamber.preferredPort){G.error(t("settings.remoteInstances.page.validation.externalPortRequired")),wn(!0);return}if(!mn&&C.remoteOpenchamber.mode==="managed"&&C.remoteOpenchamber.bindHost==="0.0.0.0"&&!C.auth.openchamberPassword?.value?.trim()){G.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),wn(!0),window.setTimeout(()=>Ca.current?.focus(),0);return}J(!0),(mn?x(C.id):ea()).catch(je=>{const We=mn?ja?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";G.error(t(We),{description:je instanceof Error?je.message:String(je)})}).finally(()=>{J(!1)})},[mn,ea,x,C,ja,t]),ir=d.useCallback(()=>{if(!C||_n)return;pe(!0),(un?x(C.id).then(()=>ea()):S(C.id)).catch(je=>{G.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:je instanceof Error?je.message:String(je)})}).finally(()=>{pe(!1)})},[ea,x,C,_n,un,S,t]),or=t(_n?"settings.remoteInstances.page.actions.connecting":un?ka?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),rr=!te&&!ie&&(Qs==="error"||Qs==="idle"||!Qs||un&&ka)&&!_n,lr=t(ja?"settings.remoteInstances.sidebar.actions.disconnect":mn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!C)return s.jsxs(Qt,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(Ve,{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(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Go()},children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[Oi>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Yo()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,jt&&we.length===0&&et.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):we.length===0&&et.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[et.map(U=>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:U.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),U.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(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ci(U.id)},children:t("settings.common.actions.cancel")})]},`pending-${U.id}`)),we.map(U=>{const je=U.clientKind==="desktop-local",We=U.lastUsedAt?Date.parse(U.lastUsedAt):Number.NaN,oe=!U.revokedAt&&(je||Number.isFinite(We)&&Date.now()-We<9e4),St=U.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):oe?U.lastTransport==="relay"&&!je?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(We)?t("settings.remoteInstances.clientAuth.lastUsed",{date:lp(We,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:Ie("h-2 w-2 shrink-0 rounded-full",U.revokedAt?"bg-muted-foreground/20":oe?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:U.label}),zc(U.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:zc(U.devicePlatform)}):null,je?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:Ie("typography-micro truncate",oe&&!U.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:St})]})}),s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Qo(U)},disabled:!!U.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},U.id)})]})]}),Ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):null]}):null,n?s.jsxs(Ve,{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(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Re(null),kt(!0)},disabled:ke,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Re(null),nt(!0)},disabled:ke,children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):Y.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):Y.map(U=>{const je=De[U.id],We=je?je.status==="ok"?"desktopHostSwitcher.status.connected":je.status==="auth"?"desktopHostSwitcher.status.authRequired":je.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":je.status==="incompatible"?"desktopHostSwitcher.status.incompatible":je.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",oe=je?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie("h-2 w-2 shrink-0 rounded-full",je?oe?"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:mi(U.label)}),se===U.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:Ie("typography-micro shrink-0",oe?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(We),oe&&typeof je?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(je.latencyMs))}):""]})]}),s.jsx("p",{className:Ie("typography-micro text-muted-foreground truncate",U.apiUrl&&"font-mono"),children:U.relay&&!U.apiUrl?t("mobile.connect.relay.badge"):mi(U.apiUrl||U.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{qo(U.id)},disabled:ke||se===U.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:se===U.id?s.jsx(Q,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"star",className:"h-3.5 w-3.5"})}),U.relay&&!U.apiUrl?null:s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Vo(U),disabled:ke,children:[s.jsx(Q,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ya(U.id)},disabled:ke,children:[s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},U.id)})}),Ae&&!pt&&!$e&&!Je?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ae}):null]}):null,n?s.jsx(Ft,{open:$e,onOpenChange:nt,children:s.jsxs(Lt,{className:"sm:max-w-lg",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx($t,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),_o()},children:[s.jsx(Be,{className:"h-8",value:Ee,onChange:U=>Le(U.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ke}),s.jsx(Be,{className:"h-8",value:ce,onChange:U=>Me(U.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ke,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Be,{className:"h-8",value:Fe,onChange:U=>me(U.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ke}),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(Ln,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.headers.description")})]}),de.map(U=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Be,{className:"h-8 font-mono text-xs",value:U.name,onChange:je=>Pe(We=>We.map(oe=>oe.id===U.id?{...oe,name:je.target.value}:oe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ke}),s.jsx(Be,{className:"h-8 font-mono text-xs",value:U.value,onChange:je=>Pe(We=>We.map(oe=>oe.id===U.id?{...oe,value:je.target.value}:oe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ke}),s.jsx("button",{type:"button",onClick:()=>Pe(je=>je.filter(We=>We.id!==U.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:ke,children:s.jsx(Q,{name:"close",className:"h-4 w-4"})})]},U.id)),s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Pe(U=>[...U,dl()]),disabled:ke,children:[s.jsx(Q,{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(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>nt(!1),disabled:ke,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:ke||!ce.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),Ae?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ae}):null]})]})}):null,n?s.jsx(Ft,{open:!!Je,onOpenChange:U=>{U||ct(null)},children:s.jsxs(Lt,{className:"sm:max-w-lg",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx($t,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Ho()},children:[s.jsx(Be,{className:"h-8",value:Qe,onChange:U=>it(U.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ke}),s.jsx(Be,{className:"h-8",value:dt,onChange:U=>qe(U.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ke,autoFocus:!0}),s.jsx(Be,{className:"h-8",value:lt,onChange:U=>ae(U.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ke}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ln,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.headers.description")})]}),fe.map(U=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Be,{className:"h-8 font-mono text-xs",value:U.name,onChange:je=>ye(We=>We.map(oe=>oe.id===U.id?{...oe,name:je.target.value}:oe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ke}),s.jsx(Be,{className:"h-8 font-mono text-xs",value:U.value,onChange:je=>ye(We=>We.map(oe=>oe.id===U.id?{...oe,value:je.target.value}:oe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ke}),s.jsx("button",{type:"button",onClick:()=>ye(je=>je.filter(We=>We.id!==U.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:ke,children:s.jsx(Q,{name:"close",className:"h-4 w-4"})})]},U.id)),s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ye(U=>[...U,dl()]),disabled:ke,children:[s.jsx(Q,{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(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ct(null),disabled:ke,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:ke,children:t("settings.common.actions.saveChanges")})]}),Ae?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ae}):null]})]})}):null,n?s.jsx(Ft,{open:pt,onOpenChange:U=>{bt||kt(U)},children:s.jsxs(Lt,{className:"sm:max-w-lg",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx($t,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":bt,onSubmit:async U=>{if(U.preventDefault(),!(bt||ke)){yt(!0);try{await Bo()}catch{Re(t("mobile.connect.error.unreachable"))}finally{yt(!1)}}},children:[s.jsx(Be,{className:"h-8",value:he,onChange:U=>{Ue(U.target.value),Re(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:ke||bt,"aria-describedby":Ae?"direct-import-error":void 0,autoFocus:!0}),Ae?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ae}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>kt(!1),disabled:ke||bt,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:ke||bt||!he.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Ft,{open:Oe,onOpenChange:ot,children:s.jsxs(Lt,{className:Rt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t(Rt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx($t,{children:t(Rt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),Rt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:U=>{U.preventDefault(),Wo()},children:[s.jsx(Be,{className:"h-8",value:Ct,onChange:U=>Bt(U.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:!!Jt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:Yn,available:!!Jt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Jt?.localUrl}].map(U=>{const je=tt===U.key;return s.jsxs("div",{className:Ie("flex items-start gap-2 py-0.5",U.available?"cursor-pointer":"opacity-45"),onClick:()=>{U.available&&qt(U.key)},role:"presentation",children:[s.jsx(wl,{checked:je,disabled:!U.available,onChange:()=>qt(U.key),ariaLabel:U.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:Ie("typography-ui-label font-normal",je?"text-foreground":"text-foreground/70"),children:U.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:U.hint})]})]},U.key)})}),tt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Ai,{checked:ss,onChange:fs,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,tt==="relay"&&Jt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Ai,{checked:ss,onChange:fs,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),Ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ot(!1),disabled:os,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:os||!Jt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Ne?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Ne,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ut?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:ut}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Jo,children:[s.jsx(Q,{name:He?"check":"file-copy",className:Ie("h-3.5 w-3.5",He&&"text-[var(--status-success)]")}),t(He?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>ot(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Ve,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:o.length}),headerAction:s.jsxs(q,{type:"button",size:"xs",className:"!font-normal",onClick:zi,children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:l?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):o.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:r.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):r.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:r.length}):t("settings.remoteInstances.page.empty.noInstances")}):o.map(U=>{const je=i[U.id],We=U.nickname?.trim()||U.sshParsed?.destination||U.id,oe=je?.phase,St=oe==="ready",hs=$c(oe),an=hs==="error"?je?.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 ${Vc(oe)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:We})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(_c(hs)),hs==="connecting"?` · ${t(Uc(oe))}`:"",St&&je?.localUrl?` · ${je.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[St?s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Vi(U.id)},children:[s.jsx(Q,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(St?x(U.id):j(U.id)).catch(As=>G.error(t(St?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:As instanceof Error?As.message:String(As)}))},children:[St?s.jsx(Q,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"plug-2",className:"h-3.5 w-3.5"}),t(St?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>N(U.id),children:[s.jsx(Q,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(U.id).catch(As=>G.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:As instanceof Error?As.message:String(As)}))},children:[s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),an?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:an}):null]},U.id)})}):null,n?s.jsx(Ft,{open:ti,onOpenChange:$n,children:s.jsxs(Lt,{className:"sm:max-w-lg",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx($t,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Vs,{value:Fi,onChange:si,"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")}]}),Fi==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Be,{className:"h-8",value:ni,onChange:U=>Li(U.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),u?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Bi.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:Bi.map(U=>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:[U.host,U.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:U.sshCommand})]}),s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Xo(U.host,U.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${U.source}:${U.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Ki()},children:[s.jsx(Be,{className:"h-8",value:ii,onChange:U=>oi(U.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:m}),s.jsx(Be,{className:"h-8",value:va,onChange:U=>ai(U.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:m,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$n(!1),disabled:m,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:m||!va.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Ft,{open:!!B,onOpenChange:U=>{U||Na()},children:s.jsxs(Lt,{className:"sm:max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx($t,{children:B?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:B}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Hi()},children:[s.jsx(Be,{value:ee,onChange:U=>L(U.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(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Na,disabled:$,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:$,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const nn=C.remoteOpenchamber.mode==="managed",pn=nn&&C.remoteOpenchamber.bindHost==="0.0.0.0",ui=pn&&!C.auth.openchamberPassword?.value?.trim(),cr=C.nickname?.trim()||C.sshParsed?.destination||C.id;return s.jsx(Ft,{open:!!C,onOpenChange:U=>{U||N(null)},children:s.jsxs(Lt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Jr} 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 ${Vc(Qs)}`}),s.jsx("span",{className:"text-foreground",children:t(_c(wa))}),wa==="connecting"?s.jsx("span",{children:t(Uc(Qs))}):null,Rs?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Rs.localUrl}):null,ka?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Ve,{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(q,{type:"button",variant:mn?"outline":"default",size:"xs",className:"!font-normal",onClick:ar,disabled:te||ie,children:[mn?s.jsx(Q,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"plug-2",className:"h-3.5 w-3.5"}),lr]}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ir,disabled:!rr,children:[s.jsx(Q,{name:"refresh",className:`h-3.5 w-3.5 ${_n||un&&!ka?"animate-spin":""}`}),or]}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{tr()},children:[s.jsx(Q,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(q,{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(C.id).then(()=>{N(null),G.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(je=>{G.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:je instanceof Error?je.message:String(je)})})},children:[s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),wa==="error"&&Rs?.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:Rs.detail}),di?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(di)}):null,Xn&&!di?s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{er(Xn)},children:t(Xn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Xn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,Rs?.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:Rs.localUrl})]}):null]}),s.jsxs(Ve,{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:C.sshCommand,onChange:U=>us(je=>({...je,sshCommand:U.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:C.nickname||"",onChange:U=>us(je=>({...je,nickname:U.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(Ys,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Tt,{value:C.remoteOpenchamber.mode,onValueChange:U=>us(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,mode:U==="external"?"external":"managed"}})),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[140px]",children:s.jsx(Kt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(at,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(at,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Gs,{open:ri,onOpenChange:wn,children:[s.jsxs(Ws,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:zn,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(Q,{name:ri?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Js,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(ps,{containerClassName:"w-fit",min:5,max:240,step:1,className:Ie(xs,"tabular-nums"),value:C.connectionTimeoutSec,onValueChange:U=>{us(je=>({...je,connectionTimeoutSec:Number.isFinite(U)?U:je.connectionTimeoutSec}))}})]}),s.jsxs(Ve,{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:qi,children:s.jsx(Ys,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(xs,"tabular-nums"),value:C.remoteOpenchamber.preferredPort,onValueChange:U=>{us(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,preferredPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{us(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),nn?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(Ys,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Tt,{value:C.remoteOpenchamber.installMethod,onValueChange:U=>us(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,installMethod:U==="npm"||U==="bun"?U:"auto"}})),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[140px]",children:s.jsx(Kt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(at,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(at,{value:"bun",children:"bun"}),s.jsx(at,{value:"npm",children:"npm"})]})]})]}):null,nn?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(Ys,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(fa,{checked:pn,onCheckedChange:U=>us(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,bindHost:U?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),pn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,nn?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(Ys,{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(fa,{checked:C.remoteOpenchamber.keepRunning,onCheckedChange:U=>us(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,keepRunning:U}}))})})]}):null]}),s.jsxs(Ve,{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(Ys,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Tt,{value:C.localForward.bindHost,onValueChange:U=>{U==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||us(je=>({...je,localForward:{...je.localForward,bindHost:U==="localhost"||U==="0.0.0.0"?U:"127.0.0.1"}}))},children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[240px]",children:s.jsx(Kt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(at,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(at,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(at,{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(Ys,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(xs,"tabular-nums"),value:C.localForward.preferredLocalPort,onValueChange:U=>{us(je=>({...je,localForward:{...je.localForward,preferredLocalPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{us(U=>({...U,localForward:{...U.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>us(U=>({...U,localForward:{...U.localForward,preferredLocalPort:go()}})),children:s.jsx(Q,{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:`${C.localForward.bindHost}:${C.localForward.preferredLocalPort||"auto"} → ${C.sshParsed?.destination||C.nickname||"remote"}:${C.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(Ve,{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(Ys,{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:C.auth.sshPassword?.value||"",onChange:U=>us(je=>({...je,auth:{...je.auth,sshPassword:{enabled:U.target.value.trim().length>0,value:U.target.value,store:je.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(Ys,{label:t(pn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(nn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Be,{className:Ie("h-7 md:max-w-sm",ui&&"border-[var(--status-error)]"),type:"password",ref:Ca,"aria-invalid":ui,value:C.auth.openchamberPassword?.value||"",onChange:U=>us(je=>({...je,auth:{...je.auth,openchamberPassword:{enabled:U.target.value.trim().length>0,value:U.target.value,store:je.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ui?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(Ve,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[C.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,C.portForwards.map((U,je)=>{const We=Vt=>{us(es=>({...es,portForwards:es.portForwards.map((ta,Nn)=>Nn===je?Vt(ta):ta)}))},oe=U.type==="remote"?"Local target":"Local listen",St=U.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.",hs=U.type==="remote"?"Remote listen":"Remote target",an=U.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",ms=Hc(U.localHost||"localhost",U.localPort),As=Hc(U.remoteHost||"localhost",U.remotePort),gn=U.type==="local"&&typeof U.localPort=="number"&&U.localPort>0,on=gn?`http://${sy(U.localHost)}:${U.localPort}`:"",Aa=!!W[U.id],Sn=U.type==="local"?t("settings.remoteInstances.page.forwardType.local"):U.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Gs,{open:Aa,onOpenChange:Vt=>{Z(es=>({...es,[U.id]:Vt}))},className:`${je>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(Ws,{className:"flex items-center gap-2 group",children:[s.jsx(Q,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Aa?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Zv(U)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Sn})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(fa,{checked:U.enabled,onCheckedChange:Vt=>We(es=>({...es,enabled:Vt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(q,{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:()=>us(Vt=>({...Vt,portForwards:Vt.portForwards.filter(es=>es.id!==U.id)})),children:s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Js,{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(Ys,{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(ty(U.type))})]})})}),s.jsxs(Tt,{value:U.type,onValueChange:Vt=>We(es=>({...es,type:Vt==="dynamic"||Vt==="remote"?Vt:"local"})),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[140px]",children:s.jsx(Kt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(at,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(at,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(at,{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(Ys,{label:oe,hint:St})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Be,{className:"h-7 w-32",value:U.localHost||"127.0.0.1",onChange:Vt=>We(es=>({...es,localHost:Vt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(xs,"tabular-nums"),value:U.localPort,onValueChange:Vt=>{We(es=>({...es,localPort:Number.isFinite(Vt)&&Vt>0?Vt:void 0}))},onClear:()=>{We(Vt=>({...Vt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),U.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(Ys,{label:hs,hint:an})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Be,{className:"h-7 w-32",value:U.remoteHost||"",onChange:Vt=>We(es=>({...es,remoteHost:Vt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Ie(xs,"tabular-nums"),value:U.remotePort,onValueChange:Vt=>{We(es=>({...es,remotePort:Number.isFinite(Vt)&&Vt>0?Vt:void 0}))},onClear:()=>{We(Vt=>({...Vt,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:U.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):U.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:As}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(Q,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(Q,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(Q,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(Q,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:As}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),gn?s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(on).then(Vt=>{Vt||G.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(Q,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},U.id)}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const U=Xv();us(je=>({...je,portForwards:[...je.portForwards,U]})),Z(je=>({...je,[U.id]:!0}))},children:[s.jsx(Q,{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(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Zo()},disabled:!_i||m,children:t("settings.common.actions.saveChanges")}),Rs?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{za(Rs.localUrl||"").then(U=>{U.ok&&G.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(Q,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{C&&Vi(C.id)},children:[s.jsx(Q,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,c?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:c}):null]})}),w,s.jsx(Ft,{open:T,onOpenChange:O,children:s.jsxs(Lt,{className:"sm:max-w-2xl",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx($t,{children:C?.nickname?.trim()||C?.sshParsed?.destination||C?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:sr,disabled:z||!Pa.trim(),children:[s.jsx(Q,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{nr()},disabled:z,children:[s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),z?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):P?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:P}):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:F.length>0?F.join(`
29
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Ft,{open:!!B,onOpenChange:U=>{U||Na()},children:s.jsxs(Lt,{className:"sm:max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx($t,{children:B?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:B}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Hi()},children:[s.jsx(Be,{value:ee,onChange:U=>L(U.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(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Na,disabled:$,children:t("settings.common.actions.cancel")}),s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:$,children:t("settings.common.actions.create")})]})]})]})})]})})},Uu=ts({providers:qs(wt())}),cy=ts({error:wt().min(1)}),dy=async()=>{const t=await Dt("/api/provider/disabled");if(t.status===404)return null;if(!t.ok)throw new Error(`Could not read disabled providers (${t.status})`);return Uu.parse(await t.json()).providers},uy=async(t,e)=>{const a=await Dt(`/api/provider/${encodeURIComponent(t)}/disabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({disabled:e})}),n=await a.json().catch(()=>null);if(!a.ok){const o=cy.safeParse(n);throw new Error(o.success?o.data.error:`Could not update the provider (${a.status})`)}return Uu.parse(n).providers},my=(t,e,a)=>t&&!e&&!a,Wc="grid grid-cols-1 gap-0.5 @xl:grid-cols-2 @3xl:grid-cols-3",$u="flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",Jc=t=>{const e=Ke.c(11),{provider:a,onSelect:n}=t;let o;e[0]!==n||e[1]!==a.id?(o=()=>n(a.id),e[0]=n,e[1]=a.id,e[2]=o):o=e[2];let i;e[3]!==a.id?(i=s.jsx(sn,{providerId:a.id,className:"size-4 shrink-0"}),e[3]=a.id,e[4]=i):i=e[4];let r;e[5]!==a.name?(r=s.jsx("span",{className:"truncate",children:a.name}),e[5]=a.name,e[6]=r):r=e[6];let l;return e[7]!==o||e[8]!==i||e[9]!==r?(l=s.jsxs("button",{type:"button",className:$u,onClick:o,children:[i,r]}),e[7]=o,e[8]=i,e[9]=r,e[10]=l):l=e[10],l},py=t=>{const e=Ke.c(56),{providers:a,loadFailed:n,onSelect:o,onSelectCustom:i}=t,{t:r}=ze(),[l,u]=d.useState(""),[m,c]=d.useState(!1);let f;e[0]!==a?(f=a??[],e[0]=a,e[1]=f):f=e[1];let p;e[2]!==f?(p=kf(f),e[2]=f,e[3]=p):p=e[3];const{popular:g,others:h}=p;let k,b,j;if(e[4]!==n||e[5]!==o||e[6]!==i||e[7]!==a||e[8]!==l||e[9]!==r){j=Symbol.for("react.early_return_sentinel");e:{if(k=r("settings.providers.page.custom.title"),a===null){let T;e[13]!==n||e[14]!==r?(T=r(n?"settings.providers.page.state.unableToLoadProviderList":"settings.providers.page.state.loading"),e[13]=n,e[14]=r,e[15]=T):T=e[15];let O;e[16]!==T?(O=s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:T}),e[16]=T,e[17]=O):O=e[17],j=O;break e}let C;e[18]!==r?(C=r("settings.providers.connect.searchPlaceholder"),e[18]=r,e[19]=C):C=e[19];let A;if(e[20]!==l||e[21]!==C?(A=s.jsx(Ko,{value:l,onChange:u,placeholder:C}),e[20]=l,e[21]=C,e[22]=A):A=e[22],b=A,l.trim().length>0){const T=Qn(a,l,gy),O=Ii([k,"other","custom","openai-compatible"],l),z=T.length===0&&!O?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:r("settings.providers.page.connect.noProvidersFound")}):s.jsxs("div",{className:Wc,children:[T.map(P=>s.jsx(Jc,{provider:P,onSelect:o},P.id)),O?s.jsxs("button",{type:"button",className:$u,onClick:i,children:[s.jsx(Q,{name:"add",className:"size-4 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"truncate",children:k})]}):null]});let M;e[23]!==b||e[24]!==z?(M=s.jsxs(s.Fragment,{children:[b,z]}),e[23]=b,e[24]=z,e[25]=M):M=e[25],j=M;break e}}e[4]=n,e[5]=o,e[6]=i,e[7]=a,e[8]=l,e[9]=r,e[10]=k,e[11]=b,e[12]=j}else k=e[10],b=e[11],j=e[12];if(j!==Symbol.for("react.early_return_sentinel"))return j;let x;e[26]!==r?(x=r("settings.providers.connect.popular"),e[26]=r,e[27]=x):x=e[27];let S;if(e[28]!==o||e[29]!==g||e[30]!==r){let C;e[32]!==o||e[33]!==r?(C=A=>s.jsx(qa,{icon:s.jsx(sn,{providerId:A.id,className:"size-5"}),title:A.name,badges:A.recommended?s.jsx(Xs,{tone:"neutral",children:r("settings.providers.connect.recommended")}):null,description:r(A.noteKey),onOpen:()=>o(A.id)},A.id),e[32]=o,e[33]=r,e[34]=C):C=e[34],S=g.map(C),e[28]=o,e[29]=g,e[30]=r,e[31]=S}else S=e[31];let v;e[35]!==r?(v=r("settings.providers.connect.customHint"),e[35]=r,e[36]=v):v=e[36];let N;e[37]!==k||e[38]!==i||e[39]!==v?(N=s.jsx(Lo,{label:k,hint:v,onClick:i}),e[37]=k,e[38]=i,e[39]=v,e[40]=N):N=e[40];let y;e[41]!==S||e[42]!==N?(y=s.jsxs("div",{className:Fo,children:[S,N]}),e[41]=S,e[42]=N,e[43]=y):y=e[43];let I;e[44]!==x||e[45]!==y?(I=s.jsx(Ve,{title:x,divider:!1,settingsItem:"providers.connect",children:y}),e[44]=x,e[45]=y,e[46]=I):I=e[46];let w;e[47]!==o||e[48]!==h||e[49]!==m||e[50]!==r?(w=h.length>0?s.jsx(Ve,{title:r("settings.providers.connect.all"),children:m?s.jsx("div",{className:Wc,children:h.map(C=>s.jsx(Jc,{provider:C,onSelect:o},C.id))}):s.jsx(q,{variant:"outline",size:"sm",className:"!font-normal",onClick:()=>c(!0),children:r("settings.providers.connect.showAll",{count:h.length})})}):null,e[47]=o,e[48]=h,e[49]=m,e[50]=r,e[51]=w):w=e[51];let D;return e[52]!==b||e[53]!==w||e[54]!==I?(D=s.jsxs(s.Fragment,{children:[b,I,w]}),e[52]=b,e[53]=w,e[54]=I,e[55]=D):D=e[55],D};function gy(t){return[t.name,t.id]}const fy=wt(),ul=t=>fy.safeParse(t?.settings?.apiKey).data??null,An=(t,e)=>t.find(a=>a.id===e),ki=t=>t==="opencode-go"?"opencode":t,fo=(t,e)=>{const a=An(t,e)?.connections,n=ki(e);if(n===e)return a;const o=An(t,n)?.connections;if(!(!a&&!o))return[...a??[],...o??[]]},Qc=t=>(t?.methods??[]).filter(e=>e.type==="oauth"||e.type==="external"),ml=t=>(t?.methods??[]).find(e=>e.type==="key"),Yc=t=>t===void 0||ml(t)!==void 0,Zc=t=>(t?.connections??[]).filter(e=>e.type==="credential"),Xc=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,zl=t=>t.status?.status==="needs_auth",hy=t=>{if(t.integrations===null)return null;const e=fo(t.integrations,t.providerId);if((e??[]).some(zl))return{kind:"reauthNeeded"};const a=(e??[]).filter(n=>n.type==="credential").length;return a>1?{kind:"accounts",count:a}:a===1||(t.optionsApiKey?.trim().length??0)>0?{kind:"connected"}:(e??[]).some(n=>n.type==="env")?{kind:"environment"}:e===void 0?null:{kind:"signInNeeded"}},by=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),xy=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,zo=t=>{const e=Ke.c(12),{t:a}=ze();if(t==="zen-promo"){let n;return e[0]!==a?(n=a("settings.classification.source.zenPromo.name"),e[0]=a,e[1]=n):n=e[1],n}if(t==="zen-key"){let n;return e[2]!==a?(n=a("settings.classification.source.zenKey.name"),e[2]=a,e[3]=n):n=e[3],n}if(t==="openrouter"){let n;return e[4]!==a?(n=a("settings.classification.source.openrouter.name"),e[4]=a,e[5]=n):n=e[5],n}if(t==="vercel"){let n;return e[6]!==a?(n=a("settings.classification.source.vercel.name"),e[6]=a,e[7]=n):n=e[7],n}if(t==="typesafe"){let n;return e[8]!==a?(n=a("settings.classification.source.typesafe.name"),e[8]=a,e[9]=n):n=e[9],n}if(t==="custom"){let n;return e[10]!==a?(n=a("settings.classification.source.custom.name"),e[10]=a,e[11]=n):n=e[11],n}return null},Ao=()=>{const t=re.getState();t.setSettingsProvidersClassificationRequested(!0),t.requestSettingsJump("providers","providers.classification")},On=t=>{const e=Ke.c(3),{onClick:a,children:n}=t;let o;return e[0]!==n||e[1]!==a?(o=s.jsx("button",{type:"button",onClick:a,className:"cursor-pointer text-[var(--primary-text)] underline-offset-4 hover:underline focus-visible:underline focus-visible:outline-none",children:n}),e[0]=n,e[1]=a,e[2]=o):o=e[2],o},Ri=()=>{const t=Ke.c(16),{t:e}=ze(),a=Wt(vy),n=Wt(yy),o=Wt(jy),i=zo(o),r=Un();if(!a)return null;if(r&&!n){let f;t[0]!==e?(f=e("settings.jevAccess.enterprise"),t[0]=e,t[1]=f):f=t[1];let p;return t[2]!==f?(p=s.jsx("p",{className:Mt,children:f}),t[2]=f,t[3]=p):p=t[3],p}let l;t[4]!==n||t[5]!==i||t[6]!==e?(l=n&&i?e("settings.jevAccess.via",{provider:i}):e("settings.jevAccess.missing"),t[4]=n,t[5]=i,t[6]=e,t[7]=l):l=t[7];let u;t[8]!==n||t[9]!==e?(u=e(n?"settings.jevAccess.manage":"settings.jevAccess.setUp"),t[8]=n,t[9]=e,t[10]=u):u=t[10];let m;t[11]!==u?(m=s.jsx(On,{onClick:Ao,children:u}),t[11]=u,t[12]=m):m=t[12];let c;return t[13]!==l||t[14]!==m?(c=s.jsxs("p",{className:Mt,children:[l," ",m]}),t[13]=l,t[14]=m,t[15]=c):c=t[15],c};function vy(t){return t.available}function yy(t){return t.jevAvailable}function jy(t){return t.classifier?.effective??null}const ky="https://opencode.ai/v2/docs/policies/",wy=t=>{const e=Ke.c(3),[a,n]=d.useState(null);let o,i;return e[0]!==t?(o=()=>{let r=!1;return n(null),Ls.configDeniesAnyProvider(t).then(l=>{r||n(l)}).catch(l=>{console.warn("[providers] could not read OpenCode provider policies:",l instanceof Error?l.message:String(l)),r||n(null)}),()=>{r=!0}},i=[t],e[0]=t,e[1]=o,e[2]=i):(o=e[1],i=e[2]),d.useEffect(o,i),a},Sy=t=>{const e=Ke.c(44),{directory:a,integrations:n}=t,{t:o}=ze(),i=wy(a),r=Ti(Ay),l=Ti(Ty),u=n===null?null:(An(n,"opencode")?.connections?.length??0)>0,m=i!==!1||u===null?null:u?"console":"open",c=m==="open";let f;e[0]!==o?(f=o("settings.providers.enterprisePolicyLink"),e[0]=o,e[1]=f):f=e[1];let p;e[2]!==f?(p=s.jsx(On,{onClick:Ey,children:f}),e[2]=f,e[3]=p):p=e[3];const g=p,h=c?"border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5":"border-[var(--status-info-border)] bg-[var(--status-info-background)]/30";let k;e[4]!==h?(k=Ie("mb-4 flex items-start gap-2 rounded-lg border p-3",h),e[4]=h,e[5]=k):k=e[5];const b=c?"error-warning":"information",j=c?"text-[var(--status-warning)]":"text-[var(--status-info)]";let x;e[6]!==j?(x=Ie("mt-0.5 size-4 shrink-0",j),e[6]=j,e[7]=x):x=e[7];let S;e[8]!==b||e[9]!==x?(S=s.jsx(Q,{name:b,className:x}),e[8]=b,e[9]=x,e[10]=S):S=e[10];let v;e[11]!==o?(v=o("settings.providers.enterpriseTitle"),e[11]=o,e[12]=v):v=e[12];let N;e[13]!==v?(N=s.jsx("p",{className:Yr,children:v}),e[13]=v,e[14]=N):N=e[14];let y;e[15]!==r||e[16]!==o?(y=r?s.jsx("p",{className:"typography-meta text-foreground",children:o("settings.providers.enterpriseManagedBy",{organization:r})}):null,e[15]=r,e[16]=o,e[17]=y):y=e[17];let I;e[18]!==l||e[19]!==o?(I=l?s.jsx("p",{className:"typography-meta text-foreground",children:o("settings.providers.enterprisePolicyUnreadable")}):null,e[18]=l,e[19]=o,e[20]=I):I=e[20];let w;e[21]!==o?(w=o("settings.providers.enterpriseMode"),e[21]=o,e[22]=w):w=e[22];let D;e[23]!==w?(D=s.jsx("p",{className:"typography-meta text-muted-foreground",children:w}),e[23]=w,e[24]=D):D=e[24];let C;e[25]!==m||e[26]!==g||e[27]!==o?(C=m==="open"?s.jsxs("p",{className:"typography-meta text-foreground",children:[o("settings.providers.enterprisePolicyMissing")," ",g]}):null,e[25]=m,e[26]=g,e[27]=o,e[28]=C):C=e[28];let A;e[29]!==m||e[30]!==g||e[31]!==o?(A=m==="console"?s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[o("settings.providers.enterprisePolicyConsole")," ",g]}):null,e[29]=m,e[30]=g,e[31]=o,e[32]=A):A=e[32];let T;e[33]!==N||e[34]!==y||e[35]!==I||e[36]!==D||e[37]!==C||e[38]!==A?(T=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[N,y,I,D,C,A]}),e[33]=N,e[34]=y,e[35]=I,e[36]=D,e[37]=C,e[38]=A,e[39]=T):T=e[39];let O;return e[40]!==T||e[41]!==k||e[42]!==S?(O=s.jsxs("div",{className:k,children:[S,T]}),e[40]=T,e[41]=k,e[42]=S,e[43]=O):O=e[43],O},Ny=t=>{const e=Ke.c(19),{onOpen:a}=t,{t:n}=ze(),o=Wt(Dy),i=Wt(My),r=Wt(Ry);if(!o)return null;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(sn,{providerId:"typesafe",className:"size-5"}),e[0]=l):l=e[0];let u;e[1]!==n?(u=n("settings.classification.page.title"),e[1]=n,e[2]=u):u=e[2];const m=i?"success":r?"neutral":"warning";let c;e[3]!==i||e[4]!==r||e[5]!==n?(c=n(i?"settings.classification.card.ready":r?"settings.classification.card.off":"settings.classification.card.notSetUp"),e[3]=i,e[4]=r,e[5]=n,e[6]=c):c=e[6];let f;e[7]!==m||e[8]!==c?(f=s.jsx(Xs,{tone:m,children:c}),e[7]=m,e[8]=c,e[9]=f):f=e[9];let p;e[10]!==n?(p=n("settings.classification.card.usedFor"),e[10]=n,e[11]=p):p=e[11];let g;e[12]!==p?(g=s.jsx("span",{className:"min-w-0 truncate",children:p}),e[12]=p,e[13]=g):g=e[13];let h;return e[14]!==a||e[15]!==u||e[16]!==f||e[17]!==g?(h=s.jsx(qa,{icon:l,title:u,subtitle:"jev",badges:f,footer:g,onOpen:a}),e[14]=a,e[15]=u,e[16]=f,e[17]=g,e[18]=h):h=e[18],h},Cy=(t,e)=>{const[a,n]=d.useState(()=>new Set);return d.useEffect(()=>{let o=!1;const i=e?`?directory=${encodeURIComponent(e)}`:"";return Promise.all(t.map(async r=>{try{const l=await Dt(`/api/provider/${encodeURIComponent(r.id)}/source${i}`,{method:"GET",headers:{Accept:"application/json"}});if(!l.ok)return null;const u=await l.json().catch(()=>null);return(u?.sources??u?.data?.sources)?.project?.exists===!0?r.id:null}catch{return null}})).then(r=>{o||n(new Set(r.filter(l=>l!==null)))}),()=>{o=!0}},[e,t]),a},Iy=t=>{const e=Ke.c(14),{status:a}=t,{t:n}=ze();let o;e:switch(a.kind){case"reauthNeeded":{let l;e[0]!==n?(l=n("settings.providers.card.status.reauthNeeded"),e[0]=n,e[1]=l):l=e[1],o=l;break e}case"accounts":{let l;e[2]!==a.count||e[3]!==n?(l=n("settings.providers.card.status.accounts",{count:a.count}),e[2]=a.count,e[3]=n,e[4]=l):l=e[4],o=l;break e}case"connected":{let l;e[5]!==n?(l=n("settings.providers.card.status.connected"),e[5]=n,e[6]=l):l=e[6],o=l;break e}case"environment":{let l;e[7]!==n?(l=n("settings.providers.card.status.environment"),e[7]=n,e[8]=l):l=e[8],o=l;break e}case"signInNeeded":{let l;e[9]!==n?(l=n("settings.providers.card.status.signInNeeded"),e[9]=n,e[10]=l):l=e[10],o=l}}const i=a.kind==="signInNeeded"||a.kind==="reauthNeeded"?"warning":a.kind==="environment"?"neutral":"success";let r;return e[11]!==o||e[12]!==i?(r=s.jsx(Xs,{tone:i,children:o}),e[11]=o,e[12]=i,e[13]=r):r=e[13],r},Py=t=>{const e=Ke.c(49),{providers:a,integrations:n,directory:o,onSelect:i,onConnect:r,onOpenClassification:l,disabledProviders:u,onEnableProvider:m}=t,{t:c}=ze(),[f,p]=d.useState(""),g=Cy(a,o);let h;e[0]!==a?(h=[...a].sort(Oy),e[0]=a,e[1]=h):h=e[1];const b=Qn(h,f,Fy);let j;e[2]!==f?(j=f.trim(),e[2]=f,e[3]=j):j=e[3];const x=j.length>0,S=Un(),v=Qt;let N;e[4]!==c?(N=c("settings.page.providers.title"),e[4]=c,e[5]=N):N=e[5];let y;e[6]!==c?(y=c("settings.providers.grid.description"),e[6]=c,e[7]=y):y=e[7];let I;e[8]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Mi,{className:"w-full min-w-0 @xl:w-56"}),e[8]=I):I=e[8];let w;e[9]!==o||e[10]!==n||e[11]!==S?(w=S?s.jsx(Sy,{directory:o,integrations:n}):null,e[9]=o,e[10]=n,e[11]=S,e[12]=w):w=e[12];let D;e[13]!==a.length||e[14]!==f||e[15]!==c?(D=a.length>0?s.jsx(Ko,{value:f,onChange:p,placeholder:c("settings.providers.grid.searchPlaceholder")}):null,e[13]=a.length,e[14]=f,e[15]=c,e[16]=D):D=e[16];const C=a.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:c("settings.providers.grid.empty")}):b.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:c("settings.providers.grid.noMatches",{query:f.trim()})}):null,A=Fo;let T;e[17]!==x||e[18]!==S||e[19]!==r||e[20]!==c?(T=x||S?null:s.jsx(Lo,{label:c("settings.providers.grid.connect"),hint:c("settings.providers.grid.connectHint"),onClick:r}),e[17]=x,e[18]=S,e[19]=r,e[20]=c,e[21]=T):T=e[21];let O;e[22]!==x||e[23]!==l?(O=x?null:s.jsx(Ny,{onOpen:l}),e[22]=x,e[23]=l,e[24]=O):O=e[24];let z;e[25]!==n||e[26]!==i||e[27]!==g||e[28]!==c?(z=_=>{const B=hy({integrations:n,providerId:_.id,optionsApiKey:ul(_)});return s.jsx(qa,{icon:s.jsx(sn,{providerId:_.id,className:"size-5"}),title:_.name||_.id,badges:B?s.jsx(Iy,{status:B}):null,footer:s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"inline-flex items-center gap-1","aria-label":c("settings.providers.card.models",{count:_.models.length}),children:[s.jsx(Q,{name:"stack",className:"size-3.5 opacity-70","aria-hidden":!0}),s.jsx("span",{className:"tabular-nums",children:_.models.length})]}),g.has(_.id)?s.jsx(So,{children:c("settings.providers.card.source.project")}):null]}),onOpen:()=>i(_.id)},_.id)},e[25]=n,e[26]=i,e[27]=g,e[28]=c,e[29]=z):z=e[29];const M=b.map(z);let P;e[30]!==T||e[31]!==O||e[32]!==M||e[33]!==A?(P=s.jsxs("div",{className:A,children:[T,O,M]}),e[30]=T,e[31]=O,e[32]=M,e[33]=A,e[34]=P):P=e[34];let R;e[35]!==u||e[36]!==m||e[37]!==c?(R=u&&u.length>0&&m?s.jsx(Ve,{title:c("settings.providers.disabled.title"),info:c("settings.providers.disabled.info"),children:s.jsx("div",{className:"space-y-1",children:u.map(_=>s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(sn,{providerId:_,className:"size-4 shrink-0 opacity-60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:_}),s.jsx(q,{size:"xs",variant:"outline",className:"!font-normal",onClick:()=>m(_),children:c("settings.providers.disabled.enable")})]},_))})}):null,e[35]=u,e[36]=m,e[37]=c,e[38]=R):R=e[38];let F;return e[39]!==v||e[40]!==P||e[41]!==R||e[42]!==N||e[43]!==y||e[44]!==I||e[45]!==w||e[46]!==D||e[47]!==C?(F=s.jsxs(v,{title:N,description:y,headerEnd:I,children:[w,D,C,P,R]}),e[39]=v,e[40]=P,e[41]=R,e[42]=N,e[43]=y,e[44]=I,e[45]=w,e[46]=D,e[47]=C,e[48]=F):F=e[48],F};function Ay(t){return t.organization}function Ty(t){return t.policyError!==null}function Ey(){Ss(ky)}function Dy(t){return t.available}function My(t){return t.jevAvailable}function Ry(t){return t.classifier?.selected==="off"}function Oy(t,e){return(t.name||t.id).localeCompare(e.name||e.id,void 0,{sensitivity:"base"})}function Fy(t){return[t.name||t.id,t.id]}const _u=t=>{const e=Ke.c(38),{disabled:a,draft:n}=t,o=a===void 0?!1:a,{t:i}=ze();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"idle"},e[0]=r):r=e[0];const[l,u]=d.useState(r),m=l.kind==="done"?l.result:null,c=zo(m?.source??null)??"";let f;e[1]!==n?(f=async()=>{const w=n?n():void 0;if(w!==null){u({kind:"running"});try{u({kind:"done",result:await cp(w)})}catch(D){const C=D;u({kind:"failed",error:C instanceof Error?C.message:String(C)})}}},e[1]=n,e[2]=f):f=e[2];const p=f;let g;e[3]!==c||e[4]!==m||e[5]!==l.error||e[6]!==l.kind||e[7]!==i?(g=()=>{if(l.kind==="failed")return{text:i("settings.classification.test.failed",{error:l.error}),ok:!1};if(!m)return null;if(m.ok)return{text:i("settings.classification.test.ok",{provider:c,model:m.model,ms:m.ms}),ok:!0};if(m.reason==="unavailable")return{text:i("settings.classification.test.unavailable"),ok:!1};if(m.reason==="timeout")return{text:i("settings.classification.test.timeout",{provider:c}),ok:!1};if(m.reason==="unparsable")return{text:i("settings.classification.test.unparsable",{provider:c}),ok:!1};if(m.reason==="network")return{text:i("settings.classification.test.network",{provider:c,error:m.message??""}),ok:!1};const w=m.status??0;return w===401||w===403?{text:i("settings.classification.test.keyRejected",{provider:c,status:w}),ok:!1}:w===404?{text:i("settings.classification.test.notFound",{provider:c}),ok:!1}:{text:i("settings.classification.test.http",{provider:c,status:w}),ok:!1}},e[3]=c,e[4]=m,e[5]=l.error,e[6]=l.kind,e[7]=i,e[8]=g):g=e[8];const h=g;let k,b,j,x,S,v;if(e[9]!==h||e[10]!==o||e[11]!==p||e[12]!==l.kind||e[13]!==i){k=h(),S="flex min-w-0 flex-col gap-1.5";let w;e[20]!==p?(w=()=>{p()},e[20]=p,e[21]=w):w=e[21];const D=o||l.kind==="running";let C;e[22]!==l.kind||e[23]!==i?(C=l.kind==="running"?i("settings.classification.test.running"):i("settings.classification.test.button"),e[22]=l.kind,e[23]=i,e[24]=C):C=e[24],e[25]!==w||e[26]!==D||e[27]!==C?(v=s.jsx(q,{size:"sm",variant:"outline",className:"self-start",onClick:w,disabled:D,children:C}),e[25]=w,e[26]=D,e[27]=C,e[28]=v):v=e[28],b="status",j="polite",x=Ie(Mt,k&&!k.ok&&"text-[var(--status-error)]"),e[9]=h,e[10]=o,e[11]=p,e[12]=l.kind,e[13]=i,e[14]=k,e[15]=b,e[16]=j,e[17]=x,e[18]=S,e[19]=v}else k=e[14],b=e[15],j=e[16],x=e[17],S=e[18],v=e[19];const N=k?.text??"";let y;e[29]!==N||e[30]!==b||e[31]!==j||e[32]!==x?(y=s.jsx("p",{role:b,"aria-live":j,className:x,children:N}),e[29]=N,e[30]=b,e[31]=j,e[32]=x,e[33]=y):y=e[33];let I;return e[34]!==y||e[35]!==S||e[36]!==v?(I=s.jsxs("div",{className:S,children:[v,y]}),e[34]=y,e[35]=S,e[36]=v,e[37]=I):I=e[37],I},Er="flex w-full min-w-0 items-center gap-2",Dr="h-8 rounded-md px-3 min-w-0 flex-1",Ly=()=>{const{t}=ze(),e=Wt(S=>S.customEndpoint),a=Wt(S=>S.setCustomEndpoint),n=Wt(S=>S.clearCustomEndpoint),[o,i]=d.useState(e?.url??""),[r,l]=d.useState(e?.model??""),[u,m]=d.useState(""),[c,f]=d.useState(!1),[p,g]=d.useState(null);d.useEffect(()=>{i(e?.url??""),l(e?.model??"")},[e?.url,e?.model]);const h=async S=>{f(!0),g(null);try{await S(),m("")}catch(v){g(v instanceof Error?v.message:String(v))}finally{f(!1)}},k=o.trim().length>0&&r.trim().length>0,b=()=>{if(!k)return;const S={url:o.trim(),model:r.trim()},v=u.trim();v&&(S.key=v),h(()=>a(S))},j=()=>{if(!k)return null;const S=u.trim();return S?{url:o.trim(),model:r.trim(),key:S}:{url:o.trim(),model:r.trim()}},x=S=>{S.key==="Enter"&&b()};return e?.pinned?s.jsx(Ve,{title:t("settings.classification.custom.title"),info:t("settings.classification.custom.info"),children:s.jsx("p",{className:xn,children:t("settings.classification.custom.pinned",{url:e.url,model:e.model})})}):s.jsx(Ve,{title:t("settings.classification.custom.title"),info:t("settings.classification.custom.info"),children:s.jsxs("div",{className:ws,children:[s.jsx(ht,{label:t("settings.classification.custom.url.label"),info:t("settings.classification.custom.url.info"),children:s.jsx("div",{className:Er,children:s.jsx(Be,{type:"url",autoComplete:"off",spellCheck:!1,value:o,onChange:S=>i(S.target.value),onKeyDown:x,placeholder:"https://example.com/v1/systemone","aria-label":t("settings.classification.custom.url.label"),className:Dr,disabled:c})})}),s.jsx(ht,{label:t("settings.classification.custom.model.label"),children:s.jsx("div",{className:Er,children:s.jsx(Be,{autoComplete:"off",spellCheck:!1,value:r,onChange:S=>l(S.target.value),onKeyDown:x,placeholder:"jev-latest","aria-label":t("settings.classification.custom.model.label"),className:Dr,disabled:c})})}),s.jsx(ht,{label:t("settings.classification.custom.key.label"),info:t("settings.classification.custom.key.info"),children:s.jsx("div",{className:Er,children:s.jsx(Be,{type:"password",autoComplete:"off",value:u,onChange:S=>m(S.target.value),onKeyDown:x,placeholder:e?.keyPresent?t("settings.classification.custom.key.replacePlaceholder"):t("settings.classification.custom.key.placeholder"),"aria-label":t("settings.classification.custom.key.label"),className:Dr,disabled:c})})}),s.jsxs(ht,{label:null,children:[s.jsx(q,{size:"sm",variant:"outline",onClick:b,disabled:c||!k,children:t("settings.classification.custom.save")}),e?s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>{h(n)},disabled:c,children:t("settings.classification.custom.remove")}):null]}),p?s.jsx("p",{className:xn,children:p}):null,s.jsx(ht,{label:null,children:s.jsx(_u,{disabled:c||!k,draft:j})})]})})},Ky="https://docs.openchamber.dev/classification-providers/",Mr=t=>{const e=Ke.c(6),{text:a,linkLabel:n,onOpen:o}=t;let i;e[0]!==n||e[1]!==o?(i=s.jsx("span",{onClick:Uy,onKeyDown:$y,children:s.jsx(On,{onClick:o,children:n})}),e[0]=n,e[1]=o,e[2]=i):i=e[2];let r;return e[3]!==i||e[4]!==a?(r=s.jsxs(s.Fragment,{children:[a," ",i]}),e[3]=i,e[4]=a,e[5]=r):r=e[5],r},zy=({titleLeading:t,onOpenProvider:e})=>{const{t:a}=ze(),n=Wt(M=>M.available),o=Wt(M=>M.loaded),i=Wt(M=>M.loadError),r=Wt(M=>M.classifier),l=Wt(M=>M.tokenPresent),u=Wt(M=>M.customEndpoint),m=Wt(M=>M.enterpriseMode),c=Wt(M=>M.load),f=Wt(M=>M.setClassifierSource),p=Wt(M=>M.setToken),g=Wt(M=>M.clearToken),h=zo(r?.effective??null),[k,b]=d.useState(""),[j,x]=d.useState(!1),[S,v]=d.useState(null);d.useEffect(()=>{c()},[c]);const N=M=>r?.sources.find(P=>P.id===M)?.usable===!0,y=async M=>{Zt("saving");try{await f(M),Zt("saved")}catch{Zt("error")}},I=async()=>{const M=k.trim();if(M){x(!0),v(null);try{await p(M),b("")}catch(P){v(P instanceof Error?P.message:String(P))}finally{x(!1)}}},w=async()=>{x(!0),v(null);try{await g()}catch(M){v(M instanceof Error?M.message:String(M))}finally{x(!1)}},D=m?u?.pinned?a("settings.classification.status.enterprisePinned"):a("settings.classification.status.enterprise"):!r||r.selected==="off"?null:r.effective===null?a("settings.classification.status.none"):r.effective!==r.selected&&h?a("settings.classification.status.fallback",{provider:h}):null,C=N("zen-promo"),A=N("zen-key"),T=N("openrouter"),O=N("vercel"),z=N("custom");return s.jsxs(Qt,{title:a("settings.classification.page.title"),titleLeading:t,description:s.jsxs("p",{className:xn,children:[a("settings.classification.page.description")," ",s.jsx(On,{onClick:()=>{Ss(Ky)},children:a("settings.classification.page.docsLink")})]}),showSaveStatus:!0,children:[i?s.jsx("p",{className:xn,children:a("settings.routing.loadError",{error:i})}):null,o?!n||!r?s.jsx("p",{className:xn,children:a("settings.classification.unavailable")}):s.jsxs(s.Fragment,{children:[s.jsx(Ve,{title:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(sn,{providerId:"typesafe",className:"size-4 shrink-0"}),a("settings.classification.jev.title")]}),info:a("settings.classification.jev.info"),divider:!1,settingsItem:"providers.classification",children:s.jsxs("div",{className:ws,children:[D?s.jsx("p",{className:Mt,children:D}):null,s.jsxs($s,{"aria-label":a("settings.classification.jev.title"),children:[s.jsx(ns,{selected:r.selected==="off",onSelect:()=>{y("off")},label:a("settings.classification.source.off.name"),description:a("settings.classification.source.off.description")}),m?null:s.jsxs(s.Fragment,{children:[C||r.selected==="zen-promo"?s.jsx(ns,{selected:r.selected==="zen-promo",onSelect:()=>{y("zen-promo")},disabled:!C,label:a("settings.classification.source.zenPromo.name"),description:a(C?"settings.classification.source.zenPromo.description":"settings.classification.source.zenPromo.ended")}):null,s.jsx(ns,{selected:r.selected==="zen-key",onSelect:()=>{y("zen-key")},disabled:!A,label:a("settings.classification.source.zenKey.name"),description:A?a("settings.classification.source.zenKey.description"):s.jsx(Mr,{text:a("settings.classification.source.zenKey.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"OpenCode Zen"}),onOpen:()=>e("opencode")})}),s.jsx(ns,{selected:r.selected==="openrouter",onSelect:()=>{y("openrouter")},disabled:!T,label:a("settings.classification.source.openrouter.name"),description:T?a("settings.classification.source.openrouter.description"):s.jsx(Mr,{text:a("settings.classification.source.openrouter.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"OpenRouter"}),onOpen:()=>e("openrouter")})}),s.jsx(ns,{selected:r.selected==="vercel",onSelect:()=>{y("vercel")},disabled:!O,label:a("settings.classification.source.vercel.name"),description:O?a("settings.classification.source.vercel.description"):s.jsx(Mr,{text:a("settings.classification.source.vercel.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"Vercel AI Gateway"}),onOpen:()=>e("vercel")})}),s.jsx(ns,{selected:r.selected==="typesafe",onSelect:()=>{y("typesafe")},disabled:!l,label:a("settings.classification.source.typesafe.name"),description:a(l?"settings.classification.source.typesafe.description":"settings.classification.source.typesafe.missing")})]}),!m||u?.pinned?s.jsx(ns,{selected:r.selected==="custom",onSelect:()=>{y("custom")},disabled:!z,label:a("settings.classification.source.custom.name"),description:u&&z?a("settings.classification.source.custom.description",{url:u.url}):a("settings.classification.source.custom.missing")}):null]}),m?null:s.jsx(ht,{label:a("settings.routing.token.label"),info:a("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:k,onChange:M=>b(M.target.value),onKeyDown:M=>{M.key==="Enter"&&I()},placeholder:a(l?"settings.routing.token.replacePlaceholder":"settings.routing.token.placeholder"),"aria-label":a("settings.routing.token.label"),className:"h-8 rounded-md px-3 min-w-0 flex-1",disabled:j}),s.jsx(q,{size:"sm",variant:"outline",onClick:()=>{I()},disabled:j||k.trim().length===0,children:a("settings.routing.token.save")}),l?s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>{w()},disabled:j,children:a("settings.routing.token.remove")}):null]})}),S?s.jsx("p",{className:xn,children:S}):null,s.jsx(ht,{label:null,children:s.jsx(_u,{disabled:r.effective===null})})]})}),!m||u?.pinned?s.jsx(Ly,{}):null]}):null]})};function Uy(t){return t.stopPropagation()}function $y(t){return t.stopPropagation()}const ed=t=>{const e=Ke.c(2),{icon:a}=t;let n;return e[0]!==a?(n=s.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:s.jsx(Q,{name:a,className:"size-4"})}),e[0]=a,e[1]=n):n=e[1],n},td=t=>{const e=Ke.c(3),{connection:a,fallback:n}=t;let o;return e[0]!==a||e[1]!==n?(o=zl(a)&&a.status?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] break-words",children:a.status.message}):s.jsx("div",{className:"typography-micro text-muted-foreground",children:n}),e[0]=a,e[1]=n,e[2]=o):o=e[2],o},sd=t=>{const e=Ke.c(11),{connection:a,account:n}=t,{t:o}=ze(),i=zl(a)?a.status?.url:void 0;if(!i)return null;let r;e[0]!==i?(r=()=>{Ss(i)},e[0]=i,e[1]=r):r=e[1];let l;e[2]!==n||e[3]!==o?(l=o("settings.providers.accounts.signInAria",{account:n}),e[2]=n,e[3]=o,e[4]=l):l=e[4];let u;e[5]!==o?(u=o("settings.providers.accounts.signIn"),e[5]=o,e[6]=u):u=e[6];let m;return e[7]!==r||e[8]!==l||e[9]!==u?(m=s.jsx(q,{variant:"outline",size:"xs",onClick:r,"aria-label":l,children:u}),e[7]=r,e[8]=l,e[9]=u,e[10]=m):m=e[10],m},_y=t=>{const e=Ke.c(32),{initial:a,onSave:n,onCancel:o}=t,{t:i}=ze(),[r,l]=d.useState(a);let u;e[0]!==r?(u=r.trim(),e[0]=r,e[1]=u):u=e[1];const m=u;let c;e[2]!==a||e[3]!==o||e[4]!==n||e[5]!==m?(c=()=>{if(m.length===0||m===a){o();return}n(m)},e[2]=a,e[3]=o,e[4]=n,e[5]=m,e[6]=c):c=e[6];const f=c;let p;e[7]!==f?(p=y=>{y.preventDefault(),f()},e[7]=f,e[8]=p):p=e[8];let g;e[9]===Symbol.for("react.memo_cache_sentinel")?(g=y=>l(y.target.value),e[9]=g):g=e[9];let h;e[10]!==o?(h=y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),o())},e[10]=o,e[11]=h):h=e[11];let k;e[12]!==i?(k=i("settings.providers.accounts.nameAria"),e[12]=i,e[13]=k):k=e[13];let b;e[14]!==h||e[15]!==k||e[16]!==r?(b=s.jsx(Be,{autoFocus:!0,value:r,onChange:g,onKeyDown:h,"aria-label":k,className:"h-8 max-w-[18rem]"}),e[14]=h,e[15]=k,e[16]=r,e[17]=b):b=e[17];let j;e[18]!==i?(j=i("settings.providers.accounts.save"),e[18]=i,e[19]=j):j=e[19];let x;e[20]!==j?(x=s.jsx(q,{type:"submit",size:"xs",children:j}),e[20]=j,e[21]=x):x=e[21];let S;e[22]!==i?(S=i("settings.providers.page.actions.cancel"),e[22]=i,e[23]=S):S=e[23];let v;e[24]!==o||e[25]!==S?(v=s.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:o,children:S}),e[24]=o,e[25]=S,e[26]=v):v=e[26];let N;return e[27]!==v||e[28]!==p||e[29]!==b||e[30]!==x?(N=s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-2",onSubmit:p,children:[b,x,v]}),e[27]=v,e[28]=p,e[29]=b,e[30]=x,e[31]=N):N=e[31],N},By=t=>{const e=Ke.c(32),{connections:a,activeId:n,unusedIds:o,busyId:i,onActivate:r,onRename:l,onRemove:u}=t,{t:m}=ze(),[c,f]=d.useState(null);let p;if(e[0]!==a||e[1]!==o){let S;e[3]!==o?(S=v=>v.type==="credential"&&!o.has(v.id),e[3]=o,e[4]=S):S=e[4],p=a.filter(S),e[0]=a,e[1]=o,e[2]=p}else p=e[2];const h=p.length>1;let k;e[5]!==a?(k=a.filter(Vy),e[5]=a,e[6]=k):k=e[6];const b=k.length>1;let j;if(e[7]!==n||e[8]!==i||e[9]!==h||e[10]!==a||e[11]!==r||e[12]!==u||e[13]!==l||e[14]!==c||e[15]!==b||e[16]!==m||e[17]!==o){let S;e[19]!==n||e[20]!==i||e[21]!==h||e[22]!==r||e[23]!==u||e[24]!==l||e[25]!==c||e[26]!==b||e[27]!==m||e[28]!==o?(S=v=>{if(v.type==="env")return s.jsxs("div",{className:"flex min-w-0 items-center gap-3 py-2.5",children:[s.jsx(ed,{icon:"terminal-box"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate font-mono typography-ui-label text-foreground",children:v.name}),s.jsx(td,{connection:v,fallback:m("settings.providers.accounts.environment")})]}),s.jsx(sd,{connection:v,account:v.name})]},`env:${v.name}`);const N=v.id===n,y=o.has(v.id),I=i!==null,w=v.method==="oauth"?m(y?"settings.providers.accounts.method.oauthUnused":"settings.providers.accounts.method.oauth"):v.method==="external"?m(y?"settings.providers.accounts.method.externalUnused":"settings.providers.accounts.method.external"):m(y?"settings.providers.accounts.method.keyUnused":"settings.providers.accounts.method.key"),D=v.method==="oauth"?"user-3":v.method==="external"?"terminal-box":"key";return s.jsxs("div",{className:Ie("flex min-w-0 items-center gap-3 py-2.5",y&&"opacity-60"),children:[s.jsx(ed,{icon:D}),c===v.id?s.jsx(_y,{initial:v.label,onCancel:()=>f(null),onSave:C=>{f(null),l(v,C)}}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:v.label}),b&&N?s.jsx("span",{className:"shrink-0 rounded-full bg-[var(--interactive-selection)] px-2 py-px text-[10px] font-medium text-[var(--interactive-selection-foreground)]",children:m("settings.providers.accounts.active")}):null]}),s.jsx(td,{connection:v,fallback:w})]}),s.jsx(sd,{connection:v,account:v.label}),h&&!N&&!y?s.jsxs(q,{variant:"outline",size:"xs",disabled:I,onClick:()=>r(v),"aria-label":m("settings.providers.accounts.useAria",{account:v.label}),children:[i===v.id?s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}):null,m("settings.providers.accounts.use")]}):null,s.jsxs(Jn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsx(q,{variant:"ghost",size:"icon",disabled:I,className:Ie(as,"shrink-0"),"aria-label":m("settings.providers.accounts.menuAria",{account:v.label}),children:s.jsx(Q,{name:"more-2",className:"size-4"})})}),s.jsxs(Gn,{align:"end",children:[s.jsxs(Fn,{onSelect:()=>f(v.id),children:[s.jsx(Q,{name:"pencil",className:"size-4"}),m("settings.providers.accounts.rename")]}),s.jsxs(Fn,{variant:"destructive",onSelect:()=>u(v),children:[s.jsx(Q,{name:"delete-bin",className:"size-4"}),m("settings.providers.accounts.remove")]})]})]})]})]},v.id)},e[19]=n,e[20]=i,e[21]=h,e[22]=r,e[23]=u,e[24]=l,e[25]=c,e[26]=b,e[27]=m,e[28]=o,e[29]=S):S=e[29],j=a.map(S),e[7]=n,e[8]=i,e[9]=h,e[10]=a,e[11]=r,e[12]=u,e[13]=l,e[14]=c,e[15]=b,e[16]=m,e[17]=o,e[18]=j}else j=e[18];let x;return e[30]!==j?(x=s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:j}),e[30]=j,e[31]=x):x=e[31],x};function Vy(t){return t.type==="credential"}const Ul={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},Rr="__custom_provider__",Hy=/^[a-z0-9][a-z0-9-_]*$/,Bu=/^https?:\/\//,qy=/^\{env:([^}]+)\}$/,To=t=>{if(!t)return;if(typeof t.package=="string"&&t.package)return t.package;const e=t.api?.npm;return typeof e=="string"&&e?`aisdk:${e}`:void 0},Vu=t=>t.settings&&typeof t.settings=="object"?t.settings:t.options&&typeof t.options=="object"?t.options:{};let Gy=0;const Eo=()=>`row-${Gy++}`,Uo=()=>({row:Eo(),id:"",name:"",contextWindow:"",maxOutputTokens:"",inputCapabilities:["text"],outputCapabilities:["text"],tools:!0,capabilitiesKnown:!1,variants:""}),nd=ts({context:ko().optional(),output:ko().optional()}),ad=ts({tools:Di(),input:qs(wt()),output:qs(wt())}),Wy=ts({id:wt(),name:wt(),limit:nd.optional(),capabilities:ad.optional(),metadata:ts({providerID:wt(),modelID:wt(),name:wt().optional(),limit:nd.optional(),capabilities:ad.optional()}).optional()}),Jy=ts({models:qs(Wy)}),Qy=ts({error:wt()}),Yy=t=>{const e=t.metadata,a=t.limit?.context??e?.limit?.context,n=t.limit?.output??e?.limit?.output,o=t.capabilities??e?.capabilities,i=!!(t.limit||t.capabilities);return{...Uo(),id:t.id,name:t.name!==t.id?t.name:e?.name??t.id,contextWindow:a?String(a):"",maxOutputTokens:n?String(n):"",inputCapabilities:o?.input??["text"],outputCapabilities:o?.output??["text"],tools:o?.tools??!0,capabilitiesKnown:!!o,...i?{metadataSource:"provider-api"}:e?{metadataSource:"models.dev"}:{}}};function Zy(t,e){switch(t){case"openai-chat":return{settings:{reasoningEffort:e}};case"openai-responses":return{settings:{reasoningEffort:e,reasoningSummary:"auto",include:["reasoning.encrypted_content"]}};case"anthropic-messages":return{settings:{thinking:{type:"adaptive",display:"summarized"},effort:e}}}}function Xy(t){const e=t.split(/[,\s]+/).map(a=>a.trim()).filter(Boolean);return e.filter((a,n)=>e.indexOf(a)===n)}function e1(t){return Object.fromEntries((t??[]).map(({id:e,...a})=>[e,a]))}const $l=()=>({row:Eo(),key:"",value:""}),t1=()=>({providerID:"",name:"",icon:null,protocol:"openai-chat",baseURL:"",apiKey:"",models:[Uo()],headers:[$l()]}),Hu={"@opencode/ai/providers/openai-compatible":"openai-chat","@opencode/ai/providers/openai":"openai-responses","@opencode/ai/providers/anthropic":"anthropic-messages"};function s1(t){const e=t?Hu[t]:void 0;if(e)return e;switch(t){case"aisdk:@ai-sdk/openai":case"@ai-sdk/openai":return"openai-responses";case"aisdk:@ai-sdk/anthropic":case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function n1(t){const e=t.trim();if(!e)return{};const n=e.match(qy)?.[1]?.trim();return n?{env:n}:{key:e}}function a1(t){const e=Vu(t),a=typeof e.baseURL=="string"?e.baseURL.trim():"";if(a&&Bu.test(a))return!0;const n=new Set([...Object.values(Ul),...Object.keys(Hu)]);return n.has(To(t)??"")?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>!i||typeof i!="object"?!1:n.has(To(i)??""))}function id(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&a1(t):!1}function od(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function rd(t){const e=Vu(t),a=typeof e.baseURL=="string"?e.baseURL:"",n=t.headers&&typeof t.headers=="object"?t.headers:e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},o=Object.entries(n).filter(m=>typeof m[0]=="string"&&typeof m[1]=="string").map(([m,c])=>({row:Eo(),key:m,value:c})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([m,c])=>{const f=c&&typeof c=="object"?c:{};return{id:m,modelID:typeof f.modelID=="string"?f.modelID:m,name:typeof f.name=="string"?f.name:m,package:typeof f.package=="string"?f.package:void 0,variants:qu.safeParse(f.variants).data,limit:Gu.safeParse(f.limit).data,capabilities:Wu.safeParse(f.capabilities).data}}):[],r=i.length>0?i.map(m=>{const c=typeof m?.modelID=="string"&&m.modelID?m.modelID:typeof m?.id=="string"?m.id:"",f=e1(m?.variants);return{row:Eo(),id:c,name:typeof m?.name=="string"?m.name:c,contextWindow:m.limit?.context?String(m.limit.context):"",maxOutputTokens:m.limit?.output?String(m.limit.output):"",inputCapabilities:m.capabilities?.input??["text"],outputCapabilities:m.capabilities?.output??["text"],tools:m.capabilities?.tools??!0,capabilitiesKnown:!!m.capabilities,variants:Object.keys(f).join(", "),savedVariants:f}}):[Uo()],l=Array.isArray(t.env)?t.env.find(m=>typeof m=="string"&&m.trim().length>0)?.trim():void 0,u=i.map(m=>To(m)).find(m=>!!m);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,icon:null,protocol:s1(To(t)??u),baseURL:a,apiKey:l?`{env:${l}}`:"",models:r,headers:o.length>0?o:[$l()]}}const qu=qs(ts({id:wt(),settings:Rn(wt(),el()).optional(),headers:Rn(wt(),wt()).optional(),body:Rn(wt(),el()).optional()})),Gu=ts({context:ko().optional(),output:ko().optional()}),Wu=ts({tools:Di().optional(),input:qs(wt()).optional(),output:qs(wt()).optional()}),i1=ts({name:wt().optional(),package:wt().optional(),env:qs(wt()).optional(),settings:Rn(wt(),el()).optional(),headers:Rn(wt(),wt()).optional(),models:Rn(wt(),ts({modelID:wt().optional(),name:wt().optional(),package:wt().optional(),variants:qu.optional(),limit:Gu.optional(),capabilities:Wu.optional()})).optional()});function o1(t,e,a=null){const n=Array.isArray(t.models)?t.models.map(r=>({...r,variants:void 0})):t.models,o=rd({...t,models:n});if(!e)return{...o,icon:a,models:o.models.map(r=>({...r,savedVariants:void 0}))};const i=rd({...e,id:t.id});return{providerID:t.id,name:e.name?.trim()?i.name:o.name,icon:a,protocol:e.package?i.protocol:o.protocol,baseURL:i.baseURL||o.baseURL,apiKey:i.apiKey,models:e.models&&Object.keys(e.models).length>0?i.models:o.models.map(r=>({...r,savedVariants:void 0})),headers:i.headers}}function r1(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:o,key:i}=n1(t.form.apiKey),r=t.disabledProviders??[],l=t.editingProviderID?.trim(),u=e?Hy.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),m=a?void 0:t.t("settings.providers.page.custom.error.name.required"),c=n?Bu.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(o||i||l&&t.allowExistingAuth&&l===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),g=r.includes(e),k=u||!!(l&&l===e)?void 0:t.existingProviderIDs.has(e)&&!g?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,j=t.form.models.map(C=>{const A=C.id.trim(),T=A?b.has(A)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(A):t.t("settings.providers.page.custom.error.required"),O=C.name.trim()?void 0:t.t("settings.providers.page.custom.error.required"),z=C.contextWindow.trim()&&!no(C.contextWindow)?t.t("settings.providers.page.custom.error.positiveInteger"):void 0,M=C.maxOutputTokens.trim()&&!no(C.maxOutputTokens)?t.t("settings.providers.page.custom.error.positiveInteger"):void 0;return{id:T,name:O,contextWindow:z,maxOutputTokens:M}}),x=j.every(C=>!C.id&&!C.name&&!C.contextWindow&&!C.maxOutputTokens),S=Object.fromEntries(t.form.models.map(C=>{const A=C.id.trim(),T={modelID:A,name:C.name.trim()},O=no(C.contextWindow),z=no(C.maxOutputTokens);(O||z)&&(T.limit={...O?{context:O}:{},...z?{output:z}:{}}),C.capabilitiesKnown&&(T.capabilities={tools:C.tools,input:C.inputCapabilities,output:C.outputCapabilities});const M=Xy(C.variants);return(M.length>0||C.savedVariants!==void 0)&&(T.variants=M.map(P=>({id:P,...C.savedVariants?.[P]??Zy(t.form.protocol,P)}))),[A,T]})),v=new Set,N=t.form.headers.map(C=>{const A=C.key.trim(),T=C.value.trim();if(!A&&!T)return{};const O=A?v.has(A.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void v.add(A.toLowerCase()):t.t("settings.providers.page.custom.error.required"),z=T?void 0:t.t("settings.providers.page.custom.error.required");return{key:O,value:z}}),y=N.every(C=>!C.key&&!C.value),I=Object.fromEntries(t.form.headers.map(C=>({key:C.key.trim(),value:C.value.trim()})).filter(C=>C.key&&C.value).map(C=>[C.key,C.value])),w={providerID:u??k,name:m,baseURL:c,apiKey:p};return!u&&!k&&!m&&!c&&!p&&x&&y?{err:w,models:j,headers:N,result:{providerID:e,name:a,icon:t.form.icon,apiKey:i,...!o&&!i?{keepsStoredCredential:!0}:{},config:l1({protocol:t.form.protocol,name:a,env:o,baseURL:n,headers:I,models:S})}}:{err:w,models:j,headers:N}}function no(t){const e=t.trim();if(!/^\d+$/.test(e))return;const a=Number(e);return Number.isSafeInteger(a)&&a>0?a:void 0}function l1(t){const e={package:Ul[t.protocol],name:t.name,settings:{baseURL:t.baseURL},models:t.models};return t.env&&(e.env=[t.env]),Object.keys(t.headers).length>0&&(e.headers=t.headers),e}function c1(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function d1(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user",hasCredential:!!(t.apiKey||t.keepsStoredCredential)}}const u1=[250,500,1e3,2e3];async function m1(t,e=a=>new Promise(n=>setTimeout(n,a))){for(let a=0;;a+=1)try{await t();return}catch(n){const o=u1[a];if(!(n instanceof Error&&/not found/i.test(n.message))||o===void 0)throw n;await e(o)}}const p1=8,g1=t=>{const e=Ke.c(78),{models:a,existingIds:n,onAdd:o,onCancel:i}=t,{t:r}=ze(),[l,u]=d.useState("");let m;e[0]!==n||e[1]!==a?(m=()=>new Set(a.filter(L=>!n.has(L.id)).map(f1)),e[0]=n,e[1]=a,e[2]=m):m=e[2];const[c,f]=d.useState(m);let p,g,h,k,b,j,x,S,v,N;if(e[3]!==n||e[4]!==a||e[5]!==l||e[6]!==c||e[7]!==r){const L=l.trim().toLocaleLowerCase();N=L?a.filter(W=>[W.id,W.name,W.metadata?.name].some(Z=>Z?.toLocaleLowerCase().includes(L))):a;let $;e[18]!==n?($=W=>!n.has(W.id),e[18]=n,e[19]=$):$=e[19],g=N.filter($),p=g.length>0&&g.every(W=>c.has(W.id)),v=()=>f(W=>{const Z=new Set(W);for(const te of g)p?Z.delete(te.id):Z.add(te.id);return Z}),S="space-y-2",x="flex items-end justify-between gap-2",b="min-w-0";let H;e[20]!==r?(H=r("settings.providers.page.custom.discovery.review"),e[20]=r,e[21]=H):H=e[21],e[22]!==H?(j=s.jsx("p",{className:Nt,children:H}),e[22]=H,e[23]=j):j=e[23],h=Mt,k=r("settings.providers.page.custom.discovery.counts",{matching:N.length,total:a.length,selected:c.size}),e[3]=n,e[4]=a,e[5]=l,e[6]=c,e[7]=r,e[8]=p,e[9]=g,e[10]=h,e[11]=k,e[12]=b,e[13]=j,e[14]=x,e[15]=S,e[16]=v,e[17]=N}else p=e[8],g=e[9],h=e[10],k=e[11],b=e[12],j=e[13],x=e[14],S=e[15],v=e[16],N=e[17];let y;e[24]!==h||e[25]!==k?(y=s.jsx("p",{className:h,children:k}),e[24]=h,e[25]=k,e[26]=y):y=e[26];let I;e[27]!==b||e[28]!==j||e[29]!==y?(I=s.jsxs("div",{className:b,children:[j,y]}),e[27]=b,e[28]=j,e[29]=y,e[30]=I):I=e[30];const w=g.length===0;let D;e[31]!==p||e[32]!==r?(D=r(p?"settings.providers.page.custom.discovery.deselectAll":"settings.providers.page.custom.discovery.selectAll"),e[31]=p,e[32]=r,e[33]=D):D=e[33];let C;e[34]!==w||e[35]!==D||e[36]!==v?(C=s.jsx(q,{type:"button",variant:"ghost",size:"xs",disabled:w,onClick:v,children:D}),e[34]=w,e[35]=D,e[36]=v,e[37]=C):C=e[37];let A;e[38]!==C||e[39]!==x||e[40]!==I?(A=s.jsxs("div",{className:x,children:[I,C]}),e[38]=C,e[39]=x,e[40]=I,e[41]=A):A=e[41];let T;e[42]!==a.length||e[43]!==l||e[44]!==r?(T=a.length>p1?s.jsxs("div",{className:"relative",children:[s.jsx(Q,{name:"search",className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),s.jsx(Be,{value:l,onChange:L=>u(L.target.value),onKeyDown:L=>{L.key==="Escape"&&l&&(L.preventDefault(),L.stopPropagation(),u(""))},placeholder:r("settings.agents.modelSelector.searchPlaceholder"),"aria-label":r("settings.agents.modelSelector.searchPlaceholder"),className:"h-8 rounded-md pl-8"})]}):null,e[42]=a.length,e[43]=l,e[44]=r,e[45]=T):T=e[45];let O;e[46]!==n||e[47]!==c||e[48]!==r||e[49]!==N?(O=N.length>0?N.map(L=>{const $=n.has(L.id),H=L.limit?.context??L.metadata?.limit?.context,W=L.limit?.output??L.metadata?.limit?.output,Z=[H?r("settings.providers.page.custom.discovery.contextValue",{value:xo(H)}):null,W?r("settings.providers.page.custom.discovery.outputValue",{value:xo(W)}):null].filter(Boolean).join(" · ");return s.jsx(st,{checked:$||c.has(L.id),disabled:$,onChange:te=>f(J=>{const ie=new Set(J);return te?ie.add(L.id):ie.delete(L.id),ie}),label:s.jsx("span",{className:"block truncate font-mono text-xs",children:L.id}),description:$?r("settings.providers.page.custom.discovery.alreadyAdded"):Z||void 0,ariaLabel:L.id,className:"py-1.5"},L.id)}):s.jsx("p",{className:"px-2 py-6 text-center typography-meta text-muted-foreground",children:r("settings.agents.modelSelector.state.noModelsFound")}),e[46]=n,e[47]=c,e[48]=r,e[49]=N,e[50]=O):O=e[50];let z;e[51]!==O?(z=s.jsx(Ps,{outerClassName:"max-h-[min(18rem,45dvh)] rounded-md border border-border/60",className:"px-2 py-1",disableHorizontal:!0,preventOverscroll:!0,useScrollShadow:!0,children:O}),e[51]=O,e[52]=z):z=e[52];const M=c.size===0;let P;e[53]!==a||e[54]!==o||e[55]!==c?(P=()=>o(a.filter(L=>c.has(L.id))),e[53]=a,e[54]=o,e[55]=c,e[56]=P):P=e[56];let R;e[57]!==c.size||e[58]!==r?(R=r("settings.providers.page.custom.discovery.importSelected",{count:c.size}),e[57]=c.size,e[58]=r,e[59]=R):R=e[59];let F;e[60]!==M||e[61]!==P||e[62]!==R?(F=s.jsx(q,{type:"button",size:"xs",className:"!font-normal",disabled:M,onClick:P,children:R}),e[60]=M,e[61]=P,e[62]=R,e[63]=F):F=e[63];let _;e[64]!==r?(_=r("settings.providers.page.custom.discovery.cancel"),e[64]=r,e[65]=_):_=e[65];let B;e[66]!==i||e[67]!==_?(B=s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:i,children:_}),e[66]=i,e[67]=_,e[68]=B):B=e[68];let V;e[69]!==F||e[70]!==B?(V=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[F,B]}),e[69]=F,e[70]=B,e[71]=V):V=e[71];let ee;return e[72]!==A||e[73]!==T||e[74]!==z||e[75]!==V||e[76]!==S?(ee=s.jsxs("div",{className:S,children:[A,T,z,V]}),e[72]=A,e[73]=T,e[74]=z,e[75]=V,e[76]=S,e[77]=ee):ee=e[77],ee};function f1(t){return t.id}const h1=["text","image","audio","video","pdf"],ld=t=>{const e=Number(t.trim());return Number.isSafeInteger(e)&&e>0?e:null},b1=t=>{const e=Ke.c(70),{model:a,errors:n,expanded:o,onToggle:i,onChange:r,onToggleCapability:l,onToolsChange:u,onRemove:m}=t,{t:c}=ze(),f=d.useId();let p;e[0]!==a.id?(p=a.id.trim(),e[0]=a.id,e[1]=p):p=e[1];const g=p;let h;e[2]!==a.name?(h=a.name.trim(),e[2]=a.name,e[3]=h):h=e[3];const k=h;let b;e[4]!==g||e[5]!==k||e[6]!==c?(b=k||g||c("settings.providers.page.custom.models.untitled"),e[4]=g,e[5]=k,e[6]=c,e[7]=b):b=e[7];const j=b;let x,S,v;if(e[8]!==a.contextWindow||e[9]!==a.inputCapabilities||e[10]!==a.maxOutputTokens||e[11]!==c){const $=ld(a.contextWindow),H=ld(a.maxOutputTokens),W=a.inputCapabilities.filter(x1);x=$?c("settings.providers.page.custom.discovery.contextValue",{value:xo($)}):null,S=H?c("settings.providers.page.custom.discovery.outputValue",{value:xo(H)}):null,v=W.length>0?W.join(", "):null,e[8]=a.contextWindow,e[9]=a.inputCapabilities,e[10]=a.maxOutputTokens,e[11]=c,e[12]=x,e[13]=S,e[14]=v}else x=e[12],S=e[13],v=e[14];let N;e[15]!==a.tools||e[16]!==c?(N=a.tools?null:c("settings.providers.page.custom.models.toolsOff"),e[15]=a.tools,e[16]=c,e[17]=N):N=e[17];let y;e[18]!==x||e[19]!==S||e[20]!==v||e[21]!==N?(y=[x,S,v,N].filter(Boolean),e[18]=x,e[19]=S,e[20]=v,e[21]=N,e[22]=y):y=e[22];const I=y.join(" · "),w=v1,D=o&&"rotate-90";let C;e[23]!==D?(C=Ie("size-4 shrink-0 text-muted-foreground transition-transform",D),e[23]=D,e[24]=C):C=e[24];let A;e[25]!==C?(A=s.jsx(Q,{name:"arrow-right-s",className:C,"aria-hidden":!0}),e[25]=C,e[26]=A):A=e[26];const T=!k&&!g&&"text-muted-foreground";let O;e[27]!==T?(O=Ie("truncate",Nt,T),e[27]=T,e[28]=O):O=e[28];let z;e[29]!==O||e[30]!==j?(z=s.jsx("span",{className:O,children:j}),e[29]=O,e[30]=j,e[31]=z):z=e[31];let M;e[32]!==g||e[33]!==k?(M=k&&g&&k!==g?s.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:g}):null,e[32]=g,e[33]=k,e[34]=M):M=e[34];let P;e[35]!==z||e[36]!==M?(P=s.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[z,M]}),e[35]=z,e[36]=M,e[37]=P):P=e[37];let R;e[38]!==I?(R=I?s.jsx("span",{className:Ie("truncate",Mt),children:I}):null,e[38]=I,e[39]=R):R=e[39];let F;e[40]!==P||e[41]!==R?(F=s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[P,R]}),e[40]=P,e[41]=R,e[42]=F):F=e[42];let _;e[43]!==f||e[44]!==o||e[45]!==i||e[46]!==A||e[47]!==F?(_=s.jsxs("button",{type:"button",onClick:i,"aria-expanded":o,"aria-controls":f,className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[var(--interactive-focus-ring)]",children:[A,F]}),e[43]=f,e[44]=o,e[45]=i,e[46]=A,e[47]=F,e[48]=_):_=e[48];let B;e[49]!==m||e[50]!==c?(B=m?s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:as,onClick:m,"aria-label":c("settings.providers.page.custom.models.remove"),children:s.jsx(Q,{name:"delete-bin",className:"size-4"})}):null,e[49]=m,e[50]=c,e[51]=B):B=e[51];let V;e[52]!==_||e[53]!==B?(V=s.jsxs("div",{className:"flex items-center gap-1 py-1",children:[_,B]}),e[52]=_,e[53]=B,e[54]=V):V=e[54];let ee;e[55]!==f||e[56]!==n?.contextWindow||e[57]!==n?.id||e[58]!==n?.maxOutputTokens||e[59]!==n?.name||e[60]!==o||e[61]!==a||e[62]!==r||e[63]!==l||e[64]!==u||e[65]!==c?(ee=o?s.jsxs("div",{id:f,className:"space-y-3 pb-4 pl-7 pr-1 pt-1",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-2 @xl:grid-cols-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.models.idLabel")}),s.jsx(Be,{value:a.id,onChange:$=>r("id",$.target.value),placeholder:c("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!n?.id,"aria-label":c("settings.providers.page.custom.models.idLabel")}),w(n?.id)]}),s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.models.nameLabel")}),s.jsx(Be,{value:a.name,onChange:$=>r("name",$.target.value),placeholder:c("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-invalid":!!n?.name,"aria-label":c("settings.providers.page.custom.models.nameLabel")}),w(n?.name)]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 @xl:grid-cols-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.models.contextWindow")}),s.jsx(Be,{inputMode:"numeric",value:a.contextWindow,onChange:$=>r("contextWindow",$.target.value),placeholder:"128000",className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!n?.contextWindow,"aria-label":c("settings.providers.page.custom.models.contextWindow")}),w(n?.contextWindow)]}),s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.models.maxOutputTokens")}),s.jsx(Be,{inputMode:"numeric",value:a.maxOutputTokens,onChange:$=>r("maxOutputTokens",$.target.value),placeholder:"16384",className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!n?.maxOutputTokens,"aria-label":c("settings.providers.page.custom.models.maxOutputTokens")}),w(n?.maxOutputTokens)]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.models.variantsLabel")}),s.jsx(Gt,{children:c("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(Be,{value:a.variants,onChange:$=>r("variants",$.target.value),placeholder:c("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":c("settings.providers.page.custom.models.variantsLabel")})]}),["inputCapabilities","outputCapabilities"].map($=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:Nt,children:c($==="inputCapabilities"?"settings.providers.page.custom.models.inputCapabilities":"settings.providers.page.custom.models.outputCapabilities")}),s.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:h1.map(H=>s.jsx(st,{checked:a[$].includes(H),onChange:()=>l($,H),label:H,ariaLabel:H},H))})]},$)),s.jsx(st,{checked:a.tools,onChange:u,label:c("settings.providers.page.custom.models.tools"),ariaLabel:c("settings.providers.page.custom.models.tools")}),a.metadataSource==="models.dev"||a.metadataSource==="provider-api"?s.jsx("p",{className:Mt,children:a.metadataSource==="models.dev"?c("settings.providers.page.custom.discovery.source.models.dev"):c("settings.providers.page.custom.discovery.source.provider-api")}):null]}):null,e[55]=f,e[56]=n?.contextWindow,e[57]=n?.id,e[58]=n?.maxOutputTokens,e[59]=n?.name,e[60]=o,e[61]=a,e[62]=r,e[63]=l,e[64]=u,e[65]=c,e[66]=ee):ee=e[66];let L;return e[67]!==V||e[68]!==ee?(L=s.jsxs("div",{className:"border-b border-border/50 last:border-b-0",children:[V,ee]}),e[67]=V,e[68]=ee,e[69]=L):L=e[69],L};function x1(t){return t!=="text"}function v1(t){return t?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:t}):null}const cd=({existingProviderIDs:t,disabledProviders:e=[],busy:a=!1,mode:n="create",initialValues:o,allowExistingAuth:i=!1,authFailureHint:r=null,onSubmit:l,onCancel:u,onDisconnect:m})=>{const{t:c}=ze(),f=n==="edit",[p,g]=d.useState(()=>o??t1()),[h,k]=d.useState({}),[b,j]=d.useState([]),[x,S]=d.useState([]),[v,N]=d.useState(!1),[y,I]=d.useState(null),[w,D]=d.useState(null),[C,A]=d.useState(()=>new Set(o?[]:p.models.map(L=>L.row))),T=d.useRef(null),O=p.providerID.trim()||"custom",{hasLogo:z}=dp(O);d.useEffect(()=>{o&&(f&&T.current===o.providerID||(T.current=f?o.providerID:null,g(o),k({}),j([]),S([]),A(new Set),D(null)))},[o,f]);const M=(L,$)=>{g(H=>({...H,[L]:$})),k(H=>({...H,[L]:void 0}))},P=(L,$,H)=>{g(W=>({...W,models:W.models.map((Z,te)=>te===L?{...Z,[$]:H,metadataSource:"manual"}:Z)})),j(W=>{const Z=[...W];return Z[L]={...Z[L]??{},[$]:void 0},Z})},R=(L,$,H)=>{g(W=>({...W,headers:W.headers.map((Z,te)=>te===L?{...Z,[$]:H}:Z)})),S(W=>{const Z=[...W];return Z[L]={...Z[L]??{},[$]:void 0},Z})},F=async()=>{N(!0),I(null);try{const L=Object.fromEntries(p.headers.map(Z=>[Z.key.trim(),Z.value.trim()]).filter(([Z,te])=>Z&&te)),$=await Dt("/api/provider/discover-models",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({providerID:f?p.providerID:void 0,baseURL:p.baseURL,apiKey:p.apiKey,headers:L,enrich:!0,metadataProviderID:p.providerID})}),H=await $.json().catch(()=>null),W=Jy.safeParse(H);if(!$.ok||!W.success)throw new Error(Qy.safeParse(H).data?.error||c("settings.providers.page.custom.discovery.failed"));D(W.data.models)}catch(L){I(L instanceof Error?L.message:c("settings.providers.page.custom.discovery.failed"))}finally{N(!1)}},_=L=>{g($=>{const H=new Set($.models.map(te=>te.id.trim()).filter(Boolean)),W=L.filter(te=>!H.has(te.id)).map(Yy),Z=$.models.filter(te=>te.id.trim()||te.name.trim());return{...$,models:[...Z,...W]}}),j([]),D(null)},B=L=>A($=>{const H=new Set($);return H.has(L)?H.delete(L):H.add(L),H}),V=(L,$,H)=>{g(W=>({...W,models:W.models.map((Z,te)=>{if(te!==L)return Z;const J=Z[$],ie=J.includes(H)?J.filter(pe=>pe!==H):[...J,H];return{...Z,[$]:ie,capabilitiesKnown:!0,metadataSource:"manual"}})}))},ee=async L=>{if(L.preventDefault(),a)return;const $=r1({form:p,t:((W,Z)=>c(W,Z)),existingProviderIDs:t,disabledProviders:e,editingProviderID:f?p.providerID:void 0,allowExistingAuth:f&&i});k($.err),j($.models),S($.headers);const H=p.models.filter((W,Z)=>Object.values($.models[Z]??{}).some(Boolean)).map(W=>W.row);H.length>0&&A(W=>new Set([...W,...H])),$.result&&await l($.result)};return s.jsxs("form",{onSubmit:ee,className:"space-y-0",children:[s.jsxs(Ve,{title:c(f?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),divider:!1,settingsItem:"providers.custom",contentClassName:ws,children:[s.jsx("p",{className:Mt,children:c("settings.providers.page.custom.description")}),r?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:r}):null,s.jsxs(Et,{label:c("settings.providers.page.custom.field.providerID.label"),info:c("settings.providers.page.custom.field.providerID.info"),children:[s.jsx(Be,{value:p.providerID,onChange:L=>M("providerID",L.target.value),placeholder:c("settings.providers.page.custom.field.providerID.placeholder"),className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:!f,disabled:f||a,"aria-invalid":!!h.providerID,"aria-label":c("settings.providers.page.custom.field.providerID.label")}),h.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:h.providerID}):null]}),s.jsx(Et,{label:c("settings.providers.page.custom.field.protocol.label"),info:c("settings.providers.page.custom.field.protocol.info"),children:s.jsxs(Tt,{value:p.protocol,onValueChange:L=>{L in Ul&&g($=>({...$,protocol:L,models:$.models.map(H=>H.savedVariants?{...H,savedVariants:{}}:H)}))},disabled:a,children:[s.jsx(Pt,{"aria-label":c("settings.providers.page.custom.field.protocol.label"),className:"w-full",children:s.jsx(Kt,{})}),s.jsxs(At,{children:[s.jsx(at,{value:"openai-chat",children:c("settings.providers.page.custom.field.protocol.openaiChat")}),s.jsx(at,{value:"openai-responses",children:c("settings.providers.page.custom.field.protocol.openaiResponses")}),s.jsx(at,{value:"anthropic-messages",children:c("settings.providers.page.custom.field.protocol.anthropicMessages")})]})]})}),s.jsxs(Et,{label:c("settings.providers.page.custom.field.name.label"),info:c("settings.providers.page.custom.field.name.info"),children:[s.jsx(Be,{value:p.name,onChange:L=>M("name",L.target.value),placeholder:c("settings.providers.page.custom.field.name.placeholder"),className:"h-8 rounded-md px-3","aria-invalid":!!h.name,"aria-label":c("settings.providers.page.custom.field.name.label")}),h.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:h.name}):null]}),s.jsx(Et,{label:c("settings.providers.page.custom.field.icon.label"),info:c("settings.providers.page.custom.field.icon.info"),children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",role:"group","aria-label":c("settings.providers.page.custom.field.icon.label"),children:[s.jsx(q,{type:"button",variant:p.icon===null?"chip":"ghost",size:"icon",className:Ie(as,p.icon===null&&"text-foreground"),"aria-label":c("settings.providers.page.custom.field.icon.option.default"),title:c("settings.providers.page.custom.field.icon.option.default"),"aria-pressed":p.icon===null,onClick:()=>g(L=>({...L,icon:null})),children:z?s.jsx(sn,{providerId:O,className:"size-4",ignoreCustomIcon:!0}):s.jsx(Q,{name:"checkbox-blank-circle",className:"size-4 text-muted-foreground"})}),$g.map(L=>s.jsx(q,{type:"button",variant:p.icon===L.id?"chip":"ghost",size:"icon",className:Ie(as,p.icon===L.id&&"text-foreground"),"aria-label":c(`settings.providers.page.custom.field.icon.option.${L.id}`),title:c(`settings.providers.page.custom.field.icon.option.${L.id}`),"aria-pressed":p.icon===L.id,onClick:()=>g($=>({...$,icon:L.id})),children:s.jsx(Q,{name:L.icon,className:"size-4"})},L.id))]})}),s.jsxs(Et,{label:c("settings.providers.page.custom.field.baseURL.label"),info:c("settings.providers.page.custom.field.baseURL.info"),children:[s.jsx(Be,{value:p.baseURL,onChange:L=>M("baseURL",L.target.value),placeholder:c("settings.providers.page.custom.field.baseURL.placeholder"),className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!h.baseURL,"aria-label":c("settings.providers.page.custom.field.baseURL.label")}),h.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:h.baseURL}):null]}),s.jsxs(Et,{label:c("settings.providers.page.custom.field.apiKey.label"),info:c(f&&i?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),children:[s.jsx(Be,{type:"password",value:p.apiKey,onChange:L=>M("apiKey",L.target.value),placeholder:c(f&&i?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!h.apiKey,"aria-label":c("settings.providers.page.custom.field.apiKey.label")}),h.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:h.apiKey}):null]})]}),s.jsxs(Ve,{title:c("settings.providers.page.custom.models.title"),contentClassName:ws,children:[s.jsxs("div",{className:`${ks} space-y-2`,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{F()},disabled:a||v||!p.baseURL.trim(),children:[s.jsx(Q,{name:"search",className:"size-3.5"}),c(v?"settings.providers.page.custom.discovery.fetching":"settings.providers.page.custom.discovery.fetch")]}),s.jsx(Gt,{children:c("settings.providers.page.custom.discovery.info")})]}),y?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",role:"alert",children:y}):null,w?s.jsx(g1,{models:w,existingIds:new Set(p.models.map(L=>L.id.trim()).filter(Boolean)),onAdd:_,onCancel:()=>D(null)}):null]}),s.jsx("div",{className:ks,children:p.models.map((L,$)=>s.jsx(b1,{model:L,errors:b[$],expanded:C.has(L.row),onToggle:()=>B(L.row),onChange:(H,W)=>P($,H,W),onToggleCapability:(H,W)=>V($,H,W),onToolsChange:H=>g(W=>({...W,models:W.models.map((Z,te)=>te===$?{...Z,tools:H,capabilitiesKnown:!0,metadataSource:"manual"}:Z)})),onRemove:p.models.length>1?()=>{g(H=>({...H,models:H.models.filter((W,Z)=>Z!==$)})),j(H=>H.filter((W,Z)=>Z!==$))}:void 0},L.row))}),s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const L=Uo();g($=>({...$,models:[...$.models,L]})),j($=>[...$,{}]),A($=>new Set([...$,L.row]))},children:c("settings.providers.page.custom.models.add")})]}),s.jsxs(Ve,{title:c("settings.providers.page.custom.headers.title"),contentClassName:ws,children:[s.jsx("p",{className:Mt,children:c("settings.providers.page.custom.headers.description")}),p.headers.map((L,$)=>s.jsx("div",{className:`${ks} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Be,{value:L.key,onChange:H=>R($,"key",H.target.value),placeholder:c("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":c("settings.providers.page.custom.headers.keyLabel")}),x[$]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x[$]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Nt,children:c("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Be,{value:L.value,onChange:H=>R($,"value",H.target.value),placeholder:c("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":c("settings.providers.page.custom.headers.valueLabel")}),x[$]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x[$]?.value}):null]})]}),s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:as,disabled:p.headers.length<=1,onClick:()=>{p.headers.length<=1||(g(H=>({...H,headers:H.headers.filter((W,Z)=>Z!==$)})),S(H=>H.filter((W,Z)=>Z!==$)))},"aria-label":c("settings.providers.page.custom.headers.remove"),children:s.jsx(Q,{name:"delete-bin",className:"size-4"})})]})},L.row)),s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{g(L=>({...L,headers:[...L.headers,$l()]})),S(L=>[...L,{}])},children:c("settings.providers.page.custom.headers.add")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[u?s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:u,disabled:a,children:c("settings.providers.page.custom.actions.back")}):null,m?s.jsx(q,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:a,children:c("settings.providers.page.actions.disconnect")}):null,s.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:a,children:c(a?"settings.providers.page.actions.saving":f?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save")})]})]})},dd=({integrationId:t,keyMethod:e,connectKey:a,onSaved:n})=>{const{t:o}=ze(),i=d.useMemo(()=>(e?.form??[]).filter(ei),[e]),[r,l]=d.useState(""),[u,m]=d.useState({}),c=d.useMemo(()=>({...Su(i),...u}),[i,u]),[f,p]=d.useState(null),[g,h]=d.useState(!1),k=async()=>{const b=r.trim();if(!b){G.error(o("settings.providers.page.toast.apiKeyRequired"));return}const j=Cu(i,c);if(j){p(o("settings.providers.page.auth.oauth.promptRequired",{field:ca(j)}));return}p(null);const x={integrationID:t,key:b},S=Iu(i,c);Object.keys(S).length>0&&(x.answer=S),h(!0);try{await a(x),G.success(o("settings.providers.page.toast.apiKeySaved")),l(""),n()}catch(v){console.error("Failed to save API key:",v),G.error(o("settings.providers.page.toast.apiKeySaveFailed"))}finally{h(!1)}};return s.jsxs("div",{className:"py-1.5 space-y-3",children:[s.jsxs("div",{children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[o("settings.providers.page.auth.apiKeyLabel"),s.jsx(Gt,{children:o("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:r,onChange:b=>l(b.target.value),placeholder:o("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(q,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{k()},disabled:g,children:o(g?"settings.providers.page.actions.saving":"settings.providers.page.actions.saveKey")})]})]}),i.length>0?s.jsx(Pu,{fields:i,values:c,onChange:(b,j)=>m(x=>({...x,[b]:j}))}):null,f?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f}):null]})},ud=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=up(t);return e.endsWith(".0")?e.slice(0,-2):e},md=async t=>{await Ls.getSdkClient().integration.connect.key(t)},In="__add_provider__",Fa="__classification__",y1=()=>{const{t}=ze(),{isMobile:e}=qn(),a=Ks(),n=rt(K=>Qd(K,a)),o=re(K=>K.settingsProvidersConnectRequested),i=re(K=>K.setSettingsProvidersConnectRequested),r=re(K=>K.settingsProvidersClassificationRequested),l=re(K=>K.setSettingsProvidersClassificationRequested),u=re(K=>K.settingsProvidersOpenRequested),m=re(K=>K.setSettingsProvidersOpenRequested),[c,f]=d.useState(()=>o?In:r?Fa:u??"");d.useEffect(()=>{o&&(f(In),i(!1))},[o,i]),d.useEffect(()=>{r&&(f(Fa),l(!1))},[r,l]),d.useEffect(()=>{u&&(f(u),m(null))},[u,m]);const p=rt(K=>K.getModelMetadata),g=re(K=>K.hiddenModels),h=re(K=>K.customProviderIcons),k=re(K=>K.setCustomProviderIcon),b=re(K=>K.toggleHiddenModel),j=re(K=>K.hideAllModels),x=re(K=>K.showAllModels),S=rt(K=>K.loadProviders);d.useEffect(()=>{a&&S({directory:a,source:"settings:providers"})},[S,a]);const[v,N]=d.useState(()=>wf()),[y,I]=d.useState(!1),w=v?.integrations??null,[D,C]=d.useState(null);d.useEffect(()=>{let K=!0;return dy().then(ue=>{K&&C(ue)}).catch(ue=>{console.warn("[providers] could not read disabled providers:",ue)}),()=>{K=!1}},[]);const A=d.useCallback(async(K,ue)=>{try{C(await uy(K,ue)),ue&&f(""),G.success(ue?t("settings.providers.disabled.toast.disabled",{provider:K}):t("settings.providers.disabled.toast.enabled",{provider:K})),S({directory:a,source:"settings:providers",fresh:!0})}catch(Ne){G.error(Ne instanceof Error?Ne.message:String(Ne))}},[S,f,a,t]),T=v===null&&!y,[O,z]=d.useState(null),[M,P]=d.useState(null),[R,F]=d.useState(""),[_,B]=d.useState(""),[V,ee]=d.useState({}),[L,$]=d.useState({}),[H,W]=d.useState(0),[Z,te]=d.useState(0),[J,ie]=d.useState(!1),pe=Un(),[X,xe]=d.useState(null),[Y,be]=d.useState(null),[De,ve]=d.useState(null),[se,ge]=d.useState(null),[ne,Se]=d.useState(null),[ke,Te]=d.useState(null),Ee=c===In,Le=Ee&&_===Rr,ce=!!(Y&&c&&Y===c&&!Ee);d.useEffect(()=>{let K=!0;return(async()=>{try{const Ne=await Nf();if(!K)return;N(Ne),I(!1)}catch(Ne){if(!K)return;console.error("Failed to load provider integrations:",Ne),I(!0),G.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}})(),()=>{K=!1}},[Z,t]);const Me=d.useMemo(()=>new Set(n.map(K=>K.id)),[n]),Fe=d.useMemo(()=>v?Sf(v,Me):null,[v,Me]);d.useEffect(()=>{c!==In||!Fe||Fe.length===0||_&&_!==Rr&&!Fe.some(K=>K.id===_)&&B("")},[c,_,Fe]),d.useEffect(()=>{if(c===In){ie(!0),xe(null),be(null),ve(null),ge(null),Se(null);return}ie(!1),xe(null),Y&&Y!==c&&(be(null),ve(null),ge(null),Se(null))},[c,Y]),d.useEffect(()=>{if(!c||c===In||c===Fa)return;const K=V[c];if(!K||w===null)return;const ue=n.find(He=>He.id===c),Ne=Xc({connections:fo(w,c),optionsApiKey:ul(ue)}),Ce=!!(ue&&id(ue,K));xy({hasCredentials:Ne,userDismissed:X===c,isEditableCustomProvider:Ce})&&ie(!0)},[c,V,n,w,X]),d.useEffect(()=>{if(!c||c===In||c===Fa)return;let K=!1;return(async()=>{try{const Ne=a?`?directory=${encodeURIComponent(a)}`:"",Ce=await Dt(`/api/provider/${encodeURIComponent(c)}/source${Ne}`,{method:"GET",headers:{Accept:"application/json"}}),He=await Ce.json().catch(()=>null);if(!Ce.ok)throw new Error(He?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const le=He?.sources??He?.data?.sources;!K&&le&&(ee(Oe=>({...Oe,[c]:le})),$(Oe=>({...Oe,[c]:i1.safeParse(He?.config??He?.data?.config).data??null})))}catch(Ne){K||console.error("Failed to load provider sources:",Ne)}})(),()=>{K=!0}},[c,H,a,t]);const me=d.useCallback(()=>{W(K=>K+1)},[]),de=d.useCallback(()=>{te(K=>K+1)},[]),Pe=d.useCallback(K=>{N(ue=>ue&&{...ue,integrations:ue.integrations.map(Ne=>Ne.id===K&&Ne.connections.length===0?{...Ne,connections:[{type:"credential",id:`pending:${K}`,label:K,method:"key"}]}:Ne)}),xe(null),ie(!1),B(""),f(K),me(),de()},[de,me,f]),he=n.find(K=>K.id===c),Ue=c?V[c]:void 0,Ae=async K=>{const ue=`custom:${K.providerID}`;z(ue),Te(K.providerID),Se(null);try{const Ne=c1(K),Ce=d1(K,{scope:Y?se??od(V[Y]):"user"}),He=await Dt(`/api/provider${a?`?directory=${encodeURIComponent(a)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ce)}),le=await He.json().catch(()=>null);if(!He.ok)throw new Error(le?.error||t("settings.providers.page.toast.customProviderSaveFailed"));if(Ne)try{await m1(()=>Ls.getSdkClient().integration.connect.key(Ne))}catch(ot){throw Se(t("settings.providers.page.custom.authFailure.keyAfterConfig")),ot}const Oe={...re.getState().customProviderIcons};K.icon?Oe[K.providerID]=K.icon:delete Oe[K.providerID],await gt({customProviderIcons:Oe}),k(K.providerID,K.icon),G.success(t("settings.providers.page.toast.customProviderSaved",{provider:K.name})),B(""),be(null),ve(null),ge(null),Se(null),Te(null),Pe(K.providerID)}catch(Ne){console.error("Failed to save custom provider:",Ne),G.error(Ne instanceof Error&&Ne.message?Ne.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{z(null)}},Re=K=>{ie(!1),Pe(K)},$e=async K=>{const ue=`disconnect:${K}`;z(ue);try{const Ne=Zc(An(w??[],K)),Ce=Ls.getSdkClient();for(const He of Ne)await Ce.credential.remove({credentialID:He.id});G.success(t("settings.providers.page.toast.providerDisconnected")),xe(null),me(),de()}catch(Ne){console.error("Failed to disconnect provider:",Ne),G.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{z(null)}},nt=async K=>{K&&(await $e(K),be(null),ve(null),ge(null),Se(null),Te(null),B(""))},pt=async(K,ue,Ne)=>{P(K.id);try{await ue(),Ne.success&&G.success(Ne.success)}catch(Ce){console.error("Provider account action failed:",Ce),G.error(Ne.failure)}finally{P(null),de()}},kt=K=>pt(K,async()=>{await Ls.getSdkClient().credential.activate({credentialID:K.id})},{success:t("settings.providers.accounts.toast.switched",{account:K.label}),failure:t("settings.providers.accounts.toast.switchFailed")}),bt=(K,ue)=>pt(K,async()=>{await Ls.getSdkClient().credential.update({credentialID:K.id,label:ue})},{failure:t("settings.providers.accounts.toast.renameFailed")}),yt=K=>pt(K,async()=>{await Ls.getSdkClient().credential.remove({credentialID:K.id}),me()},{success:t("settings.providers.accounts.toast.removed"),failure:t("settings.providers.accounts.toast.removeFailed")}),Je=()=>{B(""),f("")},ct=s.jsx(No,{label:t("settings.providers.page.back"),onClick:Je}),Qe=K=>{if(n.some(ue=>ue.id===K)){f(K);return}B(K),f(In)};if(c===Fa)return s.jsx(zy,{titleLeading:ct,onOpenProvider:Qe});if(Ee&&!pe&&!_)return s.jsx(Qt,{title:t("settings.providers.page.connect.title"),titleLeading:ct,showSaveStatus:!1,children:s.jsx(py,{providers:Fe,loadFailed:y,onSelect:B,onSelectCustom:()=>B(Rr)})});if(Ee&&!pe){const K=s.jsx(No,{label:t("settings.providers.page.back"),onClick:()=>B("")}),ue=Fe?.find(Ne=>Ne.id===_)?.name??_;return s.jsx(Qt,{title:Le?t("settings.providers.page.connect.title"):ue,titleLeading:Le?K:s.jsxs("span",{className:"flex items-center gap-2",children:[K,s.jsx(sn,{providerId:_,className:"h-5 w-5 shrink-0"})]}),showSaveStatus:!1,children:Le?s.jsx(cd,{mode:"create",existingProviderIDs:Me,busy:O?.startsWith("custom:")??!1,authFailureHint:ne,onCancel:()=>{B(""),Se(null),Te(null)},onDisconnect:ne&&ke?()=>{nt(ke)}:void 0,onSubmit:Ae}):s.jsx(Ve,{title:t("settings.providers.page.auth.title"),divider:!1,settingsItem:"providers.auth",contentClassName:"space-y-4",children:T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const Ne=An(w??[],_),Ce=Qc(An(w??[],ki(_))),He=Yc(Ne);return s.jsxs(s.Fragment,{children:[He?s.jsx(dd,{integrationId:_,keyMethod:ml(Ne),connectKey:md,onSaved:()=>Pe(_)},_):null,Ce.length>0?s.jsx(ol,{integrationId:ki(_),methods:Ce,onConnected:()=>Re(_),className:Ie(He&&"border-t border-[var(--surface-subtle)] pt-2")},_):null]})})()})})})}if(!he)return s.jsx(Py,{providers:n,integrations:w,directory:a,onSelect:f,onConnect:()=>f(In),onOpenClassification:()=>f(Fa),disabledProviders:D,onEnableProvider:K=>{A(K,!1)}});const it=Array.isArray(he.models)?he.models:[],dt=An(w??[],he.id),qe=Qc(An(w??[],ki(he.id))),lt=Yc(dt),ae=w!==null,fe=!!Ue,ye=fe&&id(he,Ue),we=Xc({connections:fo(w??[],he.id),optionsApiKey:ul(he)}),Ge=my(ae,we,ye),et=by({modelCount:it.length,integrationsLoaded:ae,hasCredentials:we,isEditableCustomProvider:ye}),mt=fo(w??[],he.id)??[],jt=he.integrationID??he.id,vt=Zc(An(w??[],jt)),Ct=vt[0]?.id??null,Bt=new Set(mt.flatMap(K=>K.type==="credential"&&!vt.some(ue=>ue.id===K.id)?[K.id]:[])),Ye=[Ue?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,Ue?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,Ue?.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(K=>K!==null),Ze=s.jsxs("span",{className:"flex items-center gap-2",children:[ct,s.jsx(sn,{providerId:he.id,className:"h-5 w-5 shrink-0"})]}),ut=s.jsxs("span",{className:"typography-settings-description text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:he.id}),Ye.length>0?s.jsxs(s.Fragment,{children:[" · ",t("settings.providers.page.configuredIn",{sources:Ye.join(", ")})]}):null]}),ft=Qn(it,R,K=>[typeof K?.name=="string"?K.name:"",typeof K?.id=="string"?K.id:""]);return ce&&ye&&De?s.jsx(Qt,{title:he.name||he.id,titleLeading:Ze,description:ut,showSaveStatus:!1,children:s.jsx(cd,{mode:"edit",existingProviderIDs:Me,initialValues:De,allowExistingAuth:we||!fe,busy:O?.startsWith("custom:")??!1,authFailureHint:ne,onCancel:()=>{be(null),ve(null),ge(null),Se(null),Te(null)},onDisconnect:()=>{nt(he.id)},onSubmit:Ae})}):s.jsxs(Qt,{title:he.name||he.id,titleLeading:Ze,description:ut,showSaveStatus:!1,children:[s.jsxs(Ve,{title:t("settings.providers.accounts.title"),info:t("settings.providers.accounts.info"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[ye&&!pe?s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Se(null),ve(o1(he,L[he.id]??null,h[he.id])),ge(od(Ue)),be(he.id)},children:t("settings.providers.page.actions.edit")}):null,D!==null?s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",title:t("settings.providers.disabled.disableHint"),onClick:()=>{A(he.id,!0)},children:t("settings.providers.disabled.disable")}):null,pe?null:s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const K=!J;ie(K),xe(K?null:he.id)},children:J?t("settings.providers.page.actions.cancel"):s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"add",className:"size-3.5"}),mt.length>0?t("settings.providers.accounts.add"):t("settings.providers.page.actions.connect")]})})]}),settingsItem:"providers.auth",contentClassName:"space-y-4",children:[mt.length>0?s.jsx(By,{connections:mt,activeId:Ct,unusedIds:Bt,busyId:M,onActivate:K=>{kt(K)},onRename:(K,ue)=>{bt(K,ue)},onRemove:K=>{yt(K)}}):!J&&Ge?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(Q,{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")}),lt?s.jsx(Gt,{children:t("settings.providers.page.auth.incompleteHint")}):null]}):null,pe?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.enterpriseMode")}):null,!J||pe?null:T?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:Ie("space-y-4",mt.length>0&&"rounded-xl border border-[var(--interactive-border)] p-4"),children:[lt?s.jsx(dd,{integrationId:he.id,keyMethod:ml(dt),connectKey:md,onSaved:()=>Pe(he.id)},he.id):null,qe.length>0&&s.jsx(ol,{integrationId:ki(he.id),methods:qe,onConnected:()=>Re(he.id),className:Ie(lt&&"border-t border-[var(--surface-subtle)] pt-2")},he.id)]})]}),et?s.jsxs(Ve,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",it.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const K=it.map(ue=>typeof ue?.id=="string"?ue.id:"").filter(ue=>ue.length>0);j(he.id,K)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(he.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(Q,{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:R,onChange:K=>F(K.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ft.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:ft.map(K=>{const ue=typeof K?.id=="string"?K.id:"",Ne=typeof K?.name=="string"?K.name:ue,Ce=ue?p(he.id,ue):void 0,He=g.some(It=>It.providerID===he.id&&It.modelID===ue),le=ud(Ce?.limit?.context),Oe=ud(Ce?.limit?.output),ot=[le?`${le} ${t("settings.providers.page.models.tokenBadge.context")}`:null,Oe?`${Oe} ${t("settings.providers.page.models.tokenBadge.output")}`:null].filter(Boolean).join(" · "),Rt=[];return Ce?.tool_call&&Rt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ce?.reasoning&&Rt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ce?.attachment&&Rt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:Ie("flex items-center gap-3",He&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ne}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e?ot||Rt.length>0?s.jsx(Gt,{className:"h-6 w-6",children:s.jsxs("div",{className:"space-y-1.5",children:[ot?s.jsx("div",{className:"font-medium",children:ot}):null,Rt.map(({key:It,icon:os,label:Xe})=>s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Q,{name:os,className:"h-3.5 w-3.5"}),Xe]},It))]})}):null:s.jsxs(s.Fragment,{children:[ot?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:ot}):null,Rt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Rt.map(({key:It,icon:os,label:Xe})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Xe,"aria-label":Xe,children:s.jsx(Q,{name:os,className:"h-3 w-3"})},It))})]}),s.jsx("button",{type:"button",onClick:()=>b(he.id,ue),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(He?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(He?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:He?s.jsx(Q,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(Q,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ue)})})]}):null]})},j1=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)},k1=t=>{const e=Ke.c(75),{onItemSelect:a}=t,{t:n}=ze(),o=ls(w1),i=ls(S1),r=ls(N1),l=ls(C1),u=ls(I1),m=ls(P1),c=ls(A1),f=ls(T1);let p,g;e[0]!==f?(p=()=>{f()},g=[f],e[0]=f,e[1]=p,e[2]=g):(p=e[1],g=e[2]),d.useEffect(p,g);const h=E1;let k;e[3]!==c?(k=J=>{J!=="usage"&&J!=="remaining"||(c(J),h({usageDisplayMode:J}))},e[3]=c,e[4]=k):k=e[4];const b=k;let j;e[5]===Symbol.for("react.memo_cache_sentinel")?(j=Ie("flex h-full flex-col","bg-background"),e[5]=j):j=e[5];let x;e[6]!==n?(x=n("settings.usage.sidebar.title"),e[6]=n,e[7]=x):x=e[7];let S;e[8]!==x?(S=s.jsx("h2",{className:`${zn} mb-3`,children:x}),e[8]=x,e[9]=S):S=e[9];let v;e[10]!==n?(v=n("settings.usage.sidebar.total",{count:vo.length}),e[10]=n,e[11]=v):v=e[11];let N;e[12]!==v?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[12]=v,e[13]=N):N=e[13];let y;e[14]!==l?(y=()=>l(),e[14]=l,e[15]=y):y=e[15];let I;e[16]!==n?(I=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=I):I=e[17];let w;e[18]!==n?(w=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=w):w=e[19];const D=u&&"animate-spin";let C;e[20]!==D?(C=Ie("h-3.5 w-3.5",D),e[20]=D,e[21]=C):C=e[21];let A;e[22]!==C?(A=s.jsx(Q,{name:"refresh",className:C}),e[22]=C,e[23]=A):A=e[23];let T;e[24]!==u||e[25]!==I||e[26]!==w||e[27]!==A||e[28]!==y?(T=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(q,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:y,"aria-label":I,title:w,disabled:u,children:A})}),e[24]=u,e[25]=I,e[26]=w,e[27]=A,e[28]=y,e[29]=T):T=e[29];let O;e[30]!==T||e[31]!==N?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,T]}),e[30]=T,e[31]=N,e[32]=O):O=e[32];let z;e[33]!==n?(z=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=z):z=e[34];let M;e[35]!==z?(M=s.jsx("span",{className:"typography-micro text-muted-foreground",children:z}),e[35]=z,e[36]=M):M=e[36];let P;e[37]!==n?(P=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=P):P=e[38];let R;e[39]!==P?(R=s.jsx(Pt,{className:"w-fit",children:s.jsx(Kt,{placeholder:P})}),e[39]=P,e[40]=R):R=e[40];let F;e[41]!==n?(F=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=F):F=e[42];let _;e[43]!==F?(_=s.jsx(at,{value:"usage",children:F}),e[43]=F,e[44]=_):_=e[44];let B;e[45]!==n?(B=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=B):B=e[46];let V;e[47]!==B?(V=s.jsx(at,{value:"remaining",children:B}),e[47]=B,e[48]=V):V=e[48];let ee;e[49]!==_||e[50]!==V?(ee=s.jsxs(At,{children:[_,V]}),e[49]=_,e[50]=V,e[51]=ee):ee=e[51];let L;e[52]!==b||e[53]!==R||e[54]!==ee||e[55]!==m?(L=s.jsxs(Tt,{value:m,onValueChange:b,children:[R,ee]}),e[52]=b,e[53]=R,e[54]=ee,e[55]=m,e[56]=L):L=e[56];let $;e[57]!==M||e[58]!==L?($=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[M,L]}),e[57]=M,e[58]=L,e[59]=$):$=e[59];let H;e[60]!==O||e[61]!==$||e[62]!==S?(H=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[S,O,$]}),e[60]=O,e[61]=$,e[62]=S,e[63]=H):H=e[63];let W;e[64]!==a||e[65]!==o||e[66]!==i||e[67]!==r||e[68]!==n?(W=vo.map(J=>{const ie=o.find(De=>De.providerId===J.id),pe=j1(ie?.usage),X=Yd(pe),xe=J.id===i,Y=ie?.configured,be=Y?X==="critical"?{backgroundColor:"var(--status-error)"}:X==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",xe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{r(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:be}),s.jsx(sn,{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}),Y===!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]=o,e[66]=i,e[67]=r,e[68]=n,e[69]=W):W=e[69];let Z;e[70]!==W?(Z=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:W}),e[70]=W,e[71]=Z):Z=e[71];let te;return e[72]!==H||e[73]!==Z?(te=s.jsxs("div",{className:j,children:[H,Z]}),e[72]=H,e[73]=Z,e[74]=te):te=e[74],te};function w1(t){return t.results}function S1(t){return t.selectedProviderId}function N1(t){return t.setSelectedProvider}function C1(t){return t.fetchAllQuotas}function I1(t){return t.isLoading}function P1(t){return t.displayMode}function A1(t){return t.setDisplayMode}function T1(t){return t.loadSettings}async function E1(t){try{await gt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const D1=t=>{const e=Ke.c(17),{percent:a,tonePercent:n,className:o}=t;let i;e[0]!==a?(i=mp(a)??0,e[0]=a,e[1]=i):i=e[1];const r=i,l=n??a;let u;e[2]!==l?(u=Yd(l),e[2]=l,e[3]=u):u=e[3];const m=u;let c;e[4]!==m?(c=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=c):c=e[5];const f=c;let p;e[6]!==o?(p=Ie("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",o),e[6]=o,e[7]=p):p=e[7];const g=`${r}%`;let h;e[8]!==f||e[9]!==g?(h={...f,width:g},e[8]=f,e[9]=g,e[10]=h):h=e[10];let k;e[11]!==r||e[12]!==h?(k=s.jsx("div",{className:"h-full transition-all duration-300",style:h,role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100}),e[11]=r,e[12]=h,e[13]=k):k=e[13];let b;return e[14]!==p||e[15]!==k?(b=s.jsx("div",{className:p,children:k}),e[14]=p,e[15]=k,e[16]=b):b=e[16],b},Or=t=>{const e=Ke.c(49),{title:a,window:n,subtitle:o,showToggle:i,toggleEnabled:r,onToggle:l,providerId:u}=t,m=i===void 0?!1:i,c=r===void 0?!1:r,{t:f}=ze(),p=ls(M1),g=re(R1),h=p==="remaining"?n.remainingPercent:n.usedPercent,k=h!==null;let b;e[0]!==p||e[1]!==f?(b=f(p==="remaining"?"settings.usage.card.bar.remaining":"settings.usage.card.bar.used"),e[0]=p,e[1]=f,e[2]=b):b=e[2];const j=b;let x;e[3]!==h||e[4]!==n.valueLabel?(x=pp(n.valueLabel,h),e[3]=h,e[4]=n.valueLabel,e[5]=x):x=e[5];const S=x;let v;if(e[6]!==f||e[7]!==g||e[8]!==n.resetAfterFormatted||e[9]!==n.resetAt||e[10]!==n.resetAtFormatted){const B=gp(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,g);v=B?f("settings.usage.card.resetsAt",{time:B}):"",e[6]=f,e[7]=g,e[8]=n.resetAfterFormatted,e[9]=n.resetAt,e[10]=n.resetAtFormatted,e[11]=v}else v=e[11];const N=v;let y;e[12]!==a?(y=fp(a),e[12]=a,e[13]=y):y=e[13];const I=y;let w;e[14]!==l||e[15]!==m||e[16]!==f||e[17]!==c?(w=m&&s.jsx(Ai,{checked:c,onChange:B=>l?.(B),ariaLabel:f("settings.usage.card.showInHeaderAria")}),e[14]=l,e[15]=m,e[16]=f,e[17]=c,e[18]=w):w=e[18];let D;e[19]!==I?(D=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:I}),e[19]=I,e[20]=D):D=e[20];let C;e[21]!==o?(C=o&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:o}),e[21]=o,e[22]=C):C=e[22];let A;e[23]!==D||e[24]!==C?(A=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[D,C]}),e[23]=D,e[24]=C,e[25]=A):A=e[25];let T;e[26]!==A||e[27]!==w?(T=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[w,A]}),e[26]=A,e[27]=w,e[28]=T):T=e[28];let O;e[29]!==u||e[30]!==n?(O=u&&s.jsx(hp,{window:n,providerId:u}),e[29]=u,e[30]=n,e[31]=O):O=e[31];const z=S==="-"?"":S;let M;e[32]!==z?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums",children:z}),e[32]=z,e[33]=M):M=e[33];let P;e[34]!==O||e[35]!==M?(P=s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[O,M]}),e[34]=O,e[35]=M,e[36]=P):P=e[36];let R;e[37]!==T||e[38]!==P?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[T,P]}),e[37]=T,e[38]=P,e[39]=R):R=e[39];let F;e[40]!==j||e[41]!==h||e[42]!==k||e[43]!==N||e[44]!==n.usedPercent?(F=k?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(D1,{percent:h,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:N}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:j})]})]}):N?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:N}):null,e[40]=j,e[41]=h,e[42]=k,e[43]=N,e[44]=n.usedPercent,e[45]=F):F=e[45];let _;return e[46]!==R||e[47]!==F?(_=s.jsxs("div",{className:"py-3",children:[R,F]}),e[46]=R,e[47]=F,e[48]=_):_=e[48],_};function M1(t){return t.displayMode}function R1(t){return t.timeFormatPreference}const O1=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,F1=({providerId:t,providerName:e})=>{const{t:a}=ze(),[n,o]=d.useState(null),[i,r]=d.useState({}),[l,u]=d.useState(!1),m=`/api/quota/credentials/${t}`;d.useEffect(()=>{Dt(m).then(async p=>{if(!p.ok)throw new Error;const g=await p.json();o(g),r({})}).catch(()=>o({configured:!1}))},[m]);const c=async(p,g,h)=>{u(!0);try{const k=await Dt(p,{method:g,headers:h?{"Content-Type":"application/json"}:void 0,body:h?JSON.stringify(h):void 0}),b=await k.json().catch(()=>null);if(!k.ok)throw new Error(b?.error);b?.configured!==void 0&&o(b),r({}),G.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(k){G.error(k instanceof Error&&k.message?k.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{u(!1)}},f=(p,g,h)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[g,s.jsx(Be,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[p]??"",onChange:k=>r(b=>({...b,[p]:k.target.value})),placeholder:n?.secretMasked??h})]});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:O1})]}),t==="zenmux"&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.zenmuxInstructions")}),t==="ollama-cloud"&&f("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&f("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="zenmux"&&f("platformApiKey",a("settings.providers.page.quotaCredentials.platformApiKey"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(q,{size:"xs",disabled:l,onClick:()=>c(m,"PUT",i),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(q,{variant:"outline",size:"xs",disabled:l,onClick:()=>c(`${m}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(q,{variant:"outline",size:"xs",disabled:l,onClick:()=>c(`${m}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(q,{variant:"destructive",size:"xs",disabled:l,onClick:()=>c(m,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},pd=(t,e)=>{if(!t)return"-";try{return Zd(t,e,{fallback:"-"})}catch{return"-"}},L1=()=>{const{t}=ze(),e=re(R=>R.timeFormatPreference),a=ls(R=>R.results),n=ls(R=>R.selectedProviderId),o=ls(R=>R.setSelectedProvider),i=ls(R=>R.loadSettings),r=ls(R=>R.fetchAllQuotas),l=ls(R=>R.isLoading),u=ls(R=>R.lastUpdated),m=ls(R=>R.refreshErrors),c=ls(R=>R.dropdownProviderIds),f=ls(R=>R.setDropdownProviderIds),p=ls(R=>R.selectedModels),g=ls(R=>R.toggleModelSelected),h=ls(R=>R.applyDefaultSelections);bp(),d.useEffect(()=>{i(),r()},[i,r]),d.useEffect(()=>{if(n||a.length===0)return;const R=a.find(F=>F.configured)?.providerId;o(R??vo[0]?.id??null)},[a,n,o]);const k=a.find(R=>R.providerId===n)??null,j=vo.find(R=>R.id===n)?.name??n??t("settings.usage.sidebar.title"),x=k?.usage,S=n?m[n]:void 0,v=S?x?t("header.services.usageRefreshFailedStale",{error:S}):S:k?.configured&&!k.ok?k.error:null,N=n?c.includes(n):!1,y=n==="exe-dev"||n==="ollama-cloud"||n==="cursor"||n==="zenmux"?n:null,I=y!==null,w=d.useCallback(R=>{if(!n)return;const F=R?Array.from(new Set([...c,n])):c.filter(_=>_!==n);f(F),gt({usageDropdownProviders:F})},[c,n,f]),D=d.useMemo(()=>x?.models?Object.entries(x.models).map(([R,F])=>({name:R,windows:F})).filter(R=>Object.keys(R.windows.windows).length>0):[],[x?.models]);d.useEffect(()=>{n&&D.length>0&&h(n,D.map(R=>R.name))},[n,D,h]);const C=d.useMemo(()=>!n||D.length===0?new Map:xp(D,R=>R.name,n),[D,n]),A=d.useMemo(()=>{if(!n)return[];const R=yp(n);return vp(R)},[n]),[T,O]=d.useState(()=>({})),z=d.useCallback(R=>{O(F=>({...F,[R]:!F[R]}))},[]),M=d.useCallback(R=>{if(!n)return;g(n,R);const F=p[n]??[],B=F.includes(R)?F.filter(ee=>ee!==R):[...F,R],V={...p,[n]:B};gt({usageSelectedModels:V})},[n,p,g]),P=n?p[n]??[]:[];return n?s.jsxs(Qt,{title:t("settings.usage.page.header.providerUsage",{provider:j}),titleLeading:s.jsx(sn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:l?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):k?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:k.planLabel,time:pd(u,e)}):t("settings.usage.page.header.lastUpdated",{time:pd(u,e)}),showSaveStatus:!0,children:[s.jsx(Ve,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(st,{checked:N,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!k&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),v&&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:v})]}),k&&!k.configured&&!I&&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")})]}),y&&s.jsx(F1,{providerId:y,providerName:j}),x?.windows&&Object.keys(x.windows).length>0&&s.jsx(Ve,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(x.windows).map(([R,F])=>s.jsx(Or,{title:R,window:F,providerId:n},R))})}),D.length>0&&s.jsxs(Ve,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[A.map(R=>{const F=C.get(R.id)??[];if(F.length===0)return null;const _=T[R.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Gs,{open:!_,onOpenChange:()=>z(R.id),children:[s.jsxs(Ws,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:R.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",F.length,")"]})]}),_?s.jsx(Q,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Q,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Js,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:F.map(B=>{const V=Object.entries(B.windows.windows);if(V.length===0)return null;const[ee,L]=V[0],$=P.includes(B.name);return s.jsx(Or,{title:ee,subtitle:Zl(B.name),window:L,showToggle:!0,toggleEnabled:$,onToggle:()=>M(B.name)},B.name)})})})]})},R.id)}),(()=>{const R=C.get(null)??[];if(R.length===0)return null;const F=T.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Gs,{open:!F,onOpenChange:()=>z("other"),children:[s.jsxs(Ws,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",R.length,")"]})]}),F?s.jsx(Q,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Q,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Js,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:R.map(_=>{const B=Object.entries(_.windows.windows);if(B.length===0)return null;const[V,ee]=B[0],L=P.includes(_.name);return s.jsx(Or,{title:V,subtitle:Zl(_.name),window:ee,showToggle:!0,toggleEnabled:L,onToggle:()=>M(_.name)},_.name)})})})]})})})()]}),k?.configured&&x&&Object.keys(x.windows??{}).length===0&&D.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")})})},K1="git.commit.generate",pl=gf(t=>({selectedPromptId:K1,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),z1=t=>{const e=Ke.c(22),{onItemSelect:a}=t,{t:n}=ze(),o=pl(U1),i=pl($1);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={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]=r):r=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l={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[1]=l):l=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=[r,l,{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[2]=u):u=e[2];const m=u;let c;e[3]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[3]=n,e[4]=c):c=e[4];let f;e[5]!==c?(f=s.jsx("h2",{className:zn,children:c}),e[5]=c,e[6]=f):f=e[6];let p;e[7]!==n?(p=n("settings.magicPrompts.sidebar.description"),e[7]=n,e[8]=p):p=e[8];let g;e[9]!==p?(g=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:p}),e[9]=p,e[10]=g):g=e[10];let h;e[11]!==f||e[12]!==g?(h=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,g]}),e[11]=f,e[12]=g,e[13]=h):h=e[13];let k;e[14]!==a||e[15]!==o||e[16]!==i||e[17]!==n?(k=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(j=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(j.groupKey)}),j.items.map(x=>{const S=o===x.id;return s.jsx("button",{type:"button",onClick:()=>{i(x.id),a?.()},className:Ie("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",S?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(x.titleKey)})},x.id)})]},j.groupKey))}),e[14]=a,e[15]=o,e[16]=i,e[17]=n,e[18]=k):k=e[18];let b;return e[19]!==h||e[20]!==k?(b=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[h,k]}),e[19]=h,e[20]=k,e[21]=b):b=e[21],b};function U1(t){return t.selectedPromptId}function $1(t){return t.setSelectedPromptId}const gd={"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"}]},"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"},{id:"session.fusion.codeInstructions",titleKey:"settings.magicPrompts.page.block.codeFusionInstructions"}]}},fd=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Fr=t=>t.endsWith(".visible"),_1=()=>{const{t}=ze(),e=d.useCallback(y=>t(y),[t]),a=pl(y=>y.selectedPromptId),[n,o]=d.useState(!0),[i,r]=d.useState({}),[l,u]=d.useState({}),[m,c]=d.useState({}),[f,p]=d.useState({}),[g,h]=d.useState(!1);d.useEffect(()=>{let y=!0;return(async()=>{o(!0);try{const w=await Sp();if(!y)return;r(w)}catch(w){console.warn("Failed to load magic prompts:",w),G.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{y&&o(!1)}})(),()=>{y=!1}},[t]);const k=gd[a]??gd["git.commit.generate"],b=d.useCallback(y=>fd(i,y)?i[y]:hr(y),[i]),j=d.useCallback(y=>l[y]??b(y),[l,b]),x=d.useCallback((y,I)=>{u(w=>w[y]===I?w:{...w,[y]:I})},[]),S=d.useCallback(async y=>{const I=j(y);if(Fr(y)&&I.trim().length===0){G.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}c(w=>({...w,[y]:!0}));try{const w=I===hr(y)?await Xl(y):await jp(y,I);r(w.overrides),G.success(t("settings.magicPrompts.page.toast.saved"))}catch(w){const D=w instanceof Error?w.message:String(w);G.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:D})}finally{c(w=>({...w,[y]:!1}))}},[j,t]),v=d.useCallback(async y=>{p(I=>({...I,[y]:!0}));try{const I=await Xl(y);r(I.overrides),u(w=>({...w,[y]:hr(y)})),G.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(I){const w=I instanceof Error?I.message:String(I);G.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:w})}finally{p(I=>({...I,[y]:!1}))}},[t]),N=d.useCallback(async()=>{h(!0);try{const y=await kp();r(y.overrides),u({}),G.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(y){const I=y instanceof Error?y.message:String(y);G.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:I})}finally{h(!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(Qt,{title:e(k.titleKey),titleAccessory:s.jsx(Gt,{contentClassName:"max-w-xs",children:e(k.descriptionKey)}),headerEnd:s.jsx(q,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{N()},disabled:g||Object.keys(i).length===0,children:t(g?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:k.blocks.map((y,I)=>{const w=wp(y.id),D=b(y.id),C=j(y.id),A=fd(i,y.id),T=C!==D,O=Fr(y.id)&&C.trim().length===0,z=m[y.id]===!0,M=f[y.id]===!0;return s.jsxs(Ve,{title:e(y.titleKey),info:w.description,description:w.placeholders&&w.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${w.placeholders.map(P=>`{{${P.key}}}`).join(", ")}`:void 0,divider:I>0,settingsItem:Fr(y.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ns,{value:C,onChange:P=>x(y.id,P.target.value),className:"min-h-[220px] font-mono text-sm"}),O&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(T?"settings.magicPrompts.page.status.unsavedChanges":A?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(q,{variant:"outline",size:"sm",onClick:()=>{v(y.id)},disabled:!A||z||M,children:t(M?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(q,{size:"sm",onClick:()=>{S(y.id)},disabled:!T||z||M||O,children:t(z?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},y.id)})})},B1=t=>{const e=Ke.c(89),{onItemSelect:a}=t,{t:n}=ze(),[o,i]=d.useState(null),[r,l]=d.useState(null),[u,m]=d.useState(null),{selectedSnippetName:c,snippets:f,setSelectedSnippet:p,setSnippetDraft:g,deleteSnippet:h,loadSnippets:k}=yo(Ms(V1));let b,j;e[0]!==k?(b=()=>{k()},j=[k],e[0]=k,e[1]=b,e[2]=j):(b=e[1],j=e[2]),d.useEffect(b,j);let x;e[3]!==a||e[4]!==p||e[5]!==g||e[6]!==f?(x=async()=>{const ve=new Set(f.map(H1));let se="new-snippet",ge=1;for(;ve.has(se);)se=`new-snippet-${ge++}`;g({name:se,scope:"global"}),p(se),a?.()},e[3]=a,e[4]=p,e[5]=g,e[6]=f,e[7]=x):x=e[7];const S=x;let v;e[8]!==o||e[9]!==h||e[10]!==n?(v=async()=>{if(!o)return;await h(o.name)?(G.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):G.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=o,e[9]=h,e[10]=n,e[11]=v):v=e[11];const N=v;let y;e[12]!==f?(y=[...f].sort(q1),e[12]=f,e[13]=y):y=e[13];const I=y;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=Ie("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let D;e[15]!==n?(D=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=D):D=e[16];let C;e[17]!==D?(C=s.jsx("h2",{className:`${zn} mb-3`,children:D}),e[17]=D,e[18]=C):C=e[18];let A;e[19]!==f.length||e[20]!==n?(A=n("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=n,e[21]=A):A=e[21];let T;e[22]!==A?(T=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[22]=A,e[23]=T):T=e[23];let O;e[24]!==n?(O=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=O):O=e[25];let z;e[26]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),e[26]=z):z=e[26];let M;e[27]!==S||e[28]!==O?(M=s.jsx(q,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:S,"aria-label":O,children:z}),e[27]=S,e[28]=O,e[29]=M):M=e[29];let P;e[30]!==T||e[31]!==M?(P=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[T,M]}),e[30]=T,e[31]=M,e[32]=P):P=e[32];let R;e[33]!==P||e[34]!==C?(R=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,P]}),e[33]=P,e[34]=C,e[35]=R):R=e[35];let F;if(e[36]!==a||e[37]!==r||e[38]!==u||e[39]!==c||e[40]!==p||e[41]!==I||e[42]!==n){let ve;e[44]!==a||e[45]!==r||e[46]!==u||e[47]!==c||e[48]!==p||e[49]!==n?(ve=se=>s.jsxs(Qa,{open:u===se.name,onOpenChange:ge=>m(ge?se.name:null),children:[s.jsxs(Ja,{render:s.jsx("div",{className:Ie("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",c===se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ge=>{ge.preventDefault(),m(se.name)}}),children:[s.jsxs("button",{onClick:()=>{p(se.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-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:["#",se.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:se.description||se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Jn,{open:r===se.name,onOpenChange:ge=>{ge&&m(null),l(ge?se.name:null)},children:[s.jsx(Wn,{asChild:!0,children:s.jsx(q,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":n("settings.snippets.sidebar.actions.more",{name:se.name}),children:s.jsx(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Fn,{onClick:ge=>{ge.stopPropagation(),i(se)},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Ga,{className:"w-fit min-w-20",children:s.jsxs(Wa,{onClick:ge=>{ge.stopPropagation(),i(se)},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${se.source}:${se.filePath}`),e[44]=a,e[45]=r,e[46]=u,e[47]=c,e[48]=p,e[49]=n,e[50]=ve):ve=e[50],F=I.map(ve),e[36]=a,e[37]=r,e[38]=u,e[39]=c,e[40]=p,e[41]=I,e[42]=n,e[43]=F}else F=e[43];let _;e[51]!==F?(_=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:F}),e[51]=F,e[52]=_):_=e[52];const B=o!==null;let V;e[53]===Symbol.for("react.memo_cache_sentinel")?(V=ve=>{ve||i(null)},e[53]=V):V=e[53];let ee;e[54]!==n?(ee=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=ee):ee=e[55];let L;e[56]!==ee?(L=s.jsx(Ut,{children:ee}),e[56]=ee,e[57]=L):L=e[57];const $=o?.name??"";let H;e[58]!==n||e[59]!==$?(H=n("settings.snippets.sidebar.dialog.deleteDescription",{name:$}),e[58]=n,e[59]=$,e[60]=H):H=e[60];let W;e[61]!==H?(W=s.jsx($t,{children:H}),e[61]=H,e[62]=W):W=e[62];let Z;e[63]!==L||e[64]!==W?(Z=s.jsxs(zt,{children:[L,W]}),e[63]=L,e[64]=W,e[65]=Z):Z=e[65];let te;e[66]===Symbol.for("react.memo_cache_sentinel")?(te=()=>i(null),e[66]=te):te=e[66];let J;e[67]!==n?(J=n("settings.common.actions.cancel"),e[67]=n,e[68]=J):J=e[68];let ie;e[69]!==J?(ie=s.jsx(q,{size:"sm",variant:"ghost",onClick:te,children:J}),e[69]=J,e[70]=ie):ie=e[70];let pe;e[71]!==n?(pe=n("settings.common.actions.delete"),e[71]=n,e[72]=pe):pe=e[72];let X;e[73]!==N||e[74]!==pe?(X=s.jsx(q,{size:"sm",onClick:N,children:pe}),e[73]=N,e[74]=pe,e[75]=X):X=e[75];let xe;e[76]!==ie||e[77]!==X?(xe=s.jsxs(Xt,{children:[ie,X]}),e[76]=ie,e[77]=X,e[78]=xe):xe=e[78];let Y;e[79]!==Z||e[80]!==xe?(Y=s.jsxs(Lt,{className:"max-w-md",children:[Z,xe]}),e[79]=Z,e[80]=xe,e[81]=Y):Y=e[81];let be;e[82]!==B||e[83]!==Y?(be=s.jsx(Ft,{open:B,onOpenChange:V,children:Y}),e[82]=B,e[83]=Y,e[84]=be):be=e[84];let De;return e[85]!==R||e[86]!==_||e[87]!==be?(De=s.jsxs("div",{className:w,children:[R,_,be]}),e[85]=R,e[86]=_,e[87]=be,e[88]=De):De=e[88],De};function V1(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function H1(t){return t.name}function q1(t,e){return t.name.localeCompare(e.name)}const G1=()=>{const{t}=ze(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:o,updateSnippet:i,createSnippet:r}=yo(Ms(w=>({selectedSnippetName:w.selectedSnippetName,snippets:w.snippets,snippetDraft:w.snippetDraft,setSnippetDraft:w.setSnippetDraft,updateSnippet:w.updateSnippet,createSnippet:w.createSnippet}))),l=d.useMemo(()=>e?a.find(w=>w.name===e||w.aliases.includes(e))??null:null,[e,a]),u=!!(n&&n.name===e&&!l),[m,c]=d.useState(""),[f,p]=d.useState("global"),[g,h]=d.useState(""),[k,b]=d.useState(""),[j,x]=d.useState(""),[S,v]=d.useState(!1),N=d.useRef(null);d.useEffect(()=>{if(u&&n){const w={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};c(w.draftName),p(w.draftScope),h(w.description),b(w.aliases),x(w.content),N.current=w}else if(l){const w={draftName:"",draftScope:"global",description:l.description??"",aliases:l.aliases.join(", "),content:l.content};h(w.description),b(w.aliases),x(w.content),N.current=w}},[l,u,e,n]);const y=d.useMemo(()=>{const w=N.current;return w?u&&m!==w.draftName||u&&f!==w.draftScope?!0:g!==w.description||k!==w.aliases||j!==w.content:!1},[k,j,g,m,f,u]),I=async()=>{const w=u?m.trim().replace(/\s+/g,"-"):e?.trim();if(!w){G.error(t("settings.snippets.page.toast.nameRequired"));return}if(!j.trim()){G.error(t("settings.snippets.page.toast.contentRequired"));return}const D=k.split(",").map(C=>C.trim()).filter(Boolean);v(!0);try{if(!(u?await r(w,j,{aliases:D,description:g,scope:f}):await i(w,{content:j,aliases:D,description:g}))){G.error(t("settings.snippets.page.toast.saveFailed"));return}G.success(t("settings.snippets.page.toast.saved")),u&&o(null)}finally{v(!1)}};return e?s.jsxs(Qt,{title:u?t("settings.snippets.page.title.new"):`#${e}`,description:l?l.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(Ve,{divider:!1,contentClassName:"space-y-0",children:[u?s.jsxs(ht,{label:"#",children:[s.jsx(Be,{value:m,onChange:w=>c(w.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Tt,{value:f,onValueChange:w=>p(w),children:[s.jsx(Pt,{size:_t,className:"w-fit min-w-[100px]",children:s.jsx(Kt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(at,{value:"global",children:t("settings.common.scope.global")}),s.jsx(at,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Et,{label:t("settings.common.field.description"),children:s.jsx(Be,{value:g,onChange:w=>h(w.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Et,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Be,{value:k,onChange:w=>b(w.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(Ve,{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(Gt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ns,{value:j,onChange:w=>x(w.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(q,{onClick:I,disabled:S||!y,size:"xs",className:"!font-normal",children:t(S?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Q,{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")})]})})},Ju=()=>{const{t}=ze(),e=rt(f=>f.settingsGitmojiEnabled),a=rt(f=>f.setSettingsGitmojiEnabled),n=_g(),o=re(f=>f.gitChangesViewMode),i=re(f=>f.setGitChangesViewMode),[r,l]=d.useState(!0),u=d.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);d.useEffect(()=>{(async()=>{try{const p=await jn();p&&(p.gitmojiEnabled!==void 0&&a(p.gitmojiEnabled),p.gitChangesViewMode!==void 0&&i(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{l(!1)}})()},[i,a]);const m=d.useCallback(async f=>{a(f);try{await gt({gitmojiEnabled:f})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),c=d.useCallback(f=>{f!==o&&(i(f),gt({gitChangesViewMode:f}))},[o,i]);return r?null:s.jsx(Ve,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(vs,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx($s,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:u.map(f=>s.jsx(ns,{selected:o===f.id,onSelect:()=>{c(f.id)},label:f.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:f.label})},f.id))})}),s.jsx(st,{settingsItem:"git.gitmoji",checked:e,onChange:f=>{m(f)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(st,{settingsItem:"git.gitignored-files",checked:n,onChange:Bg,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Lr=()=>({status:"idle",credentials:[],candidates:[],truncated:!1,discoveryAttempted:!1});function W1({selection:t,disabled:e=!1}){const{t:a}=ze(),{git:n}=Ya(),[o,i]=d.useState(Lr),[r,l]=d.useState(!1),[u,m]=d.useState(""),c=d.useRef(0),f=t?.onChange;d.useLayoutEffect(()=>{const y=()=>{c.current+=1,i(Lr()),l(!1),m("")};y();const I=Tl(()=>{y(),f?.("")});return()=>{c.current+=1,I()}},[n,f]);const p=async y=>{if(!n.managedSshCredentials||e||o.status==="loading")return;const I=++c.current,w=Yt();i(D=>({...D,status:"loading",rejection:void 0,imported:!1}));try{const D=await n.managedSshCredentials(y);if(I!==c.current||w!==Yt())return;if(D.status==="unsupported"){l(!0),i(Lr());return}if(l(!1),D.status==="available"){t?.value&&!D.credentials.some(A=>A.credentialId===t.value&&A.capability.status==="ready")&&t.onChange(""),m(""),i({status:"ready",credentials:D.credentials,candidates:[],truncated:!1,discoveryAttempted:!1});return}if(D.status==="discovered"){m(""),i(A=>({...A,status:"ready",candidates:D.candidates,truncated:D.truncated,discoveryAttempted:!0}));return}if(D.status==="rejected"){m(""),i(A=>({...A,status:"ready",rejection:D.reason}));return}m(""),t?.onChange(D.selectedCredential.credentialId);const C=y.operation==="import"?y.candidateId:"";i(A=>({...A,status:"ready",credentials:D.credentials,candidates:A.candidates.filter(T=>!("candidateId"in T)||T.candidateId!==C),truncated:!1,discoveryAttempted:!1,imported:!0}))}catch{I===c.current&&w===Yt()&&i(D=>({...D,status:"error",imported:!1}))}},g=d.useRef(p);g.current=p,d.useEffect(()=>{g.current({operation:"inventory"})},[n]);const h=y=>y.capability.status==="ready"?"":y.capability.reason==="unreadable"?a("settings.sourceControl.ssh.unreadable"):y.capability.reason==="fingerprint-mismatch"?a("settings.sourceControl.ssh.changed"):a("settings.sourceControl.ssh.unverifiable"),k=y=>y.capability.status==="ready"?"":y.capability.reason==="unreadable"?a("settings.sourceControl.ssh.unreadable"):y.capability.reason==="insecure-permissions"?a("settings.sourceControl.ssh.insecurePermissions"):a("settings.sourceControl.ssh.unverifiable"),b=()=>o.rejection?o.rejection==="candidate-expired"?a("settings.sourceControl.ssh.candidateExpired"):o.rejection==="candidate-changed"?a("settings.sourceControl.ssh.candidateChanged"):o.rejection==="fingerprint-mismatch"?a("settings.sourceControl.ssh.confirmationMismatch"):o.rejection==="inventory-full"?a("settings.sourceControl.ssh.inventoryFull"):a("settings.sourceControl.ssh.candidateUnavailable"):"",j=y=>[y.label,y.fingerprint,h(y)].filter(Boolean).join(" · "),x=o.credentials.find(y=>y.credentialId===t.value)??null,S=b(),v=e||o.status==="loading"||!n.managedSshCredentials,N=s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:t.value,onValueChange:t.onChange,disabled:e||o.status!=="ready",children:[s.jsx(Pt,{size:_t,className:"w-full","aria-label":a("settings.sourceControl.ssh.title"),children:s.jsx(Kt,{placeholder:a("settings.sourceControl.ssh.title"),children:x?j(x):void 0})}),s.jsx(At,{children:o.credentials.map(y=>s.jsx(at,{value:y.credentialId,disabled:y.capability.status!=="ready",children:j(y)},y.credentialId))})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.status==="idle"||o.status==="error"?s.jsx(q,{size:"sm",variant:"outline",disabled:v,onClick:()=>{p({operation:"inventory"})},children:a("settings.sourceControl.ssh.load")}):null,s.jsx(q,{size:"sm",variant:"outline",disabled:v,onClick:()=>{p({operation:"discover"})},children:a("settings.sourceControl.ssh.discover")})]}),o.candidates.length?s.jsx("div",{className:"space-y-4",children:o.candidates.map((y,I)=>"candidateId"in y?s.jsxs("div",{className:"space-y-2 border-t border-border/60 pt-3",children:[s.jsx("p",{className:"typography-settings-field-label text-foreground",children:y.label}),s.jsx("p",{className:Ie(Mt,"break-all"),children:y.fingerprint}),s.jsx(st,{checked:u===y.candidateId,onChange:w=>m(w?y.candidateId:""),disabled:e||o.status==="loading",className:"min-w-0 break-all",label:a("settings.sourceControl.ssh.confirmFingerprint",{fingerprint:y.fingerprint}),ariaLabel:a("settings.sourceControl.ssh.confirmFingerprint",{fingerprint:y.fingerprint})}),s.jsx(q,{size:"sm",variant:"default",disabled:e||o.status==="loading"||u!==y.candidateId,onClick:()=>{p({operation:"import",candidateId:y.candidateId,expectedFingerprint:y.fingerprint,confirmed:!0})},children:a("settings.sourceControl.ssh.import")})]},y.candidateId):s.jsx("p",{className:Mt,children:[y.label,k(y)].filter(Boolean).join(" · ")},`${y.label}-${I}`))}):null,o.status==="loading"?s.jsx("p",{role:"status",className:Mt,children:a("settings.sourceControl.transport.loading")}):null,o.status==="error"?s.jsx("p",{role:"alert",className:Ie(Mt,"text-[var(--status-error)]"),children:a("settings.sourceControl.ssh.operationFailed")}):null,S?s.jsx("p",{role:"alert",className:Ie(Mt,"text-[var(--status-error)]"),children:S}):null,o.imported?s.jsx("p",{role:"status",className:Ie(Mt,"text-[var(--status-success)]"),children:a("settings.sourceControl.ssh.imported")}):null,o.status==="ready"&&!o.credentials.length?s.jsx("p",{className:Mt,children:a("settings.sourceControl.ssh.empty")}):null,o.status==="ready"&&o.discoveryAttempted&&!o.candidates.length?s.jsx("p",{className:Mt,children:a("settings.sourceControl.ssh.discoveredEmpty")}):null,o.truncated?s.jsx("p",{role:"status",className:Ie(Mt,"text-[var(--status-warning)]"),children:a("settings.sourceControl.ssh.discoveryTruncated")}):null,r||!n.managedSshCredentials?s.jsx("p",{role:"status",className:Mt,children:a("settings.sourceControl.ssh.hostSetup")}):null]});return s.jsx(Et,{className:"min-w-0 w-full",controlClassName:"max-w-none flex-col items-stretch gap-3",label:a("settings.sourceControl.ssh.title"),info:a("settings.sourceControl.ssh.hostSetup"),children:N})}const ao="__none__",hd=t=>JSON.stringify([t.provider,t.instance,t.accountId]),bd=[{method:"system",icon:"computer",labelKey:"settings.gitIdentities.editor.auth.system",hintKey:"settings.gitIdentities.editor.auth.systemHint"},{method:"account",icon:"user-3",labelKey:"settings.gitIdentities.editor.auth.account",hintKey:"settings.gitIdentities.editor.auth.accountHint"},{method:"ssh",icon:"lock",labelKey:"settings.gitIdentities.editor.auth.ssh",hintKey:null},{method:"anonymous",icon:"global",labelKey:"settings.gitIdentities.editor.auth.anonymous",hintKey:"settings.gitIdentities.editor.auth.anonymousHint"}],xd=[{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)"}],J1=[{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"},{key:"github",Icon:"github",label:"GitHub"},{key:"gitlab",Icon:"gitlab",label:"GitLab"}],Q1=({open:t,onOpenChange:e,profileId:a})=>{const{t:n}=ze(),o=ma(Y=>Y.getProfileById),i=ma(Y=>Y.createProfile),r=ma(Y=>Y.updateProfile),l=ma(Y=>Y.deleteProfile),u=d.useMemo(()=>a&&a!=="new"?o(a):null,[a,o]),m=a==="new",c=a==="global",[f,p]=d.useState(""),[g,h]=d.useState(""),[k,b]=d.useState(""),[j,x]=d.useState(!1),[S,v]=d.useState(""),[N,y]=d.useState("keyword"),[I,w]=d.useState("branch"),[D,C]=d.useState(ao),[A,T]=d.useState("system"),[O,z]=d.useState(""),[M,P]=d.useState(!1),[R,F]=d.useState(!1),[_,B]=d.useState(!1),{sourceControl:V}=Ya(),ee=Hs(Y=>Y.identities),L=Hs(Y=>Y.entries),$=Hs(Y=>Y.refreshAll);d.useEffect(()=>{t&&!c&&$(V)},[t,c,$,V]);const H=d.useMemo(()=>ee.flatMap(Y=>{const be=L[Cl(Y)];return!be?.hasChecked||be.status?.status!=="connected"?[]:Np(Y,be.status.accounts,De=>n(Xd(De.source)))}),[L,ee,n]),W=H.find(Y=>Y.key===D)??null,Z=u?.account&&D===hd(u.account)?u.account:null,te=W?.reference??Z,J=A;d.useEffect(()=>{if(t){if(m)p(""),h(""),b(""),x(!1),v(""),y("keyword"),w("branch"),C(ao),T("system"),z("");else if(u)p(u.name),h(u.userName),b(u.userEmail),x(u.signCommits===!0),v(u.signingKey||""),y(u.color||"keyword"),w(u.icon||"branch"),C(u.account?hd(u.account):ao),T(u.transport??"system"),z(u.sshCredentialId??"");else if(c){const Y=o("global");Y&&(p(Y.name),h(Y.userName),b(Y.userEmail),x(!1),v(""),y(Y.color||"keyword"),w(Y.icon||"branch"))}}},[t,a,u,m,c,o]);const ie=async()=>{if(!g.trim()||!k.trim()){G.error(n("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(j&&!S.trim()){G.error(n("settings.gitIdentities.editor.toast.signingKeyRequired"));return}if(J==="account"&&!te){G.error(n("settings.gitIdentities.editor.toast.accountRequired"));return}if(J==="ssh"&&!O.trim()){G.error(n("settings.gitIdentities.editor.toast.sshKeyRequired"));return}P(!0);try{const Y={name:f.trim()||g.trim(),userName:g.trim(),userEmail:k.trim(),account:te,transport:J,signCommits:j,signingKey:S.trim()||null,color:N,icon:I};J==="ssh"&&(Y.sshCredentialId=O.trim());let be;if(m)be=await i(Y);else if(a)be=await r(a,Y);else return;be?(G.success(n(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):G.error(n(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(Y){console.error("Error saving profile:",Y),G.error(n("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{P(!1)}},pe=async()=>{if(!(!a||m)){B(!0);try{await l(a)?(G.success(n("settings.gitIdentities.editor.toast.profileDeleted")),F(!1),e(!1)):G.error(n("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(Y){console.error("Error deleting profile:",Y),G.error(n("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{B(!1)}}},X=d.useMemo(()=>xd.find(be=>be.key===N)?.cssVar||"var(--syntax-keyword)",[N]),xe=m?n("settings.gitIdentities.editor.title.newIdentity"):c?n("settings.gitIdentities.editor.title.globalIdentity"):u?.name||n("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Ft,{open:t,onOpenChange:e,children:s.jsxs(Lt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:xe}),s.jsx($t,{children:n(c?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!c&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Nt} block mb-1.5`,children:n("settings.gitIdentities.editor.field.profileName")}),s.jsx(Be,{value:f,onChange:Y=>p(Y.target.value),placeholder:n("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:n("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:xd.map(Y=>s.jsx("button",{type:"button",onClick:()=>y(Y.key),className:Ie("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",N===Y.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:Y.cssVar},title:Y.label},Y.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:J1.map(Y=>{const be=Y.Icon;return s.jsx("button",{type:"button",onClick:()=>w(Y.key),className:Ie("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",I===Y.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:Y.label,children:s.jsx(Q,{name:be,className:"w-3.5 h-3.5",style:{color:I===Y.key?X:"var(--surface-muted-foreground)"}})},Y.key)})})]})]}),!c&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Nt,children:n("settings.gitIdentities.editor.field.userName")}),!c&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Gt,{contentClassName:"max-w-xs",children:n("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Be,{value:g,onChange:Y=>h(Y.target.value),placeholder:n("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!c,readOnly:c,disabled:c,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Nt,children:n("settings.gitIdentities.editor.field.emailAddress")}),!c&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Gt,{contentClassName:"max-w-xs",children:n("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Be,{type:"email",value:k,onChange:Y=>b(Y.target.value),placeholder:n("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!c,readOnly:c,disabled:c,className:"h-8"})]})]}),!c&&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",{children:[s.jsx("label",{className:`${Nt} block mb-1.5`,children:n("settings.gitIdentities.editor.field.account")}),s.jsxs(Tt,{value:D,onValueChange:C,children:[s.jsx(Pt,{className:"w-full","aria-label":n("settings.gitIdentities.editor.field.account"),children:s.jsx(Kt,{children:W?.label??Z?.instance??n("settings.gitIdentities.editor.field.accountNone")})}),s.jsxs(At,{children:[H.map(Y=>s.jsx(at,{value:Y.key,children:Y.label},Y.key)),s.jsx(at,{value:ao,children:n("settings.gitIdentities.editor.field.accountNone")})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:`${Nt} block mb-1.5`,children:n("settings.gitIdentities.editor.auth.label")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:bd.map(Y=>s.jsxs(q,{size:"sm",type:"button",variant:"chip","aria-pressed":A===Y.method,onClick:()=>{T(Y.method),Y.method!=="ssh"&&z("")},children:[s.jsx(Q,{name:Y.icon,className:"w-3.5 h-3.5 mr-1"})," ",n(Y.labelKey)]},Y.method))})]}),J==="ssh"?s.jsx(W1,{selection:{value:O,onChange:z}}):s.jsx("p",{className:Mt,children:n(bd.find(Y=>Y.method===A)?.hintKey??"settings.gitIdentities.editor.auth.systemHint")})]})]}),!c&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(st,{checked:j,onChange:x,label:n("settings.gitIdentities.editor.field.signCommits"),info:n("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:n("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Nt,children:n("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Be,{value:S,onChange:Y=>v(Y.target.value),placeholder:n("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Xt,{className:"gap-2",children:[!c&&!m&&s.jsxs(q,{variant:"outline",size:"sm",onClick:()=>F(!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(Q,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",n("settings.common.actions.delete")]}),s.jsx(q,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:n(c?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!c&&s.jsx(q,{size:"sm",onClick:ie,disabled:M,children:n(M?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Ft,{open:R,onOpenChange:Y=>{_||F(Y)},children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:n("settings.gitIdentities.page.deleteDialog.title")}),s.jsx($t,{children:n("settings.gitIdentities.page.deleteDialog.description",{name:u?.name||f})})]}),s.jsxs(Xt,{children:[s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:_,children:n("settings.common.actions.cancel")}),s.jsx(q,{size:"sm",variant:"destructive",onClick:()=>{pe()},disabled:_,children:n("settings.common.actions.delete")})]})]})})]})},Y1={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",github:"github",gitlab:"gitlab"},Z1={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},X1=()=>{const t=Ke.c(103),{t:e}=ze(),{sourceControl:a}=Ya(),n=Hs(ej),{profiles:o,globalIdentity:i,defaultGitIdentityId:r,deleteProfile:l,loadProfiles:u,loadGlobalIdentity:m,loadDefaultGitIdentityId:c,setDefaultGitIdentityId:f}=ma(Ms(tj));let p,g;t[0]!==o||t[1]!==n||t[2]!==a?(p=()=>{n(a,o.map(sj))},g=[n,a,o],t[0]=o,t[1]=n,t[2]=a,t[3]=p,t[4]=g):(p=t[3],g=t[4]),d.useEffect(p,g);const[h,k]=d.useState(!1),[b,j]=d.useState(null),[x,S]=d.useState(null),[v,N]=d.useState(!1);let y,I;t[5]!==c||t[6]!==m||t[7]!==u?(y=()=>{u(),m(),c()},I=[u,m,c],t[5]=c,t[6]=m,t[7]=u,t[8]=y,t[9]=I):(y=t[8],I=t[9]),d.useEffect(y,I);let w;t[10]===Symbol.for("react.memo_cache_sentinel")?(w=ce=>{j(ce),k(!0)},t[10]=w):w=t[10];const D=w;let C;t[11]!==r||t[12]!==f||t[13]!==e?(C=async ce=>{const Me=r===ce?null:ce;if(!await f(Me)){G.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}G.success(e(Me?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[11]=r,t[12]=f,t[13]=e,t[14]=C):C=t[14];const A=C;let T;t[15]!==x||t[16]!==l||t[17]!==e?(T=async()=>{if(!x)return;N(!0),await l(x.id)?(G.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:x.name})),S(null)):G.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),N(!1)},t[15]=x,t[16]=l,t[17]=e,t[18]=T):T=t[18];const O=T;let z;t[19]!==e?(z=e("settings.page.git.title"),t[19]=e,t[20]=z):z=t[20];let M;t[21]!==e?(M=e("settings.gitIdentities.page.section.title"),t[21]=e,t[22]=M):M=t[22];let P,R;t[23]===Symbol.for("react.memo_cache_sentinel")?(R=()=>D("new"),P=s.jsx(Q,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[23]=P,t[24]=R):(P=t[23],R=t[24]);let F;t[25]!==e?(F=e("settings.common.badge.new"),t[25]=e,t[26]=F):F=t[26];let _;t[27]!==F?(_=s.jsxs(q,{size:"sm",variant:"outline",onClick:R,children:[P," ",F]}),t[27]=F,t[28]=_):_=t[28];let B;t[29]!==r||t[30]!==i||t[31]!==A||t[32]!==o.length?(B=i&&s.jsx(vd,{profile:i,isDefault:r==="global",onEdit:()=>D("global"),onToggleDefault:()=>A("global"),isReadOnly:!0,hasBorder:o.length>0}),t[29]=r,t[30]=i,t[31]=A,t[32]=o.length,t[33]=B):B=t[33];let V;if(t[34]!==r||t[35]!==A||t[36]!==o){let ce;t[38]!==r||t[39]!==A||t[40]!==o.length?(ce=(Me,Fe)=>s.jsx(vd,{profile:Me,isDefault:r===Me.id,onEdit:()=>D(Me.id),onToggleDefault:()=>A(Me.id),onDelete:()=>S(Me),hasBorder:Fe<o.length-1},Me.id),t[38]=r,t[39]=A,t[40]=o.length,t[41]=ce):ce=t[41],V=o.map(ce),t[34]=r,t[35]=A,t[36]=o,t[37]=V}else V=t[37];let ee;t[42]!==i||t[43]!==o.length||t[44]!==e?(ee=!i&&o.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(Q,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),t[42]=i,t[43]=o.length,t[44]=e,t[45]=ee):ee=t[45];let L;t[46]!==B||t[47]!==V||t[48]!==ee?(L=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[B,V,ee]}),t[46]=B,t[47]=V,t[48]=ee,t[49]=L):L=t[49];let $;t[50]!==_||t[51]!==L||t[52]!==M?($=s.jsx(Ve,{title:M,headerAction:_,settingsItem:"git.identities",children:L}),t[50]=_,t[51]=L,t[52]=M,t[53]=$):$=t[53];let H;t[54]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Ju,{}),t[54]=H):H=t[54];let W;t[55]!==$||t[56]!==z?(W=s.jsxs(Qt,{title:z,showSaveStatus:!0,className:"px-4 @xl:px-6 @3xl:px-12",children:[$,H]}),t[55]=$,t[56]=z,t[57]=W):W=t[57];let Z;t[58]!==h||t[59]!==b?(Z=s.jsx(Q1,{open:h,onOpenChange:k,profileId:b}),t[58]=h,t[59]=b,t[60]=Z):Z=t[60];const te=x!==null;let J;t[61]!==v?(J=ce=>{!ce&&!v&&S(null)},t[61]=v,t[62]=J):J=t[62];let ie;t[63]!==e?(ie=e("settings.gitIdentities.page.deleteDialog.title"),t[63]=e,t[64]=ie):ie=t[64];let pe;t[65]!==ie?(pe=s.jsx(Ut,{children:ie}),t[65]=ie,t[66]=pe):pe=t[66];const X=x?.name??"";let xe;t[67]!==e||t[68]!==X?(xe=e("settings.gitIdentities.page.deleteDialog.description",{name:X}),t[67]=e,t[68]=X,t[69]=xe):xe=t[69];let Y;t[70]!==xe?(Y=s.jsx($t,{children:xe}),t[70]=xe,t[71]=Y):Y=t[71];let be;t[72]!==pe||t[73]!==Y?(be=s.jsxs(zt,{children:[pe,Y]}),t[72]=pe,t[73]=Y,t[74]=be):be=t[74];let De;t[75]===Symbol.for("react.memo_cache_sentinel")?(De=()=>S(null),t[75]=De):De=t[75];let ve;t[76]!==e?(ve=e("settings.common.actions.cancel"),t[76]=e,t[77]=ve):ve=t[77];let se;t[78]!==v||t[79]!==ve?(se=s.jsx(q,{size:"sm",variant:"ghost",onClick:De,disabled:v,children:ve}),t[78]=v,t[79]=ve,t[80]=se):se=t[80];let ge;t[81]!==O?(ge=()=>{O()},t[81]=O,t[82]=ge):ge=t[82];let ne;t[83]!==e?(ne=e("settings.common.actions.delete"),t[83]=e,t[84]=ne):ne=t[84];let Se;t[85]!==v||t[86]!==ge||t[87]!==ne?(Se=s.jsx(q,{size:"sm",variant:"destructive",onClick:ge,disabled:v,children:ne}),t[85]=v,t[86]=ge,t[87]=ne,t[88]=Se):Se=t[88];let ke;t[89]!==se||t[90]!==Se?(ke=s.jsxs(Xt,{children:[se,Se]}),t[89]=se,t[90]=Se,t[91]=ke):ke=t[91];let Te;t[92]!==be||t[93]!==ke?(Te=s.jsxs(Lt,{className:"max-w-md",children:[be,ke]}),t[92]=be,t[93]=ke,t[94]=Te):Te=t[94];let Ee;t[95]!==te||t[96]!==J||t[97]!==Te?(Ee=s.jsx(Ft,{open:te,onOpenChange:J,children:Te}),t[95]=te,t[96]=J,t[97]=Te,t[98]=Ee):Ee=t[98];let Le;return t[99]!==W||t[100]!==Z||t[101]!==Ee?(Le=s.jsxs(s.Fragment,{children:[W,Z,Ee]}),t[99]=W,t[100]=Z,t[101]=Ee,t[102]=Le):Le=t[102],Le},vd=t=>{const e=Ke.c(58),{profile:a,isDefault:n,onEdit:o,onToggleDefault:i,onDelete:r,isReadOnly:l,hasBorder:u}=t,{t:m}=ze(),c=Cp(),[f,p]=d.useState(!1),g=Y1[a.icon||"branch"]||"git-branch",h=Vg(a)?Ip(a,c)?null:"settings.gitIdentities.page.accountGone":"settings.gitIdentities.page.incomplete",k=h!==null,b=Z1[a.color||""];let j;e[0]!==o?(j=$=>{$.currentTarget===$.target&&($.key!=="Enter"&&$.key!==" "||($.preventDefault(),o()))},e[0]=o,e[1]=j):j=e[1];const x=j;let S;e[2]!==n||e[3]!==l||e[4]!==r||e[5]!==i||e[6]!==m?(S=$=>s.jsxs(s.Fragment,{children:[s.jsx($,{onClick:H=>{H.stopPropagation(),i()},children:m(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!l&&r&&s.jsxs($,{onClick:H=>{H.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(Q,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[2]=n,e[3]=l,e[4]=r,e[5]=i,e[6]=m,e[7]=S):S=e[7];const v=S,N=u&&"border-b border-[var(--surface-subtle)]";let y;e[8]!==N?(y=Ie("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",N),e[8]=N,e[9]=y):y=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=$=>{$.preventDefault(),p(!0)},e[10]=I):I=e[10];let w;e[11]!==x||e[12]!==o||e[13]!==y?(w=s.jsx("div",{className:y,onClick:o,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:I}),e[11]=x,e[12]=o,e[13]=y,e[14]=w):w=e[14];let D;e[15]!==b?(D={color:b},e[15]=b,e[16]=D):D=e[16];let C;e[17]!==g||e[18]!==D?(C=s.jsx(Q,{name:g,className:"w-4 h-4 shrink-0",style:D}),e[17]=g,e[18]=D,e[19]=C):C=e[19];let A;e[20]!==a||e[21]!==m?(A=Pp(a,m),e[20]=a,e[21]=m,e[22]=A):A=e[22];let T;e[23]!==A?(T=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:A}),e[23]=A,e[24]=T):T=e[24];let O;e[25]!==n||e[26]!==m?(O=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:m("settings.gitIdentities.page.badge.default")}),e[25]=n,e[26]=m,e[27]=O):O=e[27];let z;e[28]!==T||e[29]!==O?(z=s.jsxs("div",{className:"flex items-center gap-1.5",children:[T,O]}),e[28]=T,e[29]=O,e[30]=z):z=e[30];let M;e[31]!==l||e[32]!==k||e[33]!==h||e[34]!==a.userEmail||e[35]!==m?(M=!l&&h?s.jsx("span",{className:k?"text-[var(--status-warning)]":void 0,children:m(h)}):a.userEmail,e[31]=l,e[32]=k,e[33]=h,e[34]=a.userEmail,e[35]=m,e[36]=M):M=e[36];let P;e[37]!==M?(P=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:M}),e[37]=M,e[38]=P):P=e[38];let R;e[39]!==z||e[40]!==P?(R=s.jsxs("div",{className:"min-w-0",children:[z,P]}),e[39]=z,e[40]=P,e[41]=R):R=e[41];let F;e[42]!==R||e[43]!==C?(F=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[C,R]}),e[42]=R,e[43]=C,e[44]=F):F=e[44];let _;e[45]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Wn,{asChild:!0,children:s.jsx(q,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:nj,children:s.jsx(Q,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[45]=_):_=e[45];let B;e[46]!==v?(B=s.jsxs(Jn,{children:[_,s.jsx(Gn,{align:"end",className:"w-fit min-w-28",children:v(Fn)})]}),e[46]=v,e[47]=B):B=e[47];let V;e[48]!==F||e[49]!==B||e[50]!==w?(V=s.jsxs(Ja,{render:w,children:[F,B]}),e[48]=F,e[49]=B,e[50]=w,e[51]=V):V=e[51];let ee;e[52]!==v?(ee=s.jsx(Ga,{className:"w-fit min-w-28",children:v(Wa)}),e[52]=v,e[53]=ee):ee=e[53];let L;return e[54]!==f||e[55]!==V||e[56]!==ee?(L=s.jsxs(Qa,{open:f,onOpenChange:p,children:[V,ee]}),e[54]=f,e[55]=V,e[56]=ee,e[57]=L):L=e[57],L};function ej(t){return t.refreshIdentityAccounts}function tj(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId}}function sj(t){return t.account}function nj(t){return t.stopPropagation()}const Qu=({guest:t})=>{const{t:e}=ze(),a=t.integration,n=br(te=>te.byId[t.id]),o=br(te=>te.setStatus),i=d.useMemo(()=>eu(t.id,t.icon,mu().authenticatedAsset),[t.id,t.icon]),r=br(te=>te.refresh),[l,u]=d.useState(!1),[m,c]=d.useState(!1),[f,p]=d.useState(!1),[g,h]=d.useState(""),[k,b]=d.useState(""),[j,x]=d.useState(""),[S,v]=d.useState(""),[N,y]=d.useState({}),[I,w]=d.useState(!1),D=d.useRef(null),[C]=d.useState(Yt),A=d.useRef(!0),T=()=>A.current&&Yt()===C,O=d.useCallback(()=>{D.current!=null&&(window.clearInterval(D.current),D.current=null),p(!1)},[]);if(d.useEffect(()=>(A.current=!0,r(t.id),()=>{A.current=!1,O()}),[t.id,r,O]),d.useEffect(()=>{n&&y(n.settings)},[n]),!a)return null;const z=a.auth,M=z==="token"&&a.token?.scheme==="basic",P=!!n?.connection.connected,R=n?.connection.account.trim()||"",F=f?e("settings.integrations.guests.status.waiting"):P?R||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),_=f?"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",B=f||l,V=a.name,ee=async()=>{if(!T())return!1;const te=g.trim();if(!te)return n?.hasClient?!0:(G.error(e("settings.integrations.guests.toast.clientRequired")),!1);Zt("saving");const J=await Fp(t.id,te,k.trim()||void 0);return T()?J?(o(t.id,J),b(""),Zt("saved"),!0):(Zt("error"),G.error(e("settings.integrations.guests.toast.saveFailed",{name:V})),!1):!1},L=async(te=N)=>{if(!T())return!1;const J=n?.settings??{};if((a.settings??[]).every(xe=>(te[xe.id]??"").trim()===(J[xe.id]??"")))return!0;Zt("saving");const X=await Ap(t.id,te);return T()?X?(o(t.id,X),Zt("saved"),!0):(Zt("error"),G.error(e("settings.integrations.guests.toast.saveFailed",{name:V})),!1):!1},$=async()=>{if(!T())return!1;const te=j.trim();if(!te)return P?!0:(G.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const J=S.trim();if(M&&!J)return G.error(e("settings.integrations.guests.toast.usernameRequired")),!1;Zt("saving");const ie=await Op(t.id,te,M?J:void 0);return T()?ie?(o(t.id,ie),x(""),v(""),Zt("saved"),!0):(Zt("error"),G.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},H=async()=>{if(!T())return;O(),c(!0);const te=n?.connection??{connected:!1,account:""};try{if(z==="token"){if(await $()){if((a.settings??[]).length>0&&!await L()||!T())return;G.success(e("settings.integrations.guests.toast.connected",{name:V}))}return}if(z==="oauth"&&!n?.hasClient&&!await ee())return;const J=await Ep(t.id);if(!T())return;if(!J){G.error(e("settings.integrations.guests.toast.startFailed",{name:V}));return}p(!0),u(!0),Ss(J);const ie=Date.now()+Dp;D.current=window.setInterval(()=>{(async()=>{if(!T()){O();return}if(Date.now()>ie){O(),G.error(e("settings.integrations.guests.toast.authorizationFailed",{name:V}));return}const pe=await r(t.id);T()&&pe&&Mp(te,pe.connection)&&(O(),G.success(e("settings.integrations.guests.toast.connected",{name:V})),rs()&&pu())})()},Rp)}catch(J){if(!T())return;console.error("Failed to start guest connect:",J),G.error(e("settings.integrations.guests.toast.startFailed",{name:V})),O()}finally{T()&&c(!1)}},W=async()=>{if(T()){c(!0);try{O();const te=await Tp(t.id);if(!T())return;if(!te){G.error(e("settings.integrations.guests.toast.disconnectFailed",{name:V}));return}o(t.id,te),G.success(e("settings.integrations.guests.toast.disconnected",{name:V}))}catch(te){if(!T())return;console.error("Failed to disconnect guest:",te),G.error(e("settings.integrations.guests.toast.disconnectFailed",{name:V}))}finally{T()&&c(!1)}}},Z=async()=>{const te=n?.redirectUri??"";!te||!(await za(te)).ok||(w(!0),window.setTimeout(()=>w(!1),1500))};return s.jsx(Gs,{open:B,onOpenChange:te=>{if(f){u(!0);return}u(te)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Ws,{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(tu,{icon:su(t.icon),iconSrc:i,className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:V}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:a.description})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",_),children:F}),s.jsx(Q,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",B&&"rotate-180")})]}),s.jsx(Js,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[z==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Et,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:g,onChange:te=>h(te.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}),s.jsx(Et,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{type:"password",value:k,onChange:te=>b(te.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})})]}):null,M?s.jsx(Et,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:S,onChange:te=>v(te.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}):null,z==="token"?s.jsx(Et,{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:j,onChange:te=>x(te.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}):null,(a.settings??[]).map(te=>s.jsx(Et,{label:te.label,controlClassName:"w-full max-w-none",children:s.jsx(Be,{value:N[te.id]??"",onChange:J=>{y(ie=>({...ie,[te.id]:J.target.value}))},onBlur:()=>{L()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})},te.id)),z==="oauth"?s.jsxs(Et,{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(q,{type:"button",size:"sm",variant:"outline",disabled:!n?.redirectUri,onClick:()=>{Z()},children:e(I?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:P?s.jsx(q,{type:"button",size:"sm",variant:"destructive",disabled:m,onClick:()=>{W()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(q,{type:"button",size:"sm",disabled:m||f,onClick:()=>{H()},children:[m?s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},aj=t=>{const e=Ke.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:o}=ze(),i=ys(ij),r=ys(oj);let l;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(l=[],e[0]=l):l=e[0],d.useEffect(rj,l),is()||gu())return null;let u,m,c,f,p,g,h,k;if(e[1]!==n||e[2]!==i||e[3]!==r||e[4]!==o){k=Symbol.for("react.early_return_sentinel");e:{const j=i.filter(lj);if(j.length===0){k=null;break e}u=Ve,e[13]!==o?(m=o("settings.integrations.guests.title"),e[13]=o,e[14]=m):m=e[14],e[15]!==o?(c=o("settings.integrations.guests.info"),e[15]=o,e[16]=c):c=e[16],f=n,p="integrations.guests",g="space-y-3";let x;e[17]!==r?(x=S=>s.jsx(Qu,{guest:S},`${r}:${S.id}`),e[17]=r,e[18]=x):x=e[18],h=j.map(x)}e[1]=n,e[2]=i,e[3]=r,e[4]=o,e[5]=u,e[6]=m,e[7]=c,e[8]=f,e[9]=p,e[10]=g,e[11]=h,e[12]=k}else u=e[5],m=e[6],c=e[7],f=e[8],p=e[9],g=e[10],h=e[11],k=e[12];if(k!==Symbol.for("react.early_return_sentinel"))return k;let b;return e[19]!==u||e[20]!==m||e[21]!==c||e[22]!==f||e[23]!==p||e[24]!==g||e[25]!==h?(b=s.jsx(u,{title:m,info:c,divider:f,settingsItem:p,contentClassName:g,children:h}),e[19]=u,e[20]=m,e[21]=c,e[22]=f,e[23]=p,e[24]=g,e[25]=h,e[26]=b):b=e[26],b};function ij(t){return t.guests}function oj(t){return t.runtimeKey}function rj(){Zs()}function lj(t){return t.source!=="bundled"&&t.integration&&Il(t)}const cj=t=>{const e=new Map;for(const a of t){const n=JSON.stringify([a.user.provider,a.user.instance,a.user.id]),o=e.get(n);o?o.accounts.push(a):e.set(n,{key:n,accounts:[a]})}return Array.from(e.values())},dj=t=>/[0-9a-f]{8}(?=-[0-9a-f]{4}-)/i.exec(t)?.[0]??null,Yu=t=>{const e=Ke.c(15),{accounts:a,avatarAlt:n,sourceLabel:o,statusLabel:i,currentLabel:r,renderActions:l}=t;let u;if(e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==l||e[4]!==o||e[5]!==i){let c;e[7]!==n||e[8]!==r||e[9]!==l||e[10]!==o||e[11]!==i?(c=f=>{const p=f.accounts[0].user;return s.jsxs("div",{className:"py-3 first:pt-0 last:pb-0",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[p.avatarUrl?s.jsx("img",{src:p.avatarUrl,alt:n(p.username),className:"size-9 shrink-0 rounded-full border border-border bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-full border border-border bg-muted",children:s.jsx(Q,{name:p.provider==="github"?"github-fill":p.provider==="gitlab"?"gitlab":"git-branch",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate typography-ui-label text-foreground",children:p.name?.trim()||p.username}),s.jsx("div",{className:"truncate font-mono typography-micro text-muted-foreground",children:p.username})]})]}),s.jsx("div",{className:"ml-12 mt-2 divide-y divide-[var(--surface-subtle)]",children:f.accounts.map(g=>{const h=o(g),k=i(g),b=f.accounts.some(j=>j!==g&&o(j)===h)?dj(g.id):null;return s.jsxs("div",{className:"flex flex-col gap-2 py-2 first:pt-0 last:pb-0 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx("span",{children:h}),k?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx("span",{className:"text-[var(--status-warning)]",children:k})]}):null,b?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx("span",{className:"font-mono",children:b})]}):null,f.accounts.length>1&&g.current?s.jsx("span",{className:"rounded-full border border-border px-1.5",children:r}):null]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:l(g)})]},g.id)})})]},f.key)},e[7]=n,e[8]=r,e[9]=l,e[10]=o,e[11]=i,e[12]=c):c=e[12],u=cj(a).map(c),e[0]=a,e[1]=n,e[2]=r,e[3]=l,e[4]=o,e[5]=i,e[6]=u}else u=e[6];let m;return e[13]!==u?(m=s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:u}),e[13]=u,e[14]=m):m=e[14],m},Zu=t=>{const e=Ke.c(34),{code:a,description:n,openLabel:o,onOpen:i,onCancel:r,disabled:l}=t,u=l===void 0?!1:l,{t:m}=ze();let c;e[0]!==m?(c=m("settings.github.page.flow.title"),e[0]=m,e[1]=c):c=e[1];let f;e[2]!==c?(f=s.jsx(Ln,{children:c}),e[2]=c,e[3]=f):f=e[3];let p;e[4]!==n?(p=s.jsx("p",{className:"typography-meta text-muted-foreground",children:n}),e[4]=n,e[5]=p):p=e[5];let g;e[6]!==f||e[7]!==p?(g=s.jsxs("div",{className:"space-y-1",children:[f,p]}),e[6]=f,e[7]=p,e[8]=g):g=e[8];let h;e[9]!==a?(h=s.jsx("code",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-1.5 font-mono text-xl tracking-widest text-foreground",children:a}),e[9]=a,e[10]=h):h=e[10];let k;e[11]!==i||e[12]!==o?(k=s.jsx(q,{size:"sm",onClick:i,children:o}),e[11]=i,e[12]=o,e[13]=k):k=e[13];let b;e[14]!==h||e[15]!==k?(b=s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[h,k]}),e[14]=h,e[15]=k,e[16]=b):b=e[16];let j;e[17]!==m?(j=m("settings.github.page.flow.waiting"),e[17]=m,e[18]=j):j=e[18];let x;e[19]!==j?(x=s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:j}),e[19]=j,e[20]=x):x=e[20];let S;e[21]!==m?(S=m("settings.common.actions.cancel"),e[21]=m,e[22]=S):S=e[22];let v;e[23]!==u||e[24]!==r||e[25]!==S?(v=s.jsx(q,{size:"sm",variant:"ghost",disabled:u,onClick:r,children:S}),e[23]=u,e[24]=r,e[25]=S,e[26]=v):v=e[26];let N;e[27]!==x||e[28]!==v?(N=s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[x,v]}),e[27]=x,e[28]=v,e[29]=N):N=e[29];let y;return e[30]!==N||e[31]!==g||e[32]!==b?(y=s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] p-3",children:[g,b,N]}),e[30]=N,e[31]=g,e[32]=b,e[33]=y):y=e[33],y},uj=()=>{const{t}=ze(),e=ha()?.sourceControl,a=Cl(ln),n=Hs(M=>M.entries[a]),o=n?.status??null,i=n?.isLoading??!1,r=n?.hasChecked??!1,l=Hs(M=>M.refreshStatus),u=Hs(M=>M.refreshInstances),m=d.useCallback(async M=>{await Ss(M)},[]),[c,f]=d.useState(!1),[p,g]=d.useState(null),[h,k]=d.useState(null),[b,j]=d.useState(0),x=d.useRef(null),S=d.useRef(""),v=d.useRef(0),N=d.useCallback(()=>{const M=Yt(),P=v.current;return()=>P===v.current&&M===Yt()},[]),y=d.useCallback(()=>{x.current!=null&&(window.clearTimeout(x.current),x.current=null),k(null)},[]),I=d.useCallback(()=>{S.current="",g(null),y()},[y]);d.useEffect(()=>{const M=Tl(()=>{v.current+=1,f(!1),I()});return()=>{v.current+=1,M()}},[I]),d.useEffect(()=>((async()=>{try{!r&&e&&await l(e,ln)}catch(M){console.warn("Failed to load GitHub auth status:",M)}})(),()=>{y()}),[r,l,e,y]);const w=d.useCallback(async()=>{const M=N();f(!0);try{if(!e)return;const P=await e.authStart(ln);if(!M())return;S.current=Yt(),g(P),j(0),k(Math.max(1,P.interval)*1e3);const R=P.verificationUriComplete||P.verificationUri;m(R)}catch(P){M()&&(console.error("Failed to start GitHub connect:",P),G.error(t("settings.github.page.toast.startConnectFailed")))}finally{M()&&f(!1)}},[N,m,e,t]);d.useEffect(()=>{if(!p?.flowId||!h||x.current!=null)return;const M=async()=>{const P=N();if(S.current!==Yt()){I();return}try{if(!e)throw new Error("Source control runtime API unavailable");const R=await e.authComplete(ln,p.flowId);if(!P()||S.current!==Yt())return;if(R.status==="connected"){if(I(),await l(e,ln,{force:!0}),!P()||(await u(e,{force:!0}),!P()))return;G.success(t("settings.github.page.toast.connected"));return}R.status==="pending"&&R.slowDown&&k(F=>F?F+5e3:5e3),R.status==="pending"&&j(F=>F+1),R.status==="error"&&(G.error(R.message||t("settings.github.page.toast.authorizationFailed")),I())}catch(R){P()&&S.current===Yt()&&(console.warn("GitHub polling failed:",R),j(F=>F+1))}};return x.current=window.setTimeout(()=>{M()},h),()=>{x.current!=null&&(window.clearTimeout(x.current),x.current=null)}},[N,p,b,h,u,l,e,I,t]);const D=d.useCallback(async M=>{const P=N();f(!0);try{if(!e||(await e.authSetCliDisabled(ln,M),!P())||(await l(e,ln,{force:!0}),!P()))return;G.success(t(M?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled"))}catch(R){P()&&(console.error("Failed to update gh CLI setting:",R),G.error(t("settings.github.page.toast.ghCliUpdateFailed")))}finally{P()&&f(!1)}},[N,l,e,t]),C=d.useCallback(async M=>{const P=N();f(!0);try{if(I(),!e||(await e.authDisconnect(ln,M),!P())||(await l(e,ln,{force:!0}),!P())||(await u(e,{force:!0}),!P()))return;G.success(t("settings.github.page.toast.disconnected"))}catch(R){P()&&(console.error("Failed to remove GitHub account:",R),G.error(t("settings.github.page.toast.disconnectFailed")))}finally{P()&&f(!1)}},[N,u,l,e,I,t]);if(i&&!r)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.sourceControl.status.checking")});const A=o?.accounts??[],T=o?.cli??null,O=o?.status==="unreachable"||o?.status==="temporarily-unavailable"?o.message||t("sessionAuth.error.networkRetry"):null,z=!!(T?.available&&!T.active&&(!T.user||T.disabled));return s.jsxs("div",{className:"space-y-3","data-settings-item":"git.github-account",children:[O&&s.jsx(ht,{label:t("sessionAuth.error.networkTitle"),description:O,children:s.jsx(q,{size:"sm",variant:"outline",disabled:c||i||!e,onClick:()=>{e&&l(e,ln,{force:!0})},children:t("sessionAuth.error.retry")})}),A.length===0?!O&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.status.notConnected")}):s.jsx(Yu,{accounts:A,avatarAlt:M=>t("settings.github.page.avatarAlt.withLogin",{login:M}),currentLabel:t("settings.sourceControl.accounts.inUse"),sourceLabel:M=>M.source==="cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth"),statusLabel:M=>M.status==="valid"?null:t("settings.sourceControl.accounts.needsAuthentication"),renderActions:M=>s.jsxs(s.Fragment,{children:[M.status==="invalid"?s.jsx(q,{size:"sm",variant:"outline",onClick:w,disabled:c,children:t("settings.sourceControl.actions.reauthenticate")}):null,s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>M.source==="cli"?D(!0):C(M.id),disabled:c,children:M.source==="cli"?t("settings.github.page.ghCli.actions.disable"):t("settings.sourceControl.actions.remove")})]})}),p?s.jsx(Zu,{code:p.userCode,description:t("settings.github.page.flow.description"),openLabel:t("settings.github.page.actions.openGithub"),onOpen:()=>{m(p.verificationUriComplete||p.verificationUri)},onCancel:I,disabled:c}):s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(q,{"data-settings-item":"git.github-connect",size:"sm",variant:A.length>0?"outline":"default",onClick:w,disabled:c,children:A.length>0?t("settings.github.page.actions.addAccount"):t("settings.github.page.actions.connect")})}),z&&T?s.jsx(ht,{label:t("settings.github.page.ghCli.title"),description:T.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.availableDescription"),className:"border-t border-[var(--surface-subtle)] pt-3",children:s.jsx(q,{size:"sm",variant:"outline",onClick:()=>D(!T.disabled),disabled:c,children:T.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})}):null]})},mj=()=>{const t=Ke.c(37),{t:e}=ze(),a=nu(ln),n=a?.status??null,o=a?.isLoading??!1,i=a?.hasChecked??!1,[r,l]=d.useState(!1),u=n?.connected===!0;let m;if(t[0]!==u||t[1]!==i||t[2]!==o||t[3]!==n||t[4]!==e){const A=n?.accounts??[],T=(A.find(pj)??A[0])?.user.username.trim()??(n?.status==="connected"?n.user.username.trim():"");m=o&&!i?e("common.loading"):u?A.length>1?e("settings.sourceControl.accounts.connectedCount",{count:A.length}):T||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=u,t[1]=i,t[2]=o,t[3]=n,t[4]=e,t[5]=m}else m=t[5];const c=m,f=u?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let p;t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Q,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=p):p=t[6];let g;t[7]!==e?(g=e("settings.integrations.github.title"),t[7]=e,t[8]=g):g=t[8];let h;t[9]!==g?(h=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:g}),t[9]=g,t[10]=h):h=t[10];let k;t[11]!==e?(k=e("settings.integrations.github.description"),t[11]=e,t[12]=k):k=t[12];let b;t[13]!==k?(b=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:k}),t[13]=k,t[14]=b):b=t[14];let j;t[15]!==h||t[16]!==b?(j=s.jsxs("div",{className:"min-w-0 flex-1",children:[h,b]}),t[15]=h,t[16]=b,t[17]=j):j=t[17];let x;t[18]!==f?(x=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",f),t[18]=f,t[19]=x):x=t[19];let S;t[20]!==c||t[21]!==x?(S=s.jsx("span",{"aria-live":"polite",className:x,children:c}),t[20]=c,t[21]=x,t[22]=S):S=t[22];const v=r&&"rotate-180";let N;t[23]!==v?(N=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",v),t[23]=v,t[24]=N):N=t[24];let y;t[25]!==N?(y=s.jsx(Q,{name:"arrow-down-s",className:N}),t[25]=N,t[26]=y):y=t[26];let I;t[27]!==y||t[28]!==j||t[29]!==S?(I=s.jsxs(Ws,{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:[p,j,S,y]}),t[27]=y,t[28]=j,t[29]=S,t[30]=I):I=t[30];let w;t[31]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Js,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(uj,{embedded:!0})}),t[31]=w):w=t[31];let D;t[32]!==I?(D=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[I,w]}),t[32]=I,t[33]=D):D=t[33];let C;return t[34]!==r||t[35]!==D?(C=s.jsx(Gs,{open:r,onOpenChange:l,children:D}),t[34]=r,t[35]=D,t[36]=C):C=t[36],C};function pj(t){return t.current}const gj={provider:"gitlab",instance:"https://gitlab.com"},Xu="overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)]",Ka="px-3 py-3",io="border-t border-[var(--surface-subtle)]",fj=t=>{try{const e=new URL(t.includes("://")?t:`https://${t}`),a=["localhost","127.0.0.1","::1","[::1]"].includes(e.hostname.toLowerCase()),n=!!(e.username||e.password||e.search||e.hash||e.pathname&&e.pathname!=="/"),o=e.protocol==="https:"||e.protocol==="http:"&&a;return n||!o?null:{provider:"gitlab",instance:e.origin}}catch{return null}},hj=({identity:t,sourceControl:e,onSaved:a})=>{const{t:n}=ze(),o=Hs(J=>J.refreshInstances),i=Hs(J=>J.refreshStatus),r=Hs(J=>J.setStatus),l=nu(t),[u,m]=d.useState(null),[c,f]=d.useState(!1),[p,g]=d.useState(0),[h,k]=d.useState(null),[b,j]=d.useState(0),[x,S]=d.useState(0),[v,N]=d.useState(""),[y,I]=d.useState(!1),[w,D]=d.useState(!1),[C,A]=d.useState(!1),[T,O]=d.useState(!1),z=d.useRef(""),M=d.useRef(0),P=d.useCallback(()=>{const J=Yt(),ie=M.current;return()=>ie===M.current&&J===Yt()},[]),R=l?.status??null,F=R?.accounts??[],_=R&&"cli"in R?R.cli:void 0,B=d.useCallback(()=>{z.current="",k(null),j(0)},[]);d.useEffect(()=>{const J=Tl(()=>{M.current+=1,B()});return()=>{M.current+=1,J()}},[B]),d.useEffect(()=>B(),[t.instance,t.provider,B]),d.useEffect(()=>{let J=!1;const ie=P();return f(!1),Promise.all([e.capabilities(t),i(e,t)]).then(([pe])=>{!J&&ie()&&m(pe)}).catch(()=>{!J&&ie()&&f(!0)}),()=>{J=!0}},[p,P,t,i,e]),d.useEffect(()=>{if(!h||b<=0)return;const J=async()=>{const pe=P();if(z.current!==Yt()){B();return}try{const X=await e.authComplete(t,h.flowId);if(!pe()||z.current!==Yt())return;if(X.status==="connected"){if(B(),I(!1),await i(e,t,{force:!0}),!pe()||(await o(e,{force:!0}),!pe()))return;a?.(),A(!1);return}if(X.status==="pending"){j((X.slowDown?b+5e3:b)||5e3),S(xe=>xe+1);return}B(),A(!0)}catch{pe()&&z.current===Yt()&&S(X=>X+1)}},ie=window.setTimeout(()=>{J()},b);return()=>window.clearTimeout(ie)},[P,h,t,a,x,b,o,i,e,B]);const V=async()=>{const J=P();D(!0),A(!1),O(!1);try{const ie=await e.authStart(t);if(!J())return;z.current=Yt(),k(ie),S(0),j(Math.max(1,ie.interval)*1e3),await Ss(ie.verificationUriComplete||ie.verificationUri)}catch{J()&&A(!0)}finally{J()&&D(!1)}},ee=async()=>{if(!v.trim())return;const J=P();D(!0),A(!1),O(!1);try{const ie=await e.authSetToken(t,v.trim());if(!J()||(r(t,ie),N(""),I(!1),await i(e,t,{force:!0}),!J())||(await o(e,{force:!0}),!J()))return;a?.()}catch(ie){if(!J())return;ie instanceof Error&&"code"in ie&&ie.code==="INVALID_TOKEN"?O(!0):A(!0)}finally{J()&&D(!1)}},L=async J=>{const ie=P();D(!0),A(!1),O(!1);try{if(await e.authDisconnect(t,J),!ie()||(await i(e,t,{force:!0}),!ie()))return;await o(e,{force:!0})}catch{ie()&&A(!0)}finally{ie()&&D(!1)}},$=async()=>{if(!_)return;const J=P();D(!0),A(!1),O(!1);try{if(await e.authSetCliDisabled(t,!_.disabled),!J())return;await i(e,t,{force:!0})}catch{J()&&A(!0)}finally{J()&&D(!1)}},H=()=>{I(!1),k(null),j(0),S(0),N(""),A(!1),O(!1)},W=F.length>0,Z=!W||y;let te;return l?.isLoading?te=n("settings.sourceControl.status.checking"):T?te=n("settings.gitlab.status.tokenRejected"):C||c||R?.status==="unreachable"?te=n("settings.gitlab.status.operationFailed"):F.length>0?te=null:te=n("settings.gitlab.status.notConnected"),s.jsxs("div",{className:Xu,children:[s.jsxs("div",{className:Ie(Ka,"flex items-start justify-between gap-4"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate text-foreground",children:t.instance}),te?s.jsx("div",{className:"typography-meta mt-0.5 text-muted-foreground",children:te}):null]}),c||R?.status==="unreachable"?s.jsx(q,{size:"sm",variant:"outline",disabled:w||l?.isLoading,onClick:()=>g(J=>J+1),children:n("sessionAuth.error.retry")}):null]}),F.length>0?s.jsx("div",{className:Ie(Ka,io),children:s.jsx(Yu,{accounts:F,avatarAlt:J=>J,currentLabel:n("settings.sourceControl.accounts.inUse"),sourceLabel:J=>n(J.source==="cli"?"settings.gitlab.cli.label":Xd(J.source)),statusLabel:J=>J.status==="valid"?null:n("settings.sourceControl.accounts.needsAuthentication"),renderActions:J=>s.jsxs(s.Fragment,{children:[J.status==="invalid"&&J.source!=="cli"?s.jsx(q,{size:"sm",variant:"outline",onClick:()=>I(!0),disabled:w,children:n("settings.sourceControl.actions.reauthenticate")}):null,s.jsx(q,{size:"sm",variant:"ghost",onClick:()=>J.source==="cli"?$():L(J.id),disabled:w,children:J.source==="cli"?n("settings.gitlab.actions.disableCli"):n("settings.sourceControl.actions.remove")})]})})}):null,W&&!y&&s.jsx("div",{className:Ie(Ka,io),children:s.jsx(q,{size:"sm",variant:"outline",onClick:()=>I(!0),disabled:w,children:n("settings.github.page.actions.addAccount")})}),Z&&s.jsxs("div",{className:Ie(ws,Ka,io),children:[u?.authenticationMethods.device.available&&!h&&s.jsx(ht,{label:n("settings.gitlab.device.label"),children:s.jsx(q,{size:"sm",onClick:V,disabled:w,children:n("settings.gitlab.actions.connect")})}),h&&s.jsx(Zu,{code:h.userCode,description:n("settings.gitlab.device.waiting"),openLabel:n("settings.gitlab.actions.openGitLab"),onOpen:()=>{Ss(h.verificationUriComplete||h.verificationUri)},onCancel:H}),u?.authenticationMethods.pat.available&&s.jsx(ht,{label:n("settings.gitlab.token.label"),info:n("settings.gitlab.token.info"),children:s.jsxs("div",{className:`${ks} flex flex-col gap-2 @xl:flex-row @xl:items-center`,children:[s.jsx(Be,{className:"h-8 w-full min-w-0 rounded-md",type:"password",value:v,onChange:J=>N(J.target.value),"aria-label":n("settings.gitlab.token.label")}),s.jsx(q,{className:"w-full @xl:w-auto",size:"sm",onClick:ee,disabled:w||!v.trim(),children:n("settings.common.actions.saveChanges")})]})}),y&&!h&&s.jsx("div",{className:"flex justify-end",children:s.jsx(q,{size:"sm",variant:"ghost",onClick:H,disabled:w,children:n("settings.common.actions.cancel")})})]}),(W||_?.disabled)&&_&&(_.available||_.disabled)&&s.jsx("div",{className:Ie(Ka,io),children:s.jsx(ht,{label:n("settings.gitlab.cli.label"),info:n("settings.gitlab.cli.info"),children:s.jsx(q,{size:"sm",variant:"outline",onClick:$,disabled:w,children:_.disabled?n("settings.gitlab.actions.enableCli"):n("settings.gitlab.actions.disableCli")})})})]})},bj=()=>{const t=Ke.c(51),{t:e}=ze(),a=ha()?.sourceControl,n=Hs(xj),o=Hs(vj),i=Hs(yj),[r,l]=d.useState(!1),[u,m]=d.useState(null),[c,f]=d.useState(""),[p,g]=d.useState(!1),[h,k]=d.useState(!1);let b;t[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>m(null),t[0]=b):b=t[0];const j=b,x=n.filter(jj),S=[...x];u&&!x.some(Y=>Y.instance===u.instance)&&S.push(u),S.length===0&&S.push(gj);let v,N;t[1]!==i?(v=()=>{a&&i(a)},N=[i,a],t[1]=i,t[2]=v,t[3]=N):(v=t[2],N=t[3]),d.useEffect(v,N);let y;t[4]!==c?(y=()=>{const Y=fj(c);if(!Y){k(!0);return}m(Y),f(""),g(!1),k(!1)},t[4]=c,t[5]=y):y=t[5];const I=y;if(!a)return null;let w;t[6]!==o?(w=Y=>o[Cl(Y)],t[6]=o,t[7]=w):w=t[7];const D=x.map(w),C=D.flatMap(kj).filter(wj),A=C.find(Sj)??C[0]??null,T=A!==null,z=D.some(Nj)&&!T?e("common.loading"):T?C.length>1?e("settings.sourceControl.accounts.connectedCount",{count:C.length}):A.user.username.trim()||e("settings.gitlab.status.connected"):e("settings.gitlab.status.notConnected"),M=T?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let P;t[8]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Q,{name:"gitlab",className:"size-5 text-foreground"})}),t[8]=P):P=t[8];let R;t[9]!==e?(R=e("settings.gitlab.title"),t[9]=e,t[10]=R):R=t[10];let F;t[11]!==R?(F=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:R}),t[11]=R,t[12]=F):F=t[12];let _;t[13]!==e?(_=e("settings.gitlab.info"),t[13]=e,t[14]=_):_=t[14];let B;t[15]!==_?(B=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:_}),t[15]=_,t[16]=B):B=t[16];let V;t[17]!==F||t[18]!==B?(V=s.jsxs("div",{className:"min-w-0 flex-1",children:[F,B]}),t[17]=F,t[18]=B,t[19]=V):V=t[19];let ee;t[20]!==M?(ee=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",M),t[20]=M,t[21]=ee):ee=t[21];let L;t[22]!==z||t[23]!==ee?(L=s.jsx("span",{"aria-live":"polite",className:ee,children:z}),t[22]=z,t[23]=ee,t[24]=L):L=t[24];const $=r&&"rotate-180";let H;t[25]!==$?(H=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",$),t[25]=$,t[26]=H):H=t[26];let W;t[27]!==H?(W=s.jsx(Q,{name:"arrow-down-s",className:H}),t[27]=H,t[28]=W):W=t[28];let Z;t[29]!==V||t[30]!==L||t[31]!==W?(Z=s.jsxs(Ws,{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:[P,V,L,W]}),t[29]=V,t[30]=L,t[31]=W,t[32]=Z):Z=t[32];let te;t[33]!==e?(te=e("settings.gitlab.instances.title"),t[33]=e,t[34]=te):te=t[34];const J=S.map(Y=>s.jsx(hj,{identity:Y,sourceControl:a,onSaved:u?.instance===Y.instance?j:void 0},`${Yt()}:${Y.instance}`));let ie;t[35]!==I||t[36]!==h||t[37]!==c||t[38]!==p||t[39]!==e?(ie=p?s.jsx("div",{className:Ie(Xu,Ka),children:s.jsx(ht,{label:e("settings.gitlab.instance.customLabel"),info:e("settings.gitlab.instance.customInfo"),description:h?e("settings.gitlab.status.operationFailed"):void 0,children:s.jsxs("div",{className:`${ks} flex flex-col gap-2 @xl:flex-row @xl:items-center`,children:[s.jsx(Be,{className:"h-8 w-full min-w-0 rounded-md",value:c,onChange:Y=>f(Y.target.value),placeholder:"https://gitlab.example.com","aria-label":e("settings.gitlab.instance.customLabel")}),s.jsx(q,{className:"w-full @xl:w-auto",size:"sm",onClick:I,children:e("settings.gitlab.actions.useInstance")}),s.jsx(q,{className:"w-full @xl:w-auto",size:"sm",variant:"ghost",onClick:()=>{f(""),g(!1),k(!1)},children:e("settings.common.actions.cancel")})]})})}):s.jsx(q,{size:"sm",variant:"outline",onClick:()=>g(!0),children:e("settings.gitlab.actions.addInstance")}),t[35]=I,t[36]=h,t[37]=c,t[38]=p,t[39]=e,t[40]=ie):ie=t[40];let pe;t[41]!==te||t[42]!==J||t[43]!==ie?(pe=s.jsx(Js,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs(vs,{title:te,contentClassName:"space-y-3",settingsItem:"git.gitlab-connect",children:[J,ie]})}),t[41]=te,t[42]=J,t[43]=ie,t[44]=pe):pe=t[44];let X;t[45]!==Z||t[46]!==pe?(X=s.jsxs("div",{"data-settings-item":"git.gitlab-account",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[Z,pe]}),t[45]=Z,t[46]=pe,t[47]=X):X=t[47];let xe;return t[48]!==r||t[49]!==X?(xe=s.jsx(Gs,{open:r,onOpenChange:l,children:X}),t[48]=r,t[49]=X,t[50]=xe):xe=t[50],xe};function xj(t){return t.identities}function vj(t){return t.entries}function yj(t){return t.refreshInstances}function jj(t){return t.provider==="gitlab"}function kj(t){return t?.status?.status==="connected"?t.status.accounts:[]}function wj(t){return t.status==="valid"}function Sj(t){return t.current}function Nj(t){return t?.isLoading&&!t.hasChecked}const oo="__none__",ro="__inherit__";function Cj({linear:t,connected:e,organizationId:a}){const{t:n}=ze(),o=dn(b=>b.projects),[i,r]=d.useState(null),[l,u]=d.useState(!1),[m,c]=d.useState(!1),f=d.useCallback(async()=>{if(!e){r(null),u(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){r(null),u(!1);return}r(b),u(!1)}catch(b){console.error("Failed to load Linear mapping:",b),u(!0)}},[e,t]);d.useEffect(()=>{f()},[f,a]);const p=d.useCallback(async b=>{const j={};for(const x of b.teams??[])x.projectPath&&(j[x.id]=x.projectPath);c(!0),Zt("saving");try{const x=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:j});if(x.connected===!1){r(null),Zt("error");return}r(x),u(!1),Zt("saved")}catch(x){console.error("Failed to save Linear mapping:",x),Zt("error")}finally{c(!1)}},[t]);if(!e)return null;if(l&&!i)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!i)return null;const g=b=>o.find(x=>x.path===b)?.label?.trim()||b,h=b=>!b||b===oo?n("settings.integrations.linear.mapping.defaultProject.placeholder"):g(b),k=b=>!b||b===ro?n("settings.integrations.linear.mapping.teams.useDefault"):g(b);return s.jsxs("div",{className:ws,children:[o.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(ht,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Tt,{value:i.defaultProjectPath||oo,disabled:m||o.length===0,onValueChange:b=>{p({...i,defaultProjectPath:b===oo?null:b})},children:[s.jsx(Pt,{size:_t,className:tn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Kt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:h})}),s.jsxs(At,{children:[s.jsx(at,{value:oo,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),i.defaultProjectPath&&!o.some(b=>b.path===i.defaultProjectPath)?s.jsx(at,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,o.map(b=>s.jsx(at,{value:b.path,children:g(b.path)},b.id))]})]})}),s.jsx(vs,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(i.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:ws,children:(i.teams??[]).map(b=>s.jsx(ht,{label:`${b.key} · ${b.name}`,children:s.jsxs(Tt,{value:b.projectPath||ro,disabled:m||o.length===0,onValueChange:j=>{p({...i,teams:(i.teams??[]).map(x=>x.id===b.id?{...x,projectPath:j===ro?null:j}:x)})},children:[s.jsx(Pt,{size:_t,className:tn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(Kt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:k})}),s.jsxs(At,{children:[s.jsx(at,{value:ro,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!o.some(j=>j.path===b.projectPath)?s.jsx(at,{value:b.projectPath,children:b.projectPath}):null,o.map(j=>s.jsx(at,{value:j.path,children:g(j.path)},j.id))]})]})},b.id))})})]})}function Ij({linear:t,connected:e}){const{t:a}=ze(),[n,o]=d.useState(null),[i,r]=d.useState(!1),[l,u]=d.useState(!1);d.useEffect(()=>{if(!e){o(null),r(!1);return}let c=!1;return t.preferencesGet().then(f=>{c||(o(f.sessionComments),r(!1))}).catch(()=>{c||r(!0)}),()=>{c=!0}},[e,t]);const m=d.useCallback(async c=>{const f=n;o(c),u(!0);try{const p=await t.preferencesSet({sessionComments:c});o(p.sessionComments),Zt("saved")}catch{o(f),Zt("error")}finally{u(!1)}},[n,t]);return e?i?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:ws,children:s.jsx(ht,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(fa,{checked:n===!0,disabled:n===null||l,onCheckedChange:c=>{m(c)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Pj=3*6e4,Aj=1500;function yd(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 Tj(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Ej=()=>{const{t}=ze(),e=ha()?.linear,a=Da(A=>A.status),n=Da(A=>A.isLoading),o=Da(A=>A.hasChecked),i=Da(A=>A.refreshStatus),r=Da(A=>A.setStatus),[l,u]=d.useState(!1),[m,c]=d.useState(!1),[f,p]=d.useState(!1),g=d.useRef(null),h=d.useCallback(()=>{g.current!=null&&(window.clearInterval(g.current),g.current=null),c(!1)},[]);d.useEffect(()=>{if(e)return o||i(e),()=>{h()}},[o,i,e,h]);const k=d.useCallback(async()=>{if(!e)return;h(),u(!0);const A=yd(Da.getState().status);try{const T=await e.authStart(rs()?"desktop":"web");c(!0),p(!0),Ss(T.authorizationUrl);const O=Date.now()+Pj;g.current=window.setInterval(()=>{(async()=>{if(Date.now()>O){h(),G.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const z=await i(e,{force:!0});Tj(A,yd(z))&&(h(),G.success(t("settings.integrations.linear.toast.connected")),pu())})()},Aj)}catch(T){console.error("Failed to start Linear connect:",T),G.error(t("settings.integrations.linear.toast.startConnectFailed")),h()}finally{u(!1)}},[i,e,h,t]),b=d.useCallback(async A=>{if(!(!e||!A)){u(!0);try{const T=await e.authActivate(A);r(T),G.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(T){console.error("Failed to switch Linear workspace:",T),G.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{u(!1)}}},[e,r,t]),j=d.useCallback(async()=>{if(e){u(!0);try{h(),await e.authDisconnect(),G.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(A){console.error("Failed to disconnect Linear:",A),G.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{u(!1)}}},[i,e,h,t]);if(!e)return null;const x=!!a?.connected,S=a?.user,v=a?.organization,y=(a?.workspaces??[]).filter(A=>!A.current),I=S?.displayName?.trim()||S?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),w=m?t("settings.integrations.linear.status.waiting"):n&&!o?t("common.loading"):x?v?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),D=m?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":x?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",C=m||f;return s.jsx(Gs,{open:C,onOpenChange:A=>{if(m){p(!0);return}p(A)},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(Ws,{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(Q,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",D),children:w}),s.jsx(Q,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",C&&"rotate-180")})]}),s.jsx(Js,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[x?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[S?.avatarUrl?s.jsx("img",{src:S.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:I}),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(Q,{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:I}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[v?.name,S?.email].filter(Boolean).join(" · ")})]})]}):m?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,x?s.jsxs(s.Fragment,{children:[s.jsx(Cj,{linear:e,connected:x,organizationId:v?.id??null}),s.jsx(Ij,{linear:e,connected:x}),y.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:y.map(A=>{const T=A.user,O=A.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:O}),T?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:T.email}):null]}),s.jsx(q,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(A.id)},disabled:l,children:t("settings.integrations.linear.actions.switchTo")})]},A.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(q,{type:"button",size:"sm",variant:"outline",onClick:()=>{k()},disabled:l||m,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(q,{type:"button",size:"sm",variant:"destructive",onClick:()=>{j()},disabled:l,children:t("settings.integrations.linear.actions.disconnect")})]})]}):m?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(q,{type:"button",size:"sm",variant:"ghost",disabled:l,onClick:h,children:t("settings.common.actions.cancel")})]}):s.jsxs(q,{type:"button",size:"sm",variant:"default",onClick:()=>{k()},disabled:l||n&&!o,children:[l?s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Kr=[{id:"opencode-claude",packageName:"@openchamber/opencode-claude",providerId:"claude-code",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"}],Dj=(t,e)=>t===e||t.startsWith(`${e}@`);function zr(t,e,a){const n=t.filter(u=>Dj(u.spec,e)),o=n.filter(u=>u.scope==="user"),i=n.filter(u=>u.scope==="project"),r=o.length===1?o[0]:null,l=a[r?.spec??e]??a[e]??null;return{userEntry:r,userEntryIsAmbiguous:o.length>1,projectEntries:i,registry:l}}function gl(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function jd(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=gl(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function Mj(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const Rj={success:"bg-[var(--status-success)]/15 text-[var(--status-success)]",warning:"bg-[var(--status-warning)]/15 text-[var(--status-warning)]",neutral:"bg-[var(--surface-muted)] text-muted-foreground"},em=t=>{const e=Ke.c(33),{settingsItem:a,logo:n,name:o,description:i,status:r,statusTone:l,open:u,onOpenChange:m,children:c}=t;let f;e[0]!==n?(f=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:n}),e[0]=n,e[1]=f):f=e[1];let p;e[2]!==o?(p=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:o}),e[2]=o,e[3]=p):p=e[3];let g;e[4]!==i?(g=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:i}),e[4]=i,e[5]=g):g=e[5];let h;e[6]!==p||e[7]!==g?(h=s.jsxs("div",{className:"min-w-0 flex-1",children:[p,g]}),e[6]=p,e[7]=g,e[8]=h):h=e[8];const k=Rj[l];let b;e[9]!==k?(b=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",k),e[9]=k,e[10]=b):b=e[10];let j;e[11]!==r||e[12]!==b?(j=s.jsx("span",{"aria-live":"polite",className:b,children:r}),e[11]=r,e[12]=b,e[13]=j):j=e[13];const x=u&&"rotate-180";let S;e[14]!==x?(S=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",x),e[14]=x,e[15]=S):S=e[15];let v;e[16]!==S?(v=s.jsx(Q,{name:"arrow-down-s",className:S}),e[16]=S,e[17]=v):v=e[17];let N;e[18]!==f||e[19]!==v||e[20]!==h||e[21]!==j?(N=s.jsxs(Ws,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[f,h,j,v]}),e[18]=f,e[19]=v,e[20]=h,e[21]=j,e[22]=N):N=e[22];let y;e[23]!==c?(y=s.jsx(Js,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:c}),e[23]=c,e[24]=y):y=e[24];let I;e[25]!==a||e[26]!==N||e[27]!==y?(I=s.jsxs("div",{"data-settings-item":a,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[N,y]}),e[25]=a,e[26]=N,e[27]=y,e[28]=I):I=e[28];let w;return e[29]!==m||e[30]!==u||e[31]!==I?(w=s.jsx(Gs,{open:u,onOpenChange:m,children:I}),e[29]=m,e[30]=u,e[31]=I,e[32]=w):w=e[32],w},Oj=t=>t.requiresManualRestart===!0||t.reloadFailed===!0,Fj=({divider:t=!0})=>{const{t:e}=ze(),a=Ks(),n=d.useCallback(()=>{re.getState().requestSettingsJump("plugins")},[]),o=d.useCallback(async P=>{if(await rt.getState().loadProviders({directory:a,source:"settings:third-party-provider-setup"}),!Qd(rt.getState(),a).some(_=>_.id===P))return!1;const F=re.getState();return F.setSettingsProvidersOpenRequested(P),F.requestSettingsJump("providers"),!0},[a]),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:u,createEntry:m,updateEntry:c,deleteEntry:f}=Ot(Ms(P=>({entries:P.entries,registryInfo:P.registryInfo,loadPlugins:P.loadPlugins,loadRegistryInfo:P.loadRegistryInfo,createEntry:P.createEntry,updateEntry:P.updateEntry,deleteEntry:P.deleteEntry}))),[p,g]=d.useState(!1),[h,k]=d.useState(null),[b,j]=d.useState(()=>new Set),[x,S]=d.useState(()=>new Set),[v,N]=d.useState(null),[y,I]=d.useState(()=>new Set),w=d.useCallback(async()=>{if(!await l({force:!0})){g(!0);return}const R=Ot.getState().entries,F=new Set(Kr.map(B=>B.packageName));for(const B of R)Kr.some(V=>B.spec===V.packageName||B.spec.startsWith(`${V.packageName}@`))&&F.add(B.spec);const _=await u({specs:[...F],force:!0});g(!_)},[l,u]);d.useEffect(()=>{w()},[w]);const D=d.useCallback((P,R)=>{j(F=>{const _=new Set(F);return R?_.add(P):_.delete(P),_})},[]),C=d.useCallback((P,R)=>{S(F=>{const _=new Set(F);return R?_.add(P):_.delete(P),_})},[]),A=d.useCallback(async(P,R,F)=>{k({pluginId:P.id,action:R});try{const _=await F();if(!_.ok){G.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}C(P.id,!1);const B=Oj(_);D(P.id,B);const V=B?{description:e("settings.integrations.thirdParty.toast.restartRequired")}:void 0;R==="install"?G.success(e("settings.integrations.thirdParty.toast.installed",{name:e(P.nameKey)}),V):R==="update"?G.success(e("settings.integrations.thirdParty.toast.updated",{name:e(P.nameKey)}),V):G.success(e("settings.integrations.thirdParty.toast.removed",{name:e(P.nameKey)}),V),await w()}finally{k(null)}},[w,C,D,e]),T=d.useCallback(async P=>{const R=zr(i,P.packageName,r),F=jd(R,P.packageName);if(F==="manage"){n();return}if(F==="setup"){k({pluginId:P.id,action:F});try{const B=await o(P.providerId);C(P.id,!B),B?D(P.id,!1):G.error(e("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{k(null)}return}const _=gl(P.packageName,R.registry);if(!_){g(!0);return}if(F==="install"){await A(P,"install",()=>m({spec:_,scope:"user"}));return}R.userEntry&&await A(P,"update",()=>c(R.userEntry.id,{spec:_}))},[m,i,n,o,r,A,C,D,e,c]),O=d.useCallback(async()=>{const P=v;if(!P)return;const R=zr(i,P.packageName,r);if(!R.userEntry||R.userEntryIsAmbiguous){N(null),n();return}N(null),await A(P,"remove",()=>f(R.userEntry.id))},[f,i,n,r,v,A]),z=d.useCallback((P,R)=>{I(F=>{const _=new Set(F);return R?_.add(P):_.delete(P),_})},[]),M=P=>{const R=zr(i,P.packageName,r),F=jd(R,P.packageName),_=gl(P.packageName,R.registry),B=h?.pluginId===P.id,V=b.has(P.id),ee=x.has(P.id),L=p||R.registry?.kind==="npm-network",$=B||V&&F!=="setup"||(F==="install"||F==="update")&&(L||!_),H=Mj(R,{registryUnavailable:L,restartRequired:V,providerUnavailable:ee});let W;switch(H.status){case"installed-version":W=H.latestVersion?e("settings.integrations.thirdParty.status.installedVersion",{version:H.latestVersion}):e("settings.integrations.thirdParty.status.installed");break;case"update-available":W=H.latestVersion?e("settings.integrations.thirdParty.status.updateAvailable",{version:H.latestVersion}):e("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":W=e("settings.integrations.thirdParty.status.notInstalled");break;case"installed":W=e("settings.integrations.thirdParty.status.installed");break;case"unpinned":W=e("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":W=e("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":W=e("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":W=e("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":W=e("settings.integrations.thirdParty.status.providerUnavailable");break}const Z=H.status==="installed-version"?"success":H.status==="update-available"||H.status==="ambiguous"||H.status==="restart-required"||H.status==="registry-unavailable"||H.status==="provider-unavailable"?"warning":"neutral",te={install:e("settings.integrations.thirdParty.actions.install"),update:e("settings.integrations.thirdParty.actions.update"),setup:e("settings.integrations.thirdParty.actions.setup"),manage:e("settings.integrations.thirdParty.actions.managePlugins")}[F],J=y.has(P.id);return s.jsx(em,{settingsItem:`integrations.third-party.${P.id}`,logo:s.jsx(sn,{providerId:P.providerId,alt:"",className:"size-5"}),name:e(P.nameKey),description:e(P.descriptionKey),status:W,statusTone:Z,open:J,onOpenChange:ie=>z(P.id,ie),children:s.jsxs("div",{className:"space-y-3",children:[R.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:e("settings.integrations.thirdParty.status.projectInstalled")}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(q,{type:"button",size:"sm",variant:F==="manage"?"outline":"default",onClick:()=>{T(P)},disabled:$,children:[B?s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}):F==="setup"?s.jsx(Q,{name:"plug-2",className:"size-3.5"}):null,te]}),s.jsxs(q,{type:"button",size:"sm",variant:"secondary",onClick:()=>{Ss(P.homepage)},children:[s.jsx(Q,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),R.userEntry&&!R.userEntryIsAmbiguous?s.jsxs(q,{type:"button",size:"sm",variant:"destructive",onClick:()=>N(P),disabled:B,children:[s.jsx(Q,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})]})},P.id)};return s.jsxs(s.Fragment,{children:[s.jsx(Ve,{title:e("settings.integrations.thirdParty.title"),info:e("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:Kr.map(M)}),s.jsx(Ft,{open:v!==null,onOpenChange:P=>!P&&N(null),children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:e("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx($t,{children:e("settings.integrations.thirdParty.dialog.remove.description",{name:v?e(v.nameKey):""})})]}),s.jsxs(Xt,{children:[s.jsx(q,{type:"button",size:"sm",variant:"ghost",onClick:()=>N(null),children:e("settings.common.actions.cancel")}),s.jsx(q,{type:"button",size:"sm",variant:"destructive",onClick:()=>{O()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},fl=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==="clone-auth-failed"?"settings.extensions.toast.cloneNeedsSignIn":t==="extract-failed"?"settings.extensions.toast.extractFailed":t==="too-large"?"settings.extensions.toast.zipTooLarge":t==="enterprise-mode"?"settings.extensions.toast.enterpriseMode":t==="unreadable"?"settings.extensions.toast.installedUnreadable":"settings.extensions.toast.failed",tm=t=>t==="not-git"?"settings.extensions.toast.notGit":t==="enterprise-mode"?"settings.extensions.toast.enterpriseUpdate":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="clone-auth-failed"?"settings.extensions.toast.cloneNeedsSignIn":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",Lj=ts({error:Dl(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","clone-auth-failed","extract-failed","too-large","enterprise-mode"]),required:wt().trim().min(1).max(64).optional(),id:wt().trim().min(1).max(128).optional()}),Kj=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"}},sm=async t=>{try{const e=Lj.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"}}},nm=async(t,e)=>{if(!t.ok)return{ok:!1,...await sm(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:Kp(a);return n==="unreadable"?{ok:!1,code:"unreadable"}:n?{ok:!0,guest:n,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},am=async(t,e={})=>{const a=Kj(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 o=await Dt("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await nm(o,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},zj=async(t,e={})=>{try{const a=await Dt("/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 nm(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},im=async t=>{const e=ys.getState(),a=Yt(),n=e.runtimeKey===a?e.guests.find(o=>o.id===t)?.storageId:void 0;try{const o=await Dt(`/api/guests/${t}`,{method:"DELETE"});return o.status===204?(n&&globalThis.indexedDB&&await Lp({runtimeKey:a,guestId:t,storageId:n}).catch(()=>{console.warn("Could not clear local extension preferences.")}),{ok:!0}):{ok:!1,code:(await sm(o)).code}}catch{return{ok:!1,code:"failed"}}},om=async(t,e)=>{try{return(await Dt(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},Uj=async(t,e)=>{try{return(await Dt(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},$j=ts({updates:Rn(wt().min(1),zp)}),_j=ts({error:Dl(["not-git","clone-failed","clone-auth-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found","enterprise-mode"]),required:wt().trim().min(1).max(64).optional()}),kd=async t=>{try{const e=await Dt("/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=$j.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},Bj=async t=>{try{const e=_j.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"}}},rm=async t=>{try{const e=await Dt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await Bj(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=Up(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},Vj={guestId:"excalidraw",gitUrl:"https://github.com/openchamber/openchamber-excalidraw",homepage:"https://github.com/openchamber/openchamber-excalidraw",nameKey:"settings.integrations.extensionCatalog.excalidraw.name",descriptionKey:"settings.integrations.extensionCatalog.excalidraw.description",logoFileName:"drawing.excalidraw"},Hj=[Vj],qj=(t,e)=>{const a=t.find(n=>n.id===e.guestId);return a?a.enterpriseBlocked?.length?{kind:"blocked",guest:a}:Ha(a)?{kind:"needs-approval",guest:a}:a.enabled===!1?{kind:"paused",guest:a}:a.update?{kind:"update-available",guest:a,version:a.update.version}:{kind:"installed",guest:a}:{kind:"not-installed"}},Gj=({divider:t=!0})=>{const{t:e}=ze(),a=ys(x=>x.guests),n=ys(x=>x.status),[o,i]=d.useState(null),[r,l]=d.useState(()=>new Set),[u,m]=d.useState(null);d.useEffect(()=>{Zs()},[]);const c=d.useCallback(()=>{re.getState().requestSettingsJump("extensions")},[]),f=d.useCallback(async(x,S,v)=>{const N=Yt();i({guestId:x.guestId,action:S});try{await v(),Yt()===N&&await Zs()}finally{i(null)}},[]),p=x=>f(x,"install",async()=>{const S=await am(x.gitUrl);if(!S.ok){G.error(S.code==="host-too-old"&&S.required?e("settings.extensions.toast.hostTooOld",{version:S.required}):e(fl(S.code)));return}G.success(e("settings.integrations.thirdParty.toast.installed",{name:e(x.nameKey)})),Ha(S.guest)&&c()}),g=x=>f(x,"update",async()=>{const S=await rm(x.guestId);if(!S.ok){G.error(S.code==="host-too-old"&&S.required?e("settings.extensions.toast.hostTooOld",{version:S.required}):e(tm(S.code)));return}Si(x.guestId),G.success(e("settings.integrations.thirdParty.toast.updated",{name:e(x.nameKey)})),Ha(S.guest)&&c()}),h=x=>f(x,"enable",async()=>{if(!await om(x.guestId,!0)){G.error(e("settings.integrations.extensionCatalog.toast.enableFailed",{name:e(x.nameKey)}));return}G.success(e("settings.integrations.extensionCatalog.toast.enabled",{name:e(x.nameKey)}))}),k=async()=>{const x=u;x&&(m(null),await f(x,"remove",async()=>{if(!(await im(x.guestId)).ok){G.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}Si(x.guestId),G.success(e("settings.integrations.thirdParty.toast.removed",{name:e(x.nameKey)}))}))},b=x=>{switch(x.kind){case"not-installed":return{status:e("settings.integrations.thirdParty.status.notInstalled"),tone:"neutral"};case"blocked":return{status:e("settings.extensions.status.enterpriseBlocked"),tone:"warning"};case"needs-approval":return{status:e("settings.integrations.extensionCatalog.status.needsApproval"),tone:"warning"};case"paused":return{status:e("settings.integrations.extensionCatalog.status.paused"),tone:"neutral"};case"update-available":return{status:e("settings.integrations.thirdParty.status.updateAvailable",{version:x.version}),tone:"warning"};case"installed":return{status:x.guest.version?e("settings.integrations.thirdParty.status.installedVersion",{version:x.guest.version}):e("settings.integrations.thirdParty.status.installed"),tone:"success"}}},j=x=>{const S=qj(a,x),v=n==="idle"||n==="loading",{status:N,tone:y}=v?{status:e("common.loading"),tone:"neutral"}:b(S),I=o?.guestId===x.guestId||v,w=r.has(x.guestId),D=s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"}),C=S.kind==="not-installed"?{label:e("settings.integrations.thirdParty.actions.install"),onClick:()=>{p(x)},variant:"default"}:S.kind==="update-available"?{label:e("settings.integrations.thirdParty.actions.update"),onClick:()=>{g(x)},variant:"default"}:S.kind==="paused"?{label:e("settings.integrations.extensionCatalog.actions.enable"),onClick:()=>{h(x)},variant:"default"}:S.kind==="needs-approval"||S.kind==="blocked"?{label:e("settings.integrations.extensionCatalog.actions.manage"),onClick:c,variant:"outline"}:null;return s.jsx(em,{settingsItem:`integrations.extensions.${x.guestId}`,logo:s.jsx($p,{filePath:x.logoFileName,className:"size-5"}),name:e(x.nameKey),description:e(x.descriptionKey),status:N,statusTone:y,open:w,onOpenChange:A=>l(T=>{const O=new Set(T);return A?O.add(x.guestId):O.delete(x.guestId),O}),children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[C?s.jsxs(q,{type:"button",size:"sm",variant:C.variant,onClick:C.onClick,disabled:I,children:[I?D:null,C.label]}):null,s.jsxs(q,{type:"button",size:"sm",variant:"secondary",onClick:()=>{Ss(x.homepage)},children:[s.jsx(Q,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),S.kind!=="not-installed"?s.jsxs(q,{type:"button",size:"sm",variant:"destructive",onClick:()=>m(x),disabled:I,children:[s.jsx(Q,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})},x.guestId)};return n==="unsupported"?null:s.jsxs(s.Fragment,{children:[s.jsx(Ve,{title:e("settings.integrations.extensionCatalog.title"),info:e("settings.integrations.extensionCatalog.info"),divider:t,settingsItem:"integrations.extensions",contentClassName:"space-y-3",children:Hj.map(j)}),s.jsx(Ft,{open:u!==null,onOpenChange:x=>!x&&m(null),children:s.jsxs(Lt,{className:"max-w-md",children:[s.jsxs(zt,{children:[s.jsx(Ut,{children:e("settings.integrations.extensionCatalog.dialog.remove.title")}),s.jsx($t,{children:e("settings.integrations.extensionCatalog.dialog.remove.description",{name:u?e(u.nameKey):""})})]}),s.jsxs(Xt,{children:[s.jsx(q,{type:"button",size:"sm",variant:"ghost",onClick:()=>m(null),children:e("settings.common.actions.cancel")}),s.jsx(q,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Wj=()=>{const t=Ke.c(26),{t:e}=ze();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=is(),t[0]=a):a=t[0];const n=!a;let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o=is(),t[1]=o):o=t[1];const i=!o,r=!!ha()?.linear,l=ys(Jj),u=ys(Qj);let m,c,f,p,g,h;if(t[2]!==l||t[3]!==u||t[4]!==e){const S=!is()&&!gu()?l.filter(Yj):[];c=n||i||r||S.length>0,m=Qt,t[11]!==e?(f=e("settings.page.integrations.title"),t[11]=e,t[12]=f):f=t[12],t[13]!==e?(p=e("settings.page.integrations.description"),t[13]=e,t[14]=p):p=t[14],g=!0,h=c?s.jsxs(Ve,{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(mj,{}):null,i?s.jsx(bj,{}):null,r?s.jsx(Ej,{}):null,S.map(v=>s.jsx(Qu,{guest:v},`${u}:${v.id}`))]}):null,t[2]=l,t[3]=u,t[4]=e,t[5]=m,t[6]=c,t[7]=f,t[8]=p,t[9]=g,t[10]=h}else m=t[5],c=t[6],f=t[7],p=t[8],g=t[9],h=t[10];let k;t[15]!==c?(k=s.jsx(Fj,{divider:c}),t[15]=c,t[16]=k):k=t[16];let b,j;t[17]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(Gj,{}),j=s.jsx(aj,{}),t[17]=b,t[18]=j):(b=t[17],j=t[18]);let x;return t[19]!==m||t[20]!==f||t[21]!==p||t[22]!==g||t[23]!==h||t[24]!==k?(x=s.jsxs(m,{title:f,description:p,showSaveStatus:g,children:[h,k,b,j]}),t[19]=m,t[20]=f,t[21]=p,t[22]=g,t[23]=h,t[24]=k,t[25]=x):x=t[25],x};function Jj(t){return t.guests}function Qj(t){return t.runtimeKey}function Yj(t){return t.source==="bundled"&&t.integration&&Il(t)}const hi="__default__",Zj=500,Xj=(t,e)=>{const a=n=>JSON.stringify({...n,categories:n.categories.map(o=>({...o,name:o.name.trim(),description:o.description.trim()}))});return a(t)===a(e)},ek=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),lm=(t,e)=>{const a=Ke.c(7),n=rt(nk);let o;e:{if(!t||!e){let r;a[0]===Symbol.for("react.memo_cache_sentinel")?(r=[],a[0]=r):r=a[0],o=r;break e}let i;if(a[1]!==e||a[2]!==t||a[3]!==n){let r;a[5]!==t?(r=m=>m.id===t,a[5]=t,a[6]=r):r=a[6];const u=n.find(r)?.models.find(m=>m.id===e);i=qd(u),a[1]=e,a[2]=t,a[3]=n,a[4]=i}else i=a[4];o=i}return o},cm=(t,e)=>t&&(e.length===0||e.includes(t))?t:null,dm=t=>{const e=Ke.c(51),{providerID:a,modelID:n,value:o,onChange:i,ariaLabel:r,className:l}=t,{t:u}=ze(),m=lm(a,n);let c,f,p,g,h,k,b,j,x,S,v;if(e[0]!==r||e[1]!==l||e[2]!==i||e[3]!==u||e[4]!==o||e[5]!==m){const T=cm(o,m)??hi;let O;e[17]!==u?(O=z=>z===hi?u("settings.routing.thinking.default"):z.charAt(0).toUpperCase()+z.slice(1),e[17]=u,e[18]=O):O=e[18],g=O,p=Tt,x=T,e[19]!==i?(S=z=>i(z===hi?null:z),e[19]=i,e[20]=S):S=e[20],v=m.length===0,f=Pt,k=_t,e[21]!==l?(b=Ie(tn,l),e[21]=l,e[22]=b):b=e[22],j=r,c=Kt,h=g(T),e[0]=r,e[1]=l,e[2]=i,e[3]=u,e[4]=o,e[5]=m,e[6]=c,e[7]=f,e[8]=p,e[9]=g,e[10]=h,e[11]=k,e[12]=b,e[13]=j,e[14]=x,e[15]=S,e[16]=v}else c=e[6],f=e[7],p=e[8],g=e[9],h=e[10],k=e[11],b=e[12],j=e[13],x=e[14],S=e[15],v=e[16];let N;e[23]!==c||e[24]!==h?(N=s.jsx(c,{children:h}),e[23]=c,e[24]=h,e[25]=N):N=e[25];let y;e[26]!==f||e[27]!==k||e[28]!==b||e[29]!==j||e[30]!==N?(y=s.jsx(f,{size:k,className:b,"aria-label":j,children:N}),e[26]=f,e[27]=k,e[28]=b,e[29]=j,e[30]=N,e[31]=y):y=e[31];let I;e[32]!==g?(I=g(hi),e[32]=g,e[33]=I):I=e[33];let w;e[34]!==I?(w=s.jsx(at,{value:hi,children:I}),e[34]=I,e[35]=w):w=e[35];let D;if(e[36]!==g||e[37]!==m){let T;e[39]!==g?(T=O=>s.jsx(at,{value:O,children:g(O)},O),e[39]=g,e[40]=T):T=e[40],D=m.map(T),e[36]=g,e[37]=m,e[38]=D}else D=e[38];let C;e[41]!==w||e[42]!==D?(C=s.jsxs(At,{children:[w,D]}),e[41]=w,e[42]=D,e[43]=C):C=e[43];let A;return e[44]!==p||e[45]!==C||e[46]!==x||e[47]!==S||e[48]!==v||e[49]!==y?(A=s.jsxs(p,{value:x,onValueChange:S,disabled:v,children:[y,C]}),e[44]=p,e[45]=C,e[46]=x,e[47]=S,e[48]=v,e[49]=y,e[50]=A):A=e[50],A},tk=t=>{const e=Ke.c(52),{category:a,expanded:n,onToggle:o,onChange:i,onReset:r,onRemove:l}=t,{t:u}=ze(),m=lm(a.model?.providerID,a.model?.modelID);let c;e[0]!==a.variant||e[1]!==m?(c=cm(a.variant,m),e[0]=a.variant,e[1]=m,e[2]=c):c=e[2];const f=c;let p;e[3]!==a.model||e[4]!==f||e[5]!==u?(p=a.model?`${a.model.modelID}${f?` / ${f}`:""}`:u("settings.routing.model.useFallback"),e[3]=a.model,e[4]=f,e[5]=u,e[6]=p):p=e[6];const g=p;let h;e[7]!==a.agent||e[8]!==g?(h=[g,a.agent].filter(Boolean),e[7]=a.agent,e[8]=g,e[9]=h):h=e[9];const k=h.join(" · "),b=!a.enabled&&"opacity-60";let j;e[10]!==b?(j=Ie("py-1",b),e[10]=b,e[11]=j):j=e[11];const x=n?"arrow-down-s":"arrow-right-s";let S;e[12]!==x?(S=s.jsx(Q,{name:x,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[12]=x,e[13]=S):S=e[13];const v=a.name||a.id;let N;e[14]!==v?(N=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:v}),e[14]=v,e[15]=N):N=e[15];let y;e[16]!==k?(y=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:k}),e[16]=k,e[17]=y):y=e[17];let I;e[18]!==n||e[19]!==o||e[20]!==y||e[21]!==S||e[22]!==N?(I=s.jsxs("button",{type:"button",onClick:o,"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:[S,N,y]}),e[18]=n,e[19]=o,e[20]=y,e[21]=S,e[22]=N,e[23]=I):I=e[23];const w=a.enabled;let D;e[24]!==i?(D=M=>i({enabled:M}),e[24]=i,e[25]=D):D=e[25];let C;e[26]!==a.name||e[27]!==u?(C=u("settings.routing.category.enabledAria",{name:a.name}),e[26]=a.name,e[27]=u,e[28]=C):C=e[28];let A;e[29]!==a.enabled||e[30]!==D||e[31]!==C?(A=s.jsx(fa,{checked:w,onCheckedChange:D,"aria-label":C}),e[29]=a.enabled,e[30]=D,e[31]=C,e[32]=A):A=e[32];let T;e[33]!==I||e[34]!==A?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[I,A]}),e[33]=I,e[34]=A,e[35]=T):T=e[35];let O;e[36]!==a.agent||e[37]!==a.description||e[38]!==a.model?.modelID||e[39]!==a.model?.providerID||e[40]!==a.name||e[41]!==a.variant||e[42]!==n||e[43]!==i||e[44]!==l||e[45]!==r||e[46]!==u?(O=n?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(Pn,{children:[s.jsx(Et,{label:u("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(Be,{value:a.name,onChange:M=>i({name:M.target.value}),"aria-label":u("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(Et,{label:u("settings.routing.category.agent"),info:u("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(jl,{agentName:a.agent??"",onChange:M=>i({agent:M||null}),filter:ak,className:Ie(en,"w-full")})}),s.jsx(Et,{label:u("settings.routing.category.model"),info:u("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(ga,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(M,P)=>i({model:{providerID:M,modelID:P},variant:null}),className:Ie(en,"w-full"),placeholder:u("settings.routing.model.useFallback")})}),s.jsx(Et,{label:u("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(dm,{providerID:a.model?.providerID,modelID:a.model?.modelID,value:a.variant,onChange:M=>i({variant:M}),ariaLabel:u("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(Et,{label:u("settings.routing.category.description"),info:u("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(Ns,{value:a.description,onChange:M=>i({description:M.target.value}),"aria-label":u("settings.routing.category.description"),rows:5,maxLength:2e3,className:"w-full"})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?s.jsx(q,{size:"sm",variant:"outline",onClick:r,children:u("settings.routing.category.reset")}):null,s.jsx(q,{size:"sm",variant:"ghost",onClick:l,children:u("settings.routing.category.remove")})]})]}):null,e[36]=a.agent,e[37]=a.description,e[38]=a.model?.modelID,e[39]=a.model?.providerID,e[40]=a.name,e[41]=a.variant,e[42]=n,e[43]=i,e[44]=l,e[45]=r,e[46]=u,e[47]=O):O=e[47];let z;return e[48]!==T||e[49]!==O||e[50]!==j?(z=s.jsxs("div",{className:j,children:[T,O]}),e[48]=T,e[49]=O,e[50]=j,e[51]=z):z=e[51],z},sk=()=>{const{t}=ze(),e=Wt(P=>P.available),a=Wt(P=>P.autoReady),n=Wt(P=>P.config),o=Wt(P=>P.builtins),i=Wt(P=>P.loaded),r=Wt(P=>P.loadError),l=Wt(P=>P.load),u=Wt(P=>P.saveConfig),[m,c]=d.useState(n),[f,p]=d.useState(""),[g,h]=d.useState(null),k=d.useRef(null),b=d.useRef(null),j=d.useRef(Promise.resolve()),x=d.useRef(0);d.useEffect(()=>{l()},[l]),d.useEffect(()=>{k.current||x.current>0||c(P=>P&&n&&Xj(n,P)?P:n)},[n]);const S=d.useCallback(()=>{const P=k.current;if(!P||(k.current=null,P.runtimeKey!==Yt()))return j.current;x.current+=1,Zt("saving");const R=j.current.then(async()=>{try{if(P.runtimeKey!==Yt()){Zt("saved");return}await u(P.config),Zt("saved")}catch{Zt("error")}finally{x.current-=1}});return j.current=R,R},[u]);d.useEffect(()=>()=>{b.current&&clearTimeout(b.current),S()},[S]);const v=rt(P=>P.settingsDefaultModel),N=rt(P=>P.settingsDefaultVariant),y=d.useRef(!1);d.useEffect(()=>{if(y.current||!i||!n||n.fallback)return;const P=Mn(v);!P||fu(P.providerId,P.modelId)||(y.current=!0,I(R=>R.fallback?R:{...R,fallback:{model:{providerID:P.providerId,modelID:P.modelId},variant:N??null}}))},[i,n,v,N]);const I=d.useCallback(P=>{c(R=>{if(!R)return R;const F=P(R);return k.current={config:F,runtimeKey:Yt()},b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null,S()},Zj),F})},[S]),w=d.useCallback((P,R)=>{I(F=>({...F,categories:F.categories.map(_=>_.id===P?{..._,...R}:_)}))},[I]),D=()=>{const P=f.trim();if(!P||!m)return;const R=ek(P)||`category-${Date.now()}`;let F=R,_=2;for(;m.categories.some(B=>B.id===F);)F=`${R}-${_++}`;I(B=>({...B,categories:[...B.categories,{id:F,builtin:!1,enabled:!0,name:P,description:"",model:null,variant:null,agent:null}]})),p(""),h(F)},C=P=>{const R=o.find(F=>F.id===P);R&&w(P,{name:R.name,description:R.description,model:null,variant:null,agent:null,enabled:!0})},A=P=>{const R=o.find(F=>F.id===P);R&&I(F=>({...F,categories:[...F.categories,{id:P,builtin:!0,enabled:!0,name:R.name,description:R.description,model:null,variant:null,agent:null}]}))},T=P=>{I(R=>({...R,categories:R.categories.filter(F=>F.id!==P)}))},O=m?.categories.filter(P=>P.enabled).length??0,z=o.filter(P=>!m?.categories.some(R=>R.id===P.id)),M=m?.enabled?m.fallback?O<2?t("settings.routing.status.tooFewCategories"):t(a?"settings.routing.status.ready":"settings.routing.status.notReady"):t("settings.routing.status.noFallback"):t("settings.routing.status.disabled");return s.jsxs(Qt,{title:t("settings.page.routing.title"),description:t("settings.page.routing.description"),showSaveStatus:!0,children:[r?s.jsx("p",{className:xn,children:t("settings.routing.loadError",{error:r})}):null,!i||!m?null:e?s.jsxs(s.Fragment,{children:[s.jsx(Ve,{title:t("settings.routing.auto.title"),divider:!1,children:s.jsxs("div",{className:ws,children:[s.jsx(Ri,{}),s.jsxs("div",{className:bs,children:[s.jsx(st,{settingsItem:"routing.enabled",checked:m.enabled,onChange:P=>I(R=>({...R,enabled:P})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")}),m.preserveCache===void 0?null:s.jsx(st,{settingsItem:"routing.preserve-cache",checked:m.preserveCache,onChange:P=>I(R=>({...R,preserveCache:P})),label:t("settings.routing.auto.preserveCache"),ariaLabel:t("settings.routing.auto.preserveCache"),info:t("settings.routing.auto.preserveCacheInfo")})]}),s.jsx("p",{className:Mt,children:M}),s.jsx(ht,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(ga,{providerId:m.fallback?.model.providerID??"",modelId:m.fallback?.model.modelID??"",onChange:(P,R)=>I(F=>({...F,fallback:{model:{providerID:P,modelID:R},variant:null}})),className:en,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(ht,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(dm,{providerID:m.fallback?.model.providerID,modelID:m.fallback?.model.modelID,value:m.fallback?.variant??null,onChange:P=>I(R=>R.fallback?{...R,fallback:{...R.fallback,variant:P}}:R),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(Ve,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:ws,children:[s.jsx("p",{className:Mt,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:m.categories.map(P=>s.jsx(tk,{category:P,expanded:g===P.id,onToggle:()=>h(R=>R===P.id?null:P.id),onChange:R=>w(P.id,R),onReset:P.builtin?()=>C(P.id):null,onRemove:()=>T(P.id)},P.id))}),z.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map(P=>s.jsx(q,{size:"sm",variant:"outline",onClick:()=>A(P.id),children:t("settings.routing.category.restore",{name:P.name})},P.id))}):null,s.jsx(ht,{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:f,onChange:P=>p(P.target.value),onKeyDown:P=>{P.key==="Enter"&&D()},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(q,{size:"sm",variant:"outline",onClick:D,disabled:f.trim().length===0,children:t("settings.routing.categories.add")})]})})]})})]}):s.jsx("p",{className:xn,children:t("settings.routing.unavailable")})]})};function nk(t){return t.providers}function ak(t){return bo(t.mode)}const ik={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"},shells:{icon:"terminal-box",titleKey:"settings.extensions.capability.shells",detailKey:"settings.extensions.capability.shells.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"},origins:{icon:"global",titleKey:"settings.extensions.capability.origins",detailKey:"settings.extensions.capability.origins.detail"}},ok=t=>{const e=Ke.c(77),{guest:a,busy:n,onApprove:o,onDecline:i,onDismiss:r}=t,{t:l}=ze();let u;e[0]!==a?.capabilities.requested?(u=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=u):u=e[1];const m=u;let c;e[2]!==a?.filesystem?(c=a?.filesystem??[],e[2]=a?.filesystem,e[3]=c):c=e[3];const f=c;let p;e[4]!==a?.origins?(p=a?.origins??[],e[4]=a?.origins,e[5]=p):p=e[5];const g=p;let h;e[6]!==a?.service?.permissions?.exec?(h=a?.service?.permissions?.exec??[],e[6]=a?.service?.permissions?.exec,e[7]=h):h=e[7];const k=h;let b;e[8]!==a?.service?.permissions?.sockets?(b=a?.service?.permissions?.sockets??[],e[8]=a?.service?.permissions?.sockets,e[9]=b):b=e[9];const j=b,x=a?.service;let S;e[10]!==x?(S=au(x,"browser"),e[10]=x,e[11]=S):S=e[11];const v=S,N=a?.integration?.apiOrigin??null,y=a!==null;let I;e[12]!==n||e[13]!==r?(I=Z=>{!Z&&!n&&r()},e[12]=n,e[13]=r,e[14]=I):I=e[14];const w=a?.name??"";let D;e[15]!==l||e[16]!==w?(D=l("settings.extensions.dialog.approveTitle",{name:w}),e[15]=l,e[16]=w,e[17]=D):D=e[17];let C;e[18]!==D?(C=s.jsx(Ut,{children:D}),e[18]=D,e[19]=C):C=e[19];const A=a?.name??"",T=a?.version?`v${a.version}`:"";let O;e[20]!==l||e[21]!==A||e[22]!==T?(O=l("settings.extensions.dialog.approveDescription",{name:A,version:T}),e[20]=l,e[21]=A,e[22]=T,e[23]=O):O=e[23];let z;e[24]!==O?(z=s.jsx($t,{children:O}),e[24]=O,e[25]=z):z=e[25];let M;e[26]!==C||e[27]!==z?(M=s.jsxs(zt,{children:[C,z]}),e[26]=C,e[27]=z,e[28]=M):M=e[28];let P;if(e[29]!==N||e[30]!==f||e[31]!==g||e[32]!==v||e[33]!==m||e[34]!==k||e[35]!==j||e[36]!==l){let Z;e[38]!==N||e[39]!==f||e[40]!==g||e[41]!==v||e[42]!==k||e[43]!==j||e[44]!==l?(Z=te=>{const J=ik[te];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(Q,{name:J.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:l(J.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:l(J.detailKey)}),te==="filesystem"&&f.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:f.map(rk)}):null,te==="origins"&&g.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:g.map(lk)}):null,te==="network"&&N?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[l("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:N})]}):null,te==="service"&&k.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[l("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:k.join(", ")})]}):null,te==="service"&&j.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[l("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:j.join(", ")})]}):null,te==="service"&&v?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:l("settings.extensions.capability.service.providesBrowser")}):null]})]},te)},e[38]=N,e[39]=f,e[40]=g,e[41]=v,e[42]=k,e[43]=j,e[44]=l,e[45]=Z):Z=e[45],P=m.map(Z),e[29]=N,e[30]=f,e[31]=g,e[32]=v,e[33]=m,e[34]=k,e[35]=j,e[36]=l,e[37]=P}else P=e[37];let R;e[46]!==P?(R=s.jsx("ul",{className:"space-y-3",children:P}),e[46]=P,e[47]=R):R=e[47];let F;e[48]!==a||e[49]!==i?(F=()=>a&&i(a),e[48]=a,e[49]=i,e[50]=F):F=e[50];let _;e[51]!==l?(_=l("settings.extensions.dialog.decline"),e[51]=l,e[52]=_):_=e[52];let B;e[53]!==n||e[54]!==F||e[55]!==_?(B=s.jsx(q,{size:"sm",variant:"ghost",disabled:n,onClick:F,children:_}),e[53]=n,e[54]=F,e[55]=_,e[56]=B):B=e[56];let V;e[57]!==a||e[58]!==o?(V=()=>a&&o(a),e[57]=a,e[58]=o,e[59]=V):V=e[59];let ee;e[60]!==l?(ee=l("settings.extensions.dialog.approve"),e[60]=l,e[61]=ee):ee=e[61];let L;e[62]!==n||e[63]!==V||e[64]!==ee?(L=s.jsx(q,{size:"sm",disabled:n,onClick:V,children:ee}),e[62]=n,e[63]=V,e[64]=ee,e[65]=L):L=e[65];let $;e[66]!==B||e[67]!==L?($=s.jsxs(Xt,{children:[B,L]}),e[66]=B,e[67]=L,e[68]=$):$=e[68];let H;e[69]!==M||e[70]!==R||e[71]!==$?(H=s.jsxs(Lt,{className:"max-w-md",children:[M,R,$]}),e[69]=M,e[70]=R,e[71]=$,e[72]=H):H=e[72];let W;return e[73]!==H||e[74]!==y||e[75]!==I?(W=s.jsx(Ft,{open:y,onOpenChange:I,children:H}),e[73]=H,e[74]=y,e[75]=I,e[76]=W):W=e[76],W};function rk(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}function lk(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const ck=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 o=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return o.username="",o.password="",o.search="",o.hash="",o.pathname=o.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),o.pathname==="/"?null:o.href}catch{return null}},Ur=(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}`},wd=t=>t.name.toLowerCase().endsWith(".zip"),dk=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",uk=t=>{const e=(t.service?.socketBindings??[]).map(o=>o.resolved?`${o.id}=${o.resolved}`:`${o.id}?`),a=(t.service?.permissions?.sockets??[]).filter(o=>!(t.service?.socketBindings??[]).some(i=>i.id===o));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},mk=t=>{const e=Ke.c(27),{guest:a,binding:n,busy:o,onSaved:i}=t,{t:r}=ze(),[l,u]=d.useState(n.override??n.resolved??""),[m,c]=d.useState(!1),[f,p]=d.useState(!n.resolved);let g;e[0]!==n.override||e[1]!==n.resolved?(g=()=>{u(n.override??n.resolved??""),n.resolved||p(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=g):g=e[2];let h;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(h=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=h):h=e[6],d.useEffect(g,h);let k;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==i||e[11]!==r?(k=async v=>{c(!0);const N=await Vp(a.id,n.id,v);if(c(!1),!N){G.error(r("settings.extensions.toast.socketSaveFailed"));return}G.success(r("settings.extensions.toast.socketSaved",{name:a.name})),p(!1),await i()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=i,e[11]=r,e[12]=k):k=e[12];const b=k;let j;e[13]!==n.override||e[14]!==n.resolved?(j=()=>{u(n.override??n.resolved??""),n.resolved&&p(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=j):j=e[15];const x=j;let S;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==o||e[20]!==x||e[21]!==f||e[22]!==b||e[23]!==m||e[24]!==r||e[25]!==l?(S=s.jsx("div",{className:"space-y-1",children:f?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(Be,{value:l,onChange:v=>u(v.target.value),placeholder:r("settings.extensions.service.socket.path",{id:n.id}),"aria-label":r("settings.extensions.service.socket.path.aria",{id:n.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:o||m,autoFocus:!0}),s.jsx(q,{type:"button",variant:"ghost",size:"xs",disabled:o||m,"aria-label":r("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(l.trim()||null)},children:r("settings.extensions.service.socket.save")}),n.override?s.jsx(q,{type:"button",variant:"ghost",size:"xs",disabled:o||m,"aria-label":r("settings.extensions.service.socket.clear.aria",{id:n.id}),onClick:()=>{b(null)},children:r("settings.extensions.service.socket.clear")}):null,n.resolved?s.jsx(q,{type:"button",variant:"ghost",size:"xs",disabled:o||m,"aria-label":r("settings.extensions.service.socket.cancel.aria",{id:n.id}),onClick:x,children:r("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?r("settings.extensions.service.socket.resolved",{path:n.resolved}):r("settings.extensions.service.socket.unresolved")}),s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:as,disabled:o||m,"aria-label":r("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>p(!0),children:s.jsx(Q,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=n.id,e[17]=n.override,e[18]=n.resolved,e[19]=o,e[20]=x,e[21]=f,e[22]=b,e[23]=m,e[24]=r,e[25]=l,e[26]=S):S=e[26],S},pk=t=>{const e=Ke.c(151),{guest:a,busy:n,onReview:o,onRemove:i,onSetEnabled:r,onUpdate:l}=t,{t:u}=ze(),[m,c]=d.useState(!1),f=a.enabled!==!1,p=(a.enterpriseBlocked?.length??0)>0;let g;e[0]!==p||e[1]!==a?(g=!p&&Ha(a),e[0]=p,e[1]=a,e[2]=g):g=e[2];const h=g;let k,b,j,x,S,v,N,y,I,w,D,C,A,T,O;if(e[3]!==f||e[4]!==p||e[5]!==a||e[6]!==h||e[7]!==m||e[8]!==u){const W=uk(a);j=!!(a.source&&a.source!=="bundled");const Z=a.source==="bundled";let te;e[24]!==a?(te=ck(a),e[24]=a,e[25]=te):te=e[25],x=te,O=a.source==="git"?a.update:void 0;let J;e[26]!==a.icon||e[27]!==a.id?(J=eu(a.id,a.icon,mu().authenticatedAsset),e[26]=a.icon,e[27]=a.id,e[28]=J):J=e[28];const ie=J;let pe;e[29]!==Z||e[30]!==a.source||e[31]!==u?(pe=Z?null:u(dk(a.source)),e[29]=Z,e[30]=a.source,e[31]=u,e[32]=pe):pe=e[32];const X=a.version?`v${a.version}`:null;let xe;e[33]!==a.entry||e[34]!==u?(xe=a.entry?null:u("settings.extensions.source.noPanel"),e[33]=a.entry,e[34]=u,e[35]=xe):xe=e[35];let Y;e[36]!==pe||e[37]!==X||e[38]!==xe?(Y=[pe,X,xe].filter(Boolean),e[36]=pe,e[37]=X,e[38]=xe,e[39]=Y):Y=e[39];const be=Y.join(" · "),De=a.path||a.id;let ve;e[40]!==f||e[41]!==p||e[42]!==h||e[43]!==u?(ve=u(p?"settings.extensions.status.enterpriseBlocked":h?"settings.extensions.status.needsApproval":f?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[40]=f,e[41]=p,e[42]=h,e[43]=u,e[44]=ve):ve=e[44];const se=ve,ge=p||h?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":f?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";b=Gs,S=m,v=c,A="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let ne;e[45]!==a.icon?(ne=su(a.icon),e[45]=a.icon,e[46]=ne):ne=e[46];let Se;e[47]!==ie||e[48]!==ne?(Se=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(tu,{icon:ne,iconSrc:ie,className:"size-5 text-foreground"})}),e[47]=ie,e[48]=ne,e[49]=Se):Se=e[49];let ke;e[50]!==a.name?(ke=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[50]=a.name,e[51]=ke):ke=e[51];let Te;e[52]!==be?(Te=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:be}),e[52]=be,e[53]=Te):Te=e[53];let Ee;e[54]!==ke||e[55]!==Te?(Ee=s.jsxs("div",{className:"min-w-0 flex-1",children:[ke,Te]}),e[54]=ke,e[55]=Te,e[56]=Ee):Ee=e[56];let Le;e[57]!==Z||e[58]!==u?(Le=Z?s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:u("settings.extensions.source.bundled")}):null,e[57]=Z,e[58]=u,e[59]=Le):Le=e[59];let ce;e[60]!==u||e[61]!==O?(ce=O?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:u("settings.extensions.update.badge",{version:O.version})}):null,e[60]=u,e[61]=O,e[62]=ce):ce=e[62];let Me;e[63]!==ge?(Me=Ie("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ge),e[63]=ge,e[64]=Me):Me=e[64];let Fe;e[65]!==se||e[66]!==Me?(Fe=s.jsx("span",{"aria-live":"polite",className:Me,children:se}),e[65]=se,e[66]=Me,e[67]=Fe):Fe=e[67];const me=m&&"rotate-180";let de;e[68]!==me?(de=Ie("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",me),e[68]=me,e[69]=de):de=e[69];let Pe;e[70]!==de?(Pe=s.jsx(Q,{name:"arrow-down-s",className:de}),e[70]=de,e[71]=Pe):Pe=e[71],e[72]!==Se||e[73]!==Ee||e[74]!==Le||e[75]!==ce||e[76]!==Fe||e[77]!==Pe?(T=s.jsxs(Ws,{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:[Se,Ee,Le,ce,Fe,Pe]}),e[72]=Se,e[73]=Ee,e[74]=Le,e[75]=ce,e[76]=Fe,e[77]=Pe,e[78]=T):T=e[78],k=Js,C="border-t border-[var(--interactive-border)] px-4 py-4",N="space-y-3",e[79]!==De?(y=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:De,children:De}),e[79]=De,e[80]=y):y=e[80],e[81]!==p||e[82]!==u?(I=p?s.jsx("p",{className:"typography-meta text-foreground",children:u("settings.extensions.enterpriseBlocked")}):null,e[81]=p,e[82]=u,e[83]=I):I=e[83],e[84]!==Z||e[85]!==u?(w=Z?s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("settings.extensions.builtIn.info")}):null,e[84]=Z,e[85]=u,e[86]=w):w=e[86],D=W?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:u("settings.extensions.service.permissions",{list:W})}):null,e[3]=f,e[4]=p,e[5]=a,e[6]=h,e[7]=m,e[8]=u,e[9]=k,e[10]=b,e[11]=j,e[12]=x,e[13]=S,e[14]=v,e[15]=N,e[16]=y,e[17]=I,e[18]=w,e[19]=D,e[20]=C,e[21]=A,e[22]=T,e[23]=O}else k=e[9],b=e[10],j=e[11],x=e[12],S=e[13],v=e[14],N=e[15],y=e[16],I=e[17],w=e[18],D=e[19],C=e[20],A=e[21],T=e[22],O=e[23];let z;e[87]!==a.service||e[88]!==u?(z=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("settings.extensions.service.warning")}):null,e[87]=a.service,e[88]=u,e[89]=z):z=e[89];let M;e[90]!==n||e[91]!==f||e[92]!==a?(M=f?(a.service?.socketBindings??[]).map(W=>s.jsx(mk,{guest:a,binding:W,busy:n,onSaved:Zs},W.id)):null,e[90]=n,e[91]=f,e[92]=a,e[93]=M):M=e[93];let P;e[94]!==n||e[95]!==a||e[96]!==l||e[97]!==u||e[98]!==O?(P=O?s.jsx(q,{type:"button",size:"sm",disabled:n,"aria-label":u("settings.extensions.update.action.aria",{name:a.name,version:O.version}),onClick:()=>{l(a)},children:u("settings.extensions.update.action")}):null,e[94]=n,e[95]=a,e[96]=l,e[97]=u,e[98]=O,e[99]=P):P=e[99];let R;e[100]!==n||e[101]!==a||e[102]!==h||e[103]!==o||e[104]!==u?(R=h?s.jsx(q,{type:"button",size:"sm",disabled:n,"aria-label":u("settings.extensions.review.aria",{name:a.name}),onClick:()=>o(a),children:u("settings.extensions.review")}):null,e[100]=n,e[101]=a,e[102]=h,e[103]=o,e[104]=u,e[105]=R):R=e[105];let F;e[106]!==n||e[107]!==f||e[108]!==a.id||e[109]!==a.name||e[110]!==r||e[111]!==u?(F=f?s.jsx(q,{type:"button",size:"sm",variant:"outline",disabled:n,"aria-label":u("settings.extensions.actions.disable.aria",{name:a.name}),onClick:()=>{r(a.id,a.name,!1)},children:u("settings.extensions.actions.disable")}):s.jsx(q,{type:"button",size:"sm",disabled:n,"aria-label":u("settings.extensions.actions.enable.aria",{name:a.name}),onClick:()=>{r(a.id,a.name,!0)},children:u("settings.extensions.actions.enable")}),e[106]=n,e[107]=f,e[108]=a.id,e[109]=a.name,e[110]=r,e[111]=u,e[112]=F):F=e[112];let _;e[113]!==n||e[114]!==j||e[115]!==a.id||e[116]!==a.name||e[117]!==i||e[118]!==u?(_=j?s.jsx(q,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":u("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{i(a.id,a.name)},children:u("settings.extensions.remove")}):null,e[113]=n,e[114]=j,e[115]=a.id,e[116]=a.name,e[117]=i,e[118]=u,e[119]=_):_=e[119];let B;e[120]!==x||e[121]!==u?(B=x?s.jsxs(q,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{Ss(x)},children:[s.jsx(Q,{name:"external-link",className:"size-4"}),u("settings.extensions.actions.openSource")]}):null,e[120]=x,e[121]=u,e[122]=B):B=e[122];let V;e[123]!==P||e[124]!==R||e[125]!==F||e[126]!==_||e[127]!==B?(V=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[P,R,F,_,B]}),e[123]=P,e[124]=R,e[125]=F,e[126]=_,e[127]=B,e[128]=V):V=e[128];let ee;e[129]!==z||e[130]!==M||e[131]!==V||e[132]!==N||e[133]!==y||e[134]!==I||e[135]!==w||e[136]!==D?(ee=s.jsxs("div",{className:N,children:[y,I,w,D,z,M,V]}),e[129]=z,e[130]=M,e[131]=V,e[132]=N,e[133]=y,e[134]=I,e[135]=w,e[136]=D,e[137]=ee):ee=e[137];let L;e[138]!==k||e[139]!==ee||e[140]!==C?(L=s.jsx(k,{className:C,children:ee}),e[138]=k,e[139]=ee,e[140]=C,e[141]=L):L=e[141];let $;e[142]!==L||e[143]!==A||e[144]!==T?($=s.jsxs("div",{className:A,children:[T,L]}),e[142]=L,e[143]=A,e[144]=T,e[145]=$):$=e[145];let H;return e[146]!==b||e[147]!==S||e[148]!==v||e[149]!==$?(H=s.jsx(b,{open:S,onOpenChange:v,children:$}),e[146]=b,e[147]=S,e[148]=v,e[149]=$,e[150]=H):H=e[150],H},gk=t=>{const e=Ke.c(24),{guest:a,busy:n,onRemove:o}=t,{t:i}=ze();let r;e[0]!==a.id||e[1]!==a.name||e[2]!==i?(r=a.name??a.id??i("settings.extensions.unreadable.unnamed"),e[0]=a.id,e[1]=a.name,e[2]=i,e[3]=r):r=e[3];const l=r,u=a.builtIn?null:a.id;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Q,{name:"error-warning",className:"size-5 text-[var(--status-error)]"})}),e[4]=m):m=e[4];let c;e[5]!==l?(c=s.jsx("div",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-foreground",children:l}),e[5]=l,e[6]=c):c=e[6];let f;e[7]!==i?(f=i("settings.extensions.unreadable.hint"),e[7]=i,e[8]=f):f=e[8];let p;e[9]!==i?(p=i("settings.extensions.status.unreadable"),e[9]=i,e[10]=p):p=e[10];let g;e[11]!==f||e[12]!==p?(g=s.jsx("span",{title:f,className:"max-w-36 shrink-0 truncate rounded-full bg-[var(--status-error)]/15 px-2 py-0.5 text-[10px] font-medium text-[var(--status-error)]",children:p}),e[11]=f,e[12]=p,e[13]=g):g=e[13];let h;e[14]!==n||e[15]!==l||e[16]!==o||e[17]!==u||e[18]!==i?(h=u?s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:as,disabled:n,title:i("settings.extensions.remove"),"aria-label":i("settings.extensions.remove.aria",{name:l}),onClick:()=>{o(u,l)},children:s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"})}):null,e[14]=n,e[15]=l,e[16]=o,e[17]=u,e[18]=i,e[19]=h):h=e[19];let k;return e[20]!==c||e[21]!==g||e[22]!==h?(k=s.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[m,c,g,h]}),e[20]=c,e[21]=g,e[22]=h,e[23]=k):k=e[23],k},fk=()=>{const t=Ke.c(185),{t:e}=ze(),a=ys(hk),n=ys(bk),o=ys(xk),i=ys(vk),r=ys(yk),[l,u]=d.useState(null),[m,c]=d.useState(!1),[f,p]=d.useState("global"),g=o==="unsupported",[h,k]=d.useState(""),b=Un(),[j,x]=d.useState(!1),[S,v]=d.useState(!1),N=d.useRef(!1),[y,I]=d.useState(null),[w,D]=d.useState(null),[C,A]=d.useState(!1),T=d.useRef(0),O=d.useRef(null);let z;t[0]===Symbol.for("react.memo_cache_sentinel")?(z=Hg(),t[0]=z):z=t[0];const M=z;let P;t[1]===Symbol.for("react.memo_cache_sentinel")?(P=[],t[1]=P):P=t[1],d.useEffect(jk,P);let R,F;t[2]!==r||t[3]!==g?(R=()=>{let Xe=!1;if(u(null),c(!1),p("global"),I(null),D(null),N.current=!1,!g)return Promise.all([_p(),Bp()]).then(tt=>{const[qt,ss]=tt;Xe||u({runtimeKey:r,profiles:qt,global:ss})}).catch(()=>{Xe||c(!0)}),()=>{Xe=!0}},F=[r,g],t[2]=r,t[3]=g,t[4]=R,t[5]=F):(R=t[4],F=t[5]),d.useEffect(R,F);const _=l?.runtimeKey===r?l:null;let B;t[6]!==e?(B=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=B):B=t[7];const V=_?.global?.userName??"",ee=_?.global?.userEmail??"";let L;t[8]!==B||t[9]!==V||t[10]!==ee?(L={id:"global",name:B,userName:V,userEmail:ee,icon:"fingerprint",color:"info"},t[8]=B,t[9]=V,t[10]=ee,t[11]=L):L=t[11];let $;t[12]!==_?.profiles||t[13]!==L?($=[L,..._?.profiles.filter(kk)??[]],t[12]=_?.profiles,t[13]=L,t[14]=$):$=t[14];const H=$;let W;t[15]!==H||t[16]!==f?(W=H.find(Xe=>Xe.id===f)??H[0],t[15]=H,t[16]=f,t[17]=W):W=t[17];const Z=W;let te,J;t[18]!==o?(te=()=>{if(o!=="ready"||N.current)return;N.current=!0;const Xe=ys.getState().runtimeKey;kd(!1).then(tt=>{tt.ok&&ys.getState().applyUpdates(tt.updates,Xe)})},J=[o],t[18]=o,t[19]=te,t[20]=J):(te=t[19],J=t[20]),d.useEffect(te,J);let ie;t[21]!==e?(ie=async()=>{v(!0);const Xe=ys.getState().runtimeKey,tt=await kd(!0);if(v(!1),!tt.ok){G.error(e("settings.extensions.toast.checkFailed"));return}ys.getState().applyUpdates(tt.updates,Xe),Object.keys(tt.updates).length===0&&G.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=ie):ie=t[22];const pe=ie;let X;t[23]!==e?(X=async Xe=>{x(!0);const tt=await rm(Xe.id);if(x(!1),!tt.ok){G.error(tt.code==="host-too-old"&&tt.required?e("settings.extensions.toast.hostTooOld",{version:tt.required}):e(tm(tt.code)));return}Si(Xe.id),G.success(e("settings.extensions.toast.updated",{name:tt.guest.name,version:tt.guest.version??""})),await Zs(),Ha(tt.guest)&&D(tt.guest)},t[23]=e,t[24]=X):X=t[24];const xe=X;let Y;if(t[25]!==a||t[26]!==e||t[27]!==n){const Xe=async(tt,qt,ss)=>{const fs=ss===void 0?{}:ss;if(!tt.ok&&tt.code==="unreadable")return k(""),I(null),G.error(e(fl(tt.code))),await Zs(),!1;if(!tt.ok){if(fs.allowConflictDialog!==!1&&(tt.code==="id-taken"||tt.code==="already-installed")){const Jt=tt.id?a.find(Cs=>Cs.id===tt.id)??n.find(Cs=>Cs.id===tt.id):void 0;return I({source:qt,name:Jt?.name??tt.id??(qt.kind==="file"?qt.file.name:qt.input)}),!1}return tt.code==="host-too-old"?G.error(tt.required?e("settings.extensions.toast.hostTooOld",{version:tt.required}):e("settings.extensions.toast.failed"),{description:tt.diagnostic?Ur(tt.diagnostic,e):void 0}):G.error(e(fl(tt.code)),{description:tt.diagnostic?Ur(tt.diagnostic,e):void 0}),!1}return k(""),I(null),G.success(tt.replaced?e("settings.extensions.toast.reinstalled",{name:tt.guest.name}):e("settings.extensions.toast.added",{name:tt.guest.name})),await Zs(),Ha(tt.guest)&&D(tt.guest),!0};Y=async(tt,qt)=>{const ss=qt===void 0?{}:qt,fs=Yt();tt.kind==="input"&&k(tt.input),x(!0);const Jt=tt.kind==="file"?await zj(tt.file,ss):await am(tt.input,{...ss,gitIdentityId:tt.gitIdentityId});x(!1),Yt()===fs&&await Xe(Jt,tt,{allowConflictDialog:!ss.replace})},t[25]=a,t[26]=e,t[27]=n,t[28]=Y}else Y=t[28];const be=Y;let De;t[29]!==h||t[30]!==be||t[31]!==Z||t[32]!==e?(De=async()=>{const Xe=h.trim();if(!Xe){G.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"input",input:Xe,gitIdentityId:Z.id})},t[29]=h,t[30]=be,t[31]=Z,t[32]=e,t[33]=De):De=t[33];const ve=De;let se;t[34]!==be?(se=async()=>{if(!M)return;const Xe=await qg("");Xe.success&&Xe.path&&await be({kind:"input",input:Xe.path})},t[34]=be,t[35]=se):se=t[35];const ge=se;let ne;t[36]!==be?(ne=async()=>{if(!M){O.current?.click();return}const Xe=await El({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Xe.success&&Xe.path&&await be({kind:"input",input:Xe.path})},t[36]=be,t[37]=ne):ne=t[37];const Se=ne;let ke;t[38]!==be||t[39]!==e?(ke=async Xe=>{const tt=Xe.target.files?.[0]??null;if(Xe.target.value="",!!tt){if(!wd(tt)){G.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"file",file:tt})}},t[38]=be,t[39]=e,t[40]=ke):ke=t[40];const Te=ke;let Ee;t[41]!==j?(Ee=Xe=>{j||(Xe.preventDefault(),T.current=T.current+1,A(!0))},t[41]=j,t[42]=Ee):Ee=t[42];const Le=Ee;let ce;t[43]!==j?(ce=Xe=>{j||(Xe.preventDefault(),Xe.dataTransfer.dropEffect="copy")},t[43]=j,t[44]=ce):ce=t[44];const Me=ce;let Fe;t[45]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>{T.current=Math.max(0,T.current-1),T.current===0&&A(!1)},t[45]=Fe):Fe=t[45];const me=Fe;let de;t[46]!==j||t[47]!==be||t[48]!==e?(de=async Xe=>{if(Xe.preventDefault(),T.current=0,A(!1),j)return;const tt=Xe.dataTransfer.items[0],qt=tt?.getAsFile()??null,fs=(tt?.webkitGetAsEntry()??null)?.isDirectory===!0,Jt=qt!==null&&!fs&&wd(qt),Cs=qt&&M?Gg(qt):null;if(Cs&&(fs||Jt)){await be({kind:"input",input:Cs});return}if(fs){G.error(e(M?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!qt||!Jt){G.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"file",file:qt})},t[46]=j,t[47]=be,t[48]=e,t[49]=de):de=t[49];const Pe=de;let he;t[50]!==y||t[51]!==be?(he=async()=>{y&&await be(y.source,{replace:!0})},t[50]=y,t[51]=be,t[52]=he):he=t[52];const Ue=he;let Ae;t[53]!==e?(Ae=async(Xe,tt)=>{x(!0);const qt=await im(Xe);if(x(!1),!qt.ok){G.error(e("settings.extensions.toast.removeFailed"));return}Si(Xe),G.success(e("settings.extensions.toast.removed",{name:tt})),await Zs()},t[53]=e,t[54]=Ae):Ae=t[54];const Re=Ae;let $e;t[55]!==e?($e=async Xe=>{x(!0);const tt=await Uj(Xe.id,Xe.capabilities.requested);if(x(!1),!tt){G.error(e("settings.extensions.toast.approveFailed"));return}D(null),G.success(e("settings.extensions.toast.approved",{name:Xe.name})),await Zs()},t[55]=e,t[56]=$e):$e=t[56];const nt=$e;let pt;t[57]!==Re?(pt=async Xe=>{D(null),await Re(Xe.id,Xe.name)},t[57]=Re,t[58]=pt):pt=t[58];const kt=pt;let bt;t[59]!==e?(bt=async(Xe,tt,qt)=>{x(!0);const ss=await om(Xe,qt);if(x(!1),!ss){G.error(e("settings.extensions.toast.enabledFailed"));return}qt||Si(Xe),G.success(qt?e("settings.extensions.toast.enabled",{name:tt}):e("settings.extensions.toast.disabled",{name:tt})),await Zs()},t[59]=e,t[60]=bt):bt=t[60];const yt=bt;let Je;t[61]!==e?(Je=e("settings.page.extensions.title"),t[61]=e,t[62]=Je):Je=t[62];let ct;t[63]!==e?(ct=e("settings.page.extensions.description"),t[63]=e,t[64]=ct):ct=t[64];let Qe;t[65]!==ve||t[66]!==ge||t[67]!==Se||t[68]!==j||t[69]!==C||t[70]!==b||t[71]!==H||t[72]!==l||t[73]!==m||t[74]!==h||t[75]!==Le||t[76]!==Me||t[77]!==Pe||t[78]!==Te||t[79]!==Z||t[80]!==e||t[81]!==g?(Qe=g?null:s.jsxs(Ve,{title:e("settings.extensions.add.action"),info:b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block",children:e("settings.extensions.add.enterpriseRule")}),s.jsx("span",{className:"mt-2 block",children:e("settings.extensions.add.info")})]}):e("settings.extensions.add.info"),children:[s.jsx(Et,{label:e("settings.extensions.add.label"),info:e(M?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:Ie("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",C&&"border-primary bg-primary/5"),onDragEnter:Le,onDragOver:Me,onDragLeave:me,onDrop:Xe=>{Pe(Xe)},children:[C?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:h,onChange:Xe=>k(Xe.target.value),onKeyDown:Xe=>{Xe.key==="Enter"&&(Xe.preventDefault(),ve())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:Ie("h-8 min-w-0 flex-1 rounded-md pl-3",M?"pr-14":"pr-8"),disabled:j}),s.jsx("input",{ref:O,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Xe=>{Te(Xe)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[M?s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:j,onClick:()=>{ge()},children:s.jsx(Q,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseZip"),"aria-label":e("settings.extensions.add.browseZip.aria"),disabled:j,onClick:()=>{Se()},children:s.jsx(Q,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(Cf,{activeProfile:Z,identities:H,onSelect:Xe=>p(Xe.id),isApplying:j||!l&&!m,iconOnly:!0})}),s.jsxs(q,{type:"button",size:"sm",disabled:j,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{ve()},children:[s.jsx(Q,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),m?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[65]=ve,t[66]=ge,t[67]=Se,t[68]=j,t[69]=C,t[70]=b,t[71]=H,t[72]=l,t[73]=m,t[74]=h,t[75]=Le,t[76]=Me,t[77]=Pe,t[78]=Te,t[79]=Z,t[80]=e,t[81]=g,t[82]=Qe):Qe=t[82];let it;t[83]!==e?(it=e("settings.extensions.section.installed"),t[83]=e,t[84]=it):it=t[84];let dt;t[85]!==j||t[86]!==pe||t[87]!==S||t[88]!==o||t[89]!==e||t[90]!==g?(dt=g?null:s.jsxs(q,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:j||S||o!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{pe()},children:[s.jsx(Q,{name:"refresh",className:Ie("h-4 w-4",S&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[85]=j,t[86]=pe,t[87]=S,t[88]=o,t[89]=e,t[90]=g,t[91]=dt):dt=t[91];let qe;t[92]!==i||t[93]!==o||t[94]!==e?(qe=o==="error"||i?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),i?`
30
+ ${Ur(i,e)}`:""]}):null,t[92]=i,t[93]=o,t[94]=e,t[95]=qe):qe=t[95];let lt;t[96]!==e||t[97]!==g?(lt=g?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[96]=e,t[97]=g,t[98]=lt):lt=t[98];let ae;t[99]!==a.length||t[100]!==o||t[101]!==e||t[102]!==n.length?(ae=o==="ready"&&a.length===0&&n.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[99]=a.length,t[100]=o,t[101]=e,t[102]=n.length,t[103]=ae):ae=t[103];let fe;if(t[104]!==j||t[105]!==a||t[106]!==Re||t[107]!==yt||t[108]!==xe){let Xe;t[110]!==j||t[111]!==Re||t[112]!==yt||t[113]!==xe?(Xe=tt=>s.jsx(pk,{guest:tt,busy:j,onReview:D,onRemove:Re,onSetEnabled:yt,onUpdate:xe},tt.id),t[110]=j,t[111]=Re,t[112]=yt,t[113]=xe,t[114]=Xe):Xe=t[114],fe=a.map(Xe),t[104]=j,t[105]=a,t[106]=Re,t[107]=yt,t[108]=xe,t[109]=fe}else fe=t[109];let ye;if(t[115]!==j||t[116]!==Re||t[117]!==n){let Xe;t[119]!==j||t[120]!==Re?(Xe=(tt,qt)=>s.jsx(gk,{guest:tt,busy:j,onRemove:Re},tt.id??`unreadable-${qt}`),t[119]=j,t[120]=Re,t[121]=Xe):Xe=t[121],ye=n.map(Xe),t[115]=j,t[116]=Re,t[117]=n,t[118]=ye}else ye=t[118];let we;t[122]!==it||t[123]!==dt||t[124]!==qe||t[125]!==lt||t[126]!==ae||t[127]!==fe||t[128]!==ye?(we=s.jsxs(Ve,{title:it,contentClassName:"space-y-3",headerAction:dt,children:[qe,lt,ae,fe,ye]}),t[122]=it,t[123]=dt,t[124]=qe,t[125]=lt,t[126]=ae,t[127]=fe,t[128]=ye,t[129]=we):we=t[129];let Ge;t[130]!==nt?(Ge=Xe=>{nt(Xe)},t[130]=nt,t[131]=Ge):Ge=t[131];let et;t[132]!==kt?(et=Xe=>{kt(Xe)},t[132]=kt,t[133]=et):et=t[133];let mt;t[134]===Symbol.for("react.memo_cache_sentinel")?(mt=()=>D(null),t[134]=mt):mt=t[134];let jt;t[135]!==w||t[136]!==j||t[137]!==Ge||t[138]!==et?(jt=s.jsx(ok,{guest:w,busy:j,onApprove:Ge,onDecline:et,onDismiss:mt}),t[135]=w,t[136]=j,t[137]=Ge,t[138]=et,t[139]=jt):jt=t[139];const vt=y!==null;let Ct;t[140]!==j?(Ct=Xe=>{!Xe&&!j&&I(null)},t[140]=j,t[141]=Ct):Ct=t[141];let Bt;t[142]!==e?(Bt=e("settings.extensions.dialog.reinstallTitle"),t[142]=e,t[143]=Bt):Bt=t[143];let Ye;t[144]!==Bt?(Ye=s.jsx(Ut,{children:Bt}),t[144]=Bt,t[145]=Ye):Ye=t[145];const Ze=y?.name??"";let ut;t[146]!==e||t[147]!==Ze?(ut=e("settings.extensions.dialog.reinstallDescription",{name:Ze}),t[146]=e,t[147]=Ze,t[148]=ut):ut=t[148];let ft;t[149]!==ut?(ft=s.jsx($t,{children:ut}),t[149]=ut,t[150]=ft):ft=t[150];let K;t[151]!==Ye||t[152]!==ft?(K=s.jsxs(zt,{children:[Ye,ft]}),t[151]=Ye,t[152]=ft,t[153]=K):K=t[153];let ue;t[154]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>I(null),t[154]=ue):ue=t[154];let Ne;t[155]!==e?(Ne=e("settings.common.actions.cancel"),t[155]=e,t[156]=Ne):Ne=t[156];let Ce;t[157]!==j||t[158]!==Ne?(Ce=s.jsx(q,{size:"sm",variant:"ghost",disabled:j,onClick:ue,children:Ne}),t[157]=j,t[158]=Ne,t[159]=Ce):Ce=t[159];let He;t[160]!==Ue?(He=()=>{Ue()},t[160]=Ue,t[161]=He):He=t[161];let le;t[162]!==e?(le=e("settings.extensions.dialog.reinstall"),t[162]=e,t[163]=le):le=t[163];let Oe;t[164]!==j||t[165]!==He||t[166]!==le?(Oe=s.jsx(q,{size:"sm",disabled:j,onClick:He,children:le}),t[164]=j,t[165]=He,t[166]=le,t[167]=Oe):Oe=t[167];let ot;t[168]!==Ce||t[169]!==Oe?(ot=s.jsxs(Xt,{children:[Ce,Oe]}),t[168]=Ce,t[169]=Oe,t[170]=ot):ot=t[170];let Rt;t[171]!==K||t[172]!==ot?(Rt=s.jsxs(Lt,{className:"max-w-md",children:[K,ot]}),t[171]=K,t[172]=ot,t[173]=Rt):Rt=t[173];let It;t[174]!==vt||t[175]!==Ct||t[176]!==Rt?(It=s.jsx(Ft,{open:vt,onOpenChange:Ct,children:Rt}),t[174]=vt,t[175]=Ct,t[176]=Rt,t[177]=It):It=t[177];let os;return t[178]!==Je||t[179]!==ct||t[180]!==Qe||t[181]!==we||t[182]!==jt||t[183]!==It?(os=s.jsxs(Qt,{title:Je,description:ct,children:[Qe,we,jt,It]}),t[178]=Je,t[179]=ct,t[180]=Qe,t[181]=we,t[182]=jt,t[183]=It,t[184]=os):os=t[184],os};function hk(t){return t.guests}function bk(t){return t.unreadable}function xk(t){return t.status}function vk(t){return t.failure}function yk(t){return t.runtimeKey}function jk(){Zs()}function kk(t){return t.id!=="global"}function wk(t,e,a=!1){if(a)return;const{surface:n,primary:o,status:i,interactive:r,markdown:l,chat:u,tools:m,syntax:c}=t.colors,f=t.metadata.variant==="dark",p=n.background,g=Fs(p,p),h=(A,T)=>mo(A,T,p)??1,k=(A,T,O)=>{if(O(A))return A;let z=0,M=1,P=T;for(let R=0;R<16;R++){const F=(z+M)/2,_=js(T,A,F,p);O(_)?(M=F,P=_):z=F}return P},b=A=>h(A,"#000000"),j=Math.min(4.6,h(g,p)),x=(A,T)=>{const O=T?"#ffffff":"#000000",M=(T?b(A)>b(p):b(A)<b(p))?js(A,p,1,p):p,P=k(M,p,F=>h(F,p)<=1.1),R=h(O,p)<1.04?O:k(P,O,F=>h(F,p)>=1.04);return k(R,p,F=>h(g,F)>=j)};n.muted=x(n.muted,!1),n.elevated=x(n.elevated,f),n.subtle=js(g,p,.025,p);const S=[p,n.muted,n.elevated],v=A=>Math.min(...S.map(T=>h(A,T))),N=A=>k(A,g,T=>v(T)>=4.6),y=(A,T,O=4.6)=>k(k(A,p,z=>h(z,p)<=T),g,z=>v(z)>=O);n.foreground=y(n.foreground,f?10:9,7),n.mutedForeground=y(n.mutedForeground,Math.min(6,h(n.foreground,p)*.7)),n.elevatedForeground=y(n.elevatedForeground,f?10:9,7);const I=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder];o.base=N(I.find(A=>A!==void 0&&v(A)>=3)??o.base),o.foreground=Fs(o.base,p),o.hover=js(g,o.base,.08,p),o.active=js(g,o.base,.16,p),o.muted=oa(o.base,.5),v(r.focusRing)<1.1&&(r.focus=o.base,r.focusRing=o.base,r.borderFocus=o.base),r.selection=k(r.selection,js(o.base,p,.18,p),A=>v(A)>=1.1);const w=f?{border:[1.217,1.245,1.117],hover:[2.304,2.356,2.115],tools:[1.199,1.207,1.156],divider:[1.41,1.442,1.294]}:{border:[1.268,1.203,1.162],hover:[1.64,1.557,1.503],tools:[1.231,1.195,1.171],divider:[1.427,1.355,1.308]},D=(A,[T,O,z])=>{const M=Math.max(T,O,z),P=V=>V+(M-V)*.2,R=V=>h(V,p)<=P(T)&&h(V,n.muted)<=P(O)&&h(V,n.elevated)<=P(z);if(R(A))return A;let F=0,_=1,B=oa(A,0);for(let V=0;V<16;V++){const ee=(F+_)/2,L=oa(A,ee);R(L)?(F=ee,B=L):_=ee}return B};r.border=D(r.border,w.border),r.borderHover=D(r.borderHover,w.hover),r.hover=D(r.hover,[1.18,1.18,1.18]),r.active=D(r.active,[1.25,1.25,1.25]),r.selection=D(r.selection,[1.6,1.7,1.45]),r.selectionForeground=Tn(n.foreground,r.selection,p);const C=(A,T,O,z)=>{const M=Hp(A,p);return N(M!==null&&M>=O&&M<=z?A:T)};i.error=C(i.error,f?"#e07777":"#b43b45",10,40),i.warning=C(i.warning,f?"#d6b467":"#916b17",65,100),i.success=C(i.success,f?"#80b888":"#357b47",125,165),i.info=C(i.info,f?"#83afe0":"#366eaa",230,275);for(const A of["error","warning","success","info"])i[`${A}Foreground`]=Fs(i[A],p),i[`${A}Background`]=oa(i[A],f?.16:.12),i[`${A}Border`]=oa(i[A],f?.45:.35);if(t.colors.pr={open:i.success,closed:i.error,draft:n.mutedForeground,blocked:C(e["terminal.ansiYellow"]??"",f?"#d99464":"#a65b25",40,65),merged:C(e["terminal.ansiMagenta"]??"",f?"#b79bd9":"#8255b0",285,325)},u){let A=k(p,g,T=>h(T,p)>=1.12);h(g,A)<j&&(A=k(p,g==="#ffffff"?"#000000":"#ffffff",T=>h(T,p)>=1.12)),u.userMessageBackground=k(js(o.base,A,.03,p),A,T=>h(T,p)>=1.1&&h(g,T)>=j),S.push(u.userMessageBackground),n.foreground=k(n.foreground,g,T=>v(T)>=7),n.mutedForeground=N(n.mutedForeground),u.userMessage=Tn(n.foreground,u.userMessageBackground,p),u.assistantMessage=n.foreground,u.timestamp=n.mutedForeground,u.typing=n.mutedForeground,u.avatarForeground=e["chat.avatarForeground"]??n.foreground,u.slashCommandBackground=e["chat.slashCommandBackground"]??o.base,u.slashCommandForeground=e["chat.slashCommandForeground"]??Fs(u.slashCommandBackground,p),u.inputWorkingBorderColor1=e["chat.inputWorkingBorderColor1"]??o.base,u.inputWorkingBorderColor2=e["chat.inputWorkingBorderColor2"]??o.hover,u.inputWorkingBorderColor3=e["chat.inputWorkingBorderColor3"]??o.muted,u.divider=D(u.divider??r.border,w.divider)}t.colors.pr&&(t.colors.pr.draft=n.mutedForeground),m&&(m.border=D(m.border??r.border,w.tools),m.title=n.foreground,m.description=n.mutedForeground,m.icon=n.mutedForeground),l&&(l.bold=js(g,n.foreground,.12,p),l.italic=n.foreground,l.blockquote=n.mutedForeground,l.blockquoteBorder=D(l.blockquoteBorder??r.border,w.divider),l.hr=D(l.hr??r.border,w.divider),l.link=N(e["textLink.foreground"]??o.base),l.linkHover=N(e["textLink.activeForeground"]??o.hover),l.listMarker=oa(o.base,.6),l.inlineCodeBackground=n.subtle,l.inlineCode=Tn(N(e["textPreformat.foreground"]??o.base),n.subtle,p)),c.base.background=k(c.base.background,p,A=>h(A,p)<=1.1),c.base.foreground=Tn(n.foreground,c.base.background,p)}const Os=oa,Sk=t=>{const e={...t,colors:{...t.colors}},a=e.kind==="dark"||e.kind==="high-contrast",n=qp(a),o=e.colors,i=o["chat.list.background"]??o["editor.background"]??n.colors.surface.background,r=o["interactive-session.foreground"]??o.foreground??o["editor.foreground"]??Fs(i,i);o.foreground??=r,o["sideBar.background"]??=o["panel.background"]??js(r,i,.03,i),!o["editorWidget.background"]&&!o["dropdown.background"]&&!o["input.background"]&&(o["editorWidget.background"]=js(r,i,.04,i),o["editorWidget.foreground"]=Tn(r,o["editorWidget.background"],i)),o.descriptionForeground??=Tn(js(r,i,.6,i),i),o["widget.border"]??=o["input.border"]??o["panel.border"]??js(r,i,.15,i),o["toolbar.hoverBackground"]??=o["list.hoverBackground"]??js(r,i,.08,i),o["toolbar.activeBackground"]??=js(r,i,.12,i),!o["list.activeSelectionBackground"]&&!o["menu.selectionBackground"]&&!o["editor.selectionBackground"]&&(o["list.activeSelectionBackground"]=js(r,i,.16,i),o["list.activeSelectionForeground"]=Tn(r,o["list.activeSelectionBackground"],i)),o["button.background"]||(o["button.background"]=o["textLink.foreground"]??o.focusBorder??r,o["button.foreground"]=Fs(o["button.background"],i)),o.focusBorder??=o["button.background"],o["editorCursor.foreground"]??=o["editor.foreground"]??r;const l=(Ee,Le)=>e.colors[Ee]??Le,u=Ee=>Ee!=="transparent"&&(mo(Ee,"#000000")!==1||mo(Ee,"#ffffff")!==1),m=(Ee,Le)=>{const ce=l(Ee,Le);return u(ce)?ce:Le},c=l("chat.list.background",l("editor.background",n.colors.surface.background)),f=l("interactive-session.foreground",l("foreground",l("editor.foreground",n.colors.surface.foreground))),g=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([Ee])=>e.colors[Ee]),h=g?l(g[0],n.colors.surface.elevated):n.colors.surface.elevated,k=Tn(f,h,c),b=g?l(g[1],k):k,j=l("sideBar.background",l("panel.background",n.colors.surface.muted)),x=l("descriptionForeground",l("input.placeholderForeground",n.colors.surface.mutedForeground)),S=l("textBlockQuote.background",j),v=n.colors.surface.overlay,N=l("button.background",l("textLink.foreground",n.colors.primary.base)),y=l("button.hoverBackground",N),I=e.colors["button.background"]?l("button.foreground",Fs(N,c)):Fs(N,c),w=Os(N,.5),C=[e.kind==="high-contrast"||e.highContrast?l("contrastBorder",""):"",l("widget.border",""),l("input.border",""),l("panel.border",""),l("sideBar.border",""),l("editorWidget.border",""),l("contrastBorder","")].find(Ee=>Ee&&u(Ee))||Os(f,a?.25:.2),A=l("toolbar.hoverBackground",l("list.hoverBackground",n.colors.interactive.hover)),T=l("toolbar.activeBackground",A),z=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([Ee])=>e.colors[Ee]),M=z.find(([Ee])=>[c,j,h].every(Le=>{const ce=mo(l(Ee,""),Le,c);return ce===null||ce>1.01}))??z[0],P=M?l(M[0],n.colors.interactive.selection):n.colors.interactive.selection,R=M?l(M[1],f):f,F=l("focusBorder",l("inputOption.activeBorder",N)),_=F,B=l("editorCursor.foreground",n.colors.interactive.cursor),V=l("editorError.foreground",l("testing.iconFailed",n.colors.status.error)),ee=m("editorError.background",Os(V,a?.16:.12)),L=l("problemsWarningIcon.foreground",l("notificationsWarningIcon.foreground",l("editorWarning.foreground",n.colors.status.warning))),$=m("editorWarning.background",Os(L,a?.16:.12)),H=l("testing.iconPassed",l("gitDecoration.addedResourceForeground",n.colors.status.success)),W=Os(H,a?.16:.12),Z=l("problemsInfoIcon.foreground",l("editorInfo.foreground",n.colors.status.info)),te=m("editorInfo.background",Os(Z,a?.16:.12)),J=l("editorLineNumber.foreground",x),ie=l("textPreformat.foreground",l("terminal.ansiGreen",n.colors.syntax.base.string)),pe=l("terminal.ansiBlue",N),X=l("terminal.ansiYellow",n.colors.syntax.base.number),xe=l("terminal.ansiCyan",n.colors.syntax.base.function),Y=l("terminal.ansiMagenta",f),be=l("terminal.ansiYellow",n.colors.syntax.base.type),De=l("chat.requestBorder",C),ve=l("diffEditor.insertedLineBackground",l("diffEditor.insertedTextBackground",W)),se=l("diffEditor.removedLineBackground",l("diffEditor.removedTextBackground",ee)),ge=l("chat.linesAddedForeground",l("gitDecoration.addedResourceForeground",H)),ne=l("chat.linesRemovedForeground",l("gitDecoration.deletedResourceForeground",V)),Se=l("gitDecoration.modifiedResourceForeground",Z),ke=l("chat.requestBubbleBackground",l("chat.requestBackground",h)),Te={...n,metadata:{...n.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:a?"dark":"light",tags:["vscode","auto"]},colors:{...n.colors,primary:{base:N,hover:y,active:y,foreground:I,muted:w},surface:{background:c,foreground:f,muted:j,mutedForeground:x,elevated:h,elevatedForeground:b,overlay:v,subtle:S},interactive:{border:C,borderHover:l("toolbar.hoverOutline",C),borderFocus:F,selection:P,selectionForeground:R,focus:F,focusRing:_,cursor:B,hover:A,active:T},status:{error:V,errorForeground:Fs(V,c),errorBackground:ee,errorBorder:Os(V,a?.45:.35),warning:L,warningForeground:Fs(L,c),warningBackground:$,warningBorder:Os(L,a?.45:.35),success:H,successForeground:Fs(H,c),successBackground:W,successBorder:Os(H,a?.45:.35),info:Z,infoForeground:Fs(Z,c),infoBackground:te,infoBorder:Os(Z,a?.45:.35)},pr:n.colors.pr?{...n.colors.pr,open:H,closed:V,draft:x}:void 0,syntax:{tokens:{},highlights:{diffAdded:ge,diffAddedBackground:ve,diffRemoved:ne,diffRemovedBackground:se,diffModified:Se,diffModifiedBackground:Os(Se,a?.16:.12),lineNumber:l("editorLineNumber.foreground",x),lineNumberActive:l("editorLineNumber.activeForeground",f)},base:{background:l("editor.background",c),foreground:l("editor.foreground",f),comment:J,keyword:pe,string:ie,number:X,function:xe,variable:Y,type:be,operator:N}},tools:{border:De,icon:l("icon.foreground",x),title:f,description:Os(x,.8),edit:{added:ge,addedBackground:ve,removed:ne,removedBackground:se,modified:Se,modifiedBackground:Os(Se,a?.16:.12),lineNumber:J}},chat:{background:c,userMessage:f,userMessageBackground:ke,assistantMessage:f,assistantMessageBackground:c,timestamp:x,divider:C,typing:l("chat.thinkingShimmer",x),avatarBackground:l("chat.avatarBackground",c),avatarForeground:l("chat.avatarForeground",f),slashCommandBackground:l("chat.slashCommandBackground",N),slashCommandForeground:l("chat.slashCommandForeground",I),inputWorkingBorderColor1:l("chat.inputWorkingBorderColor1",N),inputWorkingBorderColor2:l("chat.inputWorkingBorderColor2",y),inputWorkingBorderColor3:l("chat.inputWorkingBorderColor3",w)},markdown:{link:l("textLink.foreground",N),linkHover:l("textLink.activeForeground",y),inlineCode:l("textPreformat.foreground",ie),inlineCodeBackground:l("textPreformat.background",l("editor.background",c)),blockquote:f,blockquoteBackground:l("textBlockQuote.background","transparent"),blockquoteBorder:l("textBlockQuote.border",C),listMarker:Os(N,.6)}}};return wk(Te,t.colors,e.kind==="high-contrast"||e.highContrast===!0),Te},Do=wt().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),_l=ts({foreground:Do.optional()}),um=ts({scope:tl([wt(),qs(wt())]).optional(),settings:_l}),Nk=ts({name:wt().trim().min(1).max(160).optional(),author:wt().max(160).optional(),description:wt().max(1024).optional(),type:Dl(["light","dark","hc","hc-black","hc-light"]).optional(),include:wt().optional(),colors:Rn(wt(),Do.nullable()).default({}),tokenColors:tl([qs(um),wt()]).optional(),semanticHighlighting:Di().optional(),semanticTokenColors:Rn(wt(),tl([Do,_l])).optional()});function Ck(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(o=>({scope:o.trim(),color:e.settings.foreground}))))}function Ik(t,e){for(const a of e){let n,o=-1;for(const i of t)!i.color||!i.scope||(a===i.scope||a.startsWith(`${i.scope}.`))&&i.scope.length>=o&&(n=i.color,o=i.scope.length);if(n)return n}}function Pk(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const o=Do.safeParse(n);if(o.success)return o.data;const i=_l.safeParse(n);if(i.success&&i.data.foreground)return i.data.foreground}}function Ak(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function mm(t,e){if(new TextEncoder().encode(t).byteLength>iu)throw new ua("size");let a;try{a=Nk.parse(JSON.parse(zf(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ua("invalid")}const n=qs(um).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ua("include");const o={};for(const[I,w]of Object.entries(a.colors))w!==null&&(o[I]=w);const i=o["editor.background"];if(!i)throw new ua("background");const r=a.type?["dark","hc","hc-black"].includes(a.type):Fs(i,"#ffffff")==="#ffffff",l=r?"dark":"light",u=js(i,r?"#000000":"#ffffff",1),m=Ck(n.data),c=n.data.filter(I=>!I.scope&&I.settings.foreground).at(-1)?.settings.foreground,f=o["editor.foreground"]??c??o.foreground??Fs(u,u);o["editor.background"]=u,o["editor.foreground"]=f;const p=a.type?.startsWith("hc")??!1;p&&o.contrastBorder&&(o["widget.border"]=o.contrastBorder);const h=Sk({kind:r&&p?"high-contrast":l,colors:o,highContrast:p}),k=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},b=(I,w,D)=>Pk(k,I)??Ik(m,w)??D,j=h.colors.syntax.base.foreground,x={background:h.colors.syntax.base.background,foreground:h.colors.syntax.base.foreground,comment:b(["comment"],["comment","comment.line","comment.block"],Tn(js(f,u,.6,u),u)),keyword:b(["keyword"],["keyword","storage","keyword.control","storage.type"],j),string:b(["string"],["string","string.quoted","string.template"],j),number:b(["number"],["constant.numeric"],j),function:b(["function"],["entity.name.function","support.function"],j),variable:b(["variable"],["variable.other.readwrite","variable"],j),type:b(["type"],["entity.name.type","support.type","support.class"],j),operator:b(["operator"],["keyword.operator"],j)},S=b(["class"],["entity.name.type.class","entity.name.class"],x.type),v=b(["property"],["variable.other.property","support.type.property-name"],x.variable),N={base:x,tokens:{className:S,interface:b(["interface"],["entity.name.type.interface"],x.type),enum:b(["enum"],["entity.name.type.enum"],S),method:b(["method"],["entity.name.function.method"],x.function),variableProperty:v,parameter:b(["parameter"],["variable.parameter"],x.variable),constant:b(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],x.number),boolean:b([],["constant.language.boolean","constant.language"],x.number),punctuation:b([],["punctuation","punctuation.separator"],x.operator),stringEscape:b([],["constant.character.escape"],x.string),commentDoc:b([],["comment.block.documentation","comment.documentation"],x.comment),keywordImport:b([],["keyword.control.import","keyword.import"],x.keyword),tag:b([],["entity.name.tag"],x.keyword),tagAttribute:b([],["entity.other.attribute-name"],v)},highlights:h.colors.syntax.highlights},y=Ak(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return Gp({metadata:{id:`vscode-import-${l}`,name:y,variant:l,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...h.colors,syntax:N}})}const Tk=ts({namespace:wt(),name:wt(),version:wt(),label:wt(),icon:wt().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Ek(t,e){const a=await Dt("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!a.ok)throw new Error("catalog");return ts({items:qs(Tk).max(24)}).parse(await a.json()).items}async function Dk(t,e){const a=await Dt("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!a.ok)throw new Error("catalog");const{items:n}=ts({items:qs(ts({path:wt(),name:wt(),text:wt(),error:Di()})).max(40)}).parse(await a.json());return n.map((o,i)=>{const r=`${i}:${o.path}`;try{if(o.error)throw new Error("invalid");const l=mm(o.text,o.path);return l.metadata.name=o.name,l.metadata.author=t.namespace,{status:"ready",key:r,name:o.name,definition:l,theme:Wp(l)}}catch{return{status:"invalid",key:r,name:o.name}}})}function Mk(t){const e=Ke.c(3),{extension:a}=t,[n,o]=d.useState(!1);let i;return e[0]!==a.icon||e[1]!==n?(i=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>o(!0)}):s.jsx(Q,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=i):i=e[2],i}function Rk(t){const e=Ke.c(93),{pickFile:a,fileBusy:n,onClose:o}=t,{t:i}=ze(),r=re(Lk),{isMobile:l}=qn(),u=r||l,{importTheme:m}=xa(),[c,f]=d.useState("");let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={step:"search",status:"idle",results:[]},e[0]=p):p=e[0];const[g,h]=d.useState(p);let k;e[1]===Symbol.for("react.memo_cache_sentinel")?(k=new Set,e[1]=k):k=e[1];const[b,j]=d.useState(k);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[2]=x):x=e[2];const[S,v]=d.useState(x),[N,y]=d.useState(!1),[I,w]=d.useState(null),D=d.useRef(null);let C,A;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const W=new AbortController;D.current=W;const Z=Oo(()=>W.abort());return()=>{Z(),W.abort()}},A=[],e[3]=C,e[4]=A):(C=e[3],A=e[4]),d.useEffect(C,A);let T,O;e[5]!==c||e[6]!==g.step?(T=()=>{if(g.step!=="search")return;const W=new AbortController,Z=c.trim(),te=setTimeout(async()=>{if(!Z){h({step:"search",status:"idle",results:[]});return}h({step:"search",status:"loading",results:[]});try{const J=await Ek(Z,W.signal);W.signal.aborted||h({step:"search",status:"ready",results:J})}catch{W.signal.aborted||h({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(te),W.abort()}},O=[c,g.step],e[5]=c,e[6]=g.step,e[7]=T,e[8]=O):(T=e[7],O=e[8]),d.useEffect(T,O);let z,M;if(e[9]!==n||e[10]!==m||e[11]!==u||e[12]!==a||e[13]!==c||e[14]!==I||e[15]!==S||e[16]!==N||e[17]!==b||e[18]!==g.extension||e[19]!==g.results||e[20]!==g.status||e[21]!==g.step||e[22]!==g.variants||e[23]!==i){const W=async ve=>{const se=D.current?.signal;if(se){h({step:"package",status:"loading",extension:ve}),v(new Set),w(null),j(new Set);try{const ge=await Dk(ve,se);se.aborted||h({step:"variants",extension:ve,variants:ge})}catch{se.aborted||h({step:"package",status:"error",extension:ve})}}};let Z;e[26]!==m||e[27]!==S||e[28]!==N||e[29]!==b||e[30]!==g.step||e[31]!==g.variants||e[32]!==i?(Z=async()=>{if(g.step!=="variants"||N)return;const ve=D.current?.signal;if(!ve)return;y(!0),w(null);let se=!1;for(const ge of g.variants){if(ve.aborted)break;if(!(ge.status!=="ready"||!b.has(ge.key)||S.has(ge.key)))try{if(await m(ge.definition,{activate:!1}),ve.aborted)break;v(ne=>new Set(ne).add(ge.key)),j(ne=>{const Se=new Set(ne);return Se.delete(ge.key),Se})}catch{se=!0}}ve.aborted||(y(!1),w(se?"partial":null),se?$a.error(i("settings.themeImport.partialError")):$a.success(i("settings.themeImport.complete")))},e[26]=m,e[27]=S,e[28]=N,e[29]=b,e[30]=g.step,e[31]=g.variants,e[32]=i,e[33]=Z):Z=e[33];const te=Z;let J,ie;e[34]!==S||e[35]!==b||e[36]!==g.step||e[37]!==g.variants?(J=g.step==="variants"?g.variants.filter(ve=>ve.status==="ready"&&!S.has(ve.key)):[],ie=J.length>0&&J.every(ve=>b.has(ve.key)),e[34]=S,e[35]=b,e[36]=g.step,e[37]=g.variants,e[38]=J,e[39]=ie):(J=e[38],ie=e[39]);const pe=ie;let X;e[40]!==n||e[41]!==te||e[42]!==N||e[43]!==b||e[44]!==g.step||e[45]!==i?(X=g.step==="variants"&&s.jsx(q,{disabled:!b.size||N||n,onClick:()=>{te()},children:i(N?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=te,e[42]=N,e[43]=b,e[44]=g.step,e[45]=i,e[46]=X):X=e[46];const xe=N||n;let Y;e[47]!==i?(Y=i("settings.themeImport.chooseFile"),e[47]=i,e[48]=Y):Y=e[48];let be;e[49]!==a||e[50]!==xe||e[51]!==Y?(be=s.jsx(q,{variant:"outline",className:"self-start",disabled:xe,onClick:a,children:Y}),e[49]=a,e[50]=xe,e[51]=Y,e[52]=be):be=e[52];let De;e[53]!==X||e[54]!==be?(De=s.jsxs(s.Fragment,{children:[X,be]}),e[53]=X,e[54]=be,e[55]=De):De=e[55],z=De,M=s.jsx(s.Fragment,{children:g.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(Be,{autoFocus:!0,"aria-label":i("settings.themeImport.search"),placeholder:i("settings.themeImport.search"),value:c,maxLength:160,onChange:ve=>f(ve.target.value)}),s.jsxs("div",{className:u?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[g.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:i("common.loading")}),g.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}),g.status==="ready"&&!g.results.length&&s.jsx("p",{className:"text-muted-foreground",children:i("settings.themeImport.empty")}),g.results.map(ve=>s.jsxs(q,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{W(ve)},children:[s.jsx(Mk,{extension:ve}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ve.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ve.namespace})]})]},`${ve.namespace}.${ve.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(q,{variant:"ghost",size:"sm",className:"justify-start",disabled:N||g.step==="package"&&g.status==="loading",onClick:()=>h({step:"search",status:"idle",results:[]}),children:[s.jsx(Q,{name:"arrow-left",className:"size-4"}),i("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:g.extension.label}),I==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.partialError")}),g.step==="package"?g.status==="loading"?s.jsx("p",{role:"status",children:i("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:i("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[g.variants.length>1&&s.jsx(q,{variant:"ghost",size:"sm",className:"self-start",disabled:N||n||!J.length,onClick:()=>j(pe?new Set:new Set(J.map(Fk))),children:i(pe?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:u?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:g.variants.map(ve=>s.jsxs("div",{className:"flex items-center gap-3",children:[ve.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:ve.theme.colors.surface.background,color:ve.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ve.theme.colors.syntax.base.keyword,ve.theme.colors.syntax.base.string,ve.theme.colors.syntax.base.function].map(Ok)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[S.has(ve.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(Q,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ve.name})]}):s.jsx(st,{checked:b.has(ve.key),disabled:ve.status!=="ready"||N||n,label:ve.name,onChange:se=>j(ge=>{const ne=new Set(ge);return se?ne.add(ve.key):ne.delete(ve.key),ne})}),s.jsx("p",{className:S.has(ve.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ve.status!=="ready"?i("settings.themeImport.error.invalid"):S.has(ve.key)?i("settings.themeImport.installed"):i(ve.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ve.key))})]})]})}),e[9]=n,e[10]=m,e[11]=u,e[12]=a,e[13]=c,e[14]=I,e[15]=S,e[16]=N,e[17]=b,e[18]=g.extension,e[19]=g.results,e[20]=g.status,e[21]=g.step,e[22]=g.variants,e[23]=i,e[24]=z,e[25]=M}else z=e[24],M=e[25];const P=M;if(u){let W;e[56]!==i?(W=i("settings.themeImport.catalogTitle"),e[56]=i,e[57]=W):W=e[57];let Z;e[58]!==z?(Z=s.jsx("div",{className:"flex flex-col gap-2",children:z}),e[58]=z,e[59]=Z):Z=e[59];let te;e[60]!==i?(te=i("settings.themeImport.catalogHint"),e[60]=i,e[61]=te):te=e[61];let J;e[62]!==te?(J=s.jsx("p",{className:"typography-meta text-muted-foreground",children:te}),e[62]=te,e[63]=J):J=e[63];let ie;e[64]!==P||e[65]!==J?(ie=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[J,P]}),e[64]=P,e[65]=J,e[66]=ie):ie=e[66];let pe;return e[67]!==o||e[68]!==Z||e[69]!==ie||e[70]!==W?(pe=s.jsx(ou,{open:!0,title:W,onClose:o,footer:Z,children:ie}),e[67]=o,e[68]=Z,e[69]=ie,e[70]=W,e[71]=pe):pe=e[71],pe}let R;e[72]!==o?(R=W=>{W||o()},e[72]=o,e[73]=R):R=e[73];let F;e[74]===Symbol.for("react.memo_cache_sentinel")?(F={forceRender:!0},e[74]=F):F=e[74];let _;e[75]!==i?(_=i("settings.themeImport.catalogTitle"),e[75]=i,e[76]=_):_=e[76];let B;e[77]!==_?(B=s.jsx(Ut,{children:_}),e[77]=_,e[78]=B):B=e[78];let V;e[79]!==i?(V=i("settings.themeImport.catalogHint"),e[79]=i,e[80]=V):V=e[80];let ee;e[81]!==V?(ee=s.jsx($t,{children:V}),e[81]=V,e[82]=ee):ee=e[82];let L;e[83]!==B||e[84]!==ee?(L=s.jsxs(zt,{children:[B,ee]}),e[83]=B,e[84]=ee,e[85]=L):L=e[85];let $;e[86]!==z||e[87]!==P||e[88]!==L?($=s.jsxs(Lt,{className:"max-w-lg",backdropProps:F,children:[L,P,z]}),e[86]=z,e[87]=P,e[88]=L,e[89]=$):$=e[89];let H;return e[90]!==$||e[91]!==R?(H=s.jsx(Ft,{open:!0,onOpenChange:R,children:$}),e[90]=$,e[91]=R,e[92]=H):H=e[92],H}function Ok(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function Fk(t){return t.key}function Lk(t){return t.isMobile}function Kk(){const{t}=ze(),{importTheme:e,customThemesLoading:a}=xa(),n=Ya(),[o,i]=d.useState(!1),r=d.useCallback(()=>i(!1),[]),l=d.useRef(null),u=d.useRef(0),m=d.useRef(null),[c,f]=d.useState(!1);d.useEffect(()=>Oo(()=>{u.current+=1,i(!1)}),[]);const p=async(k,b)=>{f(!0);try{if(k.size>iu)throw new ua("size");const j=await k.text();if(b.key!==Yt()||b.generation!==u.current)throw new ua("connection");const x=await e(mm(j,k.name));$a.success(t("settings.themeImport.success",{name:x.metadata.name})),i(!1)}catch(j){const x=j instanceof ua?j.code:"invalid";$a.error(t(`settings.themeImport.error.${x}`))}finally{f(!1)}},g=async()=>{if(c)return;const k={key:Yt(),generation:u.current};if(m.current=k,!n.themeFiles){l.current?.click();return}f(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const j=b.file;await p({name:j.name,size:j.size,text:async()=>j.text},k)}return}l.current?.click()}catch{$a.error(t("settings.themeImport.error.invalid"))}finally{f(!1)}},h=async k=>{const b=k.target.files?.[0];k.target.value="",b&&!c&&m.current&&await p(b,m.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(q,{variant:"outline",size:"sm",disabled:c||a,onClick:()=>i(!0),children:[s.jsx(Q,{name:c?"loader":"add",className:c?"size-3.5 animate-spin":"size-3.5"}),t(c?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Gt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:l,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:h}),o&&s.jsx(Rk,{pickFile:()=>{g()},fileBusy:c,onClose:r})]})}const Sd=(t,e,a)=>{const n=t?.querySelector("[cmdk-list]"),o=t?.querySelector(`[cmdk-item][data-value="${CSS.escape(e)}"]`);if(!n||!o)return;const i=n.getBoundingClientRect(),r=n.offsetHeight>0?i.height/n.offsetHeight:1;if(r<=0)return;const l=o.getBoundingClientRect(),u=(l.top-i.top)/r+n.scrollTop,m=l.height/r;a?.onlyIfHidden&&u>=n.scrollTop&&u+m<=n.scrollTop+n.clientHeight||(n.scrollTop=Math.max(0,u-(n.clientHeight-m)/2))};function Nd({options:t,value:e,onValueChange:a,placeholder:n,ariaLabel:o}){const{t:i}=ze(),{deleteImportedTheme:r,customThemeIds:l}=xa(),{isMobile:u}=qn(),[m,c]=d.useState(!1),[f,p]=d.useState(""),[g,h]=d.useState(void 0),[k,b]=d.useState(null),j=d.useRef(null),x=d.useRef(null),[S,v]=d.useState(null),[N,y]=d.useState(null),I=d.useCallback(P=>{const R=P instanceof HTMLElement?P:null,F=R?.closest('[data-slot="dialog-content"], [role="dialog"]');v(F instanceof HTMLElement?F:null),y(R?.closest("main")??null)},[]);d.useEffect(()=>{if(m)return Jp.suspend()},[m]);const w=d.useRef(e);w.current=e;const D=d.useCallback(P=>{P&&Sd(P,w.current)},[]),C=t.find(P=>P.id===e),A=d.useMemo(()=>m?Qn(t,f,P=>[P.label]):t,[m,t,f]),T=P=>{a(P),c(!1)},O=async P=>{if(!k){b(P.id);try{await r(P.id),j.current?.focus()}catch{$a.error(i("settings.themeImport.deleteError"))}finally{b(null)}}},z=P=>{if(!l.includes(P.id))return null;const R=k===P.id;return s.jsx(q,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:R,"aria-label":i("settings.themeImport.delete",{name:P.label}),onPointerDown:F=>F.stopPropagation(),onClick:F=>{F.stopPropagation(),O(P)},children:s.jsx(Q,{name:R?"loader":"delete-bin",className:R?"size-4 animate-spin":"size-4"})})},M=s.jsx("div",{role:"status",className:"px-3 py-6 text-center typography-ui-label text-muted-foreground",children:i("settings.openchamber.visual.field.noThemesFound")});return u?s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button","aria-label":o,"aria-haspopup":"dialog",className:Ie(en,!C&&"text-muted-foreground"),onClick:()=>{p(""),c(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:C?.label??n}),s.jsx(Q,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(ou,{open:m,title:o,onClose:()=>c(!1),children:s.jsxs("div",{className:"flex flex-col gap-2 px-3 pb-4 pt-1",children:[s.jsx(Be,{value:f,onChange:P=>p(P.target.value),placeholder:i("settings.openchamber.visual.field.searchThemes"),"aria-label":i("settings.openchamber.visual.field.searchThemes"),className:"h-9"}),s.jsx("div",{className:"flex flex-col",role:"listbox","aria-label":o,children:A.length===0?M:A.map(P=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{type:"button",role:"option","aria-selected":P.id===e,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]",onClick:()=>T(P.id),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:P.label}),P.id===e?s.jsx(Q,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),z(P)]},P.id))})]})})]}):s.jsxs(Uf,{open:m,onOpenChange:P=>{p(""),h(P?e:void 0),c(P)},onOpenChangeComplete:P=>{if(!P){x.current?.focus();return}j.current?.focus(),Sd(j.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs($f,{ref:x,"aria-label":o,"aria-haspopup":"dialog",className:Ie(en,!C&&"text-muted-foreground"),onPointerDownCapture:P=>I(P.currentTarget),onFocusCapture:P=>I(P.currentTarget),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:C?.label??n}),s.jsx(Q,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(_f,{container:S??void 0,children:s.jsx(Bf,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:N??void 0,className:"z-[120]",children:s.jsx(Vf,{role:"dialog","aria-label":o,className:Ie(sg,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(Qp,{ref:D,className:"min-h-0 flex-1",shouldFilter:!1,value:g,onValueChange:h,children:[s.jsx(Yp,{ref:j,"aria-label":i("settings.openchamber.visual.field.searchThemes"),placeholder:i("settings.openchamber.visual.field.searchThemes"),value:f,onValueChange:p,onKeyDown:P=>{if(Zp(P)){P.stopPropagation();return}Xp(P,R=>{P.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:R,bubbles:!0,cancelable:!0}))})}}),s.jsx(eg,{label:o,className:"max-h-[20rem] p-1",children:A.length===0?M:A.map(P=>s.jsxs(tg,{value:P.id,onSelect:T,"aria-current":P.id===e?!0:void 0,className:"max-w-full typography-ui-label",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:P.label}),P.id===e?s.jsx(Q,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,z(P)]},P.id))})]})})})})]})}const zk=2e3,Uk=3,$k=(t,e)=>t.state==="unsupported"||t.state==="failed"?!0:e?t.state==="on"&&t.index?.backfill.state!=="running":t.state==="off",_k=t=>{const e=t/1e6;return new Intl.NumberFormat(Nl(),{style:"unit",unit:"megabyte",maximumFractionDigits:e<10?1:0}).format(e)},Bk=()=>{const t=Ke.c(70),{t:e}=ze(),a=re(Vk),n=re(Hk),o=re(qk),i=re(Gk);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"loading"},t[0]=r):r=t[0];const[l,u]=d.useState(r),[m,c]=d.useState(!1),f=d.useRef(o);let p,g;t[1]!==a||t[2]!==o?(p=()=>{const B=a&&o&&!f.current;f.current=o;const V=new AbortController;let ee,L=B?Uk:0;const $=()=>{ag(V.signal).then(H=>{if(V.signal.aborted)return;u({kind:"ready",status:H}),H.index?.backfill.state==="running"&&(L=0);const W=L>0;L=L-1,(!$k(H,a)||W)&&(ee=setTimeout($,zk))}).catch(()=>{V.signal.aborted||u({kind:"error"})})};return $(),()=>{V.abort(),clearTimeout(ee)}},g=[a,o],t[1]=a,t[2]=o,t[3]=p,t[4]=g):(p=t[3],g=t[4]),d.useEffect(p,g);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{c(!0),ng().then(B=>u({kind:"ready",status:B})).catch(()=>u({kind:"error"})).finally(()=>c(!1))},t[5]=h):h=t[5];const k=h,b=l.kind==="ready"?l.status:null,j=b?.state==="unsupported";let x;if(t[6]!==a||t[7]!==b?.sizeBytes||t[8]!==e||t[9]!==l.kind||t[10]!==l.status){const B=_k(b?.sizeBytes??0);if(l.kind==="loading"){let V;t[12]!==e?(V=e("settings.openchamber.messageSearch.status.loading"),t[12]=e,t[13]=V):V=t[13],x=V}else if(l.kind==="error"){let V;t[14]!==e?(V=e("settings.openchamber.messageSearch.status.error"),t[14]=e,t[15]=V):V=t[15],x=V}else if(l.status.state==="unsupported"){let V;t[16]!==e?(V=e("settings.openchamber.messageSearch.status.unsupported"),t[16]=e,t[17]=V):V=t[17],x=V}else if(!a)x=l.status.sizeBytes>0?e("settings.openchamber.messageSearch.status.offWithFile",{size:B}):e("settings.openchamber.messageSearch.status.off");else if(l.status.state==="failed"){let V;t[18]!==e?(V=e("settings.openchamber.messageSearch.status.failed"),t[18]=e,t[19]=V):V=t[19],x=V}else if(l.status.state==="on"&&l.status.index?.backfill.state==="running")x=e("settings.openchamber.messageSearch.status.indexing",{done:l.status.index.backfill.done,total:l.status.index.backfill.total,size:B});else if(l.status.state==="on"&&l.status.index)x=e("settings.openchamber.messageSearch.status.ready",{sessions:l.status.index.sessions,messages:l.status.index.messages,size:B});else{let V;t[20]!==e?(V=e("settings.openchamber.messageSearch.status.loading"),t[20]=e,t[21]=V):V=t[21],x=V}t[6]=a,t[7]=b?.sizeBytes,t[8]=e,t[9]=l.kind,t[10]=l.status,t[11]=x}else x=t[11];let S;t[22]!==e?(S=e("settings.openchamber.messageSearch.title"),t[22]=e,t[23]=S):S=t[23];let v;t[24]!==e?(v=e("settings.openchamber.messageSearch.field.enabled"),t[24]=e,t[25]=v):v=t[25];let N;t[26]!==e?(N=e("settings.openchamber.messageSearch.field.enabled"),t[26]=e,t[27]=N):N=t[27];let y;t[28]!==e?(y=e("settings.openchamber.messageSearch.field.enabledInfo"),t[28]=e,t[29]=y):y=t[29];let I;t[30]!==a||t[31]!==n||t[32]!==v||t[33]!==N||t[34]!==y||t[35]!==j?(I=s.jsx(st,{settingsItem:"chat.message-search-enabled",checked:a,onChange:n,disabled:j,label:v,ariaLabel:N,info:y}),t[30]=a,t[31]=n,t[32]=v,t[33]=N,t[34]=y,t[35]=j,t[36]=I):I=t[36];const w=a&&o,D=!a||j;let C;t[37]!==e?(C=e("settings.openchamber.messageSearch.field.reasoning"),t[37]=e,t[38]=C):C=t[38];let A;t[39]!==e?(A=e("settings.openchamber.messageSearch.field.reasoning"),t[39]=e,t[40]=A):A=t[40];let T;t[41]!==e?(T=e("settings.openchamber.messageSearch.field.reasoningInfo"),t[41]=e,t[42]=T):T=t[42];let O;t[43]!==i||t[44]!==D||t[45]!==C||t[46]!==A||t[47]!==T||t[48]!==w?(O=s.jsx(st,{settingsItem:"chat.message-search-reasoning",checked:w,onChange:i,disabled:D,label:C,ariaLabel:A,info:T}),t[43]=i,t[44]=D,t[45]=C,t[46]=A,t[47]=T,t[48]=w,t[49]=O):O=t[49];let z;t[50]!==e?(z=e("settings.openchamber.messageSearch.field.index"),t[50]=e,t[51]=z):z=t[51];let M;t[52]!==a||t[53]!==b||t[54]!==e||t[55]!==m?(M=a?s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:k,disabled:m||b?.state!=="on"&&b?.state!=="failed",children:e(m?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.rebuild")}):s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:k,disabled:m||!b||b.state==="on"||b.sizeBytes===0,children:e(m?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.delete")}),t[52]=a,t[53]=b,t[54]=e,t[55]=m,t[56]=M):M=t[56];let P;t[57]!==z||t[58]!==M?(P=s.jsx(ht,{label:z,children:M}),t[57]=z,t[58]=M,t[59]=P):P=t[59];let R;t[60]!==x?(R=s.jsx("p",{className:Mt,"aria-live":"polite",children:x}),t[60]=x,t[61]=R):R=t[61];let F;t[62]!==O||t[63]!==P||t[64]!==R?(F=s.jsxs(Hn,{children:[O,P,R]}),t[62]=O,t[63]=P,t[64]=R,t[65]=F):F=t[65];let _;return t[66]!==F||t[67]!==S||t[68]!==I?(_=s.jsxs(Ve,{title:S,settingsItem:"chat.message-search",children:[I,F]}),t[66]=F,t[67]=S,t[68]=I,t[69]=_):_=t[69],_};function Vk(t){return t.messageSearchEnabled}function Hk(t){return t.setMessageSearchEnabled}function qk(t){return t.messageSearchReasoningEnabled}function Gk(t){return t.setMessageSearchReasoningEnabled}const Wk=()=>{re.getState().requestSettingsJump("sessions","sessions.small-model")},Jk=t=>{const e=Ke.c(33),{disabled:a}=t,n=a===void 0?!1:a,{t:o}=ze(),i=re(Yk),r=re(Zk),l=Wt(Mo),u=!Un(),m=l?i:"small-model";let c;e[0]!==o?(c=o("settings.openchamber.visual.goal.checkerLabel"),e[0]=o,e[1]=c):c=e[1];let f;e[2]!==o?(f=o("settings.openchamber.visual.goal.checkerInfo"),e[2]=o,e[3]=f):f=e[3];let p;e[4]!==o?(p=o("settings.openchamber.visual.goal.checkerLabel"),e[4]=o,e[5]=p):p=e[5];const g=n||!l;let h;e[6]!==g?(h={value:"classifier",label:"Jev",disabled:g},e[6]=g,e[7]=h):h=e[7];let k;e[8]!==o?(k=o("settings.openchamber.visual.goal.checker.smallModel"),e[8]=o,e[9]=k):k=e[9];let b;e[10]!==n||e[11]!==k?(b={value:"small-model",label:k,disabled:n},e[10]=n,e[11]=k,e[12]=b):b=e[12];let j;e[13]!==h||e[14]!==b?(j=[h,b],e[13]=h,e[14]=b,e[15]=j):j=e[15];let x;e[16]!==r||e[17]!==m||e[18]!==p||e[19]!==j?(x=s.jsx(Vs,{"aria-label":p,value:m,onChange:r,options:j}),e[16]=r,e[17]=m,e[18]=p,e[19]=j,e[20]=x):x=e[20];let S;e[21]!==x||e[22]!==c||e[23]!==f?(S=s.jsx(ht,{settingsItem:"chat.session-goal-checker",label:c,info:f,children:x}),e[21]=x,e[22]=c,e[23]=f,e[24]=S):S=e[24];let v;e[25]!==u||e[26]!==l||e[27]!==m||e[28]!==o?(v=m==="classifier"?s.jsx(Ri,{}):s.jsxs("p",{className:Mt,children:[o(l?"settings.openchamber.visual.goal.checker.viaSmallModel":"settings.openchamber.visual.goal.checker.jevMissing")," ",s.jsx(On,{onClick:Wk,children:o("settings.openchamber.visual.goal.checker.smallModelLink")}),l||!u?null:s.jsxs(s.Fragment,{children:[" · ",s.jsx(On,{onClick:Ao,children:o("settings.jevAccess.setUp")})]})]}),e[25]=u,e[26]=l,e[27]=m,e[28]=o,e[29]=v):v=e[29];let N;return e[30]!==S||e[31]!==v?(N=s.jsxs("div",{className:"space-y-1",children:[S,v]}),e[30]=S,e[31]=v,e[32]=N):N=e[32],N},Qk=t=>{const e=Ke.c(32),{disabled:a}=t,n=a===void 0?!1:a,{t:o}=ze(),i=re(Xk),r=re(ew);let l;e[0]!==o?(l=o("settings.openchamber.visual.goal.maxTurnsLabel"),e[0]=o,e[1]=l):l=e[1];let u;e[2]!==o?(u=o("settings.openchamber.visual.goal.maxTurnsInfo"),e[2]=o,e[3]=u):u=e[3];let m;e[4]!==r?(m=v=>r(Math.floor(v)),e[4]=r,e[5]=m):m=e[5];let c;e[6]!==o?(c=o("settings.openchamber.visual.goal.maxTurnsLabel"),e[6]=o,e[7]=c):c=e[7];let f;e[8]!==n||e[9]!==i||e[10]!==m||e[11]!==c?(f=s.jsx(ps,{value:i,onValueChange:m,min:1,max:Wg,step:1,disabled:n,className:xs,"aria-label":c}),e[8]=n,e[9]=i,e[10]=m,e[11]=c,e[12]=f):f=e[12];let p;e[13]!==r?(p=()=>r(cc),e[13]=r,e[14]=p):p=e[14];const g=n||i===cc;let h;e[15]!==o?(h=o("settings.openchamber.visual.goal.maxTurnsResetAria"),e[15]=o,e[16]=h):h=e[16];let k;e[17]!==o?(k=o("settings.common.actions.reset"),e[17]=o,e[18]=k):k=e[18];let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"}),e[19]=b):b=e[19];let j;e[20]!==k||e[21]!==p||e[22]!==g||e[23]!==h?(j=s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:p,disabled:g,className:as,"aria-label":h,title:k,children:b}),e[20]=k,e[21]=p,e[22]=g,e[23]=h,e[24]=j):j=e[24];let x;e[25]!==j||e[26]!==f?(x=s.jsxs("div",{className:ra,children:[f,j]}),e[25]=j,e[26]=f,e[27]=x):x=e[27];let S;return e[28]!==x||e[29]!==l||e[30]!==u?(S=s.jsx(ht,{settingsItem:"chat.session-goal-max-turns",label:l,info:u,children:x}),e[28]=x,e[29]=l,e[30]=u,e[31]=S):S=e[31],S};function Yk(t){return t.sessionGoalChecker}function Zk(t){return t.setSessionGoalChecker}function Xk(t){return t.sessionGoalMaxAutoTurns}function ew(t){return t.setSessionGoalMaxAutoTurns}const tw=[{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"}],sw=[{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"}],nw=[{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"}],bi="OpenChamber - AI Coding Assistant",Cd=[{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"}],Id=[{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"}],$r=t=>t==="portrait"||t==="landscape"?t:"system",aw=[{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"}],iw=[{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"}],Pd=[{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"}],ow=[{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"}],Ad=[{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"}],Td=[{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"}],rw=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],lw=[{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"},{id:"inline-double-paste",labelKey:"settings.openchamber.visual.option.largeTextPaste.inlineDoublePaste.label"}],cw=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],dw=t=>t==="markdown"?"markdown":"plain",uw=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],mw=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],$o=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:o,t:i}=ze(),r=d.useCallback(E=>i(E),[i]),{isMobile:l}=qn(),{terminal:u}=Ya(),{browserTab:m}=If(),c=Jg(),f=re(E=>E.showReasoningTraces),p=re(E=>E.sessionRecapEnabled),g=re(E=>E.sessionSuggestionEnabled),h=re(E=>E.setSessionRecapEnabled),k=re(E=>E.setSessionSuggestionEnabled),b=re(E=>E.sessionReviewOfferEnabled),j=re(E=>E.setSessionReviewOfferEnabled),x=Wt(Mo),S=re(E=>E.sessionGoalEnabled),v=re(E=>E.setSessionGoalEnabled),N=re(E=>E.sessionGoalDefaultBudgetEnabled),y=re(E=>E.setSessionGoalDefaultBudgetEnabled),I=re(E=>E.sessionGoalDefaultBudget),w=re(E=>E.setSessionGoalDefaultBudget),D=re(E=>E.setShowReasoningTraces),C=re(E=>E.streamingAutoFollowEnabled),A=re(E=>E.setStreamingAutoFollowEnabled),T=re(E=>E.collapsibleThinkingBlocks),O=re(E=>E.setCollapsibleThinkingBlocks),z=re(E=>E.expandReasoningWhileStreaming),M=re(E=>E.setExpandReasoningWhileStreaming),P=jo(E=>E.animatedActivityIndicators),R=jo(E=>E.setAnimatedActivityIndicators),F=re(E=>E.mermaidRenderingMode),_=re(E=>E.setMermaidRenderingMode),B=re(E=>E.userMessageRenderingMode),V=re(E=>E.setUserMessageRenderingMode),ee=re(E=>E.collapsibleUserMessages),L=re(E=>E.setCollapsibleUserMessages),$=re(E=>E.stickyUserHeader),H=re(E=>E.promptNavigatorEnabled),W=re(E=>E.setStickyUserHeader),Z=re(E=>E.setPromptNavigatorEnabled),te=re(E=>E.autoSaveEnabled),J=re(E=>E.setAutoSaveEnabled),ie=re(E=>E.wideChatLayoutEnabled),pe=re(E=>E.setWideChatLayoutEnabled),X=re(E=>E.codeBlockLineWrap),xe=re(E=>E.setCodeBlockLineWrap),Y=re(E=>E.tableCellWrap),be=re(E=>E.setTableCellWrap),De=re(E=>E.copyMessagesAsPlainText),ve=re(E=>E.setCopyMessagesAsPlainText),se=re(E=>E.chatRenderMode),ge=re(E=>E.setChatRenderMode),ne=re(E=>E.activityRenderMode),Se=re(E=>E.setActivityRenderMode),ke=re(E=>E.fontSize),Te=re(E=>E.setFontSize),Ee=re(E=>E.terminalFontSize),Le=re(E=>E.setTerminalFontSize),ce=re(E=>E.terminalShell),Me=re(E=>E.setTerminalShell),Fe=re(E=>E.terminalLoginShells),me=re(E=>E.setTerminalLoginShells),de=re(E=>E.editorFontSize),Pe=re(E=>E.setEditorFontSize),{uiFont:he,monoFont:Ue}=ig(),Ae=re(E=>E.setUiFont),Re=re(E=>E.setMonoFont),$e=re(E=>E.customUiFont),nt=re(E=>E.customMonoFont),pt=re(E=>E.setCustomUiFont),kt=re(E=>E.setCustomMonoFont),bt=Un(),yt=re(E=>E.padding),Je=re(E=>E.setPadding),ct=re(E=>E.inputBarOffset),Qe=re(E=>E.setInputBarOffset),it=re(E=>E.mobileKeyboardMode),dt=re(E=>E.setMobileKeyboardMode),qe=re(E=>E.diffLayoutPreference),lt=re(E=>E.setDiffLayoutPreference),ae=re(E=>E.showTerminalQuickKeysOnDesktop),fe=re(E=>E.sessionTabsEnabled),ye=re(E=>E.setSessionTabsEnabled),we=re(E=>E.setShowTerminalQuickKeysOnDesktop),Ge=re(E=>E.fileEditorKeymap),et=re(E=>E.setFileEditorKeymap),mt=re(E=>E.fileEditorVimMappings),jt=re(E=>E.setFileEditorVimMappings),vt=d.useMemo(()=>Lf(mt).invalidLines,[mt]),Ct=dc(E=>E.followUpBehavior),Bt=dc(E=>E.setFollowUpBehavior),Ye=Ji(E=>E.scope),Ze=Ji(E=>E.entryLimit),ut=Ji(E=>E.applyScope),ft=Ji(E=>E.applyEntryLimit),K=re(E=>E.persistChatDraft),ue=re(E=>E.setPersistChatDraft),Ne=re(E=>E.inputSpellcheckEnabled),Ce=re(E=>E.setInputSpellcheckEnabled),He=re(E=>E.largeTextPasteBehavior),le=re(E=>E.setLargeTextPasteBehavior),Oe=re(E=>E.enterToSend),ot=re(E=>E.setEnterToSend),Rt=re(E=>E.enterToSendConfigured),It=re(E=>E.setEnterToSendConfigured),os=Rt?Oe:!l,Xe=re(E=>E.showToolFileIcons),tt=re(E=>E.setShowToolFileIcons),qt=re(E=>E.showTurnChangedFiles),ss=re(E=>E.setShowTurnChangedFiles),fs=re(E=>E.showExpandedBashTools),Jt=re(E=>E.setShowExpandedBashTools),Cs=re(E=>E.showExpandedEditTools),kn=re(E=>E.setShowExpandedEditTools),Yn=re(E=>E.timeFormatPreference),Oi=re(E=>E.setTimeFormatPreference),ti=re(E=>E.weekStartPreference),$n=re(E=>E.setWeekStartPreference),Fi=re(E=>E.showSplitAssistantMessageActions),si=re(E=>E.setShowSplitAssistantMessageActions),ni=re(E=>E.allowPromptingSubagentSessions),Li=re(E=>E.setAllowPromptingSubagentSessions),va=re(E=>E.draftStartersVisible),ai=re(E=>E.setDraftStartersVisible),ii=rt(E=>E.settingsMessageStreamTransport),oi=rt(E=>E.setSettingsMessageStreamTransport),ri=ii,wn=rt(E=>E.settingsDefaultFileViewerPreview),li=rt(E=>E.setSettingsDefaultFileViewerPreview),zs=re(E=>E.isSettingsDialogOpen),{themeMode:_o,setThemeMode:Bo,availableThemes:ya,customThemesLoading:Vo,reloadCustomThemes:Ho,lightThemeId:Ki,darkThemeId:zi,setLightThemePreference:qo,setDarkThemePreference:Us}=xa(),[Zn,ci]=d.useState(!1),Ui=d.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Go=re(E=>E.dockBadgeEnabled),Wo=re(E=>E.setDockBadgeEnabled),Jo=re(E=>E.alwaysShowScrollbars===!0),Qo=re(E=>E.setAlwaysShowScrollbars),Yo=Qg(),Rs=re(E=>E.desktopWindowControlsPosition),Qs=re(E=>E.setDesktopWindowControlsPosition),ja=re(E=>E.desktopWindowControlsStyle),un=re(E=>E.setDesktopWindowControlsStyle),[_n,ql]=d.useState(0),mn=re(E=>E.reportUsage),$i=re(E=>E.setReportUsage),ka=d.useCallback(E=>{$i(E),gt({reportUsage:E})},[$i]),wa=d.useCallback(E=>{const xt=a.find(ds=>ds===E);xt&&(n(xt),gt({locale:xt}))},[a,n]),Xn=d.useCallback(E=>{Qs(E),gt({desktopWindowControlsPosition:E})},[Qs]),di=d.useCallback(E=>{un(E),gt({desktopWindowControlsStyle:E})},[un]),_i=(zs||l||is())&&(t?t.includes("chatRenderMode"):!0);d.useEffect(()=>{if(!_i)return;let E=null,xt=Date.now();const ds=()=>{const fn=Date.now();fn-xt>=420&&(ql(na=>(na+1)%24),xt=fn),E=requestAnimationFrame(ds)};(typeof document>"u"||document.visibilityState==="visible")&&(E=requestAnimationFrame(ds));const Ts=()=>{document.visibilityState==="visible"&&E===null?E=requestAnimationFrame(ds):document.visibilityState!=="visible"&&E!==null&&(cancelAnimationFrame(E),E=null)};return document.addEventListener("visibilitychange",Ts),()=>{document.removeEventListener("visibilitychange",Ts),E!==null&&cancelAnimationFrame(E)}},[_i]);const us=d.useCallback(E=>{V(E),gt({userMessageRenderingMode:E})},[V]),Zo=d.useCallback(E=>{W(E),gt({stickyUserHeader:E})},[W]),Sa=d.useCallback(E=>{Z(E),gt({promptNavigatorEnabled:E})},[Z]),Na=d.useCallback(E=>{ai(E),gt({draftStartersVisible:E})},[ai]),Xo=d.useCallback(E=>{L(E),gt({collapsibleUserMessages:E})},[L]),Bi=d.useCallback(E=>{pe(E),gt({wideChatLayoutEnabled:E})},[pe]),Vi=d.useCallback(E=>{si(E),gt({showSplitAssistantMessageActions:E})},[si]),Hi=d.useCallback(E=>{Ce(E),gt({inputSpellcheckEnabled:E})},[Ce]),ea=d.useCallback(E=>{ot(E),It(!0),gt({enterToSend:E,enterToSendConfigured:!0})},[ot,It]),Ca=d.useCallback(E=>{ge(E),gt({chatRenderMode:E})},[ge]),qi=d.useCallback(E=>{oi(E),gt({messageStreamTransport:E})},[oi]),er=d.useCallback(E=>{ut(E),gt({inputHistoryScope:E})},[ut]),Ia=d.useCallback(E=>{const xt=Math.round(E);Yg(xt)&&(ft(xt),gt({inputHistoryLimit:xt}))},[ft]),tr=d.useCallback(E=>{Se(E),gt({activityRenderMode:E})},[Se]),Pa=d.useCallback(E=>{_(E),gt({mermaidRenderingMode:E})},[_]),sr=d.useCallback(E=>{tt(E),gt({showToolFileIcons:E})},[tt]),nr=d.useCallback(E=>{ss(E),gt({showTurnChangedFiles:E})},[ss]),ar=d.useCallback(E=>{li(E),gt({defaultFileViewerPreview:E}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:E}}))},[li]),ir=d.useCallback(E=>{Jt(E),gt({showExpandedBashTools:E})},[Jt]),or=d.useCallback(E=>{kn(E),gt({showExpandedEditTools:E})},[kn]),rr=d.useCallback(E=>{Oi(E),gt({timeFormatPreference:E})},[Oi]),lr=d.useCallback(E=>{$n(E),gt({weekStartPreference:E})},[$n]),nn=d.useMemo(()=>ya.filter(E=>E.metadata.variant==="light").sort((E,xt)=>E.metadata.name.localeCompare(xt.metadata.name)),[ya]),pn=d.useMemo(()=>ya.filter(E=>E.metadata.variant==="dark").sort((E,xt)=>E.metadata.name.localeCompare(xt.metadata.name)),[ya]),ui=d.useMemo(()=>nn.find(E=>E.metadata.id===Ki)??nn[0],[nn,Ki]),cr=d.useMemo(()=>pn.find(E=>E.metadata.id===zi)??pn[0],[pn,zi]),U=d.useCallback((E,xt)=>{const ds=xt==="dark"?" Dark":" Light";return E.endsWith(ds)?E.slice(0,-ds.length):E},[]),je=d.useMemo(()=>nn.map(E=>({id:E.metadata.id,label:U(E.metadata.name,"light")})),[nn,U]),We=d.useMemo(()=>pn.map(E=>({id:E.metadata.id,label:U(E.metadata.name,"dark")})),[pn,U]),oe=E=>E==="enterToSend"&&l?!1:t?t.includes(E):!0,St=is(),hs=oe("theme")&&!St,an=oe("windowControlsPosition")&&Yo,ms=oe("theme")||oe("timeFormat")||oe("weekStart"),As=St?ms:oe("theme")||an||oe("pwaInstallName")||oe("pwaOrientation")||oe("timeFormat")||oe("weekStart"),gn=oe("fontSize")||oe("terminalFontSize")||oe("editorFontSize")||oe("spacing")||oe("scrollbars")&&!hs||oe("inputBarOffset")&&l,on=oe("terminalQuickKeys")&&!l||(oe("terminalShell")||oe("terminalLoginShell"))&&!St||oe("fileEditorKeymap")||oe("autoSaveEnabled")||oe("sessionTabs")&&!St&&!l,Aa=oe("mermaidRendering")||oe("sessionGoal")&&!St||oe("userMessageRendering")||oe("chatRenderMode")||oe("messageTransport")||oe("activityRenderMode")||oe("collapsibleUserMessages")||oe("stickyUserHeader")||oe("promptNavigatorEnabled")||oe("wideChatLayout")||oe("codeBlockLineWrap")||oe("tableCellWrap")||oe("copyMessagesAsPlainText")||oe("splitAssistantMessageActions")||oe("subagentReadOnlyBanner")||oe("diffLayout")||oe("dotfiles")||oe("fileViewerPreview")||oe("reasoning")||oe("followUpBehavior")||oe("inputHistoryScope")||oe("inputHistoryLimit")||oe("persistDraft")||oe("largeTextPaste")||oe("showToolFileIcons")||oe("expandedTools")||!l&&oe("inputSpellcheck")||oe("enterToSend"),Sn=oe("chatRenderMode")||oe("activityRenderMode"),Vt=oe("messageTransport"),es=oe("userMessageRendering")||oe("mermaidRendering")||oe("diffLayout")&&!St||oe("followUpBehavior")||oe("inputHistoryScope")||oe("inputHistoryLimit"),ta=oe("sessionAssist")||oe("sessionGoal")&&!St||oe("subagentReadOnlyBanner")||oe("collapsibleUserMessages")||oe("stickyUserHeader")||oe("promptNavigatorEnabled")||oe("wideChatLayout")||oe("codeBlockLineWrap")||oe("tableCellWrap")||oe("copyMessagesAsPlainText")||oe("splitAssistantMessageActions")||oe("dotfiles")||oe("fileViewerPreview")||oe("persistDraft")||oe("largeTextPaste")||oe("showToolFileIcons")||oe("showTurnChangedFiles")||!l&&oe("inputSpellcheck")||oe("enterToSend")||oe("reasoning")||oe("expandedTools"),Nn=As||gn||on,Ht=oe("pwaInstallName")&&ba()&&m&&!rs()&&!St,cs=oe("pwaOrientation")&&ba()&&!rs()&&!St,rn=oe("mobileKeyboardMode")&&ba()&&!rs()&&!St&&Zg(),Cn=(oe("terminalShell")||oe("terminalLoginShell"))&&!St,[Ta,dr]=d.useState([]),[Tm,Em]=d.useState(0);d.useEffect(()=>Oo(()=>{dr([]),Em(E=>E+1)}),[]),d.useEffect(()=>{let E=!1;if(!(!Cn||!u.listShells))return u.listShells().then(xt=>{E||dr(xt)}).catch(()=>{E||dr([])}),()=>{E=!0}},[Cn,u,Tm]);const Dm=d.useMemo(()=>{const E=Ta.filter(xt=>xt.id!=="auto");return ce==="auto"||E.some(xt=>xt.id===ce)?E:[{id:ce,name:ce,supportsLogin:!1},...E]},[Ta,ce]),Mm=Ta.find(E=>E.id===ce)?.supportsLogin===!0,Rm=Fe.includes(ce),Om=E=>{me(E?[...Fe.filter(xt=>xt!==ce),ce]:Fe.filter(xt=>xt!==ce))},[ur,sa]=d.useState(""),[Gi,Ea]=d.useState("system"),Fm=d.useMemo(()=>{const E=Ad.find(xt=>xt.id===Yn);return r(E?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Yn,r]),Lm=d.useMemo(()=>{const E=Td.find(xt=>xt.id===ti);return r(E?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ti,r]),Km=d.useMemo(()=>{const E=Cd.find(xt=>xt.id===Gi);return E?r(E.labelKey):void 0},[Gi,r]),zm=d.useMemo(()=>{const E=Id.find(xt=>xt.id===it);return E?r(E.labelKey):void 0},[it,r]),mr=d.useCallback(async E=>{if(typeof window>"u")return;const xt=window,Ts=E.trim().replace(/\s+/g," ").slice(0,64);if(await gt({pwaAppName:Ts}),typeof xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const fn=xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ts);sa(fn);return}sa(Ts||bi),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Gl=d.useCallback(async E=>{if(typeof window>"u")return;const xt=window,ds=$r(E);if(await gt({pwaOrientation:ds}),typeof xt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ts=xt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ds);Ea(Ts);return}Ea(ds),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);d.useEffect(()=>{if(typeof window>"u"||!Ht&&!cs&&!rn)return;let E=!1;return(async()=>{try{const ds=await jn();if(!ds){E||sa(bi);return}const fn=(ds.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),na=$r(ds.pwaOrientation),Wi=fc(ds.mobileKeyboardMode);E||(Ht&&sa(fn||bi),cs&&Ea(na),rn&&dt(Wi))}catch{E||(Ht&&sa(bi),cs&&Ea("system"),rn&&dt("native"))}})(),()=>{E=!0}},[dt,rn,Ht,cs]);const pr=oe("scrollbars")?s.jsx(st,{checked:Jo,onChange:Qo,label:i("settings.openchamber.visual.field.alwaysShowScrollbars"),info:i("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[As&&s.jsxs("div",{className:"space-y-0",children:[hs&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Pn,{children:[s.jsx("div",{className:ws,children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.colorMode"),children:tw.map(E=>s.jsx(ns,{selected:_o===E.value,onSelect:()=>Bo(E.value),label:r(E.labelKey),ariaLabel:r(E.labelKey)},E.value))})}),s.jsxs("div",{className:ws,children:[s.jsx(Et,{label:i("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(Nd,{options:je,value:ui?.metadata.id??"",onValueChange:qo,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Et,{label:i("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(Nd,{options:We,value:cr?.metadata.id??"",onValueChange:Us,placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:i("settings.openchamber.visual.field.selectDarkThemeAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:Vo||Zn,onClick:()=>{const E=Date.now();ci(!0),Ho().finally(()=>{const xt=Date.now()-E;if(xt<500){window.setTimeout(()=>{ci(!1)},500-xt);return}ci(!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(Q,{name:"restart",className:Ie("h-3.5 w-3.5",Zn&&"animate-spin")}),i(Zn?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Gt,{children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(Kk,{})]})]}),Ui&&s.jsx(Hn,{settingsItem:"appearance.dock-badge",children:s.jsx(st,{checked:Go,onChange:Wo,label:i("settings.openchamber.visual.field.dockBadge"),info:i("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:i("settings.openchamber.visual.field.dockBadge")})}),pr&&s.jsx(Hn,{children:pr})]}),an&&s.jsx(Ve,{title:i("settings.openchamber.desktopNetwork.field.windowControls"),info:i("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:hs,children:s.jsxs(Pn,{children:[s.jsx(Et,{label:i("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Vs,{value:Rs,options:uw.map(E=>({value:E.id,label:r(E.labelKey)})),onChange:Xn,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Et,{label:i("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Vs,{value:ja,options:mw.map(E=>({value:E.id,label:r(E.labelKey)})),onChange:di,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),ms&&s.jsx(Ve,{title:i("settings.openchamber.visual.section.localization"),children:s.jsxs(Pn,{children:[s.jsx(Et,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Tt,{value:e,onValueChange:wa,children:[s.jsx(Pt,{"aria-label":i("settings.appearance.language.select"),size:_t,className:Ma,children:s.jsx(Kt,{children:o(e)})}),s.jsx(At,{children:a.map(E=>s.jsx(at,{value:E,children:o(E)},E))})]})}),(oe("timeFormat")||oe("weekStart"))&&s.jsxs("div",{className:ws,children:[oe("timeFormat")&&s.jsx(Et,{label:i("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Tt,{value:Yn,onValueChange:E=>rr(E),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),size:_t,className:Ma,children:s.jsx(Kt,{children:Fm})}),s.jsx(At,{children:Ad.map(E=>s.jsx(at,{value:E.id,children:r(E.labelKey)},E.id))})]})}),oe("weekStart")&&s.jsx(Et,{label:i("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Tt,{value:ti,onValueChange:E=>lr(E),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),size:_t,className:Ma,children:s.jsx(Kt,{children:Lm})}),s.jsx(At,{children:Td.map(E=>s.jsx(at,{value:E.id,children:r(E.labelKey)},E.id))})]})})]})]})}),(Ht||cs||rn)&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.appInstall"),contentClassName:ws,children:[Ht&&s.jsxs(ht,{label:i("settings.openchamber.visual.field.installAppName"),info:i("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:ks,children:[s.jsx(Be,{value:ur,onChange:E=>{sa(E.target.value)},onBlur:()=>{mr(ur)},onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),mr(ur))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{sa(bi),mr("")},className:as,"aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]}),cs&&s.jsxs(ht,{label:i("settings.openchamber.visual.field.installOrientation"),description:i("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:ks,children:[s.jsxs(Tt,{value:Gi,onValueChange:E=>{const xt=$r(E);Ea(xt),Gl(xt)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:_t,className:ec,children:s.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Km})}),s.jsx(At,{children:Cd.map(E=>s.jsx(at,{value:E.id,children:r(E.labelKey)},E.id))})]}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ea("system"),Gl("system")},disabled:Gi==="system",className:as,"aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]}),rn&&s.jsxs(ht,{label:i("settings.openchamber.visual.field.mobileKeyboardMode"),info:i("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:ks,children:[s.jsxs(Tt,{value:it,onValueChange:E=>{const xt=fc(E);dt(xt),gt({mobileKeyboardMode:xt})},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:_t,className:ec,children:s.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:zm})}),s.jsx(At,{children:Id.map(E=>s.jsx(at,{value:E.id,children:r(E.labelKey)},E.id))})]}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{dt("native"),gt({mobileKeyboardMode:"native"})},disabled:it==="native",className:as,"aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),gn&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.densityAndType"),contentClassName:ws,children:[oe("fontSize")&&!l||oe("terminalFontSize")?s.jsxs(Pn,{children:[oe("fontSize")&&!l&&s.jsxs(Et,{label:i("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full flex-wrap",children:[s.jsxs(Tt,{value:he,onValueChange:E=>Ae(E),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),size:_t,className:Ma,children:s.jsx(Kt,{children:he===Oa?i("settings.openchamber.visual.field.customFont"):uc.find(E=>E.id===he)?.label})}),s.jsxs(At,{children:[uc.map(E=>s.jsx(at,{value:E.id,disabled:bt&&!!E.source,children:s.jsx("span",{style:{fontFamily:E.stack},children:E.label})},E.id)),s.jsx(at,{value:Oa,children:i("settings.openchamber.visual.field.customFont")})]})]}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ae(mc),disabled:he===mc,className:as,"aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})}),he===Oa?s.jsx(Be,{value:$e,onChange:E=>pt(E.target.value),placeholder:i("settings.openchamber.visual.field.customFontPlaceholder"),"aria-label":i("settings.openchamber.visual.field.customFontAria"),spellCheck:!1,autoComplete:"off",className:"h-8 basis-full rounded-md px-3"}):null]}),oe("terminalFontSize")&&s.jsxs(Et,{label:i("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full flex-wrap",children:[s.jsxs(Tt,{value:Ue,onValueChange:E=>Re(E),children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),size:_t,className:Ma,children:s.jsx(Kt,{children:Ue===Oa?i("settings.openchamber.visual.field.customFont"):pc.find(E=>E.id===Ue)?.label})}),s.jsxs(At,{children:[pc.map(E=>s.jsx(at,{value:E.id,disabled:bt&&!!E.source,children:s.jsx("span",{style:{fontFamily:E.stack},children:E.label})},E.id)),s.jsx(at,{value:Oa,children:i("settings.openchamber.visual.field.customFont")})]})]}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Re(gc),disabled:Ue===gc,className:as,"aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})}),Ue===Oa?s.jsx(Be,{value:nt,onChange:E=>kt(E.target.value),placeholder:i("settings.openchamber.visual.field.customFontPlaceholder"),"aria-label":i("settings.openchamber.visual.field.customFontAria"),spellCheck:!1,autoComplete:"off",className:"h-8 basis-full rounded-md px-3"}):null]})]}):null,bt&&(oe("fontSize")&&!l||oe("terminalFontSize"))?s.jsx("p",{className:Mt,children:i("settings.openchamber.visual.field.webFontsEnterprise")}):null,oe("fontSize")&&!l||oe("terminalFontSize")||oe("editorFontSize")?s.jsxs(Pn,{children:[oe("fontSize")&&!l&&s.jsx(Et,{label:i("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:ke,onValueChange:Te,min:50,max:200,step:5,className:xs,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Ra,children:"%"}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Te(100),disabled:ke===100,className:as,"aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})}),oe("terminalFontSize")&&s.jsx(Et,{label:i("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:Ee,onValueChange:Le,min:9,max:52,step:1,className:xs}),s.jsx("span",{className:Ra,children:"px"}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Le(13),disabled:Ee===13,className:as,"aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})}),oe("editorFontSize")&&s.jsx(Et,{label:i("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:de,onValueChange:Pe,min:9,max:32,step:1,className:xs}),s.jsx("span",{className:Ra,children:"px"}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Pe(13),disabled:de===13,className:as,"aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,oe("spacing")||oe("inputBarOffset")&&l?s.jsxs(Pn,{children:[oe("spacing")&&s.jsx(Et,{label:i("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:yt,onValueChange:Je,min:50,max:200,step:5,className:xs}),s.jsx("span",{className:Ra,children:"%"}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Je(100),disabled:yt===100,className:as,"aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})}),oe("inputBarOffset")&&l&&s.jsx(Et,{label:i("settings.openchamber.visual.field.inputBarOffset"),info:i("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:ct,onValueChange:Qe,min:0,max:100,step:5,className:xs}),s.jsx("span",{className:Ra,children:"px"}),s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Qe(0),disabled:ct===0,className:as,"aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!hs&&pr]}),oe("animatedActivityIndicators")&&s.jsx(Ve,{title:i("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:bs,children:s.jsx(st,{checked:P,onChange:R,label:i("settings.openchamber.visual.field.animatedActivityIndicators"),ariaLabel:i("settings.openchamber.visual.field.animatedActivityIndicatorsAria"),info:i("settings.openchamber.visual.field.animatedActivityIndicatorsInfo"),settingsItem:"appearance.animated-activity-indicators"})}),on&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[oe("fileEditorKeymap")&&s.jsx(vs,{title:i("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(E=>s.jsx(ns,{selected:Ge===E,onSelect:()=>et(E),label:i(`settings.openchamber.visual.option.fileEditorKeymap.${E}`),ariaLabel:i(`settings.openchamber.visual.option.fileEditorKeymap.${E}`)},E))})}),oe("fileEditorKeymap")&&Ge==="vim"&&s.jsx(Et,{label:i("settings.openchamber.visual.field.fileEditorVimMappings"),info:i("settings.openchamber.visual.field.fileEditorVimMappingsInfo"),description:vt.length>0?i("settings.openchamber.visual.field.fileEditorVimMappingsInvalid",{lines:vt.join(", ")}):void 0,descriptionPlacement:"after",settingsItem:"appearance.file-editor-vim-mappings",children:s.jsx(Ns,{value:mt,onChange:E=>jt(E.target.value),placeholder:"inoremap jk <Esc>","aria-label":i("settings.openchamber.visual.field.fileEditorVimMappings"),rows:4,spellCheck:!1,className:"w-full font-mono typography-meta"})}),s.jsxs("div",{className:bs,children:[oe("autoSaveEnabled")&&s.jsx(st,{checked:te,onChange:J,label:i("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:i("settings.openchamber.visual.field.autoSaveEnabledAria"),info:i("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Cn&&s.jsx(Et,{label:i("settings.openchamber.visual.field.terminalShell"),info:i("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Tt,{value:ce,onValueChange:E=>{Xg(E)&&Me(E)},children:[s.jsx(Pt,{"aria-label":i("settings.openchamber.visual.field.terminalShellAria"),size:_t,className:Ma,children:s.jsx(Kt,{})}),s.jsxs(At,{children:[s.jsx(at,{value:"auto",children:i("settings.openchamber.visual.option.terminalShell.auto")}),Dm.map(E=>s.jsx(at,{value:E.id,children:E.name},E.id))]})]})}),Cn&&Mm&&s.jsx(st,{checked:Rm,onChange:Om,label:i("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:i("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),oe("terminalQuickKeys")&&!l&&s.jsx(st,{checked:ae,onChange:we,label:i("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:Kn("ctrl"),alt:Kn("alt")})})]}),oe("sessionTabs")&&!St&&!l&&s.jsx(vs,{title:i("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(st,{checked:fe,onChange:ye,label:i("settings.openchamber.visual.field.sessionTabs"),ariaLabel:i("settings.openchamber.visual.field.sessionTabsAria"),info:i("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Aa&&s.jsxs(s.Fragment,{children:[Sn&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.chatDisplay"),divider:Nn,contentClassName:"space-y-6",children:[oe("chatRenderMode")&&s.jsx(vs,{title:i("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:iw.map(E=>{const xt=se===E.id,ds=_n%12;return s.jsxs("button",{type:"button",onClick:()=>Ca(E.id),"aria-pressed":xt,className:Ie("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",xt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:Ie("typography-ui-label",xt?"text-inherit":"text-muted-foreground"),children:r(E.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:E.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ts=>{const fn=Ts*3+1,na=ds-fn+1,Wi=na<=0?0:na===1?42:na===2?68:92,Um=Wi>0;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Um?"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}%`}})]},Ts)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ts=>{const fn=ds>=(Ts+1)*3;return s.jsxs("div",{className:Ie("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",fn?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Ts)})})})]},E.id)})})}),oe("activityRenderMode")&&s.jsx(vs,{title:i("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),children:ow.map(E=>s.jsx(ns,{selected:ne===E.id,onSelect:()=>tr(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:r(E.labelKey)})},E.id))})})]}),Vt&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.messageStreamTransport"),divider:Sn||Nn,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Vs,{value:ri,options:Pd.map(E=>({value:E.id,label:r(E.labelKey)})),onChange:qi,"aria-label":i("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const E=Pd.find(xt=>xt.id===ri);return E?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r(E.descriptionKey)}):null})()]}),es&&s.jsx(Ve,{title:i("settings.openchamber.visual.section.chatMessageOptions"),divider:Sn||Vt||Nn,children:s.jsxs(Pn,{className:"lg:gap-y-6",children:[oe("userMessageRendering")&&s.jsx(vs,{title:i("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),children:aw.map(E=>s.jsx(ns,{selected:dw(B)===E.id,onSelect:()=>us(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:r(E.labelKey)})},E.id))})}),oe("mermaidRendering")&&s.jsx(vs,{title:i("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),children:nw.map(E=>s.jsx(ns,{selected:F===E.id,onSelect:()=>Pa(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:r(E.labelKey)})},E.id))})}),oe("diffLayout")&&!St&&s.jsx(vs,{title:i("settings.openchamber.visual.section.diffLayout"),children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),children:sw.map(E=>s.jsx(ns,{selected:qe===E.id,onSelect:()=>lt(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:r(E.labelKey)})},E.id))})}),oe("followUpBehavior")&&s.jsx(vs,{title:i("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),children:rw.map(E=>s.jsx(ns,{selected:Ct===E.id,onSelect:()=>Bt(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:r(E.labelKey)})},E.id))})}),oe("inputHistoryScope")&&s.jsx(vs,{title:i("settings.openchamber.visual.field.inputHistoryScope"),info:i("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.section.inputHistoryScopeAria"),children:cw.map(E=>s.jsx(ns,{selected:Ye===E.id,onSelect:()=>er(E.id),label:r(E.labelKey),ariaLabel:r(E.labelKey)},E.id))})}),oe("inputHistoryLimit")&&s.jsx(vs,{title:i("settings.openchamber.visual.field.inputHistoryLimit"),description:i("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:ks,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:ra,children:[s.jsx(ps,{value:Ze,onValueChange:Ia,min:tf,max:ef,step:1,className:xs,deferExternalValueWhileFocused:!0,"aria-label":i("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Ra,children:i("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),oe("messageSearch")&&!St&&s.jsx(Bk,{}),ta&&s.jsxs(s.Fragment,{children:[oe("expandedTools")&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:Sn||Vt||es||Nn,contentClassName:bs,children:[s.jsx(st,{checked:fs,onChange:ir,label:i("settings.openchamber.visual.field.bash"),ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(st,{checked:Cs,onChange:or,label:i("settings.openchamber.visual.field.editTools"),ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Ve,{title:i("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:bs,children:[s.jsx(st,{checked:va,onChange:Na,label:i("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:i("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),oe("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(st,{checked:p,onChange:h,label:i("settings.openchamber.visual.field.sessionRecap"),ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(st,{checked:g,onChange:k,label:i("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),oe("sessionAssist")&&!St&&s.jsxs("div",{children:[s.jsx(st,{checked:x&&b,onChange:j,disabled:!x,label:i("settings.openchamber.visual.field.sessionReviewOffer"),ariaLabel:i("settings.openchamber.visual.field.sessionReviewOffer"),info:i("settings.openchamber.visual.field.sessionReviewOfferInfo"),settingsItem:"chat.session-review-offer"}),s.jsx(Ri,{})]}),oe("subagentReadOnlyBanner")&&s.jsx(st,{checked:ni,onChange:Li,label:i("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),oe("sessionGoal")&&!St&&s.jsxs(Ve,{title:i("settings.openchamber.visual.goal.sectionTitle"),info:i("settings.openchamber.visual.goal.description"),contentClassName:bs,children:[s.jsx(st,{checked:S,onChange:v,label:i("settings.openchamber.visual.field.sessionGoal"),ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsx(Jk,{disabled:!S}),s.jsx(Qk,{disabled:!S}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(st,{checked:N,onChange:y,disabled:!S,label:i("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),S&&N?s.jsx(ps,{value:I,onValueChange:E=>{typeof E=="number"&&Number.isFinite(E)&&E>0&&w(Math.floor(E))},min:1e3,max:1e8,step:5e4}):null]})]}),oe("reasoning")&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:bs,children:[s.jsx(st,{checked:f,onChange:D,label:i("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),f&&s.jsx(st,{checked:T,onChange:O,label:i("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),f&&T&&s.jsx(st,{checked:z,onChange:M,label:i("settings.openchamber.visual.field.expandReasoningWhileStreaming"),ariaLabel:i("settings.openchamber.visual.field.expandReasoningWhileStreamingAria"),info:i("settings.openchamber.visual.field.expandReasoningWhileStreamingInfo")})]}),s.jsx(Ve,{title:i("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:bs,children:s.jsx(st,{checked:C,onChange:A,label:i("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:i("settings.openchamber.visual.field.streamingAutoFollowAria"),info:i("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(oe("collapsibleUserMessages")||oe("stickyUserHeader")||oe("promptNavigatorEnabled")||oe("wideChatLayout")||oe("splitAssistantMessageActions")||oe("codeBlockLineWrap")||oe("tableCellWrap")||oe("copyMessagesAsPlainText"))&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:bs,children:[oe("collapsibleUserMessages")&&s.jsx(st,{checked:ee,onChange:Xo,label:i("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),oe("stickyUserHeader")&&s.jsx(st,{checked:$,onChange:Zo,label:i("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),oe("promptNavigatorEnabled")&&s.jsx(st,{checked:H,onChange:Sa,label:i("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),oe("wideChatLayout")&&s.jsx(st,{checked:ie,onChange:Bi,label:i("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),oe("splitAssistantMessageActions")&&s.jsx(st,{checked:Fi,onChange:Vi,label:i("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),oe("codeBlockLineWrap")&&s.jsx(st,{checked:X,onChange:xe,label:i("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"}),oe("tableCellWrap")&&s.jsx(st,{checked:Y,onChange:be,label:i("settings.openchamber.visual.field.tableCellWrap"),ariaLabel:i("settings.openchamber.visual.field.tableCellWrapAria"),info:i("settings.openchamber.visual.field.tableCellWrapInfo"),settingsItem:"chat.table-cell-wrap"}),oe("copyMessagesAsPlainText")&&s.jsx(st,{checked:De,onChange:ve,label:i("settings.openchamber.visual.field.copyMessagesAsPlainText"),ariaLabel:i("settings.openchamber.visual.field.copyMessagesAsPlainTextAria"),info:i("settings.openchamber.visual.field.copyMessagesAsPlainTextInfo"),settingsItem:"chat.copy-plain-text"})]}),(oe("showToolFileIcons")||oe("showTurnChangedFiles")||oe("dotfiles")&&!is()||oe("fileViewerPreview"))&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:bs,children:[oe("showToolFileIcons")&&s.jsx(st,{checked:Xe,onChange:sr,label:i("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),oe("showTurnChangedFiles")&&s.jsx(st,{checked:qt,onChange:nr,label:i("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),oe("dotfiles")&&!is()&&s.jsx(st,{checked:c,onChange:sf,label:i("settings.openchamber.visual.field.showDotfiles"),ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),oe("fileViewerPreview")&&s.jsx(st,{checked:wn,onChange:ar,label:i("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(oe("persistDraft")||oe("largeTextPaste")||!l&&oe("inputSpellcheck")||oe("enterToSend"))&&s.jsxs(Ve,{title:i("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(oe("persistDraft")||!l&&oe("inputSpellcheck"))&&s.jsxs("div",{className:bs,children:[oe("persistDraft")&&s.jsx(st,{checked:K,onChange:ue,label:i("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!l&&oe("inputSpellcheck")&&s.jsx(st,{checked:Ne,onChange:Hi,label:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),oe("largeTextPaste")&&s.jsx(vs,{title:i("settings.openchamber.visual.field.largeTextPaste"),info:i("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx($s,{"aria-label":i("settings.openchamber.visual.field.largeTextPasteAria"),children:lw.map(E=>s.jsx(ns,{selected:He===E.id,onSelect:()=>le(E.id),label:r(E.labelKey),ariaLabel:i("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:r(E.labelKey)})},E.id))})}),oe("enterToSend")&&s.jsx(vs,{title:i("settings.openchamber.visual.field.enterToSend"),info:i("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs($s,{"aria-label":i("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(ns,{selected:os,onSelect:()=>ea(!0),label:i("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(ns,{selected:!os,onSelect:()=>ea(!1),label:i("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),oe("reportUsage")&&s.jsx(Ve,{title:i("settings.openchamber.visual.section.privacy"),children:s.jsx(st,{checked:mn,onChange:ka,label:i("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},pw=1,gw=365,Ed=30,fw=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],pm=()=>{const t=Ke.c(105),{t:e}=ze(),a=re(hw),n=re(bw),o=re(xw),i=re(vw),r=re(yw),l=re(jw),u=re(kw);let m;t[0]===Symbol.for("react.memo_cache_sentinel")?(m={autoRun:!1},t[0]=m):m=t[0];const{candidates:c,isRunning:f,runCleanup:p,action:g,status:h}=og(m),k=c.length;let b;t[1]!==p||t[2]!==e?(b=async()=>{const se=await p({force:!0}).catch(()=>(G.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!se||se.skippedReason&&se.skippedReason!=="no-candidates")){if(se.completedIds.length===0&&se.failedIds.length===0){G.message(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}se.completedIds.length>0&&G.success(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:se.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:se.completedIds.length})),se.failedIds.length>0&&G.error(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:se.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:se.failedIds.length}))}},t[1]=p,t[2]=e,t[3]=b):b=t[3];const j=b;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];const S=o?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let v;t[6]!==e||t[7]!==S?(v=e(S),t[6]=e,t[7]=S,t[8]=v):v=t[8];let N;t[9]!==e?(N=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=N):N=t[10];let y;t[11]!==e?(y=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=y):y=t[12];let I;t[13]!==a||t[14]!==i||t[15]!==N||t[16]!==y?(I=s.jsx(st,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:N,ariaLabel:y}),t[13]=a,t[14]=i,t[15]=N,t[16]=y,t[17]=I):I=t[17];let w;t[18]!==e?(w=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=w):w=t[19];let D;t[20]!==e?(D=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=D):D=t[21];let C;t[22]!==e?(C=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=C):C=t[23];let A;t[24]!==f||t[25]!==o||t[26]!==u||t[27]!==C||t[28]!==w||t[29]!==D?(A=s.jsx(st,{settingsItem:"sessions.retention-only-archived",checked:o,onChange:u,disabled:f,label:w,ariaLabel:D,info:C}),t[24]=f,t[25]=o,t[26]=u,t[27]=C,t[28]=w,t[29]=D,t[30]=A):A=t[30];let T;t[31]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=T):T=t[32];let O;t[33]!==e?(O=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=O):O=t[34];let z;t[35]===Symbol.for("react.memo_cache_sentinel")?(z=Ie(xs,"tabular-nums"),t[35]=z):z=t[35];let M;t[36]!==n||t[37]!==r||t[38]!==O?(M=s.jsx(ps,{value:n,onValueChange:r,min:pw,max:gw,step:1,"aria-label":O,className:z}),t[36]=n,t[37]=r,t[38]=O,t[39]=M):M=t[39];let P;t[40]!==e?(P=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=P):P=t[41];let R;t[42]!==P?(R=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:P}),t[42]=P,t[43]=R):R=t[43];let F;t[44]!==r?(F=()=>r(Ed),t[44]=r,t[45]=F):F=t[45];const _=n===Ed;let B;t[46]!==e?(B=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=B):B=t[47];let V;t[48]!==e?(V=e("settings.common.actions.reset"),t[48]=e,t[49]=V):V=t[49];let ee;t[50]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(Q,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=ee):ee=t[50];let L;t[51]!==F||t[52]!==_||t[53]!==B||t[54]!==V?(L=s.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:F,disabled:_,className:as,"aria-label":B,title:V,children:ee}),t[51]=F,t[52]=_,t[53]=B,t[54]=V,t[55]=L):L=t[55];let $;t[56]!==T||t[57]!==M||t[58]!==R||t[59]!==L?($=s.jsxs(ht,{settingsItem:"sessions.retention-period",label:T,children:[M,R,L]}),t[56]=T,t[57]=M,t[58]=R,t[59]=L,t[60]=$):$=t[60];let H;t[61]!==e?(H=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=H):H=t[62];let W;t[63]!==o||t[64]!==e?(W=fw.map(se=>({value:se.value,label:e(se.labelKey),disabled:o&&se.value==="archive"})),t[63]=o,t[64]=e,t[65]=W):W=t[65];let Z;t[66]!==g||t[67]!==l||t[68]!==W?(Z=s.jsx(Vs,{value:g,onChange:l,options:W}),t[66]=g,t[67]=l,t[68]=W,t[69]=Z):Z=t[69];let te;t[70]!==H||t[71]!==Z?(te=s.jsx(ht,{settingsItem:"sessions.retention-action",label:H,children:Z}),t[70]=H,t[71]=Z,t[72]=te):te=t[72];let J;t[73]!==A||t[74]!==$||t[75]!==te?(J=s.jsxs(Hn,{className:"space-y-0",children:[A,$,te]}),t[73]=A,t[74]=$,t[75]=te,t[76]=J):J=t[76];let ie;t[77]!==e?(ie=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=ie):ie=t[78];let pe;t[79]!==f||t[80]!==e?(pe=e(f?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=f,t[80]=e,t[81]=pe):pe=t[81];let X;t[82]!==j||t[83]!==f||t[84]!==pe?(X=s.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:j,disabled:f,className:"!font-normal",children:pe}),t[82]=j,t[83]=f,t[84]=pe,t[85]=X):X=t[85];let xe;t[86]!==ie||t[87]!==X?(xe=s.jsx(ht,{label:ie,children:X}),t[86]=ie,t[87]=X,t[88]=xe):xe=t[88];let Y;t[89]!==g||t[90]!==k||t[91]!==h||t[92]!==e?(Y=h==="error"?e("sessions.sidebar.group.empty.loadFailed"):h!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):g==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:k}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:k}),t[89]=g,t[90]=k,t[91]=h,t[92]=e,t[93]=Y):Y=t[93];let be;t[94]!==Y?(be=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Y}),t[94]=Y,t[95]=be):be=t[95];let De;t[96]!==xe||t[97]!==be?(De=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[xe,be]}),t[96]=xe,t[97]=be,t[98]=De):De=t[98];let ve;return t[99]!==x||t[100]!==J||t[101]!==De||t[102]!==v||t[103]!==I?(ve=s.jsxs(Ve,{title:x,info:v,children:[I,J,De]}),t[99]=x,t[100]=J,t[101]=De,t[102]=v,t[103]=I,t[104]=ve):ve=t[104],ve};function hw(t){return t.autoDeleteEnabled}function bw(t){return t.autoDeleteAfterDays}function xw(t){return t.sessionRetentionOnlyArchived}function vw(t){return t.setAutoDeleteEnabled}function yw(t){return t.setAutoDeleteAfterDays}function jw(t){return t.setSessionRetentionAction}function kw(t){return t.setSessionRetentionOnlyArchived}const gm=()=>{const t=Ke.c(17),{t:e}=ze(),a=re(ww),n=re(Sw);let o;t[0]!==e?(o=e("settings.openchamber.mergedWorktreeCleanup.title"),t[0]=e,t[1]=o):o=t[1];let i;t[2]!==e?(i=e("settings.openchamber.mergedWorktreeCleanup.info"),t[2]=e,t[3]=i):i=t[3];let r;t[4]!==e?(r=e("settings.openchamber.mergedWorktreeCleanup.field.enable"),t[4]=e,t[5]=r):r=t[5];let l;t[6]!==e?(l=e("settings.openchamber.mergedWorktreeCleanup.field.enableDescription"),t[6]=e,t[7]=l):l=t[7];let u;t[8]!==a||t[9]!==n||t[10]!==r||t[11]!==l?(u=s.jsx(st,{settingsItem:"sessions.merged-worktree-cleanup",checked:a,onChange:n,label:r,description:l}),t[8]=a,t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12];let m;return t[13]!==o||t[14]!==i||t[15]!==u?(m=s.jsx(Ve,{settingsItem:"sessions.merged-worktree-cleanup-section",title:o,info:i,children:u}),t[13]=o,t[14]=i,t[15]=u,t[16]=m):m=t[16],m};function ww(t){return t.mergedWorktreeCleanupEnabled}function Sw(t){return t.setMergedWorktreeCleanupEnabled}const fm=()=>{const t=Ke.c(39),{t:e}=ze();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=is(),t[0]=a):a=t[0];const n=a,o=re(Nw),i=re(Cw),r=re(Iw),l=re(Pw),u=re(Aw),m=re(Tw),c=Wt(Mo);let f;t[1]!==e?(f=e("settings.openchamber.sessionWork.title"),t[1]=e,t[2]=f):f=t[2];let p;t[3]!==e?(p=e("settings.openchamber.sessionWork.info"),t[3]=e,t[4]=p):p=t[4];let g;t[5]!==e?(g=e("settings.openchamber.sessionWork.field.enabled"),t[5]=e,t[6]=g):g=t[6];let h;t[7]!==e?(h=e("settings.openchamber.sessionWork.field.enabled"),t[7]=e,t[8]=h):h=t[8];let k;t[9]!==o||t[10]!==l||t[11]!==g||t[12]!==h?(k=s.jsx(st,{settingsItem:"sessions.work-enabled",checked:o,onChange:l,label:g,ariaLabel:h}),t[9]=o,t[10]=l,t[11]=g,t[12]=h,t[13]=k):k=t[13];const b=o&&r,j=!o;let x;t[14]!==e?(x=e("settings.openchamber.sessionWork.field.keepInGroup"),t[14]=e,t[15]=x):x=t[15];let S;t[16]!==e?(S=e("settings.openchamber.sessionWork.field.keepInGroup"),t[16]=e,t[17]=S):S=t[17];let v;t[18]!==e?(v=e("settings.openchamber.sessionWork.field.keepInGroupInfo"),t[18]=e,t[19]=v):v=t[19];let N;t[20]!==m||t[21]!==v||t[22]!==b||t[23]!==j||t[24]!==x||t[25]!==S?(N=s.jsx(st,{settingsItem:"sessions.work-keep-in-group",checked:b,onChange:m,disabled:j,label:x,ariaLabel:S,info:v}),t[20]=m,t[21]=v,t[22]=b,t[23]=j,t[24]=x,t[25]=S,t[26]=N):N=t[26];let y;t[27]!==i||t[28]!==o||t[29]!==c||t[30]!==u||t[31]!==e?(y=n?null:s.jsxs(Hn,{className:"space-y-0",children:[s.jsx(st,{settingsItem:"sessions.work-auto-open",checked:o&&c&&i,onChange:u,disabled:!o||!c,label:e("settings.openchamber.sessionWork.field.autoOpen"),ariaLabel:e("settings.openchamber.sessionWork.field.autoOpen"),info:e("settings.openchamber.sessionWork.field.autoOpenInfo")}),s.jsx(Ri,{})]}),t[27]=i,t[28]=o,t[29]=c,t[30]=u,t[31]=e,t[32]=y):y=t[32];let I;return t[33]!==f||t[34]!==N||t[35]!==y||t[36]!==p||t[37]!==k?(I=s.jsxs(Ve,{title:f,info:p,settingsItem:"sessions.work",children:[k,N,y]}),t[33]=f,t[34]=N,t[35]=y,t[36]=p,t[37]=k,t[38]=I):I=t[38],I};function Nw(t){return t.sessionWorkEnabled}function Cw(t){return t.sessionWorkAutoOpen}function Iw(t){return t.sessionWorkKeepInGroup}function Pw(t){return t.setSessionWorkEnabled}function Aw(t){return t.setSessionWorkAutoOpen}function Tw(t){return t.setSessionWorkKeepInGroup}const Dd=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Nl(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),hm=()=>{const{t}=ze(),e=re(I=>I.timeFormatPreference),[a,n]=d.useState(!1),[o,i]=d.useState(!0),[r,l]=d.useState(!1),[u,m]=d.useState(null),[c,f]=d.useState(!1),[p,g]=d.useState([]),[h,k]=d.useState(rg),[b,j]=d.useState(""),x=d.useMemo(()=>lg(),[]),S=d.useCallback(async()=>{i(!0),j("");try{const I=await cg();g(I)}catch(I){const w=I instanceof Error?I.message:t("settings.openchamber.passkeys.toast.loadFailed");j(w)}finally{i(!1)}},[t]);d.useEffect(()=>{let I=!1;return(async()=>{try{if(!x.supported){I||(n(!1),i(!1));return}I||n(!0)}catch{I||n(!1)}if(!I){const w=await xr();if(k(w),!w.enabled){g([]),i(!1);return}await S()}})(),()=>{I=!0,tc()}},[S,x.supported]);const v=d.useCallback(async()=>{if(!h.enabled){const I=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");j(I),G.message(I);return}if(!a){j(x.reason),G.message(x.reason);return}if(r){tc(),l(!1);return}j(""),l(!0);try{await dg(),k(await xr()),await S(),G.success(t("settings.openchamber.passkeys.toast.added"))}catch(I){if(ug(I)){G.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const w=I instanceof Error?I.message:t("settings.openchamber.passkeys.toast.addFailed");j(w),G.error(w)}finally{l(!1)}},[r,S,h.enabled,x.reason,a,t]),N=d.useCallback(async I=>{m(I),j("");try{await mg(I),k(await xr()),await S(),G.success(t("settings.openchamber.passkeys.toast.removed"))}catch(w){const D=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.removeFailed");j(D),G.error(D)}finally{m(null)}},[S,t]),y=d.useCallback(async()=>{f(!0),j("");try{await pg(),window.location.reload()}catch(I){const w=I instanceof Error?I.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");j(w),G.error(w),f(!1)}},[t]);return s.jsxs(Ve,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(ht,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(q,{type:"button",variant:r?"secondary":"outline",size:"xs",onClick:()=>{v()},disabled:o||c,className:"!font-normal",children:t(r?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:()=>{y()},disabled:o||r||c,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(c?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!h.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),h.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:x.reason}),o?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(I=>s.jsxs(ht,{label:s.jsx("span",{title:I.label,children:I.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:I.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Dd(I.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Dd(I.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:()=>{N(I.id)},disabled:u===I.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:u===I.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},I.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},bm=()=>{const t=Ke.c(14),{t:e}=ze(),a=sc(Ew),n=sc(Dw);let o;t[0]!==e?(o=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=o):o=t[1];let i;t[2]!==e?(i=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=i):i=t[3];let r;t[4]!==n||t[5]!==e||t[6]!==a?(r=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):a.map(m=>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:`${m}://`}),s.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(m),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${m}://`}),children:e("settings.common.actions.delete")})]},m)),t[4]=n,t[5]=e,t[6]=a,t[7]=r):r=t[7];let l;t[8]!==r?(l=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:r}),t[8]=r,t[9]=l):l=t[9];let u;return t[10]!==o||t[11]!==i||t[12]!==l?(u=s.jsx(Ve,{title:o,description:i,children:l}),t[10]=o,t[11]=i,t[12]=l,t[13]=u):u=t[13],u};function Ew(t){return t.trustedSchemes}function Dw(t){return t.removeTrustedScheme}const Mw=()=>{const{t}=ze(),[e,a]=d.useState(null),n=d.useRef(0);d.useEffect(()=>{let i=!1;return Ls.getConfig(null).then(r=>{!i&&n.current===0&&a(!!r.warming)},r=>console.warn("[session-warming] failed to read config",r)),()=>{i=!0}},[]);const o=d.useCallback(async i=>{const r=e,l=++n.current;a(i),Zt("saving");try{const u=await Dt("/api/config/warming",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({enabled:i})});if(!u.ok)throw new Error(`HTTP ${u.status}`);Zt("saved"),Ls.clearConfigCache()}catch(u){console.warn("[session-warming] failed to save",u),Zt("error"),l===n.current&&a(r)}},[e]);return s.jsx(st,{settingsItem:"sessions.warming",checked:e??!1,disabled:e===null,onChange:i=>{o(i)},label:t("settings.openchamber.defaults.field.sessionWarming"),info:t("settings.openchamber.defaults.field.sessionWarmingInfo")})},Rw={ask:{icon:"shield-user",color:void 0},safety:{icon:"shield-star",color:"var(--status-success)"},auto:{icon:"shield-check",color:"var(--status-info)"}},Ow=t=>{const e=Ke.c(42),{agentName:a}=t,{t:n}=ze(),o=re(Fw),i=re(Lw),r=Wt(Mo),l=zo(Wt(Kw));let u;e[0]!==o||e[1]!==r?(u=gg(o,r),e[0]=o,e[1]=r,e[2]=u):u=e[2];const m=u;let c;e[3]!==i?(c=A=>{i(A),gt({permissionDefaultMode:A})},e[3]=i,e[4]=c):c=e[4];const f=c;let p;e[5]!==a?(p=()=>{const A=a??rt.getState().currentAgentName;A&&vn.getState().setSelectedAgent(A),re.getState().requestSettingsJump("agents","agents.permissions")},e[5]=a,e[6]=p):p=e[6];const g=p;let h;e[7]!==g||e[8]!==l||e[9]!==r||e[10]!==n?(h=A=>A==="safety"&&!r?s.jsxs(s.Fragment,{children:[n("settings.sessions.permissions.explain.safetyUnavailable")," ",s.jsx(On,{onClick:Ao,children:n("settings.jevAccess.setUp")})]}):A==="safety"?s.jsxs(s.Fragment,{children:[l?n("settings.sessions.permissions.explain.safetyVia",{provider:l}):n("settings.sessions.permissions.explain.safety")," ",s.jsx(On,{onClick:Ao,children:n("settings.jevAccess.manage")})]}):s.jsxs(s.Fragment,{children:[n(A==="auto"?"settings.sessions.permissions.explain.auto":"settings.sessions.permissions.explain.ask")," ",s.jsx(On,{onClick:g,children:n("settings.sessions.permissions.agentPermissionsLink")})]}),e[7]=g,e[8]=l,e[9]=r,e[10]=n,e[11]=h):h=e[11];const k=h;let b;e[12]!==k||e[13]!==r?(b=(A,T)=>{const{icon:O,color:z}=Rw[A];return{value:A,label:s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(Q,{name:O,className:"size-3.5",style:z?{color:z}:void 0}),T]}),tooltip:k(A),disabled:A==="safety"&&!r}},e[12]=k,e[13]=r,e[14]=b):b=e[14];const j=b;let x;e[15]!==n?(x=n("settings.sessions.permissions.defaultMode"),e[15]=n,e[16]=x):x=e[16];let S;e[17]!==n?(S=n("settings.sessions.permissions.defaultModeInfo"),e[17]=n,e[18]=S):S=e[18];let v;e[19]!==n?(v=n("settings.sessions.permissions.defaultMode"),e[19]=n,e[20]=v):v=e[20];let N;e[21]!==j||e[22]!==n?(N=[j("ask",n("settings.sessions.permissions.mode.ask")),j("safety",n("settings.sessions.permissions.mode.safety")),j("auto",n("settings.sessions.permissions.mode.auto"))],e[21]=j,e[22]=n,e[23]=N):N=e[23];let y;e[24]!==f||e[25]!==m||e[26]!==v||e[27]!==N?(y=s.jsx(Vs,{"aria-label":v,value:m,onChange:f,options:N}),e[24]=f,e[25]=m,e[26]=v,e[27]=N,e[28]=y):y=e[28];let I;e[29]!==y||e[30]!==x||e[31]!==S?(I=s.jsx(ht,{settingsItem:"sessions.permission-default",label:x,info:S,children:y}),e[29]=y,e[30]=x,e[31]=S,e[32]=I):I=e[32];let w;e[33]!==k||e[34]!==m?(w=s.jsx("p",{className:Mt,children:k(m)}),e[33]=k,e[34]=m,e[35]=w):w=e[35];let D;e[36]!==r?(D=r?null:s.jsx(Ri,{}),e[36]=r,e[37]=D):D=e[37];let C;return e[38]!==I||e[39]!==w||e[40]!==D?(C=s.jsxs("div",{className:"space-y-1",children:[I,w,D]}),e[38]=I,e[39]=w,e[40]=D,e[41]=C):C=e[41],C};function Fw(t){return t.permissionDefaultMode}function Lw(t){return t.setPermissionDefaultMode}function Kw(t){return t.classifier?.effective??null}const _r=t=>{const e=Mn(t);return e||{providerId:"",modelId:""}},xm=()=>{const{t}=ze(),e=rt(se=>se.setProvider),a=rt(se=>se.setModel),n=rt(se=>se.setAgent),o=rt(se=>se.setCurrentVariant),i=rt(se=>se.setCurrentVariantOverride),r=rt(se=>se.setSettingsDefaultModel),l=rt(se=>se.setSettingsDefaultVariant),u=rt(se=>se.setSettingsDefaultAgent),m=rt(se=>se.selectionSource==="manual"),c=fg(se=>se.currentSessionId),f=nc(se=>se.getSessionModelSelection),p=nc(se=>se.getSessionAgentSelection),g=rt(se=>se.agentSelectionSource==="manual"),k=!!(rt(se=>{if(se.agentSelectionSource!=="manual")return!1;const ge=se.agents.find(ne=>ne.name===se.currentAgentName);return!!(ge?.model?.providerID&&ge.model.id)})||m&&c&&f(c)),b=!!(g&&c&&p(c)),j=d.useMemo(()=>is(),[]),x=jo(se=>se.showChatsSection),S=jo(se=>se.setShowChatsSection),v=re(se=>se.showDeletionDialog),N=re(se=>se.setShowDeletionDialog),y=rt(se=>se.providers),I=rt(se=>se.modelsMetadata),[w,D]=d.useState(),[C,A]=d.useState(),[T,O]=d.useState(),[z,M]=d.useState(!0),[P,R]=d.useState(),[F,_]=d.useState([]),[B,V]=d.useState(),[ee,L]=d.useState(!0),$=d.useMemo(()=>_r(w),[w]);d.useEffect(()=>{(async()=>{try{const ge=await jn();if(ge){const ne=ge.defaultModel?.trim()||void 0,Se=ge.defaultVariant?.trim()||void 0,ke=ge.defaultAgent?.trim()||void 0;ne!==void 0&&D(ne),Se!==void 0&&A(Se),ke!==void 0&&O(ke),ge.smallModelUseDefault!==void 0&&M(ge.smallModelUseDefault);const Te=ge.smallModelOverride?.trim();Te&&R(Te);const Ee=ge.walkthroughModelOverride?.trim();Ee&&V(Ee)}}catch(ge){console.warn("Failed to load defaults settings:",ge)}finally{L(!1)}})()},[]);const H=d.useCallback(async(se,ge)=>{const ne=se&&ge?`${se}/${ge}`:void 0;D(ne),A(void 0),l(void 0),r(ne),k||(o(void 0),se&&ge&&(y.find(ke=>ke.id===se)||fu(se,ge))&&(e(se),a(ge)));try{await gt({defaultModel:ne??"",defaultVariant:""})}catch(Se){console.warn("Failed to save default model:",Se)}},[k,y,o,a,e,r,l]),W="__default__",Z=d.useCallback(se=>se===W?t("settings.openchamber.defaults.option.default"):se.charAt(0).toUpperCase()+se.slice(1),[t]),te=d.useCallback(async se=>{const ge=se===W?void 0:se||void 0;A(ge),l(ge),k||i(ge??null,ge);try{await gt({defaultVariant:ge??""})}catch(ne){console.warn("Failed to save default variant:",ne)}},[k,i,l]),J=d.useCallback(async se=>{const ge=se||void 0;O(ge),u(ge),se&&!b&&n(se);try{await gt({defaultAgent:ge??""})}catch(ne){console.warn("Failed to save default agent:",ne)}},[b,n,u]),ie=d.useCallback(async se=>{M(se);try{await gt({smallModelUseDefault:se})}catch(ge){console.warn("Failed to save small model preference:",ge)}},[]),pe=d.useCallback(async(se,ge)=>{const ne=se&&ge?`${se}/${ge}`:void 0;R(ne);try{await gt({smallModelOverride:ne??""})}catch(Se){console.warn("Failed to save small model override:",Se)}},[]),X=d.useCallback(async(se,ge)=>{const ne=se&&ge?`${se}/${ge}`:void 0;V(ne);try{await gt({walkthroughModelOverride:ne??""})}catch(Se){console.warn("Failed to save walkthrough model override:",Se)}},[]),xe=d.useCallback((se,ge)=>I.get(`${se}/${ge}`)?.structured_output!==!1,[I]),Y=d.useMemo(()=>_r(P),[P]),be=d.useMemo(()=>_r(B),[B]);d.useEffect(()=>{let se=!1;return(async()=>{try{const ge=await Dt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ge.ok)return;const ne=await ge.json().catch(()=>null);!se&&Array.isArray(ne?.authenticatedProviders)&&_(ne.authenticatedProviders.filter(Se=>typeof Se=="string"))}catch{}})(),()=>{se=!0}},[]);const De=d.useMemo(()=>{if(!$.providerId||!$.modelId)return[];const ge=y.find(ne=>ne.id===$.providerId)?.models.find(ne=>ne.id===$.modelId);return hg(ge?.variants)},[$.modelId,$.providerId,y]),ve=De.length>0;return ee?null:s.jsx(s.Fragment,{children:s.jsx(Ve,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-4 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",$.providerId?s.jsxs("span",{className:"text-foreground",children:[$.providerId,"/",$.modelId,ve?` (${C??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),T&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:T})]})]}),s.jsxs("div",{className:ws,children:[s.jsx(ht,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ga,{providerId:$.providerId,modelId:$.modelId,onChange:H,className:en,offerAuto:!0})}),s.jsx(ht,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Tt,{value:C??W,onValueChange:te,disabled:!ve,children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:Z(C??W)})}),s.jsxs(At,{children:[s.jsx(at,{value:W,children:t("settings.openchamber.defaults.option.default")}),De.map(se=>s.jsx(at,{value:se,children:Z(se)},se))]})]})}),s.jsx(ht,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(jl,{agentName:T||"",onChange:J,filter:se=>bo(se.mode),className:en})}),j?null:s.jsx(Ow,{agentName:T})]}),s.jsxs(Hn,{className:bs,children:[s.jsx(st,{settingsItem:"sessions.deletion-dialog",checked:v,onChange:N,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx(Mw,{}),j?null:s.jsx(st,{settingsItem:"sessions.show-chats",checked:x,onChange:se=>{S(se),gt({sidebarShowChatsSection:se})},label:t("settings.openchamber.defaults.field.showChats"),ariaLabel:t("settings.openchamber.defaults.field.showChats")})]}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ln,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Gt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(st,{settingsItem:"sessions.small-model",checked:z,onChange:se=>{ie(se)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),z?null:s.jsx(ht,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ga,{providerId:Y.providerId,modelId:Y.modelId,onChange:pe,allowedProviderIds:F,className:en})}),s.jsxs(Hn,{className:bs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ln,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Gt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(ht,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ga,{providerId:be.providerId,modelId:be.modelId,onChange:X,allowedProviderIds:F,isModelAllowed:xe,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:en})})]})]})]})})})},Md={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"}},zw={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"},Uw=()=>{const{t}=ze(),e=d.useMemo(()=>rs(),[]),a=d.useMemo(()=>is(),[]),n=d.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),o=!e&&!a&&!n,i=re(L=>L.nativeNotificationsEnabled),r=re(L=>L.setNativeNotificationsEnabled),l=re(L=>L.notificationMode),u=re(L=>L.setNotificationMode),m=re(L=>L.notifyOnSubtasks),c=re(L=>L.setNotifyOnSubtasks),f=re(L=>L.notifyOnCompletion),p=re(L=>L.setNotifyOnCompletion),g=re(L=>L.notifyOnError),h=re(L=>L.setNotifyOnError),k=re(L=>L.notifyOnQuestion),b=re(L=>L.setNotifyOnQuestion),j=re(L=>L.notificationTemplates),x=re(L=>L.setNotificationTemplates),[S,v]=d.useState("default"),[N,y]=d.useState(!1),[I,w]=d.useState(!1),[D,C]=d.useState(!1);d.useEffect(()=>{if(!o){y(!1),w(!1);return}typeof Notification<"u"&&v(Notification.permission);const L=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;y(L),(async()=>{if(!L){w(!1);return}try{const H=await navigator.serviceWorker.getRegistration();if(!H){w(!1);return}const W=await H.pushManager.getSubscription();w(!!W)}catch{w(!1)}})()},[o]);const A=async L=>{if(e){r(L);return}if(!o){r(L);return}if(L&&typeof Notification<"u"&&Notification.permission==="default")try{const $=await Notification.requestPermission();v($),$==="granted"?r(!0):G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch($){console.error("Failed to request notification permission:",$),G.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else r(!!(L&&S==="granted"))},T=e||a||n||o&&typeof Notification<"u"&&Notification.permission==="granted",O=(L,$,H)=>{x(W=>({...W,[L]:{...W[L],[$]:H}}))},z=L=>{const $="=".repeat((4-L.length%4)%4),H=(L+$).replace(/-/g,"+").replace(/_/g,"/"),W=atob(H),Z=new Uint8Array(W.length);for(let te=0;te<W.length;te+=1)Z[te]=W.charCodeAt(te);return Z},M=async(L,$,H)=>{let W=null;const Z=new Promise((te,J)=>{W=setTimeout(()=>{J(new Error(H))},$)});try{return await Promise.race([L,Z])}finally{W&&clearTimeout(W)}},P=async L=>{if(L.active)return;const $=L.installing||L.waiting;$&&$.state!=="activated"&&await M(new Promise(H=>{const W=()=>{$.state==="activated"&&($.removeEventListener("statechange",W),H())};$.addEventListener("statechange",W),W()}),15e3,"Service worker activation timed out")},R=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const L=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let $=null;for(const H of L)try{const W=H.opts?navigator.serviceWorker.register("/sw.js",H.opts):navigator.serviceWorker.register("/sw.js");return await M(W,1e4,`Service worker registration timed out (${H.label})`)}catch(W){$=W}throw $ instanceof Error?$:new Error("Service worker registration failed")},F=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const L=await navigator.serviceWorker.getRegistration();if(L)return L;const $=await R();try{await $.update()}catch{}return await P($),$},_=L=>{const $=L,H=[`type=${typeof L}`,`toString=${String(L)}`,`name=${String($?.name??"")}`,`message=${String($?.message??"")}`];let W="";try{W=JSON.stringify(L)}catch{}return{summary:H.filter(Boolean).join(" | "),json:W,stack:typeof $?.stack=="string"?$.stack:""}},B=async()=>{const L=ha();if(!L?.notifications){G.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await L.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?G.success(t("settings.notifications.page.toast.testNotificationSent")):G.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch($){console.error("Test notification failed:",$),G.error(t("settings.notifications.page.toast.testNotificationFailed"))}},V=async()=>{if(!N){G.error(t("settings.notifications.page.toast.pushUnsupported"));return}const L=ha();if(!L?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const pe=await Notification.requestPermission();if(v(pe),pe!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const $=await L.push.getVapidPublicKey();if(!$?.publicKey){G.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const H=await F();await P(H);const W=await H.pushManager.getSubscription();if(!("pushManager"in H)||!H.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const te=(W??await M(H.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:z($.publicKey)}),15e3,"Push subscription timed out")).toJSON(),J=te.keys;if(!te.endpoint||!J?.p256dh||!J.auth)throw new Error("Push subscription missing keys");if(!(await M(L.push.subscribe({endpoint:te.endpoint,keys:{p256dh:J.p256dh,auth:J.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:nf()}),15e3,"Push subscribe request timed out"))?.ok){G.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}w(!0),G.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch($){console.error("[Push] Enable failed:",$);const H=_($);G.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:H.summary})}finally{C(!1)}},ee=async()=>{if(!N){w(!1);return}const L=ha();if(!L?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{const H=await(await F()).pushManager.getSubscription();if(!H){w(!1);return}const W=H.endpoint;await H.unsubscribe(),await L.push.unsubscribe({endpoint:W}),w(!1),G.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{C(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Ve,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:bs,children:[s.jsx(st,{checked:i&&T,onChange:L=>{A(L)},label:t("settings.notifications.page.delivery.enableLabel"),info:o?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&T&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(st,{checked:l==="always",onChange:L=>u(L?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(q,{type:"button",variant:"outline",size:"sm",onClick:()=>{B()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),o&&s.jsxs("div",{className:"mt-1",children:[S==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),S==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&T&&s.jsxs(s.Fragment,{children:[s.jsx(Ve,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(st,{checked:f,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(st,{checked:m,onChange:c,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(st,{checked:g,onChange:h,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(st,{checked:k,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Ve,{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(Pn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(L=>s.jsxs("section",{className:"p-2",children:[s.jsx(Ln,{className:"capitalize",children:t(zw[L])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Be,{value:j[L].title,onChange:$=>O(L,"title",$.target.value),className:"h-7",placeholder:t(Md[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:j[L].message,onChange:$=>O(L,"message",$.target.value),className:"h-7",placeholder:t(Md[L].messageKey)})]})]})]},L))})})]}),o&&s.jsx(Ve,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(st,{checked:N?I:!1,disabled:!N||D,onChange:L=>{L?V():ee()},label:t("settings.notifications.page.push.enableLabel"),description:N?void 0:t("settings.notifications.page.push.unsupportedHint"),info:N?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:D?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Es=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Vn="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",$w=[{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"}],Rd=t=>{const e=Ke.c(8),{value:a,label:n}=t,o=`${n}: ${a}/5`,i=`${a/5*100}%`;let r;e[0]!==i?(r=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:i}})}),e[0]=i,e[1]=r):r=e[1];let l;e[2]!==n?(l=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=l):l=e[3];let u;return e[4]!==o||e[5]!==r||e[6]!==l?(u=s.jsxs("span",{className:"flex items-center gap-1.5",title:o,children:[r,l]}),e[4]=o,e[5]=r,e[6]=l,e[7]=u):u=e[7],u},_w=({selectedModelId:t,onSelect:e})=>{const{t:a}=ze(),n=_e.useCallback(p=>a(p),[a]),[o,i]=_e.useState(new Map),[r,l]=_e.useState(null),u=_e.useCallback(async()=>{try{const p=await Dt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const g=await p.json();Array.isArray(g?.models)&&i(new Map(g.models.map(h=>[h.id,h])))}catch{}},[]);_e.useEffect(()=>{u()},[u]);const m=Array.from(o.values()).some(p=>p.downloading);_e.useEffect(()=>{if(!m)return;const p=setInterval(()=>{u()},2e3);return()=>clearInterval(p)},[m,u]);const c=async p=>{l(p);try{await Dt(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await u()}catch{}finally{l(null)}},f=async p=>{l(p);try{await Dt(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await u()}catch{}finally{l(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:$w.map(p=>{const g=t===p.id,h=o.get(p.id)??null;return s.jsx("div",{className:Ie("rounded-lg border border-[var(--interactive-border)] p-3",g&&"border-border bg-interactive-selection text-interactive-selection-foreground"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:k=>{(k.key===" "||k.key==="Enter")&&(k.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(wl,{checked:g,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:Ie("typography-ui-label font-normal",g?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Rd,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Rd,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),h?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:h?.installed?s.jsxs(s.Fragment,{children:[s.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:r===p.id,onClick:()=>{f(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(Q,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(Q,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):h?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Q,{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 h.downloadProgress=="number"?`${h.downloadProgress}%`:""})]}):s.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:r===p.id,onClick:()=>{c(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(Q,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},Bw=[{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)"}],hl="kokoro-en-v0_19",Vw="kokoro-multi-lang-v1_1",Hw=[{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)"}],xi=(t,e)=>`${t}:${e}`,qw=()=>{const[t,e]=_e.useState([]),[a,n]=_e.useState(null),o=_e.useCallback(async()=>{try{const l=await Dt("/api/dictation/status",{query:{provider:"local"}});if(!l.ok)return;const u=await l.json();Array.isArray(u?.ttsModels)&&e(u.ttsModels)}catch{}},[]);_e.useEffect(()=>{o()},[o]);const i=t.some(l=>l.downloading);_e.useEffect(()=>{if(!i)return;const l=setInterval(()=>{o()},2e3);return()=>clearInterval(l)},[i,o]);const r=_e.useCallback(async(l,u)=>{n(l);try{const m=u==="POST"?`/api/dictation/models/${l}/download`:`/api/dictation/models/${l}`;await Dt(m,{method:u}),await o()}catch{}finally{n(null)}},[o]);return{models:t,requestingId:a,request:r,refresh:o}},Gw=t=>{const e=Bw.map(a=>({modelId:hl,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===hl||!a.installed)){if(a.id===Vw){for(const n of Hw)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},Od=t=>{const e=Ke.c(16),{model:a,requestingId:n,request:o,t:i}=t,r=a.description??a.id;let l;e[0]!==r?(l=s.jsx("span",{className:"typography-ui-label text-foreground",children:r}),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==a.downloadProgress||e[3]!==a.downloading||e[4]!==a.id||e[5]!==a.installed||e[6]!==o||e[7]!==n||e[8]!==i?(u=a.installed?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{o(a.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(Q,{name:"delete-bin",className:"h-4 w-4"})})]}):a.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Q,{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 a.downloadProgress=="number"?`${a.downloadProgress}%`:""})]}):s.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{o(a.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(Q,{name:"download",className:"h-4 w-4"})}),e[2]=a.downloadProgress,e[3]=a.downloading,e[4]=a.id,e[5]=a.installed,e[6]=o,e[7]=n,e[8]=i,e[9]=u):u=e[9];let m;e[10]!==a.downloadError?(m=a.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:a.downloadError}):null,e[10]=a.downloadError,e[11]=m):m=e[11];let c;return e[12]!==l||e[13]!==u||e[14]!==m?(c=s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[l,u,m]}),e[12]=l,e[13]=u,e[14]=m,e[15]=c):c=e[15],c},Ww=t=>{const e=Ke.c(21),{models:a,requestingId:n,request:o}=t,{t:i}=ze(),[r,l]=_e.useState(!1),[u,m]=_e.useState("");if(a.length===0)return null;let c,f,p;if(e[0]!==u||e[1]!==a){f=[],c=[];for(const x of a)x.id===hl||x.installed||x.downloading||x.downloadError?f.push(x):c.push(x);const j=u.trim().toLowerCase();p=j?c.filter(x=>(x.description??"").toLowerCase().includes(j)||x.id.toLowerCase().includes(j)):c,e[0]=u,e[1]=a,e[2]=c,e[3]=f,e[4]=p}else c=e[2],f=e[3],p=e[4];const g=p;let h;e[5]!==f||e[6]!==o||e[7]!==n||e[8]!==i?(h=f.map(j=>s.jsx(Od,{model:j,requestingId:n,request:o,t:i},j.id)),e[5]=f,e[6]=o,e[7]=n,e[8]=i,e[9]=h):h=e[9];let k;e[10]!==c.length||e[11]!==r||e[12]!==u||e[13]!==g||e[14]!==o||e[15]!==n||e[16]!==i?(k=c.length>0?s.jsxs(Gs,{open:r,onOpenChange:l,children:[s.jsxs(Ws,{className:"group flex w-full items-center justify-between py-1 hover:bg-transparent",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:i("settings.voice.page.localTts.availableToDownload")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",c.length,")"]})]}),s.jsx(Q,{name:r?"arrow-down-s":"arrow-right-s",className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})]}),s.jsxs(Js,{className:"pt-1",children:[s.jsx("input",{type:"text",value:u,onChange:j=>m(j.target.value),placeholder:i("settings.voice.page.localTts.filterPlaceholder"),"aria-label":i("settings.voice.page.localTts.filterPlaceholder"),className:Ie(Vn,"mb-1")}),g.length===0?s.jsx("div",{className:"typography-meta py-1.5 text-muted-foreground",children:i("settings.voice.page.localTts.filterNoMatch")}):g.map(j=>s.jsx(Od,{model:j,requestingId:n,request:o,t:i},j.id))]})]}):null,e[10]=c.length,e[11]=r,e[12]=u,e[13]=g,e[14]=o,e[15]=n,e[16]=i,e[17]=k):k=e[17];let b;return e[18]!==h||e[19]!==k?(b=s.jsxs("div",{className:"flex flex-col",children:[h,k]}),e[18]=h,e[19]=k,e[20]=b):b=e[20],b},Jw=[{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"}],Br=t=>{const e=Ke.c(34),{kind:a}=t,{t:n}=ze();let o;e[0]!==a?(o=I=>I.voiceApiKeys[a],e[0]=a,e[1]=o):o=e[1];const i=rt(o),r=rt(Yw),[l,u]=_e.useState(""),[m,c]=_e.useState(!1);let f;e[2]!==a||e[3]!==r||e[4]!==n?(f=async I=>{c(!0);const w=await r(a,I);c(!1),w?u(""):G.error(n("settings.voice.page.toast.apiKeySaveFailed"))},e[2]=a,e[3]=r,e[4]=n,e[5]=f):f=e[5];const p=f;let g;e[6]!==l||e[7]!==p?(g=()=>{const I=l.trim();I&&p(I)},e[6]=l,e[7]=p,e[8]=g):g=e[8];const h=g;let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=Ie("relative",ks),e[9]=k):k=e[9];let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=I=>u(I.target.value),e[10]=b):b=e[10];let j;e[11]!==h?(j=I=>{I.key==="Enter"&&h()},e[11]=h,e[12]=j):j=e[12];let x;e[13]!==i||e[14]!==n?(x=i?n("settings.voice.page.field.apiKeySavedPlaceholder"):"sk-...",e[13]=i,e[14]=n,e[15]=x):x=e[15];let S;e[16]!==n?(S=n("settings.voice.page.field.apiKey"),e[16]=n,e[17]=S):S=e[17];let v;e[18]!==h||e[19]!==l||e[20]!==m||e[21]!==j||e[22]!==x||e[23]!==S?(v=s.jsx("input",{type:"password",value:l,disabled:m,onChange:b,onBlur:h,onKeyDown:j,placeholder:x,className:Vn,"aria-label":S}),e[18]=h,e[19]=l,e[20]=m,e[21]=j,e[22]=x,e[23]=S,e[24]=v):v=e[24];let N;e[25]!==l||e[26]!==m||e[27]!==p||e[28]!==i||e[29]!==n?(N=i&&!l&&s.jsx("button",{type:"button",onClick:()=>{p(null)},disabled:m,"aria-label":n("settings.voice.page.field.apiKeyRemove"),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Q,{name:"close",className:"w-3.5 h-3.5"})}),e[25]=l,e[26]=m,e[27]=p,e[28]=i,e[29]=n,e[30]=N):N=e[30];let y;return e[31]!==N||e[32]!==v?(y=s.jsxs("div",{className:k,children:[v,N]}),e[31]=N,e[32]=v,e[33]=y):y=e[33],y},Qw=()=>{const{t}=ze(),{isMobile:e}=qn(),a=rt(ae=>ae.voiceProvider),n=rt(ae=>ae.setVoiceProvider),o=rt(ae=>ae.speechRate),i=rt(ae=>ae.setSpeechRate),r=rt(ae=>ae.speechPitch),l=rt(ae=>ae.setSpeechPitch),u=rt(ae=>ae.speechVolume),m=rt(ae=>ae.setSpeechVolume),c=rt(ae=>ae.sayVoice),f=rt(ae=>ae.setSayVoice),p=rt(ae=>ae.localTtsVoiceId),g=rt(ae=>ae.localTtsModelId),h=rt(ae=>ae.setLocalTtsModelId),k=qw(),b=_e.useMemo(()=>Gw(k.models),[k.models]),j=rt(ae=>ae.ttsFollowTextLanguage),x=rt(ae=>ae.setTtsFollowTextLanguage),S=rt(ae=>ae.setLocalTtsVoiceId),{speak:v,stop:N,isPlaying:y,error:I}=bg(),w=_e.useCallback(()=>{if(y){N();return}const ae=b.find(fe=>fe.modelId===g&&fe.speakerId===p)?.label??String(p);v(t("settings.voice.page.preview.voiceLine",{voiceName:ae}),{model:g,speakerId:p,speed:rt.getState().speechRate})},[y,g,p,b,v,N,t]),D=rt(ae=>ae.browserVoice),C=rt(ae=>ae.setBrowserVoice),A=rt(ae=>ae.openaiVoice),T=rt(ae=>ae.setOpenaiVoice),O=rt(ae=>ae.voiceApiKeys.openai),z=rt(ae=>ae.refreshVoiceApiKeys),M=rt(ae=>ae.openaiCompatibleUrl),P=rt(ae=>ae.setOpenaiCompatibleUrl),R=rt(ae=>ae.openaiCompatibleVoice),F=rt(ae=>ae.setOpenaiCompatibleVoice),_=rt(ae=>ae.openaiCompatibleTtsModel),B=rt(ae=>ae.setOpenaiCompatibleTtsModel),V=rt(ae=>ae.showMessageTTSButtons),ee=rt(ae=>ae.ttsInputMode),L=rt(ae=>ae.setTtsInputMode),$=rt(ae=>ae.ttsChunkedMode),H=rt(ae=>ae.setTtsChunkedMode),W=rt(ae=>ae.sttProvider),Z=rt(ae=>ae.setSttProvider),te=rt(ae=>ae.sttServerUrl),J=rt(ae=>ae.setSttServerUrl),ie=rt(ae=>ae.sttModel),pe=rt(ae=>ae.setSttModel),X=rt(ae=>ae.sttLocalModel),xe=rt(ae=>ae.setSttLocalModel),Y=rt(ae=>ae.sttLanguage),be=rt(ae=>ae.setSttLanguage),De=rt(ae=>ae.setShowMessageTTSButtons),ve=rt(ae=>ae.dictationEnabled),se=rt(ae=>ae.setDictationEnabled),[ge,ne]=_e.useState(!1),[Se,ke]=_e.useState([]),[Te,Ee]=_e.useState(!1),[Le,ce]=_e.useState(null),[Me,Fe]=_e.useState(!1),[me,de]=_e.useState(!1),[Pe,he]=_e.useState(!1),[Ue,Ae]=_e.useState(null),[Re,$e]=_e.useState(!1),[nt,pt]=_e.useState(null),[kt,bt]=_e.useState([]),[yt,Je]=_e.useState(!1);_e.useEffect(()=>((async()=>{const fe=await vr.waitForVoices();bt(fe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{bt(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ct=_e.useMemo(()=>kt.filter(ae=>ae.lang).sort((ae,fe)=>{const ye=ae.lang.startsWith("en"),we=fe.lang.startsWith("en");if(ye&&!we)return-1;if(!ye&&we)return 1;const Ge=ae.lang.localeCompare(fe.lang);return Ge!==0?Ge:ae.name.localeCompare(fe.name)}),[kt]),Qe=_e.useCallback(()=>{if(yt){vr.cancelSpeech(),Je(!1);return}const ae=kt.find(Ge=>Ge.name===D),fe=ae?.name??t("settings.voice.page.preview.browserVoiceFallback"),ye=t("settings.voice.page.preview.voiceLine",{voiceName:fe});Je(!0);const we=new SpeechSynthesisUtterance(ye);we.rate=o,we.pitch=r,we.volume=u,ae&&(we.voice=ae,we.lang=ae.lang),we.onend=()=>Je(!1),we.onerror=()=>Je(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(we)},[D,kt,o,r,u,yt,t]);_e.useEffect(()=>()=>{yt&&vr.cancelSpeech()},[yt]),_e.useEffect(()=>{z({force:!0})},[z]),_e.useEffect(()=>{if(!V||a!=="openai"&&a!=="openai-compatible"){Fe(O);return}(async()=>{try{const ye=await(await Dt("/api/tts/status")).json(),we=ye.available,Ge=O,et=ye.enterpriseMode===!0;de(et),Fe(!et&&(we||Ge))}catch{Fe(O)}})()},[O,V,a]),_e.useEffect(()=>{if(!V){ne(!1),ke([]);return}Dt("/api/tts/say/status").then(ae=>ae.json()).then(ae=>{if(ne(ae.available),ae.voices){const fe=ae.voices.filter((ye,we,Ge)=>Ge.findIndex(et=>et.name===ye.name)===we).sort((ye,we)=>ye.name.localeCompare(we.name));ke(fe)}}).catch(()=>{ne(!1)})},[V]);const it=_e.useCallback(async()=>{if(Le){Es(Le),ce(null),Ee(!1);return}Ee(!0);let ae=null;try{const fe=await Dt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:c}),voice:c,rate:Math.round(100+(o-.5)*200)})});if(!fe.ok)throw new Error("Preview failed");const ye=await fe.blob(),we=URL.createObjectURL(ye);ae=new Audio(we),ae.onended=()=>{Es(ae),ce(null),Ee(!1)},ae.onerror=()=>{Es(ae),ce(null),Ee(!1)},ce(ae),await ae.play()}catch{Es(ae),ce(null),Ee(!1)}},[c,o,Le,t]);_e.useEffect(()=>()=>{Es(Le)},[Le]);const dt=_e.useCallback(async()=>{if(Ue){Es(Ue),Ae(null),he(!1);return}he(!0);let ae=null;try{const fe=await Dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:A}),voice:A,speed:o})});if(!fe.ok){const Ge=await fe.json().catch(()=>({error:"Unknown error"}));throw new Error(Ge.error||`HTTP ${fe.status}`)}const ye=await fe.blob(),we=URL.createObjectURL(ye);ae=new Audio(we),ae.onended=()=>{Es(ae),Ae(null),he(!1)},ae.onerror=()=>{Es(ae),Ae(null),he(!1)},Ae(ae),await ae.play()}catch{Es(ae),Ae(null),he(!1)}},[A,o,Ue,t]);_e.useEffect(()=>()=>{Es(Ue)},[Ue]);const qe=_e.useCallback(async()=>{if(nt){Es(nt),pt(null),$e(!1);return}if(!M.trim())return;$e(!0);let ae=null;try{const fe=await Dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:R,model:_||void 0,speed:o,baseURL:M})});if(!fe.ok){const Ge=await fe.json().catch(()=>({error:"Unknown error"}));throw new Error(Ge.error||`HTTP ${fe.status}`)}const ye=await fe.blob(),we=URL.createObjectURL(ye);ae=new Audio(we),ae.onended=()=>{Es(ae),pt(null),$e(!1)},ae.onerror=()=>{Es(ae),pt(null),$e(!1)},pt(ae),await ae.play()}catch{Es(ae),pt(null),$e(!1)}},[M,R,_,o,nt,t]);_e.useEffect(()=>()=>{Es(nt)},[nt]);const lt="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(Ve,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(st,{checked:V,onChange:De,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),V&&s.jsxs(s.Fragment,{children:[s.jsx(vs,{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(Vs,{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")},...ge?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),me&&(a==="openai"||a==="openai-compatible")&&s.jsx("p",{className:Mt,children:t("settings.voice.page.enterpriseMode")}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ie(Nt,!Me&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Ie(Mt,!Me&&"text-[var(--status-error)]/80"),children:t(Me&&!O?"settings.voice.page.field.apiKeyHintUsingConfig":Me?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsx(Br,{kind:"openai"})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ie(Nt,!M.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Gt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:Ie("relative",ks),children:[s.jsx("input",{type:"text",value:M,onChange:ae=>P(ae.target.value),placeholder:"http://localhost:8880/v1",className:Vn}),M&&s.jsx("button",{type:"button",onClick:()=>P(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Q,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Mt,children:t("settings.voice.page.field.apiKeyOptional")}),s.jsx(Br,{kind:"openaiCompatible"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",ks),children:s.jsx("input",{type:"text",value:_,onChange:ae=>B(ae.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:Vn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.voice")}),s.jsx(Gt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:Ie("flex items-center gap-2",ks),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:R,onChange:ae=>F(ae.target.value),placeholder:"af_sky",className:Vn})}),s.jsx(q,{size:"xs",variant:"ghost",onClick:qe,title:t("settings.voice.page.actions.preview"),disabled:!M.trim(),children:Re?s.jsx(Q,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(Q,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Ww,{...k}),(a==="local"||a==="say")&&s.jsx(st,{checked:j,onChange:x,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(ht,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:xi(g,p),onValueChange:ae=>{const fe=b.find(ye=>xi(ye.modelId,ye.speakerId)===ae);fe&&(h(fe.modelId),S(fe.speakerId))},children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:ae=>b.find(fe=>xi(fe.modelId,fe.speakerId)===ae)?.label??ae})}),s.jsx(At,{children:b.map(ae=>s.jsx(at,{value:xi(ae.modelId,ae.speakerId),children:ae.label},xi(ae.modelId,ae.speakerId)))})]}),s.jsx(q,{size:"xs",variant:"ghost",onClick:w,title:t("settings.voice.page.actions.preview"),children:y?s.jsx(Q,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(Q,{name:"play",className:"w-3.5 h-3.5"})}),I?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:I}):null]}),a==="openai"&&Me&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:A,onValueChange:T,children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Jw.map(ae=>s.jsx(at,{value:ae.value,children:ae.label},ae.value))})]}),s.jsx(q,{size:"xs",variant:"ghost",onClick:dt,title:t("settings.voice.page.actions.preview"),children:Pe?s.jsx(Q,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(Q,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Mt,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ge&&Se.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:c,onValueChange:f,children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Se.map(ae=>s.jsx(at,{value:ae.name,children:ae.name},ae.name))})]}),s.jsx(q,{size:"xs",variant:"ghost",onClick:it,title:t("settings.voice.page.actions.preview"),children:Te?s.jsx(Q,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(Q,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&ct.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Tt,{value:D||"$auto",onValueChange:ae=>C(ae==="$auto"?"":ae),children:[s.jsx(Pt,{size:_t,className:tn,children:s.jsx(Kt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(at,{value:"$auto",children:t("settings.voice.page.field.auto")}),ct.map(ae=>s.jsxs(at,{value:ae.name,children:[ae.name," (",ae.lang,")"]},ae.name))]})]}),s.jsx(q,{size:"xs",variant:"ghost",onClick:Qe,title:t("settings.voice.page.actions.preview"),children:yt?s.jsx(Q,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(Q,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(ht,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:o,onChange:ae=>i(Number(ae.target.value)),className:lt}),s.jsx(ps,{value:o,onValueChange:i,min:.5,max:2,step:.1,className:Ie(xs,"tabular-nums")})]}),s.jsxs(ht,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:ae=>l(Number(ae.target.value)),className:lt}),s.jsx(ps,{value:r,onValueChange:l,min:.5,max:2,step:.1,className:Ie(xs,"tabular-nums")})]}),s.jsxs(ht,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:ae=>m(Number(ae.target.value)),className:lt}),e?s.jsx(ps,{value:Math.round(u*100),onValueChange:ae=>m(ae/100),min:0,max:100,step:10,className:Ie(xs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]}),s.jsx(vs,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Vs,{value:ee,onChange:L,"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")}]})}),(a==="openai"||a==="openai-compatible")&&s.jsx(st,{checked:$,onChange:H,label:t("settings.voice.page.field.ttsChunkedMode"),ariaLabel:t("settings.voice.page.field.ttsChunkedModeAria"),info:t("settings.voice.page.tooltip.ttsChunked")})]})]}),s.jsxs(Ve,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(st,{checked:ve,onChange:se,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ve&&s.jsxs(s.Fragment,{children:[s.jsx(vs,{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(Vs,{value:W,onChange:Z,"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")}]})}),W==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx(_w,{selectedModelId:X,onSelect:xe})]}),W==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ie(Nt,!te.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Gt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:Ie("relative",ks),children:[s.jsx("input",{type:"text",value:te,onChange:ae=>J(ae.target.value),placeholder:"http://localhost:8001/v1",className:Vn}),te&&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(Q,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Mt,children:t("settings.voice.page.field.apiKeyOptional")}),s.jsx(Br,{kind:"stt"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Ie("relative",ks),children:s.jsx("input",{type:"text",value:ie,onChange:ae=>pe(ae.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:Vn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Nt,children:t("settings.voice.page.field.language")}),s.jsx(Gt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Y,onChange:ae=>be(ae.target.value),placeholder:"auto",className:Vn})})]})]})]})]})]})};function Yw(t){return t.setVoiceApiKey}const lo=[{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}],co=[{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}],Zw="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Xw="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Vr=[{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"}],e2=[".yml",".yaml",".json"],t2="settings.openchamber.tunnel.error.invalidConfigExtension",vi=t=>{const e=t.trim().toLowerCase();return e2.some(a=>e.endsWith(a))},s2=t=>t==="ngrok"?"ngrok":"cloudflared",vm=()=>{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"},n2=(t,e=vm())=>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/",Hr=(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():s2(a),o=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():vm(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():n2(a,o);return{provider:a,dependency:n,installCommand:i}},ym=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Fd=t=>{const e=Ke.c(11),{provider:a}=t;let n;e[0]!==a?(n=ym(a),e[0]=a,e[1]=n):n=e[1];const o=n,l=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let u;e[2]!==l?(u=Ie("size-4 shrink-0",l),e[2]=l,e[3]=u):u=e[3];let m;e[4]!==u?(m=s.jsx(Q,{name:"cloud",className:u}),e[4]=u,e[5]=m):m=e[5];let c;e[6]!==o?(c=s.jsx("span",{children:o}),e[6]=o,e[7]=c):c=e[7];let f;return e[8]!==m||e[9]!==c?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[m,c]}),e[8]=m,e[9]=c,e[10]=f):f=e[10],f},Bn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",bl=(t,e,a)=>t.find(o=>o.ms===e)?.value||a,Ld=(t,e,a)=>{const n=bl(t,e,a);return t.find(o=>o.value===n)?.label||n},Kd=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),o=Math.floor(a%3600/60),i=a%60;return n>0?`${n}h ${o}m`:o>0?`${o}m ${i}s`:`${i}s`},a2=(t,e)=>Zd(t,e,{hour:"2-digit",precision:"second"}),ho=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()}},i2=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const o of t){if(!o||typeof o!="object")continue;const i=o,r=typeof i.id=="string"?i.id.trim():"",l=typeof i.name=="string"?i.name.trim():"",u=ho(typeof i.hostname=="string"?i.hostname:"");!r||!l||!u||e.has(r)||a.has(u)||(e.add(r),a.add(u),n.push({id:r,name:l,hostname:u}))}return n},o2=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,r2=()=>{const{t}=ze(),e=re(K=>K.timeFormatPreference),a=d.useCallback(K=>t(K),[t]),[n,o]=d.useState("checking"),[i,r]=d.useState(!1),[l,u]=d.useState(null),[m,c]=d.useState(null),[f,p]=d.useState(null),[g,h]=d.useState(null),[k,b]=d.useState(null),[j,x]=d.useState(!1),[S,v]=d.useState(!1),[N,y]=d.useState(!1),[I,w]=d.useState("cloudflare"),[D,C]=d.useState(()=>Hr("cloudflare")),[A,T]=d.useState([]),[O,z]=d.useState("quick"),[M,P]=d.useState(null),[R,F]=d.useState([]),[_,B]=d.useState({}),[V,ee]=d.useState(""),[L,$]=d.useState({}),[H,W]=d.useState(new Set),[Z,te]=d.useState(!1),[J,ie]=d.useState(""),[pe,X]=d.useState(""),[xe,Y]=d.useState(""),[be,De]=d.useState(1800*1e3),[ve,se]=d.useState(480*60*1e3),[ge,ne]=d.useState(""),[Se,ke]=d.useState([]),[Te,Ee]=d.useState(()=>Date.now()),[Le,ce]=d.useState(null),Me=t(t2),Fe=d.useRef(null),me=d.useMemo(()=>M?!vi(M):!1,[M]),de=d.useMemo(()=>R.find(K=>K.id===V)||R[0]||null,[R,V]),Pe=d.useMemo(()=>Se.map(K=>{const ue=K.expiresAt<=Te,Ne=K.status==="active"&&!ue,Ce=Ne?Kd(K.expiresAt-Te):K.inactiveReason==="expired"||ue?"expired":"inactive",He=Ce==="expired"?t("settings.openchamber.tunnel.state.expired"):K.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),le=Bn(K.mode);return{...K,isActive:Ne,mode:le,remainingTextForSession:Ce,inactiveLabel:He}}),[Te,Se,t]),he=d.useMemo(()=>l?.connectUrl?l.bootstrapExpiresAt===null?!0:l.bootstrapExpiresAt>Te:!1,[Te,l?.bootstrapExpiresAt,l?.connectUrl]),Ue=d.useMemo(()=>!l||n!=="active"&&n!=="stopping"?!1:m===O,[m,n,l,O]),Ae=d.useMemo(()=>!l||n!=="active"||!m?!1:m!==O,[m,n,l,O]),Re=d.useMemo(()=>{if(typeof Le=="number"&&Number.isFinite(Le)&&Le>0)return Le;if(typeof window>"u")return null;const ue=Ei()||window.location.href;let Ne=0;try{Ne=Number(new URL(ue).port)}catch{Ne=Number(window.location.port)}return Number.isFinite(Ne)&&Ne>0?Ne:null},[Le]),$e=d.useMemo(()=>A.find(K=>K.provider===I)??null,[A,I]),nt=d.useMemo(()=>{const K=new Set($e?.modes?.map(ue=>ue.key).filter(ue=>ue==="quick"||ue==="managed-remote"||ue==="managed-local"));return K.size===0?Vr:Vr.filter(ue=>K.has(ue.value))},[$e]),pt=d.useMemo(()=>nt.some(K=>K.value==="managed-remote"||K.value==="managed-local"),[nt]),kt=d.useMemo(()=>D.provider===I?D:Hr(I),[D,I]),bt=d.useCallback(async K=>{await Ss(K)},[]),yt=d.useCallback((K,ue)=>(C(Hr(ue,K)),K.available===!0),[]),Je=d.useCallback(async(K,ue)=>{try{const Ne=await Dt("/api/openchamber/tunnel/check",{query:{provider:K},...ue?{signal:ue}:{}});if(!Ne.ok)return null;const Ce=await Ne.json();if(ue?.aborted)return null;const He=yt(Ce,K);return o(le=>le==="checking"||le==="starting"||le==="active"||le==="stopping"?le:He?"idle":"not-available"),He}catch{return null}},[yt]),ct=d.useCallback(async K=>{try{const[ue,Ne,Ce,He]=await Promise.all([Dt("/api/openchamber/tunnel/check",{signal:K}),Dt("/api/openchamber/tunnel/status",{signal:K}),jn(),Dt("/api/openchamber/tunnel/providers",{signal:K})]),le=await ue.json(),Oe=await Ne.json(),ot=Ce??{},Rt=He.ok?await He.json():{},It=Oe.ttlConfig?.bootstrapTtlMs??(ot.tunnelBootstrapTtlMs===void 0?1800*1e3:ot.tunnelBootstrapTtlMs),os=typeof Oe.ttlConfig?.sessionTtlMs=="number"?Oe.ttlConfig.sessionTtlMs:ot.tunnelSessionTtlMs??480*60*1e3,Xe=Bn(Oe.mode??ot.tunnelMode),tt=ot.tunnelProvider??"cloudflare",qt=ot.managedLocalTunnelConfigPath??null,ss=yt(le,tt),fs=i2(Oe?.managedRemoteTunnelPresets),Jt=typeof Oe.managedRemoteTunnelHostname=="string"?Oe.managedRemoteTunnelHostname:"",Cs=fs.length>0?fs:Jt?[{id:`legacy-${ho(Jt)}`,name:Jt,hostname:ho(Jt)}]:[],kn=Cs[0]?.id||"";if(r(Oe.enterpriseMode===!0),De(It),se(os),w(tt),T(Array.isArray(Rt?.providers)?Rt.providers:[]),z(Xe),P(qt),F(Cs),ee(kn),ke(Array.isArray(Oe.activeSessions)?Oe.activeSessions:[]),c(Oe.activeTunnelMode?Bn(Oe.activeTunnelMode):Oe.active&&Oe.mode?Bn(Oe.mode):null),W(new Set(Array.isArray(Oe.managedRemoteTunnelTokenPresetIds)?Oe.managedRemoteTunnelTokenPresetIds:[])),ce(typeof Oe.localPort=="number"?Oe.localPort:null),Oe.active&&Oe.url){u({url:Oe.url,connectUrl:null,bootstrapExpiresAt:typeof Oe.bootstrapExpiresAt=="number"?Oe.bootstrapExpiresAt:null}),o("active");return}o(ss?"idle":"not-available")}catch{K.aborted||(o("error"),h(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[yt,t]);d.useEffect(()=>{const K=new AbortController;return ct(K.signal),()=>K.abort()},[ct]),d.useEffect(()=>{if(!l?.connectUrl){p(null);return}let K=!1;return vu.toDataURL(l.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(ue=>{K||p(ue)}).catch(()=>{K||p(null)}),()=>{K=!0}},[l?.connectUrl]),d.useEffect(()=>{if(!l?.bootstrapExpiresAt){ne(t("settings.openchamber.tunnel.state.noExpiry"));return}let K=null,ue=Date.now();const Ne=()=>{const le=l.bootstrapExpiresAt?l.bootstrapExpiresAt-Date.now():0;le<=0?ne(t("settings.openchamber.tunnel.state.expired")):ne(Kd(le))},Ce=()=>{const le=Date.now();le-ue>=1e3&&(Ne(),ue=le),K=requestAnimationFrame(Ce)};Ne(),(typeof document>"u"||document.visibilityState==="visible")&&(K=requestAnimationFrame(Ce));const He=()=>{document.visibilityState==="visible"&&K===null?K=requestAnimationFrame(Ce):document.visibilityState!=="visible"&&K!==null&&(cancelAnimationFrame(K),K=null)};return document.addEventListener("visibilitychange",He),()=>{document.removeEventListener("visibilitychange",He),K!==null&&cancelAnimationFrame(K)}},[t,l?.bootstrapExpiresAt]),d.useEffect(()=>{let K=null,ue=Date.now();const Ne=()=>{const He=Date.now();He-ue>=1e3&&(Ee(He),ue=He),K=requestAnimationFrame(Ne)};(typeof document>"u"||document.visibilityState==="visible")&&(K=requestAnimationFrame(Ne));const Ce=()=>{document.visibilityState==="visible"&&K===null?K=requestAnimationFrame(Ne):document.visibilityState!=="visible"&&K!==null&&(cancelAnimationFrame(K),K=null)};return document.addEventListener("visibilitychange",Ce),()=>{document.removeEventListener("visibilitychange",Ce),K!==null&&cancelAnimationFrame(K)}},[]),d.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let K=!1;const ue=async()=>{try{const Ce=await Dt("/api/openchamber/tunnel/status");if(!Ce.ok||K)return;const He=await Ce.json();if(K)return;ke(Array.isArray(He.activeSessions)?He.activeSessions:[]),W(new Set(Array.isArray(He.managedRemoteTunnelTokenPresetIds)?He.managedRemoteTunnelTokenPresetIds:[])),ce(typeof He.localPort=="number"?He.localPort:null)}catch{}},Ne=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ue()},5e3);return()=>{K=!0,window.clearInterval(Ne)}},[n]);const Qe=d.useCallback(async K=>{y(!0);try{await gt(K),Object.prototype.hasOwnProperty.call(K,"tunnelMode")&&K.tunnelMode&&z(K.tunnelMode),Object.prototype.hasOwnProperty.call(K,"tunnelProvider")&&typeof K.tunnelProvider=="string"&&w(K.tunnelProvider),Object.prototype.hasOwnProperty.call(K,"managedLocalTunnelConfigPath")&&P(K.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(K,"managedRemoteTunnelPresets")&&K.managedRemoteTunnelPresets&&F(K.managedRemoteTunnelPresets)}catch{G.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),it=d.useCallback(async(K,ue)=>{v(!0);try{await gt({tunnelBootstrapTtlMs:K,tunnelSessionTtlMs:ue})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{v(!1)}},[t]),dt=d.useCallback(async K=>{const ue=K.token.trim();if(ue)try{const Ne={...L,[K.presetId]:ue};await gt({managedRemoteTunnelPresetTokens:Ne}),W(Ce=>{const He=new Set(Ce);return He.add(K.presetId),He})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[L,t]),qe=d.useCallback(async K=>{b(null),h(null);const ue=A.find(Ce=>Ce.provider===K),Ne=ue?.modes?.some(Ce=>Ce.key===O)?O:Bn(ue?.modes?.[0]?.key);await Qe({tunnelProvider:K,tunnelMode:Ne}),Je(K)},[A,Je,Qe,O]),lt=d.useCallback(async()=>{const K=await El({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(K.success&&typeof K.path=="string"&&K.path.trim().length>0){const ue=K.path.trim();if(!vi(ue)){G.error(Me);return}P(ue),await Qe({managedLocalTunnelConfigPath:ue});return}Fe.current?.click()},[Me,Qe]),ae=d.useCallback(K=>{const ue=K.trim();P(ue.length>0?ue:null)},[]),fe=d.useCallback(async()=>{if(M&&!vi(M)){G.error(Me);return}await Qe({managedLocalTunnelConfigPath:M})},[Me,M,Qe]),ye=d.useCallback(async()=>{P(null),await Qe({managedLocalTunnelConfigPath:null})},[Qe]),we=d.useCallback(async K=>{const ue=K.target.files?.[0];if(!ue)return;const Ne=ue.name.trim();if(Ne.length!==0){if(!vi(Ne)){G.error(Me);return}P(Ne),await Qe({managedLocalTunnelConfigPath:Ne}),K.target.value=""}},[Me,Qe]),Ge=d.useCallback(async()=>{if(h(null),b(null),O==="managed-local"&&M&&!vi(M)){h(Me),G.error(Me);return}o("starting");try{let K="",ue="";if(O==="managed-remote"){if(!de){o("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),G.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}K=de.hostname,ue=(L[de.id]||"").trim(),await Qe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:R})}const Ne=await Dt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:O,...O==="managed-remote"&&de?{managedRemoteTunnelPresetId:de.id,managedRemoteTunnelPresetName:de.name}:{},...O==="managed-remote"&&K?{managedRemoteTunnelHostname:K}:{},...O==="managed-remote"&&ue?{managedRemoteTunnelToken:ue}:{},...O==="managed-local"&&M?{configPath:M}:{}})}),Ce=await Ne.json();if(!Ne.ok||!Ce.ok){if(O==="managed-remote"&&typeof Ce.error=="string"&&Ce.error.includes("Managed remote tunnel token is required")){o("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),G.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}o("error"),h(Ce.error||t("settings.openchamber.tunnel.toast.startFailed")),G.error(Ce.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const He=typeof Ce.url=="string"?Ce.url:"";if(!He){o("error"),h(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),G.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(u({url:He,connectUrl:typeof Ce.connectUrl=="string"?Ce.connectUrl:null,bootstrapExpiresAt:typeof Ce.bootstrapExpiresAt=="number"?Ce.bootstrapExpiresAt:null}),c(Ce.activeTunnelMode?Bn(Ce.activeTunnelMode):Ce.mode?Bn(Ce.mode):O),ke(Array.isArray(Ce.activeSessions)?Ce.activeSessions:[]),Array.isArray(Ce.managedRemoteTunnelTokenPresetIds)&&W(new Set(Ce.managedRemoteTunnelTokenPresetIds)),typeof Ce.localPort=="number"&&ce(Ce.localPort),typeof Ce.mode=="string"&&z(Bn(Ce.mode)),o("active"),Ce.replacedTunnel){const le=typeof Ce.revokedBootstrapCount=="number"?Ce.revokedBootstrapCount:0,Oe=typeof Ce.invalidatedSessionCount=="number"?Ce.invalidatedSessionCount:0;le===1&&Oe===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):le===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Oe})):Oe===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:le})):G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:le,invalidatedSessionCount:Oe}))}else G.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{o("error"),h(t("settings.openchamber.tunnel.toast.startFailed")),G.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Me,R,Qe,de,L,t,I,O,M]),et=d.useCallback(async()=>{o("stopping");try{await Dt("/api/openchamber/tunnel/stop",{method:"POST"});const K=await Dt("/api/openchamber/tunnel/status");if(K.ok){const ue=await K.json();ke(Array.isArray(ue.activeSessions)?ue.activeSessions:[]),W(new Set(Array.isArray(ue.managedRemoteTunnelTokenPresetIds)?ue.managedRemoteTunnelTokenPresetIds:[])),ce(typeof ue.localPort=="number"?ue.localPort:null)}u(null),c(null),p(null),o("idle"),G.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{o("error"),h(t("settings.openchamber.tunnel.toast.stopFailed")),G.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),mt=d.useCallback(async()=>{if(l?.connectUrl)try{await navigator.clipboard.writeText(l.connectUrl),x(!0),G.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{G.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,l?.connectUrl]),jt=d.useCallback(async K=>{const ue=lo.find(Ne=>Ne.value===K);ue&&(De(ue.ms),await it(ue.ms,ve))},[it,ve]),vt=d.useCallback(async K=>{const ue=co.find(Ne=>Ne.value===K);!ue||ue.ms===null||(se(ue.ms),await it(be,ue.ms))},[be,it]),Ct=d.useCallback(async K=>{b(null),h(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&o("idle"),await Qe({tunnelMode:K,managedRemoteTunnelPresets:R})},[R,Qe,n]),Bt=d.useCallback(async(K,ue)=>{try{await gt({managedRemoteTunnelPresets:ue})}catch{G.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ye=d.useCallback(K=>{const ue=R.find(Ne=>Ne.id===K);ue&&(ee(ue.id),b(null),Bt(ue,R))},[R,Bt]),Ze=d.useCallback(async()=>{const K=J.trim(),ue=ho(pe),Ne=xe.trim();if(!K){G.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!ue){G.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ne){G.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(R.some(le=>le.hostname===ue)){G.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ce={id:o2(),name:K,hostname:ue},He=[...R,Ce];F(He),ee(Ce.id),B(le=>({...le,[Ce.id]:!0})),$(le=>({...le,[Ce.id]:Ne})),b(null),te(!1),ie(""),X(""),Y(""),await Qe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:He,managedRemoteTunnelPresetTokens:{...L,[Ce.id]:Ne}}),await dt({presetId:Ce.id,presetName:Ce.name,hostname:Ce.hostname,token:Ne}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[R,pe,J,xe,dt,Qe,L,t]),ut=d.useCallback(async K=>{const ue=R.find(Oe=>Oe.id===K);if(!ue)return;const Ne=R.filter(Oe=>Oe.id!==ue.id),Ce=Ne[0]?.id||"",He=V===ue.id?Ce:V,le=Object.fromEntries(Object.entries(L).filter(([Oe,ot])=>Oe!==ue.id&&ot.trim().length>0));F(Ne),ee(He),B(Oe=>{const ot={...Oe};return delete ot[ue.id],ot}),$(Oe=>{const ot={...Oe};return delete ot[ue.id],ot}),W(Oe=>{const ot=new Set(Oe);return ot.delete(ue.id),ot}),b(null),await Qe({managedRemoteTunnelPresets:Ne,managedRemoteTunnelPresetTokens:le}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[R,Qe,V,L,t]),ft="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")})}):i?s.jsx(Ve,{title:t("settings.openchamber.tunnel.title"),divider:!1,children:s.jsx("p",{className:xn,children:t("settings.openchamber.tunnel.enterpriseMode")})}):s.jsx(Ve,{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:[Pe.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(Q,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Yr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Pe.map(K=>{const ue=K.mode==="quick",Ne=K.mode==="managed-remote",Ce=ue?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ne?"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)]",He=K.isActive?ue?"text-[var(--status-warning)]":Ne?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",le=t(ue?"settings.openchamber.tunnel.badge.quick":Ne?"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(Q,{name:"checkbox-blank-circle-fill",className:Ie("size-2.5 shrink-0",He)}),s.jsx("span",{className:Ie("typography-micro rounded border px-1.5 py-0.5 uppercase",Ce),children:le}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:a2(K.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:K.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:K.remainingTextForSession}):K.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:K.inactiveLabel})})]},K.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(Q,{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:Yr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:kt.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:kt.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Nt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Tt,{value:I,onValueChange:K=>{qe(K)},disabled:N||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:_t,className:"max-w-[16rem]",children:s.jsx(Kt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:ym(I)})}),s.jsxs(At,{children:[A.length>0?A.map(K=>s.jsx(at,{value:K.provider,children:s.jsx(Fd,{provider:K.provider})},K.provider)):s.jsx(at,{value:"cloudflare",children:s.jsx(Fd,{provider:"cloudflare"})}),s.jsx(at,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Nt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:nt.map(K=>s.jsxs(ru,{children:[s.jsx(lu,{asChild:!0,children:s.jsx(q,{variant:"chip",size:"xs","aria-pressed":O===K.value,className:"!font-normal",onClick:()=>{Ct(K.value)},disabled:N||n==="starting"||n==="stopping",children:a(K.labelKey)})}),s.jsx(xg,{sideOffset:8,className:"max-w-xs",children:a(K.tooltipKey)})]},K.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(Nt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Tt,{value:bl(lo,be,"1800000"),onValueChange:K=>{jt(K)},disabled:S||N||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:_t,className:"max-w-[11rem] min-w-0",children:s.jsx(Kt,{className:"truncate",children:Ld(lo,be,"1800000")})}),s.jsx(At,{children:lo.map(K=>s.jsx(at,{value:K.value,children:K.label},K.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Ie(Nt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Tt,{value:bl(co,ve,"28800000"),onValueChange:K=>{vt(K)},disabled:S||N||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:_t,className:"max-w-[11rem] min-w-0",children:s.jsx(Kt,{className:"truncate",children:Ld(co,ve,"28800000")})}),s.jsx(At,{children:co.map(K=>s.jsx(at,{value:K.value,children:K.label},K.value))})]})]})]}),O==="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(Q,{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")}),pt&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),O==="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 Re=="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:",Re]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Ln,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>te(K=>!K),disabled:n==="starting"||n==="stopping"||N,children:[s.jsx(Q,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),R.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:R.map((K,ue)=>{const Ne=L[K.id]||"",Ce=H.has(K.id),He=_[K.id]??!1;return s.jsx("div",{className:Ie(ue<R.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Gs,{open:He,onOpenChange:le=>{B(Oe=>({...Oe,[K.id]:le})),le&&Ye(K.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Ws,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||N,children:[He?s.jsx(Q,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(Q,{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:K.name})]}),s.jsx(q,{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:K.name}),onClick:()=>{ut(K.id)},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(Q,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Js,{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:K.hostname})]}),s.jsx(Be,{type:"password",value:Ne,onChange:le=>{const Oe=le.target.value;b(null),$(ot=>({...ot,[K.id]:Oe}))},onBlur:le=>{const Oe=le.currentTarget.value.trim();Oe&&dt({presetId:K.id,presetName:K.name,hostname:K.hostname,token:Oe})},placeholder:t(Ce?"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(q,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ne.trim().length===0,onClick:()=>{dt({presetId:K.id,presetName:K.name,hostname:K.hostname,token:Ne})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},K.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),Z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Be,{value:J,onChange:K=>ie(K.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),s.jsx(Be,{value:pe,onChange:K=>X(K.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),s.jsx(Be,{type:"password",value:xe,onChange:K=>Y(K.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:N||n==="starting"||n==="stopping"}),typeof Re=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Re]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ze()},disabled:N||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{te(!1),ie(""),X(""),Y("")},disabled:N||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Gt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!de&&k&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:k})]}),O==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Nt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Fe,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:K=>{we(K)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Be,{value:M||"",onChange:K=>{ae(K.target.value)},onBlur:()=>{fe()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||N}),s.jsx(q,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{lt()},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(Q,{name:"folder",className:"size-3.5"})}),M&&s.jsx(q,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{ye()},disabled:n==="starting"||n==="stopping"||N,children:s.jsx(Q,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(M?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),me&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Me})]})}),!Ue&&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(Q,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[O==="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:()=>{bt(Zw)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(Q,{name:"external-link",className:"size-3.5"})]})]}),O==="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:()=>{bt(Xw)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(Q,{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(Vr.find(K=>K.value===O)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),O==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Nt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Tt,{value:V||(R[0]?.id??""),onValueChange:K=>{Ye(K)},disabled:N||n==="starting"||n==="stopping"||R.length<=1,children:[s.jsx(Pt,{size:_t,children:s.jsx(Kt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:de?.name})}),s.jsx(At,{fitContent:!0,children:R.map(K=>s.jsx(at,{value:K.id,children:K.name},K.id))})]})]}),Ae&&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(Q,{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(q,{size:"sm",variant:"outline",onClick:Ge,disabled:n==="starting"||N||O==="managed-remote"&&!de||O==="managed-local"&&me,className:Ie(ft,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ue&&l&&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:l.url})]}),he&&l.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:l.connectUrl}),s.jsxs(q,{size:"sm",variant:"ghost",onClick:mt,className:"shrink-0 gap-1.5",children:[j?s.jsx(Q,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(Q,{name:"file-copy",className:"size-3.5"}),t(j?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",l.bootstrapExpiresAt?ge: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:[f?s.jsx("img",{src:f,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(q,{size:"sm",variant:"outline",onClick:Ge,disabled:n==="stopping"||N||O==="managed-local"&&me,className:ft,children:[s.jsx(Q,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(q,{size:"sm",variant:"ghost",onClick:et,disabled:n==="stopping"||N,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(Q,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&g&&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:g}),s.jsx(q,{size:"sm",variant:"ghost",onClick:Ge,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},jm=()=>{const{t}=ze(),e=Ti(h=>h.opencodeBinary),[a,n]=_e.useState(""),[o,i]=_e.useState(!0),[r,l]=_e.useState(!1),u=re(h=>h.showOpenCodeUpdateNotifications),m=re(h=>h.setShowOpenCodeUpdateNotifications);_e.useEffect(()=>{let h=!1;return(async()=>{try{const k=await jn();if(h||!k)return;n(k.opencodeBinary??"")}catch{}finally{h||i(!1)}})(),()=>{h=!0}},[]);const c=_e.useCallback(async()=>{if(!(typeof window>"u")&&rs())try{const h=await El();h.success&&h.path&&h.path.trim().length>0&&n(h.path.trim())}catch{}},[]),f=_e.useCallback(async()=>{l(!0);try{const h=a.trim(),k=h.length>=2&&(h.startsWith('"')&&h.endsWith('"')||h.startsWith("'")&&h.endsWith("'"))?h.slice(1,-1).trim():h;await gt({opencodeBinary:k}),await Vd({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(h){if(h?.requiresManualRestart){G.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}G.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{l(!1)}},[t,a]),p=_e.useCallback(async()=>{l(!0);try{await xu(t)}finally{l(!1)}},[t]),g=_e.useCallback(h=>{m(h),gt({showOpenCodeUpdateNotifications:h})},[m]);return s.jsx(Ve,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(ht,{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"}),"."]}),description:e?t("settings.openchamber.opencodeCli.field.pinnedByAdministrator"):void 0,alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(Be,{value:e??a,onChange:h=>n(h.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:o||r||e!==null,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:c,disabled:o||r||!rs()||e!==null,className:as,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(Q,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Hn,{className:bs,children:[s.jsx(st,{settingsItem:"sessions.opencode-update-notifications",checked:u,onChange:g,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsxs("div",{className:"flex flex-wrap justify-start gap-2 py-1.5","data-settings-item":"sessions.opencode-restart",children:[s.jsx(q,{type:"button",size:"xs",onClick:f,disabled:o||r||e!==null,className:"shrink-0 !font-normal",children:t(r?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")}),s.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:o||r,className:"shrink-0 !font-normal",children:t("settings.openchamber.opencodeCli.actions.restart")})]})]})]})})},km=()=>{const{t}=ze(),e=Un(),[a,n]=d.useState({state:"loading"}),[o,i]=d.useState(!1),[r,l]=d.useState(!1);d.useEffect(()=>{let c=!1;return Pf().then(f=>{c||n({state:"ready",names:f.names})}).catch(()=>{c||n({state:"failed"})}),()=>{c=!0}},[]);const u=d.useCallback(async c=>{Zt("saving");try{const f=await Af(c);return n({state:"ready",names:f.names}),i(!0),Zt("saved"),!0}catch{return Zt("error"),G.error(t("settings.environment.editor.saveFailed")),!1}},[t]),m=d.useCallback(async()=>{l(!0);try{await xu(t),i(!1)}finally{l(!1)}},[t]);return s.jsx(Ve,{title:t("settings.environment.user.title"),info:t("settings.environment.user.info"),settingsItem:"general.environment-variables",children:s.jsxs("div",{className:"space-y-3",children:[e?s.jsx("p",{className:Mt,children:t("settings.environment.user.enterpriseNote")}):null,a.state==="failed"?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.environment.editor.loadFailed")}):s.jsx(Tf,{names:a.state==="ready"?a.names:[],disabled:a.state!=="ready",onSet:(c,f)=>u({[c]:f}),onRemove:c=>u({[c]:null})}),o&&!e?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:Mt,children:t("settings.environment.user.restartNote")}),s.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:()=>{m()},disabled:r,className:"shrink-0 !font-normal",children:t(r?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.restart")})]}):null]})})},qr="builtin",l2=t=>t.filter(e=>Il(e)&&au(e.service,"browser")),c2="pl-[3.75rem]",uo=t=>{const e=Ke.c(23),{icon:a,title:n,summary:o,info:i,ariaLabel:r,checked:l,onChange:u,settingsItem:m}=t;let c;e[0]!==a?(c=s.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-foreground",children:s.jsx(Q,{name:a,className:"size-4"})}),e[0]=a,e[1]=c):c=e[1];let f;e[2]!==n?(f=s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:n}),e[2]=n,e[3]=f):f=e[3];let p;e[4]!==i?(p=s.jsx(Gt,{children:i}),e[4]=i,e[5]=p):p=e[5];let g;e[6]!==f||e[7]!==p?(g=s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[f,p]}),e[6]=f,e[7]=p,e[8]=g):g=e[8];let h;e[9]!==o?(h=s.jsx("p",{className:"typography-meta text-muted-foreground",children:o}),e[9]=o,e[10]=h):h=e[10];let k;e[11]!==g||e[12]!==h?(k=s.jsxs("div",{className:"min-w-0 flex-1",children:[g,h]}),e[11]=g,e[12]=h,e[13]=k):k=e[13];let b;e[14]!==r||e[15]!==l||e[16]!==u?(b=s.jsx(fa,{checked:l,onCheckedChange:u,"aria-label":r}),e[14]=r,e[15]=l,e[16]=u,e[17]=b):b=e[17];let j;return e[18]!==m||e[19]!==c||e[20]!==k||e[21]!==b?(j=s.jsxs("div",{"data-settings-item":m,className:"flex items-center gap-3 px-4 py-3",children:[c,k,b]}),e[18]=m,e[19]=c,e[20]=k,e[21]=b,e[22]=j):j=e[22],j},wm=()=>{const t=Ke.c(130),{t:e}=ze(),a=re(d2),n=re(u2),o=re(m2),i=re(p2),r=re(g2),l=re(f2),u=ys(h2),m=re(b2),c=re(x2),f=re(v2),p=re(y2),g=re(j2),h=re(k2),k=re(w2);let b;t[0]!==n?(b=$e=>{n($e),gt({agentControlToolEnabled:$e})},t[0]=n,t[1]=b):b=t[1];const j=b;let x;t[2]!==i?(x=$e=>{i($e),gt({agentWebToolEnabled:$e})},t[2]=i,t[3]=x):x=t[3];const S=x;let v;t[4]!==g?(v=$e=>{g($e),gt({agentNotifyToolEnabled:$e})},t[4]=g,t[5]=v):v=t[5];const N=v;let y;t[6]!==k?(y=$e=>{k($e),gt({agentToolsCodeMode:$e})},t[6]=k,t[7]=y):y=t[7];const I=y;let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=[],t[8]=w):w=t[8],_e.useEffect(S2,w);let D;t[9]!==u?(D=l2(u),t[9]=u,t[10]=D):D=t[10];const C=D;let A;t[11]!==r||t[12]!==C?(A=C.some($e=>$e.id===r)?r:qr,t[11]=r,t[12]=C,t[13]=A):A=t[13];const T=A;let O;t[14]!==l?(O=$e=>{l($e),gt({browserProvider:$e})},t[14]=l,t[15]=O):O=t[15];const z=O;let M;t[16]!==f?(M=$e=>{f($e),gt({agentMemoryToolEnabled:$e}).finally(()=>{$e&&vg.getState().refresh()})},t[16]=f,t[17]=M):M=t[17];const P=M;let R;t[18]!==e?(R=e("settings.openchamber.tools.title"),t[18]=e,t[19]=R):R=t[19];let F;t[20]!==e?(F=e("settings.openchamber.tools.field.agentControlTool"),t[20]=e,t[21]=F):F=t[21];let _;t[22]!==e?(_=e("settings.openchamber.tools.field.agentControlToolSummary"),t[22]=e,t[23]=_):_=t[23];let B;t[24]!==e?(B=e("settings.openchamber.tools.field.agentControlToolInfo"),t[24]=e,t[25]=B):B=t[25];let V;t[26]!==e?(V=e("settings.openchamber.tools.field.agentControlToolAria"),t[26]=e,t[27]=V):V=t[27];let ee;t[28]!==a||t[29]!==j||t[30]!==F||t[31]!==_||t[32]!==B||t[33]!==V?(ee=s.jsx(uo,{icon:"node-tree",settingsItem:"sessions.agent-control-tool",checked:a,onChange:j,title:F,summary:_,info:B,ariaLabel:V}),t[28]=a,t[29]=j,t[30]=F,t[31]=_,t[32]=B,t[33]=V,t[34]=ee):ee=t[34];let L;t[35]!==e?(L=e("settings.openchamber.tools.field.agentWebTool"),t[35]=e,t[36]=L):L=t[36];let $;t[37]!==e?($=e("settings.openchamber.tools.field.agentWebToolSummary"),t[37]=e,t[38]=$):$=t[38];let H;t[39]!==e?(H=e("settings.openchamber.tools.field.agentWebToolInfo"),t[39]=e,t[40]=H):H=t[40];let W;t[41]!==e?(W=e("settings.openchamber.tools.field.agentWebToolAria"),t[41]=e,t[42]=W):W=t[42];let Z;t[43]!==o||t[44]!==S||t[45]!==L||t[46]!==$||t[47]!==H||t[48]!==W?(Z=s.jsx(uo,{icon:"global",settingsItem:"sessions.agent-web-tool",checked:o,onChange:S,title:L,summary:$,info:H,ariaLabel:W}),t[43]=o,t[44]=S,t[45]=L,t[46]=$,t[47]=H,t[48]=W,t[49]=Z):Z=t[49];let te;t[50]===Symbol.for("react.memo_cache_sentinel")?(te=Ie("flex min-w-0 items-center gap-2 pb-3 pr-4",c2),t[50]=te):te=t[50];let J;t[51]!==e?(J=e("settings.openchamber.tools.browserProvider.label"),t[51]=e,t[52]=J):J=t[52];let ie;t[53]!==J?(ie=s.jsx("span",{className:"truncate typography-meta text-muted-foreground",children:J}),t[53]=J,t[54]=ie):ie=t[54];let pe;t[55]!==e?(pe=e("settings.openchamber.tools.browserProvider.info"),t[55]=e,t[56]=pe):pe=t[56];let X;t[57]!==pe?(X=s.jsx(Gt,{children:pe}),t[57]=pe,t[58]=X):X=t[58];const xe=!o||C.length===0;let Y;t[59]!==e?(Y=e("settings.openchamber.tools.browserProvider.aria"),t[59]=e,t[60]=Y):Y=t[60];let be;t[61]!==C||t[62]!==e?(be=s.jsx(Kt,{children:$e=>$e===qr?e("settings.openchamber.tools.browserProvider.option.builtin"):C.find(nt=>nt.id===$e)?.name??null}),t[61]=C,t[62]=e,t[63]=be):be=t[63];let De;t[64]!==Y||t[65]!==be?(De=s.jsx(Pt,{size:_t,className:"ml-auto w-auto min-w-0 max-w-[14rem]","aria-label":Y,children:be}),t[64]=Y,t[65]=be,t[66]=De):De=t[66];let ve;t[67]!==e?(ve=e("settings.openchamber.tools.browserProvider.option.builtin"),t[67]=e,t[68]=ve):ve=t[68];let se;t[69]!==ve?(se=s.jsx(at,{value:qr,children:ve}),t[69]=ve,t[70]=se):se=t[70];let ge;t[71]!==C?(ge=C.map(N2),t[71]=C,t[72]=ge):ge=t[72];let ne;t[73]!==se||t[74]!==ge?(ne=s.jsxs(At,{children:[se,ge]}),t[73]=se,t[74]=ge,t[75]=ne):ne=t[75];let Se;t[76]!==z||t[77]!==T||t[78]!==xe||t[79]!==De||t[80]!==ne?(Se=s.jsxs(Tt,{value:T,onValueChange:z,disabled:xe,children:[De,ne]}),t[76]=z,t[77]=T,t[78]=xe,t[79]=De,t[80]=ne,t[81]=Se):Se=t[81];let ke;t[82]!==ie||t[83]!==X||t[84]!==Se?(ke=s.jsxs("div",{"data-settings-item":"sessions.browser-provider",className:te,children:[ie,X,Se]}),t[82]=ie,t[83]=X,t[84]=Se,t[85]=ke):ke=t[85];let Te;t[86]!==Z||t[87]!==ke?(Te=s.jsxs("div",{children:[Z,ke]}),t[86]=Z,t[87]=ke,t[88]=Te):Te=t[88];let Ee;t[89]!==e?(Ee=e("settings.openchamber.tools.field.agentNotifyTool"),t[89]=e,t[90]=Ee):Ee=t[90];let Le;t[91]!==e?(Le=e("settings.openchamber.tools.field.agentNotifyToolSummary"),t[91]=e,t[92]=Le):Le=t[92];let ce;t[93]!==e?(ce=e("settings.openchamber.tools.field.agentNotifyToolInfo"),t[93]=e,t[94]=ce):ce=t[94];let Me;t[95]!==e?(Me=e("settings.openchamber.tools.field.agentNotifyToolAria"),t[95]=e,t[96]=Me):Me=t[96];let Fe;t[97]!==p||t[98]!==N||t[99]!==Ee||t[100]!==Le||t[101]!==ce||t[102]!==Me?(Fe=s.jsx(uo,{icon:"notification-3",settingsItem:"sessions.agent-notify-tool",checked:p,onChange:N,title:Ee,summary:Le,info:ce,ariaLabel:Me}),t[97]=p,t[98]=N,t[99]=Ee,t[100]=Le,t[101]=ce,t[102]=Me,t[103]=Fe):Fe=t[103];let me;t[104]!==c||t[105]!==m||t[106]!==P||t[107]!==e?(me=c?s.jsx(uo,{icon:"brain",settingsItem:"sessions.agent-memory-tool",checked:m,onChange:P,title:e("settings.openchamber.tools.field.agentMemoryTool"),summary:e("settings.openchamber.tools.field.agentMemoryToolSummary"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria")}):null,t[104]=c,t[105]=m,t[106]=P,t[107]=e,t[108]=me):me=t[108];let de;t[109]!==ee||t[110]!==Te||t[111]!==Fe||t[112]!==me?(de=s.jsxs("div",{className:"max-w-[44rem] divide-y divide-[var(--interactive-border)] rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[ee,Te,Fe,me]}),t[109]=ee,t[110]=Te,t[111]=Fe,t[112]=me,t[113]=de):de=t[113];let Pe;t[114]!==e?(Pe=e("settings.openchamber.tools.field.agentToolsCodeMode"),t[114]=e,t[115]=Pe):Pe=t[115];let he;t[116]!==e?(he=e("settings.openchamber.tools.field.agentToolsCodeModeAria"),t[116]=e,t[117]=he):he=t[117];let Ue;t[118]!==e?(Ue=e("settings.openchamber.tools.field.agentToolsCodeModeInfo"),t[118]=e,t[119]=Ue):Ue=t[119];let Ae;t[120]!==h||t[121]!==I||t[122]!==Pe||t[123]!==he||t[124]!==Ue?(Ae=s.jsx(st,{className:"mt-4",settingsItem:"sessions.agent-tools-code-mode",checked:h,onChange:I,label:Pe,ariaLabel:he,info:Ue}),t[120]=h,t[121]=I,t[122]=Pe,t[123]=he,t[124]=Ue,t[125]=Ae):Ae=t[125];let Re;return t[126]!==de||t[127]!==Ae||t[128]!==R?(Re=s.jsxs(Ve,{title:R,children:[de,Ae]}),t[126]=de,t[127]=Ae,t[128]=R,t[129]=Re):Re=t[129],Re};function d2(t){return t.agentControlToolEnabled}function u2(t){return t.setAgentControlToolEnabled}function m2(t){return t.agentWebToolEnabled}function p2(t){return t.setAgentWebToolEnabled}function g2(t){return t.browserProvider}function f2(t){return t.setBrowserProvider}function h2(t){return t.guests}function b2(t){return t.agentMemoryToolEnabled}function x2(t){return t.agentMemoryFeatureAvailable}function v2(t){return t.setAgentMemoryToolEnabled}function y2(t){return t.agentNotifyToolEnabled}function j2(t){return t.setAgentNotifyToolEnabled}function k2(t){return t.agentToolsCodeMode}function w2(t){return t.setAgentToolsCodeMode}function S2(){Zs()}function N2(t){return s.jsx(at,{value:t.id,children:t.name},t.id)}const Sm=new Set(["shift","control","alt","meta"]),Nm=3,C2=3e3,Cm={maxKeys:Nm,macModifiers:Sg()};function Bl(t,{macModifiers:e}){const a=[];return e?(t.metaKey&&a.push("mod"),t.ctrlKey&&a.push("ctrl")):(t.ctrlKey&&a.push("mod"),t.metaKey&&a.push("super")),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a}function Vl(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 I2(t){return t.action.customizable}function zd(t,e){if(Vl(t)>e.maxKeys)return null;const a=Bl(t,e);return a.length>0?Ro(a.join("+")):null}function P2(t,e){if(Sm.has(t.key.toLowerCase())||Vl(t,!0)>e.maxKeys)return null;const a=kg(wg(t));return a?Ro([...Bl(t,e),a].join("+")):null}function A2(t,e){const a=t.key.toLowerCase();if(!Sm.has(a)||Vl(t,!0)>e.maxKeys)return null;const n=Bl({metaKey:t.metaKey||a==="meta",ctrlKey:t.ctrlKey||a==="control",shiftKey:t.shiftKey||a==="shift",altKey:t.altKey||a==="alt"},e);return n.length>0?Ro(n.join("+")):null}function Ud(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function T2(t,e,a,n=2,o={}){const i={...Cm,...o};if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:zd(e,i)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const r=P2(e,i);if(r){if(t.settled){const u=[r];return{chords:u,livePreview:null,settled:u.length>=n}}const l=t.chords.length<n?[...t.chords,r]:t.chords;return{chords:l,livePreview:null,settled:l.length>=n}}return{...t,livePreview:zd(e,i)}}const Hl=t=>{const e=Ke.c(122),{action:a,overrides:n,onSave:o,onOpenChange:i,maxChords:r,maxKeys:l}=t,u=r===void 0?2:r,m=l===void 0?Nm:l,{t:c}=ze();let f;e[0]!==c?(f=se=>c(se.settingsLabelKey),e[0]=c,e[1]=f):f=e[1];const p=f;let g;e[2]!==p?(g=se=>se.action.customizable?p(se.action):Kn(se.action.defaultBinding),e[2]=p,e[3]=g):g=e[3];const h=g;let k;e[4]===Symbol.for("react.memo_cache_sentinel")?(k={chords:[],livePreview:null,settled:!1},e[4]=k):k=e[4];const[b,j]=d.useState(k),x=d.useRef(null);let S,v;e[5]!==a?(S=()=>{a&&(j({chords:[],livePreview:null,settled:!1}),x.current?.focus())},v=[a],e[5]=a,e[6]=S,e[7]=v):(S=e[6],v=e[7]),d.useEffect(S,v);const N=b.chords.length===1&&!b.settled;let y,I;e[8]!==N?(y=()=>{if(!N)return;const se=window.setTimeout(()=>j(Ud),C2);return()=>window.clearTimeout(se)},I=[N],e[8]=N,e[9]=y,e[10]=I):(y=e[9],I=e[10]),d.useEffect(y,I);let w;e[11]!==b.chords?(w=Ro(b.chords.join(" ")),e[11]=b.chords,e[12]=w):w=e[12];const D=w;let C;e[13]!==a||e[14]!==D||e[15]!==n?(C=a&&D?yg(a.id,D,n):[],e[13]=a,e[14]=D,e[15]=n,e[16]=C):C=e[16];const A=C;let T;e[17]!==A?(T=A.find(E2),e[17]=A,e[18]=T):T=e[18];const O=T;let z,M,P,R,F,_,B,V,ee,L,$,H,W,Z,te;if(e[19]!==a||e[20]!==p||e[21]!==D||e[22]!==h||e[23]!==A||e[24]!==u||e[25]!==m||e[26]!==i||e[27]!==o||e[28]!==O||e[29]!==b||e[30]!==c){const se=A.filter(I2);F=se.find(D2);const ge=se.find(M2),ne=A.find(R2);let Se;e[46]!==i?(Se=()=>i(!1),e[46]=i,e[47]=Se):Se=e[47],P=Se,R=()=>{b.settled||j(Ud),!(!a||!D||O||F)&&(o(a.id,D,ge?.action.id),P())};let ke;e[48]!==a||e[49]!==u||e[50]!==m||e[51]!==b?(ke=($e,nt)=>{$e.preventDefault(),$e.stopPropagation();const pt=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(nt==="keyup"&&pt&&b.chords.length===0){const bt=A2($e,{...Cm,maxKeys:m});if(bt){j({chords:[bt],livePreview:null,settled:!0});return}}const kt=T2(b,{altKey:$e.altKey,code:$e.nativeEvent.code,ctrlKey:$e.ctrlKey,isComposing:$e.nativeEvent.isComposing,key:$e.key,metaKey:$e.metaKey,repeat:$e.repeat,shiftKey:$e.shiftKey},nt,u,{maxKeys:m});j(pt&&kt.chords.length>1?b:kt)},e[48]=a,e[49]=u,e[50]=m,e[51]=b,e[52]=ke):ke=e[52];const Te=ke;M=Ft,Z=a!==null,te=O2,z=Lt,_="max-w-md",B=x,V=!1;let Ee;e[53]!==a||e[54]!==p||e[55]!==c?(Ee=a?c("settings.openchamber.keyboardShortcuts.dialog.title",{action:p(a)}):"",e[53]=a,e[54]=p,e[55]=c,e[56]=Ee):Ee=e[56];let Le;e[57]!==Ee?(Le=s.jsx(Ut,{children:Ee}),e[57]=Ee,e[58]=Le):Le=e[58];const ce=u===1?"settings.openchamber.keyboardShortcuts.dialog.instructionsSingle":"settings.openchamber.keyboardShortcuts.dialog.instructions";let Me;e[59]!==c||e[60]!==ce?(Me=c(ce),e[59]=c,e[60]=ce,e[61]=Me):Me=e[61];let Fe;e[62]!==Me?(Fe=s.jsx($t,{children:Me}),e[62]=Me,e[63]=Fe):Fe=e[63],e[64]!==Le||e[65]!==Fe?(ee=s.jsxs(zt,{children:[Le,Fe]}),e[64]=Le,e[65]=Fe,e[66]=ee):ee=e[66];let me,de;e[67]!==Te?(me=$e=>Te($e,"keydown"),de=$e=>Te($e,"keyup"),e[67]=Te,e[68]=me,e[69]=de):(me=e[68],de=e[69]);let Pe;e[70]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>j(F2),e[70]=Pe):Pe=e[70];let he;e[71]!==b.chords?(he=b.chords.map(L2),e[71]=b.chords,e[72]=he):he=e[72];let Ue;e[73]!==b.livePreview?(Ue=b.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:Kn(b.livePreview)}):null,e[73]=b.livePreview,e[74]=Ue):Ue=e[74];let Ae;e[75]!==b.chords.length||e[76]!==b.livePreview||e[77]!==c?(Ae=b.chords.length===0&&!b.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:c("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[75]=b.chords.length,e[76]=b.livePreview,e[77]=c,e[78]=Ae):Ae=e[78];let Re;e[79]!==he||e[80]!==Ue||e[81]!==Ae?(Re=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[he,Ue,Ae]}),e[79]=he,e[80]=Ue,e[81]=Ae,e[82]=Re):Re=e[82],e[83]!==me||e[84]!==de||e[85]!==Re?(L=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:x,onKeyDown:me,onKeyUp:de,onBlur:Pe,children:Re}),e[83]=me,e[84]=de,e[85]=Re,e[86]=L):L=e[86],$=b.settled&&O?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:c("settings.openchamber.keyboardShortcuts.error.internalConflict")}):b.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:c("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:p(F.action)})}):null,H=b.settled&&ge&&!O&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:c("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:p(ge.action)})}):null,W=b.settled&&ne&&!O&&!F?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:c("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:h(ne)})}):null,e[19]=a,e[20]=p,e[21]=D,e[22]=h,e[23]=A,e[24]=u,e[25]=m,e[26]=i,e[27]=o,e[28]=O,e[29]=b,e[30]=c,e[31]=z,e[32]=M,e[33]=P,e[34]=R,e[35]=F,e[36]=_,e[37]=B,e[38]=V,e[39]=ee,e[40]=L,e[41]=$,e[42]=H,e[43]=W,e[44]=Z,e[45]=te}else z=e[31],M=e[32],P=e[33],R=e[34],F=e[35],_=e[36],B=e[37],V=e[38],ee=e[39],L=e[40],$=e[41],H=e[42],W=e[43],Z=e[44],te=e[45];let J;e[87]!==D||e[88]!==b.settled||e[89]!==c?(J=b.settled&&D&&jg(D)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:c("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[87]=D,e[88]=b.settled,e[89]=c,e[90]=J):J=e[90];let ie;e[91]!==c?(ie=c("settings.common.actions.cancel"),e[91]=c,e[92]=ie):ie=e[92];let pe;e[93]!==P||e[94]!==ie?(pe=s.jsx(q,{type:"button",variant:"ghost",size:"sm",onClick:P,children:ie}),e[93]=P,e[94]=ie,e[95]=pe):pe=e[95];const X=!D||b.settled&&(!!O||!!F);let xe;e[96]!==c?(xe=c("settings.openchamber.keyboardShortcuts.actions.confirm"),e[96]=c,e[97]=xe):xe=e[97];let Y;e[98]!==R||e[99]!==X||e[100]!==xe?(Y=s.jsx(q,{type:"button",size:"sm",disabled:X,onClick:R,children:xe}),e[98]=R,e[99]=X,e[100]=xe,e[101]=Y):Y=e[101];let be;e[102]!==pe||e[103]!==Y?(be=s.jsxs(Xt,{children:[pe,Y]}),e[102]=pe,e[103]=Y,e[104]=be):be=e[104];let De;e[105]!==z||e[106]!==_||e[107]!==B||e[108]!==V||e[109]!==ee||e[110]!==L||e[111]!==$||e[112]!==H||e[113]!==W||e[114]!==J||e[115]!==be?(De=s.jsxs(z,{className:_,initialFocus:B,showCloseButton:V,children:[ee,L,$,H,W,J,be]}),e[105]=z,e[106]=_,e[107]=B,e[108]=V,e[109]=ee,e[110]=L,e[111]=$,e[112]=H,e[113]=W,e[114]=J,e[115]=be,e[116]=De):De=e[116];let ve;return e[117]!==M||e[118]!==Z||e[119]!==te||e[120]!==De?(ve=s.jsx(M,{open:Z,onOpenChange:te,children:De}),e[117]=M,e[118]=Z,e[119]=te,e[120]=De,e[121]=ve):ve=e[121],ve};function E2(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function D2(t){return t.kind==="prefix"}function M2(t){return t.kind==="exact"}function R2(t){return t.kind==="contextual-prefix"}function O2(t,e){t||e.cancel()}function F2(t){return{...t,livePreview:null}}function L2(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:Kn(t)},`${t}-${e}`)}const Gr=[.3,.35,.4,.45,.5,.6,1],K2=t=>{const e=Ke.c(41),{quake:a,miniChatCombo:n,onReleaseMiniChatShortcut:o}=t,{t:i}=ze(),[r,l]=_e.useState(!1),u=re(z2),m=re(U2);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=Pl().find($2)??null,e[0]=c):c=e[0];const f=c;let p;e[1]!==n||e[2]!==u?(p=n?{...u,mini_chat_global:n}:u,e[1]=n,e[2]=u,e[3]=p):p=e[3];const g=p;let h=Gr[0];for(const P of Gr)Math.abs(P-a.heightFraction)<Math.abs(h-a.heightFraction)&&(h=P);const k=String(h),{saveShortcut:b}=a;let j;e[4]!==o||e[5]!==b||e[6]!==m||e[7]!==u?(j=(P,R,F)=>{b(R).then(_=>{if(!(!_||!F)){if(F==="mini_chat_global"){o();return}m(F,En),gt({shortcutOverrides:{...u,[F]:En}})}})},e[4]=o,e[5]=b,e[6]=m,e[7]=u,e[8]=j):j=e[8];const x=j;if(!a.supported)return null;const S=a.enabled;let v;e[9]!==a?(v=P=>{P!==a.enabled&&a.setEnabled(P)},e[9]=a,e[10]=v):v=e[10];const N=a.isSaving;let y;e[11]!==i?(y=i("settings.openchamber.desktopNetwork.field.quakeMode"),e[11]=i,e[12]=y):y=e[12];let I;e[13]!==i?(I=i("settings.openchamber.desktopNetwork.field.quakeModeDescription"),e[13]=i,e[14]=I):I=e[14];let w;e[15]!==i?(w=i("settings.openchamber.desktopNetwork.field.quakeModeAria"),e[15]=i,e[16]=w):w=e[16];let D;e[17]!==a.enabled||e[18]!==a.isSaving||e[19]!==v||e[20]!==y||e[21]!==I||e[22]!==w?(D=s.jsx(st,{settingsItem:"sessions.desktop-quake-mode",checked:S,onChange:v,disabled:N,label:y,info:I,ariaLabel:w}),e[17]=a.enabled,e[18]=a.isSaving,e[19]=v,e[20]=y,e[21]=I,e[22]=w,e[23]=D):D=e[23];let C;e[24]!==a||e[25]!==i?(C=a.enabled?s.jsxs(ht,{label:i("settings.openchamber.desktopNetwork.field.quakeModeShortcut"),info:i("settings.openchamber.desktopNetwork.field.quakeModeShortcutDescription"),description:a.combo&&!a.active?s.jsx("span",{className:"block text-[var(--status-warning)]",children:i("settings.openchamber.desktopNetwork.field.quakeModeShortcutInactive")}):void 0,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:a.combo?Kn(a.combo):i("settings.openchamber.keyboardShortcuts.unassigned")}),s.jsx(q,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",disabled:a.isSaving,onClick:()=>l(!0),children:i("settings.openchamber.keyboardShortcuts.actions.edit")}),a.storedCombo?s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",disabled:a.isSaving,onClick:()=>{a.saveShortcut(null)},children:i("settings.common.actions.reset")}):null]}):null,e[24]=a,e[25]=i,e[26]=C):C=e[26];let A;e[27]!==k||e[28]!==a||e[29]!==i?(A=a.enabled?s.jsx(ht,{label:i("settings.openchamber.desktopNetwork.field.quakeModeHeight"),info:i("settings.openchamber.desktopNetwork.field.quakeModeHeightDescription"),children:s.jsxs(Tt,{value:k,onValueChange:P=>{const R=Number(P);Number.isFinite(R)&&a.setHeight(R)},disabled:a.isSaving,children:[s.jsx(Pt,{size:_t,className:tn,"aria-label":i("settings.openchamber.desktopNetwork.field.quakeModeHeightAria"),children:s.jsx(Kt,{})}),s.jsx(At,{children:Gr.map(_2)})]})}):null,e[27]=k,e[28]=a,e[29]=i,e[30]=A):A=e[30];const T=r?f:null;let O;e[31]===Symbol.for("react.memo_cache_sentinel")?(O=P=>{P||l(!1)},e[31]=O):O=e[31];let z;e[32]!==x||e[33]!==g||e[34]!==T?(z=s.jsx(Hl,{action:T,overrides:g,onSave:x,onOpenChange:O,maxChords:1,maxKeys:5}),e[32]=x,e[33]=g,e[34]=T,e[35]=z):z=e[35];let M;return e[36]!==D||e[37]!==C||e[38]!==A||e[39]!==z?(M=s.jsxs(s.Fragment,{children:[D,C,A,z]}),e[36]=D,e[37]=C,e[38]=A,e[39]=z,e[40]=M):M=e[40],M};function z2(t){return t.shortcutOverrides}function U2(t){return t.setShortcutOverride}function $2(t){return t.id==="quake_mode_global"}function _2(t){return s.jsx(at,{value:String(t),children:`${Math.round(t*100)}%`},t)}const B2=(t,e)=>{const{t:a}=ze(),[n,o]=_e.useState(null),[i,r]=_e.useState(!1);_e.useEffect(()=>{if(!t){o(null);return}let g=!1;return(async()=>{const h=await hu();g||o(h)})(),()=>{g=!0}},[t]);const l=n?.supported===!0,u=_e.useCallback(async g=>{if(!l||i)return null;r(!0),e(null);try{const h=await g();if(!h?.supported)throw new Error(a("settings.openchamber.desktopNetwork.error.quakeModeSaveFailed"));return o(h),h}catch(h){return e(h instanceof Error?h.message:a("settings.openchamber.desktopNetwork.error.quakeModeSaveFailed")),null}finally{r(!1)}},[i,e,l,a]),m=_e.useCallback(g=>{u(()=>af(g))},[u]),c=_e.useCallback(async g=>{const h=await u(()=>Zr(g));return h?h.error==="unsupported-combo"?(e(a("settings.openchamber.desktopNetwork.error.quakeModeShortcutUnsupported")),!1):!0:!1},[u,e,a]),f=_e.useCallback(g=>{u(()=>of(g))},[u]),p=_e.useCallback(()=>{Zr(En).then(g=>{g&&o(g)})},[]);return{supported:l,enabled:n?.enabled===!0,combo:n?.combo??null,storedCombo:n?.storedCombo??null,active:n?.active===!0,heightFraction:n?.heightFraction??1,isSaving:i,setEnabled:m,saveShortcut:c,setHeight:f,release:p}},Im=()=>{const{t}=ze(),e=rs()&&Za(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",n=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[o,i]=_e.useState(!1),[r,l]=_e.useState(!1),[u,m]=_e.useState(!1),[c,f]=_e.useState(""),[p,g]=_e.useState(!1),[h,k]=_e.useState(!1),[b,j]=_e.useState(null),[x,S]=_e.useState(!0),[v,N]=_e.useState(!1),[y,I]=_e.useState(!1),[w,D]=_e.useState(!1),[C,A]=_e.useState(!1),[T,O]=_e.useState(!1),[z,M]=_e.useState(!1),[P,R]=_e.useState(!1),[F,_]=_e.useState(!0),[B,V]=_e.useState(!0),[ee,L]=_e.useState(!1),[$,H]=_e.useState(!1),[W,Z]=_e.useState(!1),[te,J]=_e.useState(!1),[ie,pe]=_e.useState(!1),[X,xe]=_e.useState(!1),[Y,be]=_e.useState(null),[De,ve]=_e.useState(!1),[se,ge]=_e.useState(!1),[ne,Se]=_e.useState(!1),ke=re(ye=>ye.shortcutOverrides),Te=re(ye=>ye.setShortcutOverride),Ee=_e.useMemo(()=>Pl().find(ye=>ye.id==="mini_chat_global")??null,[]),[Le,ce]=_e.useState(null),Me=B2(e,ce),{release:Fe}=Me,me=_e.useMemo(()=>Me.combo?{...ke,quake_mode_global:Me.combo}:ke,[Me.combo,ke]),[de,Pe]=_e.useState(null);_e.useEffect(()=>{if(!e){S(!1);return}let ye=!1;return(async()=>{try{const we=await jn();if(!we)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(ye)return;const Ge=we.desktopLanAccessEnabled===!0;i(Ge),l(Ge),m(we.hasDesktopUiPassword===!0),f(""),g(!1),k(we.desktopLanAccessActive===!0),j(we.desktopLanAccessBlockedReason??null);const et=we.desktopMacMenuBarEnabled!==!1;_(et),V(et);const mt=we.desktopLinuxNativeFrame===!0;L(mt),H(mt),ce(null)}catch(we){ye||ce(we instanceof Error?we.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{ye||S(!1)}})(),()=>{ye=!0}},[e,t]),_e.useEffect(()=>{if(!e){I(!1);return}let ye=!1;return(async()=>{const we=await rf();ye||(I(we?.supported===!0),D(we?.enabled===!0))})(),()=>{ye=!0}},[e]),_e.useEffect(()=>{if(!e){O(!1);return}let ye=!1;return(async()=>{const we=await lf();ye||(O(we?.supported===!0),M(we?.enabled===!0))})(),()=>{ye=!0}},[e]),_e.useEffect(()=>{if(!e){Z(!1);return}let ye=!1;return(async()=>{const we=await cf();ye||(Z(we?.supported===!0),J(we?.enabled===!0))})(),()=>{ye=!0}},[e]),_e.useEffect(()=>{if(!e){xe(!1);return}let ye=!1;return(async()=>{const we=await bu();ye||(xe(we?.supported===!0),be(we?.combo??null),ve(we?.active===!0))})(),()=>{ye=!0}},[e]),_e.useEffect(()=>{if(!e||!r){Pe(null);return}let ye=!1;return(async()=>{const we=await uu();ye||Pe(we)})(),()=>{ye=!0}},[r,e]);const he=c.trim(),Ue=he.length>0||p,Ae=r!==o||Ue||B!==F||$!==ee,Re=_e.useMemo(()=>{if(typeof window>"u")return null;const we=Ei()||window.location.href;let Ge=0;try{Ge=Number(new URL(we).port)}catch{Ge=Number(window.location.port)}return Number.isFinite(Ge)&&Ge>0?Ge:null},[]),$e=r&&h&&de&&Re?`http://${de}:${Re}`:null,nt=he.length>0||u&&!p,pt=r&&!nt,kt=o&&!h&&b==="missing-password",bt=Ti(ye=>ye.networkAccessBlocked)||b==="enterprise-mode",yt=x||v||!Ae||pt,Je=_e.useCallback(ye=>{f(ye),ye.trim()&&g(!1)},[]),ct=_e.useCallback(()=>{f(""),g(!0),l(!1)},[]),Qe=_e.useCallback(async()=>{if(!y||C)return;const ye=!w;D(ye),A(!0),ce(null);try{const we=await df(ye);if(!we?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));D(we.enabled)}catch(we){D(!ye),ce(we instanceof Error?we.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{A(!1)}},[C,w,y,t]),it=_e.useCallback(async()=>{if(!T||P)return;const ye=!z;M(ye),R(!0),ce(null);try{const we=await uf(ye);if(!we)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!we.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));M(we.enabled)}catch(we){M(!ye),ce(we instanceof Error?we.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{R(!1)}},[P,z,T,t]),dt=_e.useCallback(async()=>{if(!W||ie)return;const ye=!te;J(ye),pe(!0),ce(null);try{const we=await mf(ye);if(!we?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));J(we.enabled)}catch(we){J(!ye),ce(we instanceof Error?we.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{pe(!1)}},[ie,te,W,t]),qe=_e.useCallback(async ye=>{if(!X||se)return!1;ge(!0),ce(null);try{const we=await Xr(ye);if(!we?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutSaveFailed"));return be(we.combo??null),ve(we.active===!0),we.error==="unsupported-combo"?(ce(t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutUnsupported")),!1):!0}catch(we){return ce(we instanceof Error?we.message:t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutSaveFailed")),!1}finally{ge(!1)}},[se,X,t]),lt=_e.useCallback((ye,we,Ge)=>{qe(we).then(et=>{if(!(!et||!Ge)){if(Ge==="quake_mode_global"){Fe();return}Te(Ge,En),gt({shortcutOverrides:{...ke,[Ge]:En}})}})},[qe,Fe,Te,ke]),ae=_e.useCallback(()=>{Xr(null).then(ye=>{ye&&(be(ye.combo??null),ve(ye.active===!0))})},[]),fe=_e.useCallback(async()=>{if(Ae){N(!0),ce(null);try{if(!(await gt({desktopLanAccessEnabled:r,...he?{desktopUiPassword:he}:p?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:B,desktopLinuxNativeFrame:$})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),he?m(!0):p&&m(!1),f(""),g(!1),_(B),L($),!await pf())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(ye){ce(ye instanceof Error?ye.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),N(!1)}}},[$,B,r,Ae,he,p,t]);return e?s.jsxs(Ve,{title:t("settings.openchamber.desktopNetwork.title"),children:[s.jsxs("div",{className:"space-y-3",children:[y||a||n||T||W||X||Me.supported?s.jsxs("div",{className:bs,children:[y?s.jsx(st,{settingsItem:"sessions.desktop-launch-at-login",checked:w,onChange:ye=>{ye!==w&&Qe()},disabled:C,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(st,{settingsItem:"sessions.desktop-mac-menu-bar",checked:B,onChange:V,disabled:x||v,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,n?s.jsx(st,{settingsItem:"sessions.desktop-linux-native-frame",checked:$,onChange:H,disabled:x||v,label:t("settings.openchamber.desktopNetwork.field.linuxNativeFrame"),info:t("settings.openchamber.desktopNetwork.field.linuxNativeFrameDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.linuxNativeFrame")}):null,T?s.jsx(st,{settingsItem:"sessions.desktop-minimize-to-tray",checked:z,onChange:ye=>{ye!==z&&it()},disabled:P,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,W?s.jsx(st,{settingsItem:"sessions.desktop-keep-awake",checked:te,onChange:ye=>{ye!==te&&dt()},disabled:ie,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null,X?s.jsxs(ht,{settingsItem:"sessions.desktop-mini-chat-global-shortcut",label:t("settings.openchamber.desktopNetwork.field.miniChatGlobalShortcut"),info:t("settings.openchamber.desktopNetwork.field.miniChatGlobalShortcutDescription"),description:Y&&!De?s.jsx("span",{className:"block text-[var(--status-warning)]",children:t("settings.openchamber.desktopNetwork.field.miniChatGlobalShortcutInactive")}):void 0,children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:Y?Kn(Y):t("settings.openchamber.keyboardShortcuts.unassigned")}),s.jsx(q,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",disabled:se,onClick:()=>Se(!0),children:t("settings.openchamber.keyboardShortcuts.actions.edit")}),Y?s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",disabled:se,onClick:()=>{qe(null)},children:t("settings.common.actions.reset")}):null]}):null,s.jsx(K2,{quake:Me,miniChatCombo:Y,onReleaseMiniChatShortcut:ae})]}):null,s.jsxs(Et,{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:c,onChange:ye=>Je(ye.target.value),placeholder:t(u&&!p?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:x||v,required:r&&!nt,"aria-invalid":pt}),u&&!p?s.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:ct,disabled:x||v,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:bs,children:s.jsx(st,{settingsItem:"sessions.desktop-lan-access",checked:r&&!bt,onChange:l,disabled:x||v||bt,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:bt?s.jsx("span",{className:"block",children:t("settings.openchamber.desktopNetwork.field.enterpriseBlocked")}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),pt||kt?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")})}),Le?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Le}):null,$e&&!bt?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(Ae&&!o?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:$e})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(q,{type:"button",size:"xs",onClick:fe,disabled:yt,className:"shrink-0 !font-normal",children:t(v?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]}),s.jsx(Hl,{action:ne?Ee:null,overrides:me,onSave:lt,onOpenChange:ye=>{ye||Se(!1)},maxChords:1,maxKeys:5})]}):null},V2=["session","models","panels","navigation","application"],H2=()=>{const t=Ke.c(34),{t:e}=ze(),a=re(q2),n=re(G2),o=re(W2),i=re(J2),[r,l]=d.useState(null),[u,m]=d.useState(null);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{bu().then(F=>m(F?.combo??null)).catch(Q2)},t[0]=c):c=t[0];const f=c;let p,g;t[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{f()},g=[f],t[1]=p,t[2]=g):(p=t[1],g=t[2]),d.useEffect(p,g);const[h,k]=d.useState(null);let b;t[3]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{hu().then(F=>k(F?.combo??null)).catch(Y2)},t[3]=b):b=t[3];const j=b;let x,S;t[4]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{j()},S=[j],t[4]=x,t[5]=S):(x=t[4],S=t[5]),d.useEffect(x,S);let v;t[6]===Symbol.for("react.memo_cache_sentinel")?(v=Pl(),t[6]=v):v=t[6];const N=v,y=Z2;let I;t[7]!==n||t[8]!==a?(I=(F,_,B)=>{const V={...a,[F]:_};n(F,_),B==="mini_chat_global"?Xr(null).then(ee=>{ee&&m(ee.combo)}):B==="quake_mode_global"?Zr(En).then(ee=>{ee&&k(ee.combo)}):B&&(V[B]=En,n(B,En)),y(V)},t[7]=n,t[8]=a,t[9]=I):I=t[9];const w=I;let D;t[10]!==o||t[11]!==a?(D=F=>{const _={...a};delete _[F],o(F),y(_)},t[10]=o,t[11]=a,t[12]=D):D=t[12];const C=D;let A;t[13]!==a||t[14]!==e?(A=F=>{const _="prefixStyle"in F&&F.prefixStyle,B=_?Ng(F.id,a):cu(F.id,a),V=Kn(B,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!_||!B||B===En)return V;const ee=F.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${V}${ee}`},t[13]=a,t[14]=e,t[15]=A):A=t[15];const T=A;let O;t[16]!==u||t[17]!==h||t[18]!==a?(O={...a},u&&(O.mini_chat_global=u),h&&(O.quake_mode_global=h),t[16]=u,t[17]=h,t[18]=a,t[19]=O):O=t[19];let z;t[20]!==i||t[21]!==C||t[22]!==T||t[23]!==a||t[24]!==e?(z=V2.map((F,_)=>{const B=N.filter(V=>V.category===F);return B.length===0?null:s.jsx(Ve,{settingsItem:_===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${F}`),divider:_!==0,info:_===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:_===0?s.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),y({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:B.map(V=>s.jsxs(ht,{label:e(V.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:T(V)}),s.jsx(q,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{f(),j(),l(V)},children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),V.id in a?s.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>C(V.id),children:e("settings.common.actions.reset")}):null]},V.id))})},F)}),t[20]=i,t[21]=C,t[22]=T,t[23]=a,t[24]=e,t[25]=z):z=t[25];let M;t[26]===Symbol.for("react.memo_cache_sentinel")?(M=F=>{F||l(null)},t[26]=M):M=t[26];let P;t[27]!==r||t[28]!==O||t[29]!==w?(P=s.jsx(Hl,{action:r,overrides:O,onSave:w,onOpenChange:M}),t[27]=r,t[28]=O,t[29]=w,t[30]=P):P=t[30];let R;return t[31]!==z||t[32]!==P?(R=s.jsxs(s.Fragment,{children:[z,P]}),t[31]=z,t[32]=P,t[33]=R):R=t[33],R};function q2(t){return t.shortcutOverrides}function G2(t){return t.setShortcutOverride}function W2(t){return t.clearShortcutOverride}function J2(t){return t.resetAllShortcutOverrides}function Q2(){}function Y2(){}function Z2(t){gt({shortcutOverrides:t})}const Pm=()=>{const t=Ke.c(2),[e,a]=d.useState(0);let n,o;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Oo(()=>a(d0)),o=[],t[0]=n,t[1]=o):(n=t[0],o=t[1]),d.useEffect(n,o),e},X2=t=>{const e=Ke.c(91),{section:a}=t,{t:n}=ze(),{isMobile:o}=qn(),i=Pm();let r;e[0]!==o?(r=o&&ba(),e[0]=o,e[1]=r):r=e[1];const l=r;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=is(),e[2]=u):u=e[2];const m=u;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=rs()&&Za(),e[3]=c):c=e[3];const f=c;if(!a){let L;e[4]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx($o,{}),e[4]=L):L=e[4];let $;e[5]!==i?($=s.jsx(xm,{},i),e[5]=i,e[6]=$):$=e[6];let H,W,Z;e[7]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(fm,{}),W=f&&s.jsx(Im,{}),Z=!m&&s.jsx(jm,{}),e[7]=H,e[8]=W,e[9]=Z):(H=e[7],W=e[8],Z=e[9]);let te;e[10]!==i?(te=!m&&s.jsx(km,{},i),e[10]=i,e[11]=te):te=e[11];let J,ie,pe,X,xe;e[12]===Symbol.for("react.memo_cache_sentinel")?(J=!m&&s.jsx(wm,{}),ie=s.jsx(pm,{}),pe=!m&&s.jsx(gm,{}),X=s.jsx(bm,{}),xe=ba()&&!rs()&&!m&&!Al()&&s.jsx(hm,{}),e[12]=J,e[13]=ie,e[14]=pe,e[15]=X,e[16]=xe):(J=e[12],ie=e[13],pe=e[14],X=e[15],xe=e[16]);let Y;e[17]!==l?(Y=l&&s.jsx(yu,{}),e[17]=l,e[18]=Y):Y=e[18];let be;return e[19]!==Y||e[20]!==$||e[21]!==te?(be=s.jsxs(Qt,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[L,$,H,W,Z,te,J,ie,pe,X,xe,Y]}),e[19]=Y,e[20]=$,e[21]=te,e[22]=be):be=e[22],be}let p;e[23]!==i||e[24]!==a?(p=()=>{switch(a){case"general":return s.jsx(t0,{});case"visual":return s.jsx(s0,{});case"chat":return s.jsx(n0,{});case"sessions":return s.jsx(a0,{runtimeEndpointEpoch:i});case"shortcuts":return s.jsx(e0,{});case"git":return s.jsx(i0,{});case"notifications":return s.jsx(o0,{});case"voice":return s.jsx(r0,{});case"tunnel":return s.jsx(c0,{});case"spaces":return s.jsx(l0,{});default:return null}},e[23]=i,e[24]=a,e[25]=p):p=e[25];const g=p;let h;e[26]!==n?(h=n("settings.page.general.title"),e[26]=n,e[27]=h):h=e[27];let k;e[28]!==n?(k=n("settings.page.appearance.title"),e[28]=n,e[29]=k):k=e[29];let b;e[30]!==n?(b=n("settings.page.chat.title"),e[30]=n,e[31]=b):b=e[31];let j;e[32]!==n?(j=n("settings.page.sessions.title"),e[32]=n,e[33]=j):j=e[33];let x;e[34]!==n?(x=n("settings.page.shortcuts.title"),e[34]=n,e[35]=x):x=e[35];let S;e[36]!==n?(S=n("settings.page.git.title"),e[36]=n,e[37]=S):S=e[37];let v;e[38]!==n?(v=n("settings.page.git.title"),e[38]=n,e[39]=v):v=e[39];let N;e[40]!==n?(N=n("settings.page.notifications.title"),e[40]=n,e[41]=N):N=e[41];let y;e[42]!==n?(y=n("settings.page.voice.title"),e[42]=n,e[43]=y):y=e[43];let I;e[44]!==n?(I=n("settings.page.tunnel.title"),e[44]=n,e[45]=I):I=e[45];let w;e[46]!==n?(w=n("settings.openchamber.spaces.title"),e[46]=n,e[47]=w):w=e[47];let D;e[48]!==S||e[49]!==v||e[50]!==N||e[51]!==y||e[52]!==I||e[53]!==w||e[54]!==h||e[55]!==k||e[56]!==b||e[57]!==j||e[58]!==x?(D={general:h,visual:k,chat:b,sessions:j,shortcuts:x,git:S,github:v,notifications:N,voice:y,tunnel:I,spaces:w},e[48]=S,e[49]=v,e[50]=N,e[51]=y,e[52]=I,e[53]=w,e[54]=h,e[55]=k,e[56]=b,e[57]=j,e[58]=x,e[59]=D):D=e[59];const C=D[a];let A;e[60]!==n?(A=n("settings.page.general.description"),e[60]=n,e[61]=A):A=e[61];let T;e[62]!==n?(T=n("settings.page.appearance.description"),e[62]=n,e[63]=T):T=e[63];let O;e[64]!==n?(O=n("settings.page.chat.description"),e[64]=n,e[65]=O):O=e[65];let z;e[66]!==n?(z=n("settings.page.sessions.description"),e[66]=n,e[67]=z):z=e[67];let M;e[68]!==n?(M=n("settings.page.shortcuts.description"),e[68]=n,e[69]=M):M=e[69];let P;e[70]!==n?(P=n("settings.page.notifications.description"),e[70]=n,e[71]=P):P=e[71];let R;e[72]!==n?(R=n("settings.page.voice.description"),e[72]=n,e[73]=R):R=e[73];let F;e[74]!==n?(F=n("settings.page.tunnel.description"),e[74]=n,e[75]=F):F=e[75];let _;e[76]!==A||e[77]!==T||e[78]!==O||e[79]!==z||e[80]!==M||e[81]!==P||e[82]!==R||e[83]!==F?(_={general:A,visual:T,chat:O,sessions:z,shortcuts:M,git:void 0,github:void 0,notifications:P,voice:R,tunnel:F,spaces:void 0},e[76]=A,e[77]=T,e[78]=O,e[79]=z,e[80]=M,e[81]=P,e[82]=R,e[83]=F,e[84]=_):_=e[84];const B=_[a];let V;e[85]!==g?(V=g(),e[85]=g,e[86]=V):V=e[86];let ee;return e[87]!==B||e[88]!==C||e[89]!==V?(ee=s.jsx(Qt,{title:C,description:B,showSaveStatus:!0,className:"openchamber-page-body",children:V}),e[87]=B,e[88]=C,e[89]=V,e[90]=ee):ee=e[90],ee},e0=()=>{const t=Ke.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(H2,{}),t[0]=e):e=t[0],e},t0=()=>{const t=Ke.c(14);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=is(),t[0]=e):e=t[0];const a=e,n=Pm();let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o=rs()&&Za(),t[1]=o):o=t[1];const i=o;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=ba()&&!rs()&&!a&&!Al(),t[2]=r):r=t[2];const l=r;let u,m,c,f;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=i&&s.jsx(Im,{}),m=l&&s.jsx(hm,{}),c=s.jsx(bm,{}),f=!a&&s.jsx(jm,{}),t[3]=u,t[4]=m,t[5]=c,t[6]=f):(u=t[3],m=t[4],c=t[5],f=t[6]);let p;t[7]!==n?(p=!a&&s.jsx(km,{},n),t[7]=n,t[8]=p):p=t[8];let g;t[9]===Symbol.for("react.memo_cache_sentinel")?(g=!a&&s.jsx(wm,{}),t[9]=g):g=t[9];let h;t[10]===Symbol.for("react.memo_cache_sentinel")?(h=a?[]:["sessionTabs"],t[10]=h):h=t[10];let k;t[11]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx($o,{visibleSettings:["fileEditorKeymap",...h,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]}),t[11]=k):k=t[11];let b;return t[12]!==p?(b=s.jsxs(s.Fragment,{children:[u,m,c,f,p,g,k]}),t[12]=p,t[13]=b):b=t[13],b},s0=()=>{const t=Ke.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=is(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx($o,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=n):n=t[1],n},n0=()=>{const t=Ke.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx($o,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","promptNavigatorEnabled","wideChatLayout","codeBlockLineWrap","tableCellWrap","copyMessagesAsPlainText","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","messageSearch","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[0]=e):e=t[0],e},a0=t=>{const e=Ke.c(7),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(xm,{},a),e[0]=a,e[1]=n):n=e[1];let o,i,r;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(fm,{}),i=s.jsx(pm,{}),r=!is()&&s.jsx(gm,{}),e[2]=o,e[3]=i,e[4]=r):(o=e[2],i=e[3],r=e[4]);let l;return e[5]!==n?(l=s.jsxs(s.Fragment,{children:[n,o,i,r]}),e[5]=n,e[6]=l):l=e[6],l},i0=()=>{const t=Ke.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ju,{}),t[0]=e):e=t[0],e},o0=()=>{const t=Ke.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Uw,{}),t[0]=e):e=t[0],e},r0=()=>{const t=Ke.c(1);if(is())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Qw,{}),t[0]=e):e=t[0],e},l0=()=>{if(Ke.c(1),is()||!sl)return null},c0=()=>{const t=Ke.c(1);if(is())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(r2,{}),t[0]=e):e=t[0],e};function d0(t){return t+1}const u0=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.animated-activity-indicators",page:"appearance",titleKey:"settings.openchamber.visual.field.animatedActivityIndicators",descriptionKey:"settings.openchamber.visual.field.animatedActivityIndicatorsInfo",keywords:["spinner","animation","session","activity","motion","running","indicator"]},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-review-offer",page:"chat",titleKey:"settings.openchamber.visual.field.sessionReviewOffer",descriptionKey:"settings.openchamber.visual.field.sessionReviewOfferInfo",keywords:["review","walkthrough","changes","diff","jev","classification"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-checker",page:"chat",titleKey:"settings.openchamber.visual.goal.checkerLabel",keywords:["goal","progress","check","jev","classification","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-max-turns",page:"chat",titleKey:"settings.openchamber.visual.goal.maxTurnsLabel",keywords:["goal","turns","limit","continuations","safety"],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","collapse","expand","streaming"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.table-cell-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.tableCellWrap",descriptionKey:"settings.openchamber.visual.field.tableCellWrapInfo",keywords:["table","wrap","cell","columns","markdown"]},{id:"chat.copy-plain-text",page:"chat",titleKey:"settings.openchamber.visual.field.copyMessagesAsPlainText",descriptionKey:"settings.openchamber.visual.field.copyMessagesAsPlainTextInfo",keywords:["copy","clipboard","plain text","markdown","selection"]},{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.message-search",page:"chat",titleKey:"settings.openchamber.messageSearch.title",keywords:["search","find","index","messages","history","full text"],isAvailable:t=>!t.isVSCode},{id:"chat.message-search-enabled",page:"chat",titleKey:"settings.openchamber.messageSearch.field.enabled",keywords:["search","find","index","messages"],isAvailable:t=>!t.isVSCode},{id:"chat.message-search-reasoning",page:"chat",titleKey:"settings.openchamber.messageSearch.field.reasoning",keywords:["search","reasoning","thinking","index"],isAvailable:t=>!t.isVSCode},{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","double paste","ctrl v","cmd v"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.warming",page:"sessions",titleKey:"settings.openchamber.defaults.field.sessionWarming",descriptionKey:"settings.openchamber.defaults.field.sessionWarmingInfo",keywords:["warming","warm","cache","prompt cache","keep-alive","idle"]},{id:"sessions.permission-default",page:"sessions",titleKey:"settings.sessions.permissions.defaultMode",descriptionKey:"settings.sessions.permissions.defaultModeInfo",keywords:["permissions","auto-accept","accept","safety net","ask","shield","approval","new session"],isAvailable:t=>!t.isVSCode},{id:"sessions.show-chats",page:"sessions",titleKey:"settings.openchamber.defaults.field.showChats",keywords:["chats","sidebar","hide","show","section"],isAvailable:t=>!t.isVSCode},{id:"sessions.work",page:"sessions",titleKey:"settings.openchamber.sessionWork.title",descriptionKey:"settings.openchamber.sessionWork.info",keywords:["in work","in progress","track","done","inbox","sidebar","jev"]},{id:"sessions.work-enabled",page:"sessions",titleKey:"settings.openchamber.sessionWork.field.enabled",keywords:["in work","in progress","track","done","sidebar"]},{id:"sessions.work-auto-open",page:"sessions",titleKey:"settings.openchamber.sessionWork.field.autoOpen",descriptionKey:"settings.openchamber.sessionWork.field.autoOpenInfo",keywords:["in work","automatic","jev","classification","track"],isAvailable:t=>!t.isVSCode},{id:"sessions.work-keep-in-group",page:"sessions",titleKey:"settings.openchamber.sessionWork.field.keepInGroup",descriptionKey:"settings.openchamber.sessionWork.field.keepInGroupInfo",keywords:["in work","track","project group","folder","sidebar","keep"]},{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.merged-worktree-cleanup",page:"sessions",titleKey:"settings.openchamber.mergedWorktreeCleanup.field.enable",descriptionKey:"settings.openchamber.mergedWorktreeCleanup.field.enableDescription",keywords:["pr","pull request","merged","worktree","branch","archive","cleanup","remove"]},{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-linux-native-frame",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.linuxNativeFrame",descriptionKey:"settings.openchamber.desktopNetwork.field.linuxNativeFrameDescription",keywords:["desktop","linux","title bar","titlebar","window","frame","decorations","gnome","kde"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isLinux},{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-mini-chat-global-shortcut",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.miniChatGlobalShortcut",descriptionKey:"settings.openchamber.desktopNetwork.field.miniChatGlobalShortcutDescription",keywords:["desktop","mini chat","shortcut","hotkey","global","keyboard"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-quake-mode",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.quakeMode",descriptionKey:"settings.openchamber.desktopNetwork.field.quakeModeDescription",keywords:["desktop","quake","dropdown","hotkey","shortcut","height","global","background","tray","terminal"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-restart",page:"general",titleKey:"settings.openchamber.opencodeCli.actions.restart",keywords:["opencode","restart","reload","plugin"],isAvailable:t=>!t.isVSCode},{id:"general.environment-variables",page:"general",titleKey:"settings.environment.user.title",descriptionKey:"settings.environment.user.info",keywords:["environment","env","variables","api key","token","secret","opencode","terminal","git"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.browser-provider",page:"general",titleKey:"settings.openchamber.tools.browserProvider.label",descriptionKey:"settings.openchamber.tools.browserProvider.info",keywords:["agent","browser","provider","extension","chrome","server","headless"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-notify-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentNotifyTool",descriptionKey:"settings.openchamber.tools.field.agentNotifyToolInfo",keywords:["agent","tool","notify","notification","alert","ping","openchamber"],isAvailable:t=>!t.isVSCode},{id:"general.isolated-spaces",page:"isolated-spaces",titleKey:"settings.openchamber.spaces.field.enabled",descriptionKey:"settings.openchamber.spaces.field.enabledInfo",keywords:["isolated","space","spaces","container","docker","sandbox","agent"],isAvailable:t=>!t.isVSCode&&sl},{id:"general.isolated-spaces-idle-stop",page:"isolated-spaces",titleKey:"settings.openchamber.spaces.idleStop.enabled",descriptionKey:"settings.openchamber.spaces.idleStop.enabledInfo",keywords:["idle","stop","space","spaces","container","hours","timeout","sleep"],isAvailable:t=>!t.isVSCode&&sl&&re.getState().isolatedSpacesEnabled},{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&&re.getState().agentMemoryFeatureAvailable},{id:"git.gitlab-account",page:"integrations",titleKey:"settings.gitlab.title",descriptionKey:"settings.gitlab.info",keywords:["gitlab","account","oauth","pat","merge request","issues","glab"],isAvailable:t=>!t.isVSCode},{id:"git.gitlab-connect",page:"integrations",titleKey:"settings.gitlab.actions.connect",keywords:["gitlab","connect","add account","oauth","pat","token","instance"],isAvailable:t=>!t.isVSCode},{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:"sessions.agent-tools-code-mode",page:"general",titleKey:"settings.openchamber.tools.field.agentToolsCodeMode",descriptionKey:"settings.openchamber.tools.field.agentToolsCodeModeInfo",keywords:["agent","tool","code mode","codemode","execute","openchamber"],isAvailable:t=>!t.isVSCode},{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&&!t.jevBlockedByEnterprise},{id:"routing.preserve-cache",page:"routing",titleKey:"settings.routing.auto.preserveCache",descriptionKey:"settings.routing.auto.preserveCacheInfo",keywords:["cache","prompt cache","auto","routing","switch","model","cost"],isAvailable:t=>!t.isVSCode&&t.routingAvailable&&!t.jevBlockedByEnterprise},{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&&!t.jevBlockedByEnterprise},{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&&!t.jevBlockedByEnterprise},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","account","transport","ssh","ssh key","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.environment",page:"projects",titleKey:"settings.projects.environment.title",descriptionKey:"settings.projects.environment.info",keywords:["environment","env","variables","direnv","devenv","nix","envrc","path","terminal","git hooks"],isAvailable:t=>!t.isVSCode},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".openchamber","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.color",page:"agents",titleKey:"settings.agents.page.field.color",descriptionKey:"settings.agents.page.field.colorTooltip",keywords:["colour","hex","accent"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.steps",page:"agents",titleKey:"settings.agents.page.field.steps",descriptionKey:"settings.agents.page.field.stepsTooltip",keywords:["steps","loop","tool calls"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","rules","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.variant",page:"commands",titleKey:"settings.agents.page.field.variant",keywords:["variant","reasoning","thinking"]},{id:"commands.subagent",page:"commands",titleKey:"settings.commands.page.field.subagent",descriptionKey:"settings.commands.page.field.subagentTooltip",keywords:["subagent","background","child session"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout","code mode","codemode"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.classification",page:"providers",titleKey:"settings.classification.page.title",descriptionKey:"settings.classification.page.description",keywords:["jev","typesafe","zen","api key","token","safety net","auto","routing","classification","promotion","off","disable","privacy","custom endpoint","base url","openai-compatible","system one","self-hosted","proxy"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{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.accounts.title",keywords:["api key","oauth","credentials","accounts","switch account","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"web-search.provider",page:"web-search",titleKey:"settings.webSearch.section.provider",descriptionKey:"settings.webSearch.section.providerInfo",keywords:["web search","websearch","internet","default provider","disable","off","random"]},{id:"web-search.keys",page:"web-search",titleKey:"settings.webSearch.section.keys",keywords:["api key","exa","tavily","firecrawl","parallel","tinyfish","credentials"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description","manual","invocation","autoinvoke"]},{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&&!t.enterpriseMode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{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&&!t.enterpriseMode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{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&&!t.enterpriseMode},{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&&!t.enterpriseMode},{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:"git.github-connect",page:"integrations",titleKey:"settings.github.page.actions.connect",keywords:["github","connect","add account","oauth","device flow"],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.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",descriptionKey:"settings.integrations.thirdParty.info",keywords:["plugin","provider","install","update","remove","subscription"],isAvailable:t=>!t.isVSCode},{id:"integrations.third-party.opencode-claude",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",keywords:["claude","anthropic","claude code","pro","max","agent sdk","@openchamber/opencode-claude"],isAvailable:t=>!t.isVSCode},{id:"integrations.extensions",page:"integrations",titleKey:"settings.integrations.extensionCatalog.title",descriptionKey:"settings.integrations.extensionCatalog.info",keywords:["extension","install","update","remove","openchamber"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"integrations.extensions.excalidraw",page:"integrations",titleKey:"settings.integrations.extensionCatalog.excalidraw.name",descriptionKey:"settings.integrations.extensionCatalog.excalidraw.description",keywords:["excalidraw","drawing","diagram","canvas","whiteboard","obsidian","sketch"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{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 $d(t){return t.trim().toLocaleLowerCase()}function m0({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:o}){const i=$d(t);if(!i)return[];const r=a?new Set(a):null,l=i.split(/\s+/).filter(Boolean);return u0.flatMap(u=>{if(r&&!r.has(u.page))return[];const m=La(u.page);if(!m||m.isAvailable&&!m.isAvailable(e)||u.isAvailable&&!u.isAvailable(e))return[];const c=n(u.titleKey),f=u.descriptionKey?n(u.descriptionKey):null,p=$d([c,f,o(u.page),...u.keywords??[]].filter(Boolean).join(" "));return l.every(g=>p.includes(g))?[{...u,title:c,description:f,pageTitle:o(u.page)}]:[]})}const _d=280,p0=32,Am="__openchamberSettingsDetail",g0=30,f0=["general","appearance","chat","notifications","sessions","routing","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","isolated-spaces","providers","web-search","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],h0=["general","projects","opencode","content"];function b0(t,e,a,n,o){const i=is(),r=!t&&ba();return{isVSCode:i,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:a,enterpriseMode:n,jevBlockedByEnterprise:o}}function Bd(t,e){return t.isAvailable?t.isAvailable(e):!0}function yi(t,e){const a=new Set(e);let n=t,o=1;for(;a.has(n);)n=`${t}-${o}`,o+=1;return n}function Wr(t){const e=t?.[Am];return e?.page==null||e.stage!=="page-content"?null:{page:nl(e.page),stage:e.stage}}function x0(){return window.history.state??{}}const R0=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:o="nav",registerBackHandler:i})=>{const{t:r}=ze(),l=qn(),u=e??l.isMobile,m=re(me=>me.settingsPage),c=re(me=>me.isSettingsDialogOpen),f=re(me=>me.setSettingsPage),p=re(me=>me.shortcutOverrides.open_settings),g=nl(m),[h,k]=d.useState(o),b=d.useRef(o==="nav"?g:null);d.useEffect(()=>{!u&&g==="home"&&f("general")},[u,f,g]);const[j,x]=d.useState(""),[S,v]=d.useState(null),[N,y]=d.useState(0),I=d.useRef(null),w=d.useRef(!1),D=d.useRef([]),C=d.useRef(0),A=d.useRef(!1),T=d.useMemo(()=>rs(),[]),O=d.useMemo(()=>rs()&&Za(),[]),z=d.useMemo(()=>rs()&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),M=d.useMemo(()=>rs()&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),P=d.useMemo(()=>rs()&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),R=re(me=>me.routingFeatureAvailable),F=Un(),_=Cg(),B=d.useMemo(()=>b0(T,u,R,F,_),[T,u,R,F,_]),V=d.useMemo(()=>{const me=n?new Set(n):null;return Ef.filter(de=>de.slug!=="home").filter(de=>!me||me.has(de.slug)).filter(de=>Bd(de,B)).filter(de=>!(B.isVSCode&&de.slug==="projects")).filter(de=>!(u&&de.slug==="shortcuts"))},[B,u,n]),ee=d.useMemo(()=>{const me=new Map(f0.map((de,Pe)=>[de,Pe]));return V.slice().sort((de,Pe)=>(me.get(de.slug)??999)-(me.get(Pe.slug)??999))},[V]),L=dn(me=>me.activeProjectId),$=Ks();d.useEffect(()=>{if(!(!c&&!B.isVSCode&&!a)){if(g==="agents"){vn.getState().loadAgents($);return}if(g==="commands"){Va.getState().loadCommands($);return}if(g==="mcp"){Dn.getState().loadMcpConfigs({directory:$});return}if(g==="plugins"){Ot.getState().loadPlugins();return}(g==="skills.installed"||g==="skills.catalog")&&(Bs.getState().loadSkills($),bn.getState().loadCatalog()),g==="snippets"&&yo.getState().loadSnippets()}},[L,c,a,B.isVSCode,$,g]);const H=d.useCallback(me=>{if(f(me),b.current=me,!u)return;const de=La(me);if(!de||de.slug==="home"){k("nav");return}k(de.kind==="split"?"page-sidebar":"page-content")},[u,f]),W=d.useMemo(()=>La(g),[g]),Z=d.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel","isolated-spaces":"spaces"}),[]),te=d.useCallback(me=>{switch(me){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"web-search":return r("settings.page.webSearch.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"extensions":return r("settings.page.extensions.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"routing":return r("settings.page.routing.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"isolated-spaces":return r("settings.openchamber.spaces.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),J=d.useMemo(()=>m0({query:j,runtimeCtx:{...B,isDesktopLocalOrigin:O,isMac:z,isWindows:M,isLinux:P},visiblePageSlugs:n,t:r,getPageTitle:te}),[te,O,z,M,P,B,j,r,n]),ie=d.useCallback(me=>{if(me.id.startsWith("agents.")){const de=vn.getState(),Pe=yi("new-agent",de.agents.map(he=>he.name));return de.setAgentDraft({name:Pe,scope:"user"}),de.setSelectedAgent(Pe),me.id==="agents.create"?"agents.name":me.id}if(me.id.startsWith("commands.")){const de=Va.getState(),Pe=yi("new-command",de.commands.map(he=>he.name));return de.setCommandDraft({name:Pe,scope:"user"}),de.setSelectedCommand(Pe),me.id==="commands.create"?"commands.name":me.id}if(me.id.startsWith("mcp.")){const de=Dn.getState(),Pe=yi("new-mcp-server",de.mcpServers.map(he=>he.name));return de.setMcpDraft({name:Pe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1}),de.setSelectedMcp(Pe),me.id==="mcp.create"?"mcp.server":me.id}if(me.id.startsWith("snippets.")){const de=yo.getState(),Pe=yi("new-snippet",de.snippets.map(he=>he.name));return de.setSnippetDraft({name:Pe,scope:"global"}),de.setSelectedSnippet(Pe),me.id==="snippets.create"?"snippets.content":me.id}if(me.id.startsWith("skills.")){const de=Bs.getState(),Pe=yi("new-skill",de.skills.map(he=>he.name));return de.setSkillDraft({name:Pe,scope:"user",source:"opencode",description:"",instructions:""}),de.setSelectedSkill(Pe),me.id==="skills.create"?"skills.basic-information":me.id}return me.id==="providers.connect"&&re.getState().setSettingsProvidersConnectRequested(!0),me.id==="providers.classification"&&re.getState().setSettingsProvidersClassificationRequested(!0),me.id==="plugins.create"?"plugins.spec":me.id},[]),pe=d.useMemo(()=>{const me=[],de=new Map;for(const Pe of J){let he=de.get(Pe.page);he||(he={page:Pe.page,pageTitle:Pe.pageTitle,results:[]},de.set(Pe.page,he),me.push(he)),he.results.push(Pe)}return me},[J]);d.useEffect(()=>{y(0),C.current=0,A.current=!1},[j]),d.useEffect(()=>{C.current=N},[N]),d.useEffect(()=>{D.current[N]?.scrollIntoView({block:"nearest"})},[N]),d.useEffect(()=>{N>=J.length&&y(Math.max(0,J.length-1)),D.current.length=J.length},[N,J.length]);const X=d.useCallback(me=>{const de=ie(me);v(de),H(me.page),u&&k("page-content"),me.id==="plugins.create"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[u,H,ie]),xe=d.useCallback(me=>{if(j.trim()){if(me.key==="Escape"){me.preventDefault(),x("");return}if(J.length!==0){if(me.key==="ArrowDown"){me.preventDefault(),A.current=!0,y(de=>(de+1)%J.length);return}if(me.key==="ArrowUp"){me.preventDefault(),A.current=!0,y(de=>(de-1+J.length)%J.length);return}if(me.key==="Enter"){me.preventDefault();const de=(C.current%J.length+J.length)%J.length,Pe=J[de]??J[0];Pe&&X(Pe)}}}},[X,j,J]),Y=re(me=>me.settingsJumpRequest);d.useEffect(()=>{Y&&(re.getState().clearSettingsJumpRequest(),v(Y.itemId),H(nl(Y.page)),u&&k("page-content"))},[u,H,Y]),d.useEffect(()=>{const me=S;if(!me)return;let de=!1,Pe=0,he=0;const Ue=()=>{if(de)return;const Ae=globalThis.CSS?.escape?globalThis.CSS.escape(me):me.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=I.current?.querySelector(`[data-settings-item="${Ae}"]`);if(!Re){Pe+=1,Pe<g0&&(he=window.requestAnimationFrame(Ue));return}v(null),Re.scrollIntoView({block:"center",behavior:"smooth"}),Re.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Re.removeAttribute("data-settings-search-highlight")},1600)};return he=window.requestAnimationFrame(Ue),()=>{de=!0,window.cancelAnimationFrame(he)}},[S,g]);const be=d.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:zn,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),De=d.useCallback((me,de)=>{switch(me){case"projects":return s.jsx(Mv,{onItemSelect:de.onItemSelect});case"agents":return s.jsx(dh,{onItemSelect:de.onItemSelect});case"commands":return s.jsx(tb,{onItemSelect:de.onItemSelect});case"skills.installed":return s.jsx(Bx,{onItemSelect:de.onItemSelect});case"usage":return s.jsx(k1,{onItemSelect:de.onItemSelect});case"magic-prompts":return s.jsx(z1,{onItemSelect:de.onItemSelect});case"snippets":return s.jsx(B1,{onItemSelect:de.onItemSelect});default:return null}},[]),ve=d.useCallback(me=>{const de=La(me);if(de&&!Bd(de,B))return be();switch(me){case"projects":return s.jsx(Kv,{});case"remote-instances":return s.jsx(ly,{});case"agents":return s.jsx(Lh,{});case"behavior":return s.jsx(Bh,{});case"commands":return s.jsx(lb,{});case"mcp":return s.jsx(Gb,{});case"plugins":return s.jsx(Nx,{});case"skills.installed":return s.jsx(Kc,{view:"installed"});case"skills.catalog":return s.jsx(Kc,{view:"catalog"});case"providers":return s.jsx(y1,{});case"web-search":return s.jsx(Wh,{});case"usage":return s.jsx(L1,{});case"about":return s.jsx(Qt,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(yu,{})});case"magic-prompts":return s.jsx(_1,{});case"snippets":return s.jsx(G1,{});case"git":return s.jsx(X1,{});case"integrations":return s.jsx(Wj,{});case"routing":return s.jsx(sk,{});case"extensions":return s.jsx(fk,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":case"isolated-spaces":{const Pe=Z[me]??"visual";return s.jsx(X2,{section:Pe})}default:return null}},[Z,be,B,r]);d.useEffect(()=>{if(!u||h!=="nav"||g==="home"||b.current===g)return;const me=La(g);!me||me.slug==="home"||(b.current=g,k(me.kind==="split"?"page-sidebar":"page-content"))},[u,h,g]);const se=u&&h!=="nav",ge=u&&h==="page-content"&&W?.kind==="split",ne=r(ge?"settings.view.actions.back":se?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),Se=cu("open_settings",p===void 0?void 0:{open_settings:p}),ke=Se?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Kn(Se)}):r("settings.view.actions.closeSettings"),Te=d.useCallback(me=>{if(B.isVSCode)return;const de=Wr(window.history.state);de?.page===me&&de.stage==="page-content"||window.history.pushState({...x0(),[Am]:{page:me,stage:"page-content"}},"",window.location.href)},[B.isVSCode]),Ee=d.useCallback(()=>{w.current=!0,k("page-content"),Te(g)},[Te,g]);d.useEffect(()=>{if(!u||h!=="page-content"||!w.current)return;w.current=!1;const me=window.requestAnimationFrame(()=>{I.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(me)}},[u,h,g]);const Le=d.useCallback(()=>{if(ge){if(Wr(window.history.state)?.page===g&&!B.isVSCode){window.history.back();return}k("page-sidebar");return}k("nav")},[ge,B.isVSCode,g]);d.useEffect(()=>{if(i)return i(()=>!u||h==="nav"?!1:(Le(),!0)),()=>i(null)},[Le,u,h,i]),d.useEffect(()=>{if(!u||B.isVSCode)return;const me=de=>{if(La(g)?.kind!=="split")return;if(Wr(de.state)?.page===g){k("page-content");return}k(he=>he==="page-content"?"page-sidebar":he)};return window.addEventListener("popstate",me),()=>{window.removeEventListener("popstate",me)}},[u,B.isVSCode,g]);const ce=()=>{const me=j.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(Q,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:j,onChange:de=>x(de.target.value),onKeyDown:xe,placeholder:r("settings.view.search.placeholder"),"aria-label":r("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),me&&s.jsx("button",{type:"button",onClick:()=>x(""),"aria-label":r("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(Q,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(Ps,{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:me?J.length>0?(()=>{let de=0;return pe.map(Pe=>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:Pe.pageTitle}),Pe.results.map(he=>{const Ue=de;de+=1;const Ae=Ue===N,Re=!!he.description;return s.jsxs("button",{type:"button",ref:$e=>{D.current[Ue]=$e},onMouseMove:()=>{A.current=!1,y(Ue)},onClick:()=>X(he),className:Ie("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Re?"min-h-11 py-1.5":"py-2",Ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:he.title}),Re&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:he.description})]},he.id)})]},Pe.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const de=new Map;for(const he of ee){const Ue=he.group,Ae=de.get(Ue);Ae?Ae.push(he):de.set(Ue,[he])}return h0.map(he=>({group:he,pages:de.get(he)??[]})).filter(he=>he.pages.length>0).map(({group:he,pages:Ue},Ae)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:Ie("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ae===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${he}`)}),Ue.map(Re=>{const $e=g===Re.slug&&!(u&&h==="nav"),nt=Df(Re.slug);return!nt&&Re.slug!=="mcp"?null:s.jsx(ru,{children:s.jsx(lu,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>H(Re.slug),"aria-current":$e?"page":void 0,className:Ie("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",$e?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Re.slug==="mcp"?s.jsx(Ig,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(Q,{name:nt,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:te(Re.slug)}),Re.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:r("settings.view.badge.beta")})]})]})})},Re.slug)})]},he))})()})})]})},Me=()=>{if(h==="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(aa,{children:ce()})})});if(!W)return s.jsx("div",{className:"flex-1 bg-background"});if(h==="page-sidebar"){if(W.kind!=="split"){const de=ve(g);return s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(aa,{children:de})})}return s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(aa,{children:De(g,{onItemSelect:Ee})})})}const me=ve(g);return s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(aa,{children:me})})},Fe=()=>{if(!W||g==="home")return null;const me=t?p0:0,de=s.jsx(ju.Provider,{value:me,children:s.jsx(aa,{children:ve(g)})});return W.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:Ie("border-r",B.isVSCode?"bg-background":"bg-sidebar"),style:{width:_d,minWidth:_d,borderColor:"var(--interactive-border)"},children:s.jsx(aa,{children:De(g,{})})}),s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,verticalTrackStart:me,children:de})]}):s.jsx(Ps,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,verticalTrackStart:me,children:de})};return s.jsxs("div",{ref:I,"data-settings-view":"true",className:Ie("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[u?s.jsxs("div",{className:Ie("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",h!=="nav"&&"border-b","bg-background"),style:h!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[se?s.jsx("button",{type:"button",onClick:Le,"aria-label":ne,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(Q,{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:h==="nav"?r("settings.view.home.title"):W?te(W.slug):r("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:ke,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(Q,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[se&&s.jsx("div",{className:Ie("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Le,"aria-label":r("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(Q,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:Ie("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:ke,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(Q,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:u?Me():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Ie("relative flex h-full min-h-0 w-36 min-w-36 flex-col overflow-hidden border-r sm:w-64 sm:min-w-64",T?"bg-sidebar":B.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(aa,{children:ce()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Fe()})]})})]})};export{yu as A,R0 as S};