@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
@@ -1,30 +0,0 @@
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 $e,r as Ge}from"./vendor-react-BUCujlKS.js";import{f as _e,B,I as J,o as Ss,bP as Qn,t as q,O as mm,iy as pm,fb as qe,gd as Pt,g as _a,fD as kd,b as un,_ as va,h as je,aV as gm,iz as ar,iA as fm,c$ as $t,c_ as Tt,d1 as dt,d0 as Et,cZ as Dt,a8 as He,fK as Rn,iB as wd,iC as hm,ak as Co,iD as bi,iE as ya,cE as js,cy as zt,cz as Ut,cA as Bt,cB as Vt,cC as Ht,cD as ns,iF as Xr,aW as On,bN as mn,de as Ga,dg as Ja,aU as Fn,aT as Kn,di as Qa,dj as Ya,iG as Mr,iH as xn,au as Tn,at as ln,f$ as Wt,iI as Ws,iJ as el,gb as Mt,l as rt,gg as yt,ga as qt,iK as Rt,d2 as Ts,fM as fa,gf as qs,gh as dn,gc as ls,hy as gs,iL as bs,ge as Sd,dJ as ct,iM as Nd,iN as xm,iO as bm,iP as Si,iQ as vm,iR as is,dY as zn,fV as ks,iS as Vs,hY as qa,i4 as tn,iT as Ba,iU as Cd,iV as tl,fO as sl,ay as ha,iW as Rr,al as Wn,iX as El,iY as ym,b6 as nl,iZ as Dl,i_ as Ln,i$ as Ft,gv as al,j0 as il,j1 as ua,j2 as Id,j3 as Pn,dc as Io,j4 as Ml,a_ as jm,d3 as km,dU as wm,$ as Sm,a0 as Nm,a1 as Cm,N as Za,g$ as Ni,j5 as Im,j6 as Pm,cT as Am,d4 as Lr,j7 as Pd,j8 as Qt,P as bn,j9 as Or,ja as Tm,jb as ws,jc as go,jd as Em,gi as Ad,je as Dm,n as ds,fq as fo,y as Td,x as Mm,i as Rm,j as Lm,fr as Om,jf as Fm,p as Km,jg as zm,jh as Um,ji as Rl,hr as Ed,jj as $m,jk as ir,jl as Ll,jm as _m,jn as Bm,jo as Vm,jp as Hm,jq as ho,jr as xs,js as vs,aG as Gs,cP as ol,jt as qm,cK as Dd,aF as Wm,aI as Gm,b0 as Jm,i3 as or,e9 as Md,ct as Rd,ea as Ld,ju as Qm,jv as Ym,jw as Zm,jx as Xm,jy as ep,jz as tp,jA as sp,jB as np,cu as As,jC as cn,jD as rl,cI as rn,cH as Od,be as La,jE as ap,jF as Fd,jG as ip,jH as Wa,b3 as op,jI as vi,jJ as Cn,fP as Kd,jK as zd,fU as rp,fT as lp,jL as cp,jM as Us,jN as ys,hN as la,jO as An,jP as lo,jQ as dp,fA as up,jR as Ud,jS as ma,jT as mp,jU as pp,Z as $d,dV as gp,e0 as fp,e1 as hp,du as xp,jV as bp,e2 as vp,dS as yp,bV as jp,jW as kp,jX as Gn,jY as wp,jZ as ll,j_ as ca,b8 as Sp,g9 as Oa,j$ as Ol,k0 as Fa,cv as Jn,k1 as Np,k2 as Cp,k3 as Ip,k4 as Pp,k5 as rr,k6 as Fl,k7 as Ap,k8 as Tp,k9 as Ep,ka as Dp,kb as Kl,kc as Mp,z as Rp,m as zl,fL as Lp,kd as Op,ke as lr,av as _d,aw as Bd,ax as Fp,fv as Kp,kf as Po,kg as zp,kh as Up,ki as $p,kj as _p,kk as Vd,kl as yi,dK as Bp,cw as Hd,dZ as Vp,b4 as Vn,b5 as Hp}from"./useAppFontEffects-DCqCVGlT.js";import{h as Lt,i as cl,u as ne,T as os,eW as qp,eX as Ul,bP as ji,aX as En,bO as qd,bQ as Wp,z as bt,aT as yn,H as Ps,a as Xt,L as cs,N as Xa,W as cr,dK as $l,dR as _l,$ as ri,p as Gp,eY as Jp,k as Qp,dJ as da,eZ as Yp,az as Bl,dO as Zp,e_ as Xp,e$ as eg,s as Vl,e as Ii,dN as tg,dP as sg,f0 as Wd,aR as ss,f1 as ng,a7 as ag,f2 as ig,b3 as dl,A as og,ap as Gd,f3 as Jd,c1 as Qd,C as xa,bV as Yd,at as rg,au as lg,ba as ul,f4 as cg,D as Ao,f5 as Hl,f6 as dg,a6 as ug,v as ql,bk as Wl,c5 as Wi,bF as mg,f7 as pg,ao as ba,f8 as gg,eU as Ka,f9 as Gl,eS as Jl,fa as Ql,bi as Yl,fb as fg,fc as hg,fd as xg,fe as bg,ff as Zl,b as vg,fg as yg,fh as jg,fi as kg,fj as Zd,fk as wg,fl as Sg,fm as Ng,fn as Xd,aL as Cg}from"./index-vQ1Pg1cr.js";import{u as Os,c as Ig}from"./vendor-zustand-BAGL70zf.js";import{o as rs,s as Nt,b as Pi,l as Pg,r as Dn,c as Fr,a as sn,n as xo,_ as ml,u as Kr}from"./vendor-zod-CxRSdNoV.js";import{u as Ag,ao as Xl,aZ as Tg,a_ as Eg,a$ as Dg,as as Js,au as Qs,at as Ys,m as pa,aF as Mg,a6 as Is,I as Rg,aV as Lg,aC as eu,b0 as Og,b1 as Fg,b2 as Kg,b3 as zr,b4 as Ua,b5 as Ur,aD as zg,aE as Ug}from"./runtimeEndpointReset-DqLJC6L1.js";import{s as $g,p as _g}from"./vendor-yaml-3778uTud.js";import{c as ec,s as Bg,C as tc,P as Vg}from"./shikiHighlight-CXgZnvHh.js";import{getResolvedShikiTheme as Hg}from"./appThemeRegistry-CxzMxR-H.js";import{E as sc}from"./vendor-codemirror-view-Bniqp7p5.js";import{Q as tu}from"./vendor-qrcode-DTJ12-WC.js";import{toast as Va}from"./vendor-sonner-DFyL3AvE.js";import{s as qg}from"./vendor-strip-json-comments-5dJlOkP1.js";import{Y as Wg,U as Gg,X as Jg,W as Qg,V as Yg}from"./vendor-base-ui-DX96QhTP.js";import{_ as Zg}from"./vendor-vite-runtime-DD1OZmLC.js";const nc=()=>{const{t}=_e(),[e,n]=d.useState(null);d.useEffect(()=>{let i=!1;const o=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const c=await Lt("/api/system/info",{signal:o?.signal,headers:{Accept:"application/json"}});if(!c.ok)return;const l=await c.json().catch(()=>null);if(!l||i)return;const m=typeof l.port=="number"&&Number.isFinite(l.port)&&l.port>0?l.port:null,u=typeof l.tunnelUrl=="string"&&l.tunnelUrl.trim().length>0?l.tunnelUrl.trim():null;n({port:m,tunnelUrl:u})}catch{}})(),()=>{i=!0,o?.abort()}},[]);const a=[];return e?.port!==null&&e?.port!==void 0&&a.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&a.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),a.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(i=>s.jsxs(B,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Ss(i.url)},children:[s.jsx(J,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},ac="https://github.com/openchamber/openchamber",Xg="https://discord.gg/ZYRSdnwwKA",ic="https://x.com/openchamber_dev",ef=800,tf={info:null,checking:!1,available:!1,error:null};function sf(t){const e=$e.c(5),[n,a]=d.useState(tf);let i;e[0]!==t?(i=async()=>{if(t){a(nf);try{const c=await Tg();a({info:c,checking:!1,available:c.available,error:null})}catch(c){const l=c;a({info:null,checking:!1,available:!1,error:l instanceof Error?l.message:String(l)})}}},e[0]=t,e[1]=i):i=e[1];const o=i;let r;return e[2]!==o||e[3]!==n?(r={...n,check:o},e[2]=o,e[3]=n,e[4]=r):r=e[4],r}function nf(t){return{...t,checking:!0,error:null}}function af(t){const e=$e.c(11),[n,a]=d.useState(null);let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={kind:"idle"},e[0]=i):i=e[0];const[o,r]=d.useState(i);let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=async()=>{try{const x=await Eg();return a(x),x}catch{return null}},e[1]=c):c=e[1];const l=c;let m,u;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{l()},u=[l],e[2]=m,e[3]=u):(m=e[2],u=e[3]),d.useEffect(m,u);let f;e[4]!==t?(f=async()=>{r({kind:"upgrading"});try{const x=await Dg(t);r({kind:"installed",version:x})}catch(x){const S=x;r({kind:"failed",error:S instanceof Error?S.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 x=>{await x().catch(of);const S=await l();S?.currentVersion&&r(b=>b.kind!=="installed"||b.version&&b.version.replace(/^v/,"")!==S.currentVersion?b:{kind:"idle"})},e[6]=g):g=e[6];const h=g;let j;return e[7]!==o||e[8]!==n||e[9]!==p?(j={status:n,phase:o,refresh:l,upgrade:p,reloadAfterUpgrade:h},e[7]=o,e[8]=n,e[9]=p,e[10]=j):j=e[10],j}function of(){}function rf(t){const[e,n]=d.useState(null);return d.useEffect(()=>{if(!t)return;let a=!1;return Zg(async()=>{const{App:i}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:i}},__vite__mapDeps([0,1,2])).then(({App:i})=>i.getInfo()).then(i=>{a||n(i.version.trim()||null)}).catch(()=>{}),()=>{a=!0}},[t]),e}const su=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=_e(),[n,a]=d.useState(t),[i,o]=d.useState(!1),[r,c]=d.useState(null),l=Ag(Os(O=>({info:O.info,checking:O.checking,available:O.available,error:O.error,downloading:O.downloading,downloaded:O.downloaded,installing:O.installing,progress:O.progress,runtimeType:O.runtimeType,checkForUpdates:O.checkForUpdates,downloadUpdate:O.downloadUpdate,restartToUpdate:O.restartToUpdate}))),{isMobile:m}=Qn(),u=d.useMemo(()=>cl(),[]),f=sf(u),p=rf(u),g=u?{info:f.info,checking:f.checking,available:f.available,error:f.error,checkForUpdates:f.check,runtimeType:"web"}:{info:l.info,checking:l.checking,available:l.available,error:l.error,checkForUpdates:l.checkForUpdates,runtimeType:l.runtimeType},h=r||g.info?.currentVersion||"unknown",j=af(e("opencodeUpdate.toast.failed.description")),x=j.status?.currentVersion??null,S=j.phase.kind==="installed"?null:j.status?.availableVersion??null,[b,w]=d.useState(!1),k=(()=>{const O=g.info?.version||"";return u?g.info?.packageManager==="electron"?e("settings.openchamber.about.actions.updateDesktopToVersion",{version:O}):e("settings.openchamber.about.actions.updateServerToVersion",{version:O}):e("settings.openchamber.about.actions.updateOpenChamberToVersion",{version:O})})(),I=g.available&&g.info?.installBlocked==="service-manager",y=g.info?.updateCommand||"openchamber update",E=()=>{g.checkForUpdates(),j.refresh()},v=async()=>{(await _a(y)).ok&&(w(!0),setTimeout(()=>w(!1),2e3))},R=()=>{j.reloadAfterUpgrade(async()=>{await kd({message:e("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})})},C=I?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.serviceManagerUpdate",{version:g.info?.version||""})}),s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-elevated/50 p-1 pl-3",children:[s.jsx("code",{className:"flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm text-foreground",children:y}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",onClick:()=>{v()},"aria-label":e(b?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:s.jsx(J,{name:b?"check":"clipboard",className:"size-4"})})]})]}):null,T=(()=>{const{phase:O}=j;if(O.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:O.version?e("settings.openchamber.about.openCode.installedVersion",{version:O.version}):e("settings.openchamber.about.openCode.installed")}),s.jsx(B,{type:"button",size:"sm",variant:"outline",onClick:R,children:e("opencodeUpdate.toast.actions.reload")})]});if(!S)return null;if(!j.status?.supported)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.openCode.manualUpdate",{version:S})});const A=O.kind==="upgrading";return s.jsxs("div",{className:"space-y-2",children:[s.jsxs(B,{type:"button",size:"sm",variant:"outline",onClick:()=>{j.upgrade()},disabled:A,children:[s.jsx(J,{name:A?"loader":"download",className:A?"size-4 animate-spin":"size-4"}),A?e("opencodeUpdate.toast.upgrading.title"):e("settings.openchamber.about.actions.updateOpenCodeToVersion",{version:S})]}),O.kind==="failed"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:O.error})]})})();d.useEffect(()=>{let O=!1;return(async()=>{try{const N=await Lt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const M=await N.json().catch(()=>null),F=typeof M?.openchamberVersion=="string"&&M.openchamberVersion.trim().length>0?M.openchamberVersion.trim():null;O||c(F)}catch{O||c(null)}})(),()=>{O=!0}},[]);const P=d.useRef(!1);d.useEffect(()=>{if(g.checking)o(!0),P.current=!0;else if(i){const O=setTimeout(()=>{o(!1),P.current&&!g.available&&!g.error&&(q.success(e(u?"settings.openchamber.about.toast.serverLatestVersion":"settings.openchamber.about.toast.latestVersion")),P.current=!1)},ef);return()=>clearTimeout(O)}},[e,u,g.checking,i,g.available,g.error]);const L=g.checking||i;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(mm,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${pm}`,children:"OpenChamber"}),s.jsx("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:u?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:h})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:x||e("settings.openchamber.about.state.unknown")})}),p&&s.jsx("p",{children:e("settings.openchamber.about.native.appVersion",{version:p})})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:h})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:x||e("settings.openchamber.about.state.unknown")})})]})}),s.jsx(nc,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!g.available&&!g.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:E,disabled:L,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[L?s.jsx(J,{name:"loader",className:"size-4 animate-spin"}):s.jsx(J,{name:"refresh",className:"size-4"}),e(L?"settings.openchamber.about.state.checking":u?"settings.openchamber.about.actions.checkServerForUpdates":"settings.openchamber.about.actions.checkForUpdates")]}),!L&&g.available&&!I&&s.jsxs(B,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(J,{name:"download",className:"size-4"}),k]})]}),C,T&&s.jsx("div",{className:"flex justify-center text-center",children:T}),g.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:g.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:ac,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(J,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Xg,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(J,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:ic,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(J,{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(Xl,{open:n,onOpenChange:a,info:g.info,downloading:l.downloading,downloaded:l.downloaded,installing:l.installing,progress:l.progress,error:g.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:g.runtimeType})]}):s.jsxs(qe,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:h})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:x||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[g.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(J,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!g.checking&&g.available&&!I&&s.jsxs(B,{size:"sm",variant:"default",onClick:()=>a(!0),children:[s.jsx(J,{name:"download",className:"h-4 w-4 mr-1"}),k]}),!g.checking&&!g.available&&!g.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(B,{size:"sm",variant:"outline",onClick:E,disabled:g.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),C&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:C}),T&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:T}),g.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:g.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(nc,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:ac,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(J,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:ic,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(J,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Xl,{open:n,onOpenChange:a,info:g.info,downloading:l.downloading,downloaded:l.downloaded,installing:l.installing,progress:l.progress,error:g.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:g.runtimeType})]})},lf=(t,e,n)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===n)??e[0])?.path??null,Zs=()=>{const t=$e.c(4),e=ne(cf),n=un(df),a=un(uf);let i;return t[0]!==a||t[1]!==n||t[2]!==e?(i=lf(e,n,a),t[0]=a,t[1]=n,t[2]=e,t[3]=i):i=t[3],i};function cf(t){return t.settingsProjectPath}function df(t){return t.projects}function uf(t){return t.activeProjectId}const mf=t=>[...t].sort((e,n)=>(e.label||e.path).localeCompare(n.label||n.path)),Ai=t=>{const e=$e.c(75),{className:n}=t,{t:a}=_e(),{currentTheme:i}=va(),o=ne(pf),[r,c]=d.useState(!1),l=un(gf),m=Zs(),u=ne(ff),f=os();let p;e[0]!==l?(p=mf(l),e[0]=l,e[1]=p):p=e[1];const g=p;let h;e[2]!==m||e[3]!==g?(h=g.find(L=>L.path===m)??g[0]??null,e[2]=m,e[3]=g,e[4]=h):h=e[4];const j=h;if(f||!j)return null;let x;e[5]!==u||e[6]!==g?(x=L=>{const O=g.find(A=>A.id===L);O&&u(O.path)},e[5]=u,e[6]=g,e[7]=x):x=e[7];const S=x;if(o){let L;e[8]!==n?(L=je(n),e[8]=n,e[9]=L):L=e[9];let O;e[10]!==a?(O=a("settings.shared.projectSelector.switchProjectAria"),e[10]=a,e[11]=O):O=e[11];let A;e[12]!==a?(A=a("settings.shared.projectSelector.switchProjectTitle"),e[12]=a,e[13]=A):A=e[13];let N,M;e[14]===Symbol.for("react.memo_cache_sentinel")?(N=()=>c(!0),M=je(gm({size:"touch"}),"w-full min-w-0"),e[14]=N,e[15]=M):(N=e[14],M=e[15]);let F;e[16]!==j||e[17]!==i?(F=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(ar,{project:j,theme:i})}),e[16]=j,e[17]=i,e[18]=F):F=e[18];let H;e[19]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(J,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=H):H=e[19];let W;e[20]!==r||e[21]!==O||e[22]!==A||e[23]!==M||e[24]!==F?(W=s.jsxs("button",{type:"button","aria-label":O,title:A,"aria-haspopup":"dialog","aria-expanded":r,onClick:N,className:M,children:[F,H]}),e[20]=r,e[21]=O,e[22]=A,e[23]=M,e[24]=F,e[25]=W):W=e[25];let G;e[26]!==W||e[27]!==L?(G=s.jsx("div",{className:L,children:W}),e[26]=W,e[27]=L,e[28]=G):G=e[28];let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=()=>c(!1),e[29]=$):$=e[29];const z=j.id;let U;e[30]!==a?(U=a("settings.shared.projectSelector.sheetTitle"),e[30]=a,e[31]=U):U=e[31];let _;e[32]!==a?(_=a("settings.shared.projectSelector.searchPlaceholder"),e[32]=a,e[33]=_):_=e[33];let V;e[34]!==j.id||e[35]!==i||e[36]!==S||e[37]!==r||e[38]!==g||e[39]!==U||e[40]!==_?(V=s.jsx(fm,{open:r,onClose:$,projects:g,selectedProjectId:z,onSelectProject:S,theme:i,title:U,searchPlaceholder:_}),e[34]=j.id,e[35]=i,e[36]=S,e[37]=r,e[38]=g,e[39]=U,e[40]=_,e[41]=V):V=e[41];let Z;return e[42]!==G||e[43]!==V?(Z=s.jsxs(s.Fragment,{children:[G,V]}),e[42]=G,e[43]=V,e[44]=Z):Z=e[44],Z}let b;e[45]!==n?(b=je(n),e[45]=n,e[46]=b):b=e[46];const w=j.id;let k;e[47]!==S?(k=L=>{L&&S(L)},e[47]=S,e[48]=k):k=e[48];let I;e[49]!==a?(I=a("settings.shared.projectSelector.switchProjectAria"),e[49]=a,e[50]=I):I=e[50];let y;e[51]!==a?(y=a("settings.shared.projectSelector.switchProjectTitle"),e[51]=a,e[52]=y):y=e[52];let E;e[53]!==j||e[54]!==i?(E=s.jsx($t,{children:s.jsx(ar,{project:j,theme:i})}),e[53]=j,e[54]=i,e[55]=E):E=e[55];let v;e[56]!==I||e[57]!==y||e[58]!==E?(v=s.jsx(Tt,{size:"settings",className:"w-full","aria-label":I,title:y,children:E}),e[56]=I,e[57]=y,e[58]=E,e[59]=v):v=e[59];let R;if(e[60]!==i||e[61]!==g){let L;e[63]!==i?(L=O=>s.jsx(dt,{value:O.id,className:"max-w-[24rem] truncate",children:s.jsx(ar,{project:O,theme:i})},O.id),e[63]=i,e[64]=L):L=e[64],R=g.map(L),e[60]=i,e[61]=g,e[62]=R}else R=e[62];let C;e[65]!==R?(C=s.jsx(Et,{fitContent:!0,children:R}),e[65]=R,e[66]=C):C=e[66];let T;e[67]!==j.id||e[68]!==v||e[69]!==C||e[70]!==k?(T=s.jsxs(Dt,{value:w,onValueChange:k,children:[v,C]}),e[67]=j.id,e[68]=v,e[69]=C,e[70]=k,e[71]=T):T=e[71];let P;return e[72]!==T||e[73]!==b?(P=s.jsx("div",{className:b,children:T}),e[72]=T,e[73]=b,e[74]=P):P=e[74],P};function pf(t){return t.isMobile}function gf(t){return t.projects}function ff(t){return t.setSettingsProjectPath}const pl=t=>{const e=$e.c(16),{value:n,onChange:a}=t,{t:i}=_e();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(J,{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]=o):o=e[0];let r;e[1]!==a?(r=f=>a(f.target.value),e[1]=a,e[2]=r):r=e[2];let c;e[3]!==a||e[4]!==n?(c=f=>{f.key==="Escape"&&n&&(f.preventDefault(),f.stopPropagation(),a(""))},e[3]=a,e[4]=n,e[5]=c):c=e[5];let l;e[6]!==i?(l=i("settings.common.sidebar.searchPlaceholder"),e[6]=i,e[7]=l):l=e[7];let m;e[8]!==i?(m=i("settings.common.sidebar.searchPlaceholder"),e[8]=i,e[9]=m):m=e[9];let u;return e[10]!==r||e[11]!==c||e[12]!==l||e[13]!==m||e[14]!==n?(u=s.jsxs("div",{className:"relative mt-3",children:[o,s.jsx(He,{value:n,onChange:r,onKeyDown:c,placeholder:l,"aria-label":m,className:"h-8 pl-7 typography-meta"})]}),e[10]=r,e[11]=c,e[12]=l,e[13]=m,e[14]=n,e[15]=u):u=e[15],u},gl=t=>{const e=$e.c(5),{query:n}=t,{t:a}=_e();let i;e[0]!==n||e[1]!==a?(i=a("settings.common.sidebar.noMatches",{query:n.trim()}),e[0]=n,e[1]=a,e[2]=i):i=e[2];let o;return e[3]!==i?(o=s.jsx("p",{className:"px-2 py-6 text-center typography-meta text-muted-foreground",children:i}),e[3]=i,e[4]=o):o=e[4],o};function hf(t,e){return`opencode:sidebar-group:${t}:${e}`}const $r=t=>{const e=$e.c(33),{label:n,count:a,storageKey:i,defaultExpanded:o,children:r}=t,c=o===void 0?!0:o;let l;e[0]!==n||e[1]!==i?(l=hf(i,n),e[0]=n,e[1]=i,e[2]=l):l=e[2];const m=l,u=d.useId();let f;e[3]!==c||e[4]!==m?(f=()=>{try{const T=localStorage.getItem(m);if(T!==null)return T==="true"}catch{}return c},e[3]=c,e[4]=m,e[5]=f):f=e[5];const[p,g]=Ge.useState(f);let h,j;e[6]!==p||e[7]!==m?(h=()=>{try{localStorage.setItem(m,String(p))}catch{}},j=[m,p],e[6]=p,e[7]=m,e[8]=h,e[9]=j):(h=e[8],j=e[9]),Ge.useEffect(h,j);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>g(xf),e[10]=x):x=e[10];let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=je("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]=S):S=e[11];const b=!p&&"-rotate-90";let w;e[12]!==b?(w=je("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",b),e[12]=b,e[13]=w):w=e[13];let k;e[14]!==w?(k=s.jsx(J,{name:"arrow-down-s",className:w}),e[14]=w,e[15]=k):k=e[15];let I;e[16]!==n?(I=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=I):I=e[17];let y;e[18]!==a?(y=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=y):y=e[19];let E;e[20]!==u||e[21]!==p||e[22]!==k||e[23]!==I||e[24]!==y?(E=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":p,"aria-controls":u,className:S,children:[k,I,y]}),e[20]=u,e[21]=p,e[22]=k,e[23]=I,e[24]=y,e[25]=E):E=e[25];const v=!p;let R;e[26]!==r||e[27]!==u||e[28]!==v?(R=s.jsx("div",{id:u,hidden:v,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]=u,e[28]=v,e[29]=R):R=e[29];let C;return e[30]!==E||e[31]!==R?(C=s.jsxs("div",{children:[E,R]}),e[30]=E,e[31]=R,e[32]=C):C=e[32],C};function xf(t){return!t}const bf=({onItemSelect:t})=>{const{t:e}=_e(),[n,a]=d.useState(""),[i,o]=d.useState(null),[r,c]=d.useState(""),[l,m]=d.useState(null),[u,f]=d.useState(!1),[p,g]=d.useState(null),{selectedAgentName:h,setSelectedAgent:j,setAgentDraft:x,createAgent:S,deleteAgent:b,loadAgents:w,fetchAgentEntity:k}=Rn(Os($=>({selectedAgentName:$.selectedAgentName,setSelectedAgent:$.setSelectedAgent,setAgentDraft:$.setAgentDraft,createAgent:$.createAgent,deleteAgent:$.deleteAgent,loadAgents:$.loadAgents,fetchAgentEntity:$.fetchAgentEntity}))),I=Zs(),y=Rn($=>wd($,I));d.useEffect(()=>{w(I)},[w,I]);const E="bg-background",v=()=>{const $="new-agent";let z=$,U=1;for(;y.some(_=>_.name===z);)z=`${$}-${U}`,U++;x({name:z,scope:"user"}),j(z),t?.()},R=async $=>{if(bi($)){q.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}m($)},C=()=>{m(null)},T=async()=>{if(l){f(!0);try{(await b(l.name,l.scope,I)).ok?(q.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})),C()):q.error(e("settings.agents.sidebar.toast.deleteFailed"))}catch($){const z=$ instanceof Error?$.message:"",U=/built-in|not deletable|not found/i.test(z);q.error(e(U?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed"))}f(!1)}},P=async $=>{const z=$.name;let U=1,_=`${z}-copy`;for(;y.some(Q=>Q.name===_);)U++,_=`${z}-copy-${U}`;const V=$,Z=await k($.name,I);if(!Z){q.error(e("settings.agents.sidebar.toast.renameFailed"));return}const Y=Z.config.request?.body;x({name:_,scope:Z.scope??V.scope??"user",description:Z.config.description??void 0,model:Z.config.model??null,system:Z.config.system??void 0,steps:Z.config.steps??void 0,temperature:Y?.temperature,top_p:Y?.top_p,mode:Z.config.mode??V.mode,permissions:Z.config.permissions??void 0,hidden:Z.config.hidden}),j(_),t?.()},L=$=>{c($.name),o($)},O=async()=>{if(!i)return;const $=r.trim().replace(/\s+/g,"-");if(!$){q.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if($===i.name){o(null);return}if(y.some(V=>V.name===$)){q.error(e("settings.agents.sidebar.toast.agentExists"));return}const z=i,U=await k(i.name,I);if(!U){q.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await S({...U.config,name:$,scope:U.scope??z.scope},I)).ok?(await b(i.name,z.scope,I)).ok?(q.success(e("settings.agents.sidebar.toast.agentRenamed",{name:$})),j($)):q.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):q.error(e("settings.agents.sidebar.toast.renameFailed")),o(null)},A=$=>{switch($){case"primary":return s.jsx(J,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(J,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(J,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},N=y.filter(hm),M=N.filter($=>Co([$.name,$.description],n)),F=M.filter(bi),H=M.filter($=>!bi($)),{groupedCustomAgents:W,ungroupedCustomAgents:G}=Ge.useMemo(()=>{const $={},z=[];for(const _ of H){const V=_;V.group?($[V.group]||($[V.group]=[]),$[V.group].push(_)):z.push(_)}return{groupedCustomAgents:Object.keys($).sort((_,V)=>_.localeCompare(V)).map(_=>({name:_,agents:$[_]})),ungroupedCustomAgents:z}},[H]);return s.jsxs("div",{className:je("flex h-full flex-col",E),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${ya} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ai,{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:N.length})}),s.jsx(B,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:v,children:s.jsx(J,{name:"add",className:"h-3.5 w-3.5"})})]}),N.length>0?s.jsx(pl,{value:n,onChange:a}):null]}),s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:N.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(J,{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")})]}):M.length===0?s.jsx(gl,{query:n}):s.jsxs(s.Fragment,{children:[F.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),F.map($=>s.jsx(dr,{agent:$,isSelected:h===$.name,onSelect:()=>{j($.name),t?.()},onDuplicate:()=>{P($)},getAgentModeIcon:A,isMenuOpen:p===$.name,onMenuOpenChange:z=>g(z?$.name:null)},$.name))]}),H.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")}),W.map(({name:$,agents:z})=>s.jsx($r,{label:$,count:z.length,storageKey:"agents",children:z.map(U=>s.jsx(dr,{agent:U,isSelected:h===U.name,onSelect:()=>{j(U.name),t?.()},onRename:()=>L(U),onDelete:()=>R(U),onDuplicate:()=>{P(U)},getAgentModeIcon:A,isMenuOpen:p===U.name,onMenuOpenChange:_=>g(_?U.name:null)},U.name))},$)),G.map($=>s.jsx(dr,{agent:$,isSelected:h===$.name,onSelect:()=>{j($.name),t?.()},onRename:()=>L($),onDelete:()=>R($),onDuplicate:()=>{P($)},getAgentModeIcon:A,isMenuOpen:p===$.name,onMenuOpenChange:z=>g(z?$.name:null)},$.name))]})]})}),s.jsx(zt,{open:l!==null,onOpenChange:$=>{!$&&!u&&C()},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.agents.sidebar.dialog.deleteTitle")}),s.jsx(Ht,{children:e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""})})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:C,disabled:u,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:T,disabled:u,children:e("settings.common.actions.delete")})]})]})}),s.jsx(zt,{open:i!==null,onOpenChange:$=>!$&&o(null),children:s.jsxs(Ut,{children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.description",{name:i?.name??""})})]}),s.jsx(He,{value:r,onChange:$=>c($.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:$=>{$.key==="Enter"&&O()}}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>o(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:O,children:e("settings.common.actions.rename")})]})]})})]})},dr=t=>{const e=$e.c(51),{agent:n,isSelected:a,onSelect:i,onDelete:o,onRename:r,onDuplicate:c,getAgentModeIcon:l,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=_e(),p=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=Xr(),e[0]=g):g=e[0];const h=g,[j,x]=d.useState(!1);let S;e[1]!==o||e[2]!==c||e[3]!==r||e[4]!==f?(S=G=>s.jsxs(s.Fragment,{children:[r&&s.jsxs(G,{onClick:$=>{$.stopPropagation(),r()},children:[s.jsx(J,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(G,{onClick:$=>{$.stopPropagation(),c()},children:[s.jsx(J,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),o&&s.jsxs(G,{onClick:$=>{$.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[1]=o,e[2]=c,e[3]=r,e[4]=f,e[5]=S):S=e[5];const b=S,w=a?"bg-interactive-selection":"hover:bg-interactive-hover";let k;e[6]!==w?(k=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",w),e[6]=w,e[7]=k):k=e[7];let I;e[8]===Symbol.for("react.memo_cache_sentinel")?(I=h?void 0:G=>{G.preventDefault(),x(!0)},e[8]=I):I=e[8];let y;e[9]!==k?(y=s.jsx("div",{className:k,onContextMenu:I}),e[9]=k,e[10]=y):y=e[10];let E;e[11]!==n.name?(E=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[11]=n.name,e[12]=E):E=e[12];let v;e[13]!==n.mode||e[14]!==l?(v=l(n.mode),e[13]=n.mode,e[14]=l,e[15]=v):v=e[15];let R;e[16]!==n||e[17]!==p.scope||e[18]!==f?(R=(p.scope||bi(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:bi(n)?f("settings.agents.sidebar.badge.system"):p.scope}),e[16]=n,e[17]=p.scope,e[18]=f,e[19]=R):R=e[19];let C;e[20]!==E||e[21]!==v||e[22]!==R?(C=s.jsxs("div",{className:"flex items-center gap-1.5",children:[E,v,R]}),e[20]=E,e[21]=v,e[22]=R,e[23]=C):C=e[23];let T;e[24]!==n.description?(T=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[24]=n.description,e[25]=T):T=e[25];let P;e[26]!==i||e[27]!==C||e[28]!==T?(P=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:[C,T]}),e[26]=i,e[27]=C,e[28]=T,e[29]=P):P=e[29];let L;e[30]!==u?(L=G=>{G&&x(!1),u(G)},e[30]=u,e[31]=L):L=e[31];let O;e[32]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=O):O=e[32];let A;e[33]!==b?(A=s.jsx(On,{align:"end",className:"w-fit min-w-20",children:b(mn)}),e[33]=b,e[34]=A):A=e[34];let N;e[35]!==m||e[36]!==L||e[37]!==A?(N=s.jsxs(Kn,{open:m,onOpenChange:L,children:[O,A]}),e[35]=m,e[36]=L,e[37]=A,e[38]=N):N=e[38];let M;e[39]!==P||e[40]!==N?(M=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,N]}),e[39]=P,e[40]=N,e[41]=M):M=e[41];let F;e[42]!==M||e[43]!==y?(F=s.jsx(Qa,{render:y,children:M}),e[42]=M,e[43]=y,e[44]=F):F=e[44];let H;e[45]!==b?(H=s.jsx(Ga,{className:"w-fit min-w-20",children:b(Ja)}),e[45]=b,e[46]=H):H=e[46];let W;return e[47]!==j||e[48]!==F||e[49]!==H?(W=s.jsxs(Ya,{open:j,onOpenChange:x,children:[F,H]}),e[47]=j,e[48]=F,e[49]=H,e[50]=W):W=e[50],W},es=t=>{const e=$e.c(22),{children:n,className:a,outerClassName:i,title:o,titleLeading:r,titleAccessory:c,description:l,headerEnd:m,showSaveStatus:u,onBlurCapture:f}=t,p=u===void 0?!1:u,g=o!=null||l!=null||m!=null||p,h=typeof o=="string"||typeof o=="number",j=r!=null||c!=null;let x;e[0]!==i?(x=je("h-full overlay-scrollbar-wrapper--stable-gutter",i),e[0]=i,e[1]=x):x=e[1];let S;e[2]!==a?(S=je("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",a),e[2]=a,e[3]=S):S=e[3];let b;e[4]!==l||e[5]!==g||e[6]!==j||e[7]!==m||e[8]!==h||e[9]!==p||e[10]!==o||e[11]!==c||e[12]!==r?(b=g&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[o!=null?h?j?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:je(Mr,"min-w-0 truncate"),children:o}),s.jsx("span",{className:"shrink-0",children:c})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Mr,children:o}):o:null,l!=null?typeof l=="string"||typeof l=="number"?s.jsx("p",{className:xn,children:l}):l:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[m,p&&s.jsx(yf,{})]})]}),e[4]=l,e[5]=g,e[6]=j,e[7]=m,e[8]=h,e[9]=p,e[10]=o,e[11]=c,e[12]=r,e[13]=b):b=e[13];let w;e[14]!==n||e[15]!==f||e[16]!==S||e[17]!==b?(w=s.jsxs("div",{className:S,onBlurCapture:f,children:[b,n]}),e[14]=n,e[15]=f,e[16]=S,e[17]=b,e[18]=w):w=e[18];let k;return e[19]!==x||e[20]!==w?(k=s.jsx(js,{outerClassName:x,className:"w-full @container",children:w}),e[19]=x,e[20]=w,e[21]=k):k=e[21],k},vf=500,yf=()=>{const t=$e.c(13),{t:e}=_e(),n=d.useSyncExternalStore(qp,Ul,Ul),[a,i]=d.useState(!1);let o,r;if(t[0]!==n?(o=()=>{if(n!=="saving"){i(!1);return}const u=setTimeout(()=>i(!0),vf);return()=>clearTimeout(u)},r=[n],t[0]=n,t[1]=o,t[2]=r):(o=t[1],r=t[2]),d.useEffect(o,r),n==="error"){let u;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(J,{name:"error-warning",className:"size-3.5"}),t[3]=u):u=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:[u,s.jsx("span",{children:f})]}),t[6]=f,t[7]=p):p=t[7],p}if(n!=="saving"||!a)return null;let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=c):c=t[8];let l;t[9]!==e?(l=e("settings.common.actions.saving"),t[9]=e,t[10]=l):l=t[10];let m;return t[11]!==l?(m=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[c,s.jsx("span",{children:l})]}),t[11]=l,t[12]=m):m=t[12],m},Ls={ok:!0,changed:!1},vn={ok:!0,changed:!0},fs=t=>({ok:!1,reason:t}),jf=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,ei=t=>{const{t:e}=_e(),[n,a]=d.useState(0),i=d.useRef(t);i.current=t;const o=d.useRef(e);o.current=e;const r=d.useRef(!1),c=d.useRef(!1),l=d.useRef(!1),m=d.useCallback(()=>{a(p=>p+1)},[]),u=d.useCallback(p=>{jf(p.target)&&m()},[m]),f=d.useCallback(async()=>{r.current=!0;try{for(;;){c.current=!1;let p;try{p=await i.current()}catch(g){p={ok:!1,reason:g instanceof Error?g.message:String(g)}}if(!l.current)return;if(!c.current){p.ok||q.error(o.current("settings.common.status.saveFailedReason",{reason:p.reason}));return}}}finally{r.current=!1}},[]);return d.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]),d.useEffect(()=>{if(n!==0){if(r.current){c.current=!0;return}f()}},[n,f]),{requestSave:m,onBlurCapture:u}},kf=["allow","ask","deny"],wf=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],Sf=["openchamber","openchamber_web","openchamber_memory","openchamber_notify"],Nf=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),nu=t=>Nf.has(t),Cf=[{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"}],oc=()=>({global:null,keys:{},source:[]}),oa=t=>({global:t.global,source:t.source,keys:Object.fromEntries(Object.entries(t.keys).map(([e,n])=>[e,{effect:n.effect,patterns:n.patterns.map(a=>({...a}))}]))}),If=t=>{const e={global:null,keys:{},source:t.map(n=>({...n}))};for(const n of t){if(nu(n.action))continue;if(n.action==="*"){n.resource==="*"&&(e.global=n.effect);continue}const a=e.keys[n.action]??{effect:null,patterns:[]};if(n.resource==="*")a.effect=n.effect;else{const i=a.patterns.findIndex(o=>o.pattern===n.resource);i>=0?a.patterns[i]={pattern:n.resource,effect:n.effect}:a.patterns.push({pattern:n.resource,effect:n.effect})}e.keys[n.action]=a}return e},Pf=t=>t.action!=="*"||t.resource==="*",ga=(t,e)=>`${t}\0${e}`,Af=t=>{const e=new Map;t.global!==null&&e.set(ga("*","*"),t.global);for(const[n,a]of Object.entries(t.keys)){a.effect!==null&&e.set(ga(n,"*"),a.effect);for(const i of a.patterns){const o=i.pattern.trim();o.length!==0&&e.set(ga(n,o),i.effect)}}return e},_r=t=>{const e=Af(t),n=new Set,a=[];for(const o of t.source){if(nu(o.action))continue;if(!Pf(o)){a.push({...o});continue}const r=ga(o.action,o.resource),c=e.get(r);c!==void 0&&(a.push({action:o.action,resource:o.resource,effect:c}),n.add(r))}const i=ga("*","*");t.global!==null&&!n.has(i)&&a.unshift({action:"*",resource:"*",effect:t.global});for(const[o,r]of Object.entries(t.keys)){const c=ga(o,"*");if(r.effect!==null&&!n.has(c)){const l=a.findIndex(u=>u.action===o),m={action:o,resource:"*",effect:r.effect};l>=0?a.splice(l,0,m):a.push(m)}for(const l of r.patterns){const m=l.pattern.trim();if(m.length===0)continue;const u=ga(o,m),f=e.get(u);f===void 0||n.has(u)||(n.add(u),a.push({action:o,resource:m,effect:f}))}}return a},Tf=(t,e)=>JSON.stringify(_r(t))===JSON.stringify(_r(e)),Ef=(t,e)=>{const n=[...Cf,...e.global,...e.agentGlobal?[{action:"*",resource:"*",effect:e.agentGlobal}]:[]];let a="ask";for(const i of n)i.resource==="*"&&(i.action==="*"||i.action===t)&&(a=i.effect);return a},Df=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Mf=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),Rf={effect:null,patterns:[]},Lf=t=>{const e=$e.c(163),{agent:n,registerSave:a,requestSave:i}=t,{t:o}=_e(),r=Rn(Of),c=Rn(Ff);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=[],e[0]=l):l=e[0];const[m,u]=d.useState(l),[f,p]=d.useState(oc),[g,h]=d.useState(oc),[j,x]=d.useState(!0),[S,b]=d.useState(!1);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w={},e[1]=w):w=e[1];const[k,I]=d.useState(w),[y,E]=d.useState(""),[v,R]=d.useState(0),C=n.name,T=Zs(),P=Tn(Kf);let L;e[2]!==T?(L=be=>el(be,T),e[2]=T,e[3]=L):L=e[3];const O=Tn(L);let A;e[4]!==T?(A=be=>be.getStatusForDirectory(T),e[4]=T,e[5]=A):A=e[5];const N=ln(A);let M,F;e[6]!==P||e[7]!==T?(M=()=>{P({directory:T})},F=[P,T],e[6]=P,e[7]=T,e[8]=M,e[9]=F):(M=e[8],F=e[9]),d.useEffect(M,F);let H;e[10]!==C||e[11]!==c||e[12]!==T?(H=()=>{let be=!1;return x(!0),b(!1),(async()=>{const Re=await c(C,T);if(be)return;if(!Re){b(!0),x(!1);return}const X=If(Re.agent);u(Re.global),p(oa(X)),h(X),I({}),x(!1)})(),()=>{be=!0}},e[10]=C,e[11]=c,e[12]=T,e[13]=H):H=e[13];let W;e[14]!==C||e[15]!==c||e[16]!==v||e[17]!==T?(W=[C,c,v,T],e[14]=C,e[15]=c,e[16]=v,e[17]=T,e[18]=W):W=e[18],d.useEffect(H,W);let G;e[19]!==C||e[20]!==f||e[21]!==g||e[22]!==T||e[23]!==o||e[24]!==r?(G=async()=>Tf(g,f)?Ls:(await r(C,{permissions:_r(g)},T)).ok?(p(oa(g)),vn):fs(o("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=C,e[20]=f,e[21]=g,e[22]=T,e[23]=o,e[24]=r,e[25]=G):G=e[25];const $=G;let z,U;e[26]!==a||e[27]!==$?(z=()=>(a($),()=>a(null)),U=[a,$],e[26]=a,e[27]=$,e[28]=z,e[29]=U):(z=e[28],U=e[29]),d.useEffect(z,U);let _;e[30]!==O?(_=O.map(zf),e[30]=O,e[31]=_):_=e[31];const V=_;let Z;if(e[32]!==V||e[33]!==g.keys){Z=[...wf,...Sf];const be=new Set(V.map(Uf));let Re;e[35]!==g.keys?(Re=Object.keys(g.keys),e[35]=g.keys,e[36]=Re):Re=e[36];for(const X of Re)!Z.includes(X)&&!be.has(X)&&Z.push(X);e[32]=V,e[33]=g.keys,e[34]=Z}else Z=e[34];const Y=Z;let Q;e[37]!==N||e[38]!==o?(Q=be=>{switch(N?.[be]?.status.status){case"connected":return o("settings.mcp.page.status.label.connected");case"failed":return o("settings.mcp.page.status.label.failed");case"needs_auth":return o("settings.mcp.page.status.label.needsAuth");case"disabled":return o("settings.agents.page.permissionsEditor.mcpStatus.disabled");case"pending":return o("settings.agents.page.permissionsEditor.mcpStatus.pending");default:return null}},e[37]=N,e[38]=o,e[39]=Q):Q=e[39];const ue=Q;let ge;e[40]!==m||e[41]!==g.global?(ge=be=>Ef(be,{global:m,agentGlobal:g.global}),e[40]=m,e[41]=g.global,e[42]=ge):ge=e[42];const fe=ge;let Ie;e[43]!==i?(Ie=be=>{h(Re=>({...Re,global:be})),i()},e[43]=i,e[44]=Ie):Ie=e[44];const te=Ie;let Ce;e[45]!==i?(Ce=(be,Re)=>{h(X=>{const ce=oa(X),Oe=ce.keys[be]??{effect:null,patterns:[]};return Oe.effect=Re,Oe.effect===null&&Oe.patterns.length===0?delete ce.keys[be]:ce.keys[be]=Oe,ce}),i()},e[45]=i,e[46]=Ce):Ce=e[46];const ie=Ce;let ae;e[47]!==i?(ae=(be,Re,X,ce,Oe)=>{h(We=>{const nt=oa(We),at=nt.keys[be]??{effect:null,patterns:[]};return at.patterns[Re]={pattern:X,effect:ce},nt.keys[be]=at,nt}),Oe&&i()},e[47]=i,e[48]=ae):ae=e[48];const re=ae;let ye;e[49]===Symbol.for("react.memo_cache_sentinel")?(ye=be=>{h(Re=>{const X=oa(Re),ce=X.keys[be]??{effect:null,patterns:[]};return ce.patterns.push({pattern:"",effect:"allow"}),X.keys[be]=ce,X}),I(Re=>({...Re,[be]:!0}))},e[49]=ye):ye=e[49];const Ee=ye;let Pe;e[50]!==i?(Pe=(be,Re)=>{h(X=>{const ce=oa(X),Oe=ce.keys[be];return Oe?(Oe.patterns.splice(Re,1),Oe.effect===null&&Oe.patterns.length===0&&delete ce.keys[be],ce):X}),i()},e[50]=i,e[51]=Pe):Pe=e[51];const ke=Pe;let Te;e[52]!==y||e[53]!==i?(Te=()=>{const be=y.trim();!be||be==="*"||(h(Re=>{if(Re.keys[be])return Re;const X=oa(Re);return X.keys[be]={effect:"ask",patterns:[]},X}),E(""),i())},e[52]=y,e[53]=i,e[54]=Te):Te=e[54];const de=Te;let Me;e[55]!==o?(Me=be=>o(be==="allow"?"settings.agents.page.permissionsEditor.action.allow":be==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=o,e[56]=Me):Me=e[56];const Se=Me;let Le,Ke,oe,le,xe,De,Ve,Be,Ne;if(e[57]!==Se||e[58]!==fe||e[59]!==k||e[60]!==j||e[61]!==S||e[62]!==V||e[63]!==ue||e[64]!==g.global||e[65]!==g.keys||e[66]!==ke||e[67]!==te||e[68]!==ie||e[69]!==re||e[70]!==o||e[71]!==Y){Ne=Symbol.for("react.early_return_sentinel");e:{const be=o("settings.agents.page.permissionsEditor.action.inherit"),Re=o("settings.agents.page.permissionsEditor.action.default");let X;e[81]!==Se?(X=Xe=>[...Xe?[{value:"inherit",label:Xe}]:[],...kf.map(gt=>({value:gt,label:Se(gt)}))],e[81]=Se,e[82]=X):X=e[82];const ce=X,Oe=(Xe,gt,Ue,ee)=>{const ve=ee===void 0?be:ee;return s.jsx(Ws,{value:Xe??"inherit",options:ce(ve),onChange:Fe=>gt(Fe==="inherit"?null:Fe),"aria-label":Ue})};if(j){let Xe;e[83]!==o?(Xe=o("settings.agents.page.section.toolPermissions"),e[83]=o,e[84]=Xe):Xe=e[84];let gt;e[85]!==o?(gt=o("common.loading"),e[85]=o,e[86]=gt):gt=e[86];let Ue;e[87]!==gt?(Ue=s.jsx("p",{className:Mt,children:gt}),e[87]=gt,e[88]=Ue):Ue=e[88];let ee;e[89]!==Xe||e[90]!==Ue?(ee=s.jsx(qe,{title:Xe,children:Ue}),e[89]=Xe,e[90]=Ue,e[91]=ee):ee=e[91],Ne=ee;break e}if(S){let Xe;e[92]!==o?(Xe=o("settings.agents.page.section.toolPermissions"),e[92]=o,e[93]=Xe):Xe=e[93];let gt;e[94]!==o?(gt=o("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=o,e[95]=gt):gt=e[95];let Ue;e[96]!==gt?(Ue=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:gt}),e[96]=gt,e[97]=Ue):Ue=e[97];let ee;e[98]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>R($f),e[98]=ee):ee=e[98];let ve;e[99]!==o?(ve=o("settings.agents.page.permissionsEditor.actions.retry"),e[99]=o,e[100]=ve):ve=e[100];let Fe;e[101]!==ve?(Fe=s.jsx(B,{variant:"outline",size:"xs",onClick:ee,children:ve}),e[101]=ve,e[102]=Fe):Fe=e[102];let se;e[103]!==Ue||e[104]!==Fe?(se=s.jsxs("div",{className:"flex items-center gap-3",children:[Ue,Fe]}),e[103]=Ue,e[104]=Fe,e[105]=se):se=e[105];let Ae;e[106]!==Xe||e[107]!==se?(Ae=s.jsx(qe,{title:Xe,children:se}),e[106]=Xe,e[107]=se,e[108]=Ae):Ae=e[108],Ne=Ae;break e}const We=(Xe,gt,Ue)=>{const ee=g.keys[Xe]??Rf,ve=Mf.has(Xe)||ee.patterns.length>0,Fe=k[Xe]===!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:ve?()=>I(se=>({...se,[Xe]:!Fe})):void 0,className:je("flex min-w-0 items-center gap-1.5 text-left",!ve&&"cursor-default"),"aria-expanded":ve?Fe:void 0,children:[s.jsx(J,{name:Fe&&ve?"arrow-down-s":"arrow-right-s",className:je("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ve&&"opacity-0")}),s.jsx("span",{className:Pt,children:gt}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:Xe}),Ue&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:Ue}),ee.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.agents.page.permissionsEditor.effectiveHint",{action:Se(fe(Xe))})}),ee.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:o("settings.agents.page.permissionsEditor.ruleCount",{count:String(ee.patterns.length)})})]}),Oe(ee.effect,se=>ie(Xe,se),o("settings.agents.page.permissionsEditor.keyAria",{key:Xe}))]}),Fe&&ve&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[ee.patterns.map((se,Ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:se.pattern,onChange:tt=>re(Xe,Ae,tt.target.value,se.effect,!1),placeholder:o("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":o("settings.agents.page.permissionsEditor.patternActionAria",{key:Xe}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Ws,{value:se.effect,options:ce(),onChange:tt=>re(Xe,Ae,se.pattern,tt,!0),"aria-label":o("settings.agents.page.permissionsEditor.patternActionAria",{key:Xe})}),s.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>ke(Xe,Ae),"aria-label":o("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(J,{name:"close",className:"h-3.5 w-3.5"})})]},Ae)),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(Xe),children:[s.jsx(J,{name:"add",className:"mr-1 h-3.5 w-3.5"}),o("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},Xe)};Le=qe,e[109]!==o?(Ke=o("settings.agents.page.section.toolPermissions"),e[109]=o,e[110]=Ke):Ke=e[110],oe="agents.permissions",e[111]!==o?(le=o("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=o,e[112]=le):le=e[112],xe="space-y-4";let nt;e[113]!==o?(nt=o("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=o,e[114]=nt):nt=e[114];let at;e[115]!==nt?(at=s.jsx("span",{className:Pt,children:nt}),e[115]=nt,e[116]=at):at=e[116];let vt;e[117]!==o?(vt=o("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=o,e[118]=vt):vt=e[118];let kt;e[119]!==vt?(kt=s.jsx(Wt,{children:vt}),e[119]=vt,e[120]=kt):kt=e[120];let xt;e[121]!==Se||e[122]!==fe||e[123]!==g.global||e[124]!==o?(xt=g.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.agents.page.permissionsEditor.effectiveHint",{action:Se(fe("*"))})}),e[121]=Se,e[122]=fe,e[123]=g.global,e[124]=o,e[125]=xt):xt=e[125];let It;e[126]!==at||e[127]!==kt||e[128]!==xt?(It=s.jsxs("div",{className:"flex items-center gap-1.5",children:[at,kt,xt]}),e[126]=at,e[127]=kt,e[128]=xt,e[129]=It):It=e[129];const _t=g.global;let Ye;e[130]!==o?(Ye=o("settings.agents.page.permissionsEditor.defaultAria"),e[130]=o,e[131]=Ye):Ye=e[131],De=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[It,Oe(_t,te,Ye,Re)]}),Ve=s.jsx("div",{children:Y.map(Xe=>We(Xe,Df(Xe),null))}),Be=V.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:Pt,children:o("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(Wt,{children:o("settings.agents.page.permissionsEditor.mcpInfo")})]}),V.map(Xe=>We(Xe.key,Xe.server,ue(Xe.server)))]})}e[57]=Se,e[58]=fe,e[59]=k,e[60]=j,e[61]=S,e[62]=V,e[63]=ue,e[64]=g.global,e[65]=g.keys,e[66]=ke,e[67]=te,e[68]=ie,e[69]=re,e[70]=o,e[71]=Y,e[72]=Le,e[73]=Ke,e[74]=oe,e[75]=le,e[76]=xe,e[77]=De,e[78]=Ve,e[79]=Be,e[80]=Ne}else Le=e[72],Ke=e[73],oe=e[74],le=e[75],xe=e[76],De=e[77],Ve=e[78],Be=e[79],Ne=e[80];if(Ne!==Symbol.for("react.early_return_sentinel"))return Ne;let Je;e[132]===Symbol.for("react.memo_cache_sentinel")?(Je=be=>E(be.target.value),e[132]=Je):Je=e[132];let ut;e[133]!==de?(ut=be=>{be.key==="Enter"&&(be.preventDefault(),de())},e[133]=de,e[134]=ut):ut=e[134];let ht;e[135]!==o?(ht=o("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=o,e[136]=ht):ht=e[136];let st;e[137]!==y||e[138]!==ut||e[139]!==ht?(st=s.jsx(He,{value:y,onChange:Je,onKeyDown:ut,placeholder:ht,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=y,e[138]=ut,e[139]=ht,e[140]=st):st=e[140];let jt;e[141]!==y?(jt=y.trim(),e[141]=y,e[142]=jt):jt=e[142];const St=!jt;let Ze;e[143]===Symbol.for("react.memo_cache_sentinel")?(Ze=s.jsx(J,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=Ze):Ze=e[143];let it;e[144]!==o?(it=o("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=o,e[145]=it):it=e[145];let et;e[146]!==de||e[147]!==St||e[148]!==it?(et=s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:de,disabled:St,children:[Ze,it]}),e[146]=de,e[147]=St,e[148]=it,e[149]=et):et=e[149];let mt;e[150]!==st||e[151]!==et?(mt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[st,et]}),e[150]=st,e[151]=et,e[152]=mt):mt=e[152];let ft;return e[153]!==Le||e[154]!==Ke||e[155]!==oe||e[156]!==le||e[157]!==xe||e[158]!==De||e[159]!==Ve||e[160]!==Be||e[161]!==mt?(ft=s.jsxs(Le,{title:Ke,settingsItem:oe,info:le,contentClassName:xe,children:[De,Ve,Be,mt]}),e[153]=Le,e[154]=Ke,e[155]=oe,e[156]=le,e[157]=xe,e[158]=De,e[159]=Ve,e[160]=Be,e[161]=mt,e[162]=ft):ft=e[162],ft};function Of(t){return t.updateAgent}function Ff(t){return t.fetchAgentPermissions}function Kf(t){return t.loadMcpConfigs}function zf(t){return{key:`${t.name}_*`,server:t.name}}function Uf(t){return t.key}function $f(t){return t+1}const fl=t=>{const e=$e.c(11),{legacy:n,path:a,className:i}=t,{t:o}=_e();if(!n)return null;let r;e[0]!==i?(r=je("mb-4 flex items-start gap-1.5",Mt,i),e[0]=i,e[1]=r):r=e[1];const c=a??void 0;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(J,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),e[2]=l):l=e[2];let m;e[3]!==o?(m=o("settings.common.legacyFormat.note"),e[3]=o,e[4]=m):m=e[4];let u;e[5]!==m?(u=s.jsx("span",{children:m}),e[5]=m,e[6]=u):u=e[6];let f;return e[7]!==r||e[8]!==c||e[9]!==u?(f=s.jsxs("p",{className:r,title:c,children:[l,u]}),e[7]=r,e[8]=c,e[9]=u,e[10]=f):f=e[10],f},_f=(t,e)=>{const n=En(e);if(!n)return[];const a=t.find(o=>o.id===n.providerId),i=Wp(a?.models,n.modelId);return Sd(i)},Bf=()=>{const{t}=_e(),e=rt(de=>de.providers),{selectedAgentName:n,getAgentByName:a,createAgent:i,updateAgent:o,fetchAgentEntity:r,agentDraft:c,setAgentDraft:l,setSelectedAgent:m}=Rn(Os(de=>({selectedAgentName:de.selectedAgentName,getAgentByName:de.getAgentByName,createAgent:de.createAgent,updateAgent:de.updateAgent,fetchAgentEntity:de.fetchAgentEntity,agentDraft:de.agentDraft,setAgentDraft:de.setAgentDraft,setSelectedAgent:de.setSelectedAgent}))),u=Zs(),f=Rn(de=>wd(de,u)),p=n?a(n,u):null,g=!!(c&&c.name===n&&!p),h=g?"":p?.description?.trim()??"",j=g?"":p?.system?.trim()??"",[x,S]=d.useState(""),[b,w]=d.useState("user"),[k,I]=d.useState(""),[y,E]=d.useState("subagent"),[v,R]=d.useState(""),[C,T]=d.useState(""),[P,L]=d.useState(void 0),[O,A]=d.useState(void 0),[N,M]=d.useState(void 0),[F,H]=d.useState(""),[W,G]=d.useState(!1),[$,z]=d.useState(null),U=d.useRef({}),_=d.useRef(null),V=d.useCallback(de=>{_.current=de},[]),Z=d.useRef(null),Y=JSON.stringify([n,u,g]),Q=d.useRef(Y);Q.current=Y;const ue=d.useRef(null),ge={description:k,mode:y,model:v,variant:C,steps:P,temperature:O,topP:N,system:F},fe=d.useRef(ge);fe.current=ge;const Ie=d.useMemo(()=>_f(e,v),[v,e]),te=Ie.length>0,Ce=C||"__default",ie=te,ae=d.useMemo(()=>C&&!Ie.includes(C)?[C,...Ie]:Ie,[C,Ie]);d.useEffect(()=>{if(!g||!c)return;ue.current=null;const de=ji(c.model),Me=c.name||"",Se=c.scope||"user",Le=c.description||"",Ke=c.mode||"subagent",oe=de?`${de.providerID}/${de.modelID}`:"",le=de?.variant||"",xe=c.steps??void 0,De=c.temperature??void 0,Ve=c.top_p??void 0,Be=c.system||"";U.current={},z(null),S(Me),w(Se),I(Le),E(Ke),R(oe),T(le),L(xe),A(De),M(Ve),H(Be),Z.current={draftName:Me,draftScope:Se,description:Le,mode:Ke,model:oe,variant:le,steps:xe,temperature:De,topP:Ve,system:Be}},[c,g]),d.useEffect(()=>{if(g||!n)return;let de=!1;return(async()=>{const Me=await r(n,u);if(de||Q.current!==Y||!Me)return;const Se=Me.config;U.current=Se;const Le=ji(Se.model),Ke=Se.request?.body,oe={draftName:"",draftScope:"user",description:Se.description||"",mode:Se.mode||p?.mode||"subagent",model:Le?`${Le.providerID}/${Le.modelID}`:"",variant:Le?.variant||"",steps:Se.steps??void 0,temperature:Ke?.temperature,topP:Ke?.top_p,system:Se.system||""},le=Z.current,xe=fe.current,De=le!==null&&(xe.description!==le.description||xe.mode!==le.mode||xe.model!==le.model||xe.variant!==le.variant||xe.steps!==le.steps||xe.temperature!==le.temperature||xe.topP!==le.topP||xe.system!==le.system);z({legacy:Me.legacy===!0,path:Me.path,source:Me.source}),!(ue.current===Y&&De)&&(ue.current=Y,I(oe.description),E(oe.mode),R(oe.model),T(oe.variant),L(oe.steps),A(oe.temperature),M(oe.topP),H(oe.system),Z.current=oe)})(),()=>{de=!0}},[r,g,p,n,u,Y]);const re=d.useCallback(de=>{const Me=En(v.trim()),Se=Me?qd({providerID:Me.providerId,modelID:Me.modelId,variant:C.trim()||void 0}):null,Le=U.current.request,Ke={...Le?.body};O===void 0?delete Ke.temperature:Ke.temperature=O,N===void 0?delete Ke.top_p:Ke.top_p=N;const oe=Le?.headers,le={};oe&&Object.keys(oe).length>0&&(le.headers=oe),Object.keys(Ke).length>0&&(le.body=Ke);const xe=k.trim(),De=F.trim(),Ve={name:de,mode:y,model:Se,steps:P??null,system:De||(g?void 0:null),request:Object.keys(le).length>0?le:null};return xe&&(Ve.description=xe),g&&b&&(Ve.scope=b),g&&c?.hidden!==void 0&&(Ve.hidden=c.hidden),g&&c?.permissions?.length&&(Ve.permissions=c.permissions),Ve},[c,k,b,g,y,v,P,F,O,N,C]),ye=d.useCallback(async()=>{const de=Z.current,Me=n?.trim();if(g||!de||!Me)return Ls;const Se=_.current?await _.current():Ls;if(k===de.description&&y===de.mode&&v===de.model&&C===de.variant&&P===de.steps&&O===de.temperature&&N===de.topP&&F===de.system||!Se.ok)return Se;const Ke=re(Me);return(await o(Me,Ke,u)).ok?(Q.current!==Y||(U.current={...U.current,model:Ke.model,system:Ke.system??void 0,steps:Ke.steps,request:Ke.request??void 0},Z.current={...de,description:k,mode:y,model:v,variant:C,steps:P,temperature:O,topP:N,system:F}),vn):fs(t("settings.agents.page.toast.updateFailed"))},[re,k,g,y,v,n,Y,u,P,F,t,O,N,o,C]),Ee=ei(ye),{requestSave:Pe}=Ee,ke=async()=>{const de=x.trim().replace(/\s+/g,"-");if(!de){q.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(f.some(Me=>Me.name===de)){q.error(t("settings.agents.sidebar.toast.agentExists"));return}G(!0);try{(await i(re(de),u)).ok?(l(null),q.success(t("settings.agents.page.toast.created"))):q.error(t("settings.agents.page.toast.createFailed"))}catch(Me){console.error("Error creating agent:",Me);const Se=Me instanceof Error&&Me.message?Me.message:t("settings.agents.page.toast.saveUnexpectedError");q.error(Se)}finally{G(!1)}},Te=()=>{l(null),m(null)};return n?s.jsxs(es,{title:g?t("settings.agents.page.title.new"):n,description:t(g?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:Ee.onBlurCapture,children:[!g&&$&&s.jsx(fl,{legacy:$.legacy,path:$.path}),!g&&$?.source==="none"&&s.jsxs("p",{className:`mb-4 flex items-start gap-1.5 ${Mt}`,children:[s.jsx(J,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),s.jsx("span",{children:t("settings.agents.page.runtimeProvided.note")})]}),s.jsxs(qe,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[g&&s.jsxs(yt,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:x,onChange:de=>S(de.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:b,onValueChange:de=>w(de),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Et,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Rt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ts,{value:k,onChange:de=>I(de.target.value),placeholder:h||t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Rt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Ws,{"aria-label":t("settings.agents.page.field.mode"),value:y,onChange:de=>{E(de),Pe()},options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(qe,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(yt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(fa,{providerId:En(v)?.providerId??"",modelId:En(v)?.modelId??"",onChange:(de,Me)=>{R(de&&Me?`${de}/${Me}`:""),T(""),Pe()},className:qs})}),s.jsx(yt,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:ie?s.jsxs(Dt,{value:Ce,onValueChange:de=>{T(de==="__default"?"":de),Pe()},children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:de=>de==="__default"?t("chat.modelControls.default"):de})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"__default",children:t("chat.modelControls.default")}),ae.map(de=>s.jsx(dt,{value:de,children:de},de))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:C,onChange:de=>T(de.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!v&&!C,className:"h-8 w-40 rounded-md px-3"}),C&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{T(""),Pe()},className:ls,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(J,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(yt,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(gs,{value:O,fallbackValue:.7,onValueChange:A,onClear:()=>{A(void 0),Pe()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:bs}),O!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{A(void 0),Pe()},className:ls,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(J,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(yt,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(gs,{value:N,fallbackValue:.9,onValueChange:M,onClear:()=>{M(void 0),Pe()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:bs}),N!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{M(void 0),Pe()},className:ls,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(J,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(yt,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(gs,{value:P,fallbackValue:20,onValueChange:L,onClear:()=>{L(void 0),Pe()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:bs}),P!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{L(void 0),Pe()},className:ls,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(J,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(qe,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ts,{value:F,onChange:de=>H(de.target.value),placeholder:j||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(Lf,{agent:p,registerSave:V,requestSave:Pe}),g&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(B,{onClick:()=>{ke()},disabled:W||!x.trim(),size:"xs",className:"!font-normal",children:t(W?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(B,{variant:"ghost",onClick:Te,disabled:W,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(J,{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 Vf(t,e){return t.kind==="file"?t.content:e??""}const rc=rs({content:Nt(),exists:Pi(),path:Nt().min(1).optional()}),Hf=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},qf=t=>t.length>0&&!t.endsWith(`
3
- `)?`${t}
4
- `:t,Gi={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Wf=(t,e)=>t==="custom"?e:bm(t),Gf=t=>t==="custom"?"custom":Nd(t)?t:"concise",lc={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"},Jf=()=>{const{t}=_e(),[e,n]=d.useState(""),[a,i]=d.useState("AGENTS.md"),[o,r]=d.useState(Gi.responseStyleEnabled),[c,l]=d.useState(Gi.responseStylePreset),[m,u]=d.useState(Gi.responseStyleCustomInstructions),[f,p]=d.useState(!0),g=d.useRef(null),h=d.useRef(null);d.useEffect(()=>{const k=new AbortController;return(async()=>{try{const[y,E]=await Promise.all([yn(),Lt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:k.signal})]);let v=Gi,R;y&&(v={...v,responseStyleEnabled:y.responseStyleEnabled===!0,responseStylePreset:Gf(y.responseStylePreset),responseStyleCustomInstructions:y.responseStyleCustomInstructions??""},y.globalBehaviorPrompt!==void 0&&(R=y.globalBehaviorPrompt));let C={kind:"missing"};if(E.ok){const T=rc.parse(await E.json());if(k.signal.aborted)return;i(T.path??"AGENTS.md"),h.current=T.exists?T.content:null,T.exists&&(C={kind:"file",content:T.content})}v={...v,prompt:Vf(C,R)},n(v.prompt),r(v.responseStyleEnabled),l(v.responseStylePreset),u(v.responseStyleCustomInstructions),g.current=v}catch(y){y.name!=="AbortError"&&console.warn("Failed to load behavior settings:",y)}finally{p(!1)}})(),()=>k.abort()},[]);const j=d.useRef(e);j.current=e,d.useEffect(()=>{let k=null;const I=async()=>{if(document.visibilityState!=="visible"||!g.current)return;k?.abort();const E=new AbortController;k=E;try{const v=await Lt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:E.signal});if(!v.ok)return;const R=rc.parse(await v.json()),C=g.current;if(E.signal.aborted||!C||!R.exists||R.content===h.current||j.current!==C.prompt)return;h.current=R.content,g.current={...C,prompt:R.content},n(R.content)}catch(v){v instanceof DOMException&&v.name==="AbortError"||console.warn("Failed to refresh AGENTS.md:",v)}},y=()=>{I()};return window.addEventListener("focus",y),document.addEventListener("visibilitychange",y),()=>{k?.abort(),window.removeEventListener("focus",y),document.removeEventListener("visibilitychange",y)}},[]);const x=d.useCallback(async()=>{const k=g.current;if(!k||f)return Ls;const I=e!==k.prompt,y=o!==k.responseStyleEnabled||c!==k.responseStylePreset||m!==k.responseStyleCustomInstructions;if(!I&&!y)return Ls;const E=I?qf(e):k.prompt;if(I){const R=await Lt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:E,expectedContent:h.current})});if(R.status===409)return fs(t("settings.behavior.page.toast.agentsMdChangedOnDisk"));if(!R.ok)return fs(await Hf(R,t("settings.behavior.page.toast.saveFailed")));h.current=E,n(C=>C===e?E:C)}return(await bt({...I?{globalBehaviorPrompt:E}:{},responseStyleEnabled:o,responseStylePreset:c,responseStyleCustomInstructions:m})).ok?(g.current={prompt:E,responseStyleEnabled:o,responseStylePreset:c,responseStyleCustomInstructions:m},vn):fs(t("settings.behavior.page.toast.saveFailed"))},[f,e,m,o,c,t]),S=ei(x),{requestSave:b}=S,w=Wf(c,m);return s.jsxs(es,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:S.onBlurCapture,children:[s.jsx(qe,{title:t("settings.behavior.page.section.systemPrompt"),divider:!1,info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:a})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:s.jsx(Ts,{value:e,onChange:k=>n(k.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"})}),s.jsxs(qe,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(ct,{checked:o,onChange:k=>{r(k),b()},disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(yt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Dt,{value:c,onValueChange:k=>{l(k),b()},disabled:f||!o,children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{children:k=>k==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Nd(k)?t(lc[k]):null})}),s.jsxs(Et,{children:[xm.map(k=>s.jsx(dt,{value:k,children:t(lc[k])},k)),s.jsx(dt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ts,{value:w,onChange:k=>u(k.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!o||c!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Qf=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),Yf=t=>{const e=$e.c(73),{snapshot:n}=t,{t:a}=_e(),i=Si(th),o=n.selection,r=n.projectOverride!==null;let c;e[0]!==r||e[1]!==o||e[2]!==i||e[3]!==a?(c=O=>{r||Qf(O,o)||i(O).then(A=>{A||q.error(a("settings.webSearch.toast.saveFailed"))})},e[0]=r,e[1]=o,e[2]=i,e[3]=a,e[4]=c):c=e[4];const l=c,m=o.kind==="provider"&&!n.providers.some(O=>O.id===o.id)?o.id:null;let u;e[5]!==a?(u=a("settings.webSearch.section.provider"),e[5]=a,e[6]=u):u=e[6];let f;e[7]!==a?(f=a("settings.webSearch.section.providerInfo"),e[7]=a,e[8]=f):f=e[8];let p;e[9]!==a?(p=a("settings.webSearch.section.provider"),e[9]=a,e[10]=p):p=e[10];const g=o.kind==="default";let h;e[11]!==l?(h=()=>l({kind:"default"}),e[11]=l,e[12]=h):h=e[12];let j;e[13]!==a?(j=a("settings.webSearch.option.default"),e[13]=a,e[14]=j):j=e[14];let x;e[15]!==a?(x=a("settings.webSearch.option.defaultDescription"),e[15]=a,e[16]=x):x=e[16];let S;e[17]!==r||e[18]!==g||e[19]!==h||e[20]!==j||e[21]!==x?(S=s.jsx(is,{selected:g,onSelect:h,disabled:r,label:j,description:x}),e[17]=r,e[18]=g,e[19]=h,e[20]=j,e[21]=x,e[22]=S):S=e[22];let b;e[23]!==l||e[24]!==r||e[25]!==o.kind||e[26]!==n.providers.length||e[27]!==a?(b=n.providers.length>0?s.jsx(is,{selected:o.kind==="random",onSelect:()=>l({kind:"random"}),disabled:r,label:a("settings.webSearch.option.random"),description:a("settings.webSearch.option.randomDescription")}):null,e[23]=l,e[24]=r,e[25]=o.kind,e[26]=n.providers.length,e[27]=a,e[28]=b):b=e[28];let w;if(e[29]!==l||e[30]!==r||e[31]!==o.id||e[32]!==o.kind||e[33]!==n.providers){let O;e[35]!==l||e[36]!==r||e[37]!==o.id||e[38]!==o.kind?(O=A=>s.jsx(is,{selected:o.kind==="provider"&&o.id===A.id,onSelect:()=>l({kind:"provider",id:A.id}),disabled:r,label:A.name},A.id),e[35]=l,e[36]=r,e[37]=o.id,e[38]=o.kind,e[39]=O):O=e[39],w=n.providers.map(O),e[29]=l,e[30]=r,e[31]=o.id,e[32]=o.kind,e[33]=n.providers,e[34]=w}else w=e[34];let k;e[40]!==m||e[41]!==a?(k=m?s.jsx(is,{selected:!0,onSelect:sh,label:m,description:a("settings.webSearch.option.missing")}):null,e[40]=m,e[41]=a,e[42]=k):k=e[42];const I=o.kind==="off";let y;e[43]!==l?(y=()=>l({kind:"off"}),e[43]=l,e[44]=y):y=e[44];let E;e[45]!==a?(E=a("settings.webSearch.option.off"),e[45]=a,e[46]=E):E=e[46];let v;e[47]!==r||e[48]!==I||e[49]!==y||e[50]!==E?(v=s.jsx(is,{selected:I,onSelect:y,disabled:r,label:E}),e[47]=r,e[48]=I,e[49]=y,e[50]=E,e[51]=v):v=e[51];let R;e[52]!==b||e[53]!==w||e[54]!==k||e[55]!==v||e[56]!==p||e[57]!==S?(R=s.jsxs(Vs,{"aria-label":p,children:[S,b,w,k,v]}),e[52]=b,e[53]=w,e[54]=k,e[55]=v,e[56]=p,e[57]=S,e[58]=R):R=e[58];let C;e[59]!==n.projectOverride||e[60]!==a?(C=n.projectOverride?s.jsx("p",{className:`${Mt} mt-2 break-all`,children:a("settings.webSearch.state.projectOverride",{path:n.projectOverride})}):null,e[59]=n.projectOverride,e[60]=a,e[61]=C):C=e[61];let T;e[62]!==n.providers.length||e[63]!==a?(T=n.providers.length===0?s.jsx("p",{className:`${Mt} mt-2`,children:a("settings.webSearch.state.noProviders")}):null,e[62]=n.providers.length,e[63]=a,e[64]=T):T=e[64];let P;e[65]!==R||e[66]!==C||e[67]!==T?(P=s.jsxs("div",{children:[R,C,T]}),e[65]=R,e[66]=C,e[67]=T,e[68]=P):P=e[68];let L;return e[69]!==u||e[70]!==P||e[71]!==f?(L=s.jsx(qe,{title:u,info:f,divider:!1,settingsItem:"web-search.provider",children:P}),e[69]=u,e[70]=P,e[71]=f,e[72]=L):L=e[72],L},Zf=t=>{const e=$e.c(27),{provider:n,access:a,locked:i}=t,{t:o}=_e(),r=Si(nh),c=Si(ah),[l,m]=d.useState(""),[u,f]=d.useState(!1);let p;e[0]!==a.envNames||e[1]!==o?(p=a.envNames.length>0?o("settings.webSearch.keys.envHint",{names:a.envNames.join(", ")}):void 0,e[0]=a.envNames,e[1]=o,e[2]=p):p=e[2];const g=p;let h;e[3]!==l||e[4]!==n.id||e[5]!==n.name||e[6]!==r||e[7]!==o?(h=async()=>{const I=l.trim();if(!I)return;f(!0);const y=await r(n.id,I);f(!1),y?(m(""),q.success(o("settings.webSearch.toast.keySaved",{provider:n.name}))):q.error(o("settings.webSearch.toast.keySaveFailed"))},e[3]=l,e[4]=n.id,e[5]=n.name,e[6]=r,e[7]=o,e[8]=h):h=e[8];const j=h;let x;e[9]!==n.id||e[10]!==c||e[11]!==o?(x=async()=>{f(!0);const I=await c(n.id);f(!1),I||q.error(o("settings.webSearch.toast.keyRemoveFailed"))},e[9]=n.id,e[10]=c,e[11]=o,e[12]=x):x=e[12];const S=x,b=a.key;let w;e[13]!==u||e[14]!==l||e[15]!==S||e[16]!==j||e[17]!==i||e[18]!==n.name||e[19]!==b.kind||e[20]!==b.name||e[21]!==o?(w=b.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:o("settings.webSearch.keys.saved")}),s.jsx(B,{variant:"outline",size:"xs",disabled:u,onClick:()=>{S()},children:o("settings.webSearch.keys.remove")})]}):b.kind==="env"?s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("settings.webSearch.keys.fromEnv",{name:b.name})}):i?null:s.jsxs("div",{className:`${ks} flex items-center gap-2`,children:[s.jsx(He,{type:"password",value:l,onChange:I=>m(I.target.value),onKeyDown:I=>{I.key==="Enter"&&j()},placeholder:o("settings.webSearch.keys.placeholder"),"aria-label":o("settings.webSearch.keys.inputAria",{provider:n.name}),className:"h-8 min-w-0 flex-1 rounded-md px-3 font-mono text-xs"}),s.jsx(B,{size:"xs",disabled:u||l.trim().length===0,onClick:()=>{j()},children:o("settings.webSearch.keys.save")})]}),e[13]=u,e[14]=l,e[15]=S,e[16]=j,e[17]=i,e[18]=n.name,e[19]=b.kind,e[20]=b.name,e[21]=o,e[22]=w):w=e[22];let k;return e[23]!==g||e[24]!==n.name||e[25]!==w?(k=s.jsx(yt,{label:n.name,info:g,children:w}),e[23]=g,e[24]=n.name,e[25]=w,e[26]=k):k=e[26],k},Xf=t=>{const e=$e.c(29),{snapshot:n}=t,{t:a}=_e(),i=zn(),o=n.access;let r,c,l,m,u,f,p,g;if(e[0]!==o||e[1]!==i||e[2]!==n.providers||e[3]!==a){g=Symbol.for("react.early_return_sentinel");e:{const x=o?n.providers.flatMap(S=>{const b=o[S.id];return b&&b.key.kind!=="unsupported"?[{provider:S,access:b}]:[]}):[];if(o&&x.length===0){g=null;break e}r=qe,e[12]!==a?(u=a("settings.webSearch.section.keys"),e[12]=a,e[13]=u):u=e[13],e[14]!==a?(f=a("settings.webSearch.section.keysInfo"),e[14]=a,e[15]=f):f=e[15],p="web-search.keys",c="space-y-4",e[16]!==i||e[17]!==a?(l=i?s.jsx("p",{className:Mt,children:a("settings.webSearch.keys.enterpriseMode")}):null,e[16]=i,e[17]=a,e[18]=l):l=e[18],m=o===null?s.jsx("p",{className:Mt,children:a("settings.webSearch.state.keysUnavailable")}):x.map(S=>{const{provider:b,access:w}=S;return s.jsx(Zf,{provider:b,access:w,locked:i},b.id)})}e[0]=o,e[1]=i,e[2]=n.providers,e[3]=a,e[4]=r,e[5]=c,e[6]=l,e[7]=m,e[8]=u,e[9]=f,e[10]=p,e[11]=g}else r=e[4],c=e[5],l=e[6],m=e[7],u=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]!==c||e[20]!==l||e[21]!==m?(h=s.jsxs("div",{className:c,children:[l,m]}),e[19]=c,e[20]=l,e[21]=m,e[22]=h):h=e[22];let j;return e[23]!==r||e[24]!==u||e[25]!==f||e[26]!==p||e[27]!==h?(j=s.jsx(r,{title:u,info:f,settingsItem:p,children:h}),e[23]=r,e[24]=u,e[25]=f,e[26]=p,e[27]=h,e[28]=j):j=e[28],j},eh=()=>{const t=$e.c(17),{t:e}=_e(),n=Si(ih),a=Si(oh);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=vm(),t[0]=i):i=t[0];const o=i;let r,c;t[1]!==a?(r=()=>{a()},c=[a,o],t[1]=a,t[2]=r,t[3]=c):(r=t[2],c=t[3]),d.useEffect(r,c);const l=n.kind==="ready"&&n.snapshot.scope===o?n.snapshot:null;let m;t[4]!==e?(m=e("settings.page.webSearch.title"),t[4]=e,t[5]=m):m=t[5];let u;t[6]!==e?(u=e("settings.page.webSearch.description"),t[6]=e,t[7]=u):u=t[7];let f;t[8]!==a||t[9]!==l||t[10]!==n.kind||t[11]!==e?(f=l?s.jsxs(s.Fragment,{children:[s.jsx(Yf,{snapshot:l}),s.jsx(Xf,{snapshot:l})]}):n.kind==="failed"?s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.webSearch.state.loadFailed")}),s.jsx(B,{variant:"outline",size:"xs",onClick:()=>{a()},children:e("settings.webSearch.actions.retry")})]})}):s.jsx(qe,{divider:!1,children:s.jsx("p",{className:Mt,children:e("settings.webSearch.state.loading")})}),t[8]=a,t[9]=l,t[10]=n.kind,t[11]=e,t[12]=f):f=t[12];let p;return t[13]!==m||t[14]!==u||t[15]!==f?(p=s.jsx(es,{title:m,description:u,showSaveStatus:!0,children:f}),t[13]=m,t[14]=u,t[15]=f,t[16]=p):p=t[16],p};function th(t){return t.setSelection}function sh(){}function nh(t){return t.saveKey}function ah(t){return t.removeKey}function ih(t){return t.state}function oh(t){return t.load}const rh=t=>{const e=$e.c(183),{onItemSelect:n}=t,{t:a}=_e(),[i,o]=d.useState(""),[r,c]=d.useState(null),[l,m]=d.useState(""),[u,f]=d.useState(null),[p,g]=d.useState(null),[h,j]=d.useState(!1),[x,S]=d.useState(null),{selectedCommandName:b,setSelectedCommand:w,setCommandDraft:k,createCommand:I,deleteCommand:y,loadCommands:E}=qa(Os(lh)),v=Zs();let R;e[0]!==v?(R=Ye=>Cd(Ye,v),e[0]=v,e[1]=R):R=e[1];const C=qa(R);let T;e[2]!==v?(T=Ye=>tl(Ye,v),e[2]=v,e[3]=T):T=e[3];const P=tn(T),L=tn(ch);let O,A;e[4]!==E||e[5]!==L||e[6]!==v?(O=()=>{E(v),L(v)},A=[E,L,v],e[4]=E,e[5]=L,e[6]=v,e[7]=O,e[8]=A):(O=e[7],A=e[8]),d.useEffect(O,A);let N;e[9]!==P?(N=new Set(P.map(dh)),e[9]=P,e[10]=N):N=e[10];const M=N;let F;if(e[11]!==C||e[12]!==M){let Ye;e[14]!==M?(Ye=Xe=>!M.has(Xe.name),e[14]=M,e[15]=Ye):Ye=e[15],F=C.filter(Ye),e[11]=C,e[12]=M,e[13]=F}else F=e[13];const H=F;let W,G;e[16]!==b||e[17]!==w||e[18]!==M?(W=()=>{b&&M.has(b)&&w(null)},G=[b,w,M],e[16]=b,e[17]=w,e[18]=M,e[19]=W,e[20]=G):(W=e[19],G=e[20]),d.useEffect(W,G);let $;e[21]!==C||e[22]!==n||e[23]!==k||e[24]!==w?($=()=>{let Ye="new-command",Xe=1;for(;C.some(gt=>gt.name===Ye);)Ye=`new-command-${Xe}`,Xe++;k({name:Ye,scope:"user"}),w(Ye),n?.()},e[21]=C,e[22]=n,e[23]=k,e[24]=w,e[25]=$):$=e[25];const z=$;let U;e[26]!==a?(U=async Ye=>{if(Ba(Ye)){q.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(Ye),g("delete")},e[26]=a,e[27]=U):U=e[27];const _=U;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Ye=>{Ba(Ye)&&(f(Ye),g("reset"))},e[28]=V):V=e[28];const Z=V;let Y;e[29]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{f(null),g(null)},e[29]=Y):Y=e[29];const Q=Y;let ue;e[30]!==u||e[31]!==p||e[32]!==y||e[33]!==v||e[34]!==a?(ue=async()=>{if(!u||!p)return;j(!0),await y(u.name,v)?(p==="delete"?q.success(a("settings.commands.sidebar.toast.commandDeleted",{name:u.name})):q.success(a("settings.commands.sidebar.toast.commandReset",{name:u.name})),Q()):p==="delete"?q.error(a("settings.commands.sidebar.toast.deleteFailed")):q.error(a("settings.commands.sidebar.toast.resetFailed")),j(!1)},e[30]=u,e[31]=p,e[32]=y,e[33]=v,e[34]=a,e[35]=ue):ue=e[35];const ge=ue;let fe;e[36]!==C||e[37]!==k||e[38]!==w?(fe=Ye=>{const Xe=Ye.name;let gt=1,Ue=`${Xe}-copy`;for(;C.some(ee=>ee.name===Ue);)gt++,Ue=`${Xe}-copy-${gt}`;k({name:Ue,scope:Ye.scope||"user",description:Ye.description,template:Ye.template,agent:Ye.agent,model:Ye.model,subagent:Ye.subagent}),w(Ue)},e[36]=C,e[37]=k,e[38]=w,e[39]=fe):fe=e[39];const Ie=fe;let te;e[40]===Symbol.for("react.memo_cache_sentinel")?(te=Ye=>{m(Ye.name),c(Ye)},e[40]=te):te=e[40];const Ce=te;let ie;e[41]!==C||e[42]!==I||e[43]!==y||e[44]!==r||e[45]!==l||e[46]!==w||e[47]!==v||e[48]!==a?(ie=async()=>{if(!r)return;const Ye=l.trim().replace(/\s+/g,"-");if(!Ye){q.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ye===r.name){c(null);return}if(C.some(gt=>gt.name===Ye)){q.error(a("settings.commands.sidebar.toast.commandExists"));return}await I({name:Ye,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},v)?await y(r.name,v)?(q.success(`Command renamed to "${Ye}"`),w(Ye)):q.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):q.error(a("settings.commands.sidebar.toast.renameFailed")),c(null)},e[41]=C,e[42]=I,e[43]=y,e[44]=r,e[45]=l,e[46]=w,e[47]=v,e[48]=a,e[49]=ie):ie=e[49];const ae=ie;let re,ye,Ee,Pe,ke,Te;if(e[50]!==H||e[51]!==z||e[52]!==_||e[53]!==Ie||e[54]!==n||e[55]!==x||e[56]!==i||e[57]!==b||e[58]!==w||e[59]!==a){let Ye;e[66]!==i?(Ye=we=>Co([we.name,we.description],i),e[66]=i,e[67]=Ye):Ye=e[67];const Xe=H.filter(Ye),gt=Xe.filter(Ba),Ue=Xe.filter(uh);e[68]===Symbol.for("react.memo_cache_sentinel")?(ke=je("flex h-full flex-col","bg-background"),e[68]=ke):ke=e[68];let ee;e[69]!==a?(ee=a("settings.commands.sidebar.title"),e[69]=a,e[70]=ee):ee=e[70];let ve;e[71]!==ee?(ve=s.jsx("h2",{className:`${ya} mb-3`,children:ee}),e[71]=ee,e[72]=ve):ve=e[72];let Fe;e[73]===Symbol.for("react.memo_cache_sentinel")?(Fe=s.jsx(Ai,{className:"mb-3"}),e[73]=Fe):Fe=e[73];let se;e[74]!==H.length||e[75]!==a?(se=a("settings.commands.sidebar.total",{count:H.length}),e[74]=H.length,e[75]=a,e[76]=se):se=e[76];let Ae;e[77]!==se?(Ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:se}),e[77]=se,e[78]=Ae):Ae=e[78];let tt;e[79]===Symbol.for("react.memo_cache_sentinel")?(tt=s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),e[79]=tt):tt=e[79];let ot;e[80]!==z?(ot=s.jsx(B,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:z,children:tt}),e[80]=z,e[81]=ot):ot=e[81];let At;e[82]!==Ae||e[83]!==ot?(At=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ae,ot]}),e[82]=Ae,e[83]=ot,e[84]=At):At=e[84];let pe;e[85]!==H.length||e[86]!==i?(pe=H.length>0?s.jsx(pl,{value:i,onChange:o}):null,e[85]=H.length,e[86]=i,e[87]=pe):pe=e[87],e[88]!==ve||e[89]!==At||e[90]!==pe?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,Fe,At,pe]}),e[88]=ve,e[89]=At,e[90]=pe,e[91]=Te):Te=e[91],re=js,ye="flex-1 min-h-0",Ee="space-y-1 px-3 py-2",Pe=H.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(J,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.commands.sidebar.empty.description")})]}):Xe.length===0?s.jsx(gl,{query:i}):s.jsxs(s.Fragment,{children:[gt.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:a("settings.commands.sidebar.section.builtIn")}),[...gt].sort(mh).map(we=>s.jsx(cc,{command:we,isSelected:b===we.name,onSelect:()=>{w(we.name),n?.()},onReset:()=>Z(we),onDuplicate:()=>Ie(we),isMenuOpen:x===we.name,onMenuOpenChange:ze=>S(ze?we.name:null)},we.name))]}),Ue.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:a("settings.commands.sidebar.section.custom")}),[...Ue].sort(ph).map(we=>s.jsx(cc,{command:we,isSelected:b===we.name,onSelect:()=>{w(we.name),n?.()},onRename:()=>Ce(we),onDelete:()=>_(we),onDuplicate:()=>Ie(we),isMenuOpen:x===we.name,onMenuOpenChange:ze=>S(ze?we.name:null)},we.name))]})]}),e[50]=H,e[51]=z,e[52]=_,e[53]=Ie,e[54]=n,e[55]=x,e[56]=i,e[57]=b,e[58]=w,e[59]=a,e[60]=re,e[61]=ye,e[62]=Ee,e[63]=Pe,e[64]=ke,e[65]=Te}else re=e[60],ye=e[61],Ee=e[62],Pe=e[63],ke=e[64],Te=e[65];let de;e[92]!==re||e[93]!==ye||e[94]!==Ee||e[95]!==Pe?(de=s.jsx(re,{outerClassName:ye,className:Ee,children:Pe}),e[92]=re,e[93]=ye,e[94]=Ee,e[95]=Pe,e[96]=de):de=e[96];const Me=u!==null&&p!==null;let Se;e[97]!==h?(Se=Ye=>{!Ye&&!h&&Q()},e[97]=h,e[98]=Se):Se=e[98];let Le;e[99]!==p||e[100]!==a?(Le=a(p==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[99]=p,e[100]=a,e[101]=Le):Le=e[101];let Ke;e[102]!==Le?(Ke=s.jsx(Vt,{children:Le}),e[102]=Le,e[103]=Ke):Ke=e[103];let oe;e[104]!==u?.name||e[105]!==p||e[106]!==a?(oe=p==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:u?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:u?.name??""}),e[104]=u?.name,e[105]=p,e[106]=a,e[107]=oe):oe=e[107];let le;e[108]!==oe?(le=s.jsx(Ht,{children:oe}),e[108]=oe,e[109]=le):le=e[109];let xe;e[110]!==Ke||e[111]!==le?(xe=s.jsxs(Bt,{children:[Ke,le]}),e[110]=Ke,e[111]=le,e[112]=xe):xe=e[112];let De;e[113]!==a?(De=a("settings.common.actions.cancel"),e[113]=a,e[114]=De):De=e[114];let Ve;e[115]!==h||e[116]!==De?(Ve=s.jsx(B,{size:"sm",variant:"ghost",onClick:Q,disabled:h,children:De}),e[115]=h,e[116]=De,e[117]=Ve):Ve=e[117];let Be;e[118]!==p||e[119]!==a?(Be=a(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[118]=p,e[119]=a,e[120]=Be):Be=e[120];let Ne;e[121]!==ge||e[122]!==h||e[123]!==Be?(Ne=s.jsx(B,{size:"sm",onClick:ge,disabled:h,children:Be}),e[121]=ge,e[122]=h,e[123]=Be,e[124]=Ne):Ne=e[124];let Je;e[125]!==Ve||e[126]!==Ne?(Je=s.jsxs(ns,{children:[Ve,Ne]}),e[125]=Ve,e[126]=Ne,e[127]=Je):Je=e[127];let ut;e[128]!==xe||e[129]!==Je?(ut=s.jsxs(Ut,{className:"max-w-md",children:[xe,Je]}),e[128]=xe,e[129]=Je,e[130]=ut):ut=e[130];let ht;e[131]!==Me||e[132]!==Se||e[133]!==ut?(ht=s.jsx(zt,{open:Me,onOpenChange:Se,children:ut}),e[131]=Me,e[132]=Se,e[133]=ut,e[134]=ht):ht=e[134];const st=r!==null;let jt;e[135]===Symbol.for("react.memo_cache_sentinel")?(jt=Ye=>!Ye&&c(null),e[135]=jt):jt=e[135];let St;e[136]!==a?(St=a("settings.commands.sidebar.renameDialog.title"),e[136]=a,e[137]=St):St=e[137];let Ze;e[138]!==St?(Ze=s.jsx(Vt,{children:St}),e[138]=St,e[139]=Ze):Ze=e[139];const it=r?.name??"";let et;e[140]!==a||e[141]!==it?(et=a("settings.commands.sidebar.renameDialog.description",{name:it}),e[140]=a,e[141]=it,e[142]=et):et=e[142];let mt;e[143]!==et?(mt=s.jsx(Ht,{children:et}),e[143]=et,e[144]=mt):mt=e[144];let ft;e[145]!==Ze||e[146]!==mt?(ft=s.jsxs(Bt,{children:[Ze,mt]}),e[145]=Ze,e[146]=mt,e[147]=ft):ft=e[147];let be;e[148]===Symbol.for("react.memo_cache_sentinel")?(be=Ye=>m(Ye.target.value),e[148]=be):be=e[148];let Re;e[149]!==a?(Re=a("settings.commands.sidebar.renameDialog.placeholder"),e[149]=a,e[150]=Re):Re=e[150];let X;e[151]!==ae?(X=Ye=>{Ye.key==="Enter"&&ae()},e[151]=ae,e[152]=X):X=e[152];let ce;e[153]!==l||e[154]!==Re||e[155]!==X?(ce=s.jsx(He,{value:l,onChange:be,placeholder:Re,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:X}),e[153]=l,e[154]=Re,e[155]=X,e[156]=ce):ce=e[156];let Oe;e[157]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>c(null),e[157]=Oe):Oe=e[157];let We;e[158]!==a?(We=a("settings.common.actions.cancel"),e[158]=a,e[159]=We):We=e[159];let nt;e[160]!==We?(nt=s.jsx(B,{size:"sm",variant:"ghost",onClick:Oe,children:We}),e[160]=We,e[161]=nt):nt=e[161];let at;e[162]!==a?(at=a("settings.common.actions.rename"),e[162]=a,e[163]=at):at=e[163];let vt;e[164]!==ae||e[165]!==at?(vt=s.jsx(B,{size:"sm",onClick:ae,children:at}),e[164]=ae,e[165]=at,e[166]=vt):vt=e[166];let kt;e[167]!==nt||e[168]!==vt?(kt=s.jsxs(ns,{children:[nt,vt]}),e[167]=nt,e[168]=vt,e[169]=kt):kt=e[169];let xt;e[170]!==ft||e[171]!==ce||e[172]!==kt?(xt=s.jsxs(Ut,{children:[ft,ce,kt]}),e[170]=ft,e[171]=ce,e[172]=kt,e[173]=xt):xt=e[173];let It;e[174]!==st||e[175]!==xt?(It=s.jsx(zt,{open:st,onOpenChange:jt,children:xt}),e[174]=st,e[175]=xt,e[176]=It):It=e[176];let _t;return e[177]!==ke||e[178]!==Te||e[179]!==de||e[180]!==ht||e[181]!==It?(_t=s.jsxs("div",{className:ke,children:[Te,de,ht,It]}),e[177]=ke,e[178]=Te,e[179]=de,e[180]=ht,e[181]=It,e[182]=_t):_t=e[182],_t},cc=t=>{const e=$e.c(47),{command:n,isSelected:a,onSelect:i,onDelete:o,onReset:r,onRename:c,onDuplicate:l,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=_e();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=Xr(),e[0]=p):p=e[0];const g=p,[h,j]=d.useState(!1);let x;e[1]!==o||e[2]!==l||e[3]!==c||e[4]!==r||e[5]!==f?(x=H=>s.jsxs(s.Fragment,{children:[c&&s.jsxs(H,{onClick:W=>{W.stopPropagation(),c()},children:[s.jsx(J,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),s.jsxs(H,{onClick:W=>{W.stopPropagation(),l()},children:[s.jsx(J,{name:"file-copy",className:"h-4 w-4 mr-px"}),f("settings.common.actions.duplicate")]}),r&&s.jsxs(H,{onClick:W=>{W.stopPropagation(),r()},children:[s.jsx(J,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),o&&s.jsxs(H,{onClick:W=>{W.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[1]=o,e[2]=l,e[3]=c,e[4]=r,e[5]=f,e[6]=x):x=e[6];const S=x,b=a?"bg-interactive-selection":"hover:bg-interactive-hover";let w;e[7]!==b?(w=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b),e[7]=b,e[8]=w):w=e[8];let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=g?void 0:H=>{H.preventDefault(),j(!0)},e[9]=k):k=e[9];let I;e[10]!==w?(I=s.jsx("div",{className:w,onContextMenu:k}),e[10]=w,e[11]=I):I=e[11];let y;e[12]!==n.name?(y=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=y):y=e[13];let E;e[14]!==n||e[15]!==f?(E=(n.scope||Ba(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Ba(n)?f("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=f,e[16]=E):E=e[16];let v;e[17]!==y||e[18]!==E?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[y,E]}),e[17]=y,e[18]=E,e[19]=v):v=e[19];let R;e[20]!==n.description?(R=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[20]=n.description,e[21]=R):R=e[21];let C;e[22]!==i||e[23]!==R||e[24]!==v?(C=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[v,R]}),e[22]=i,e[23]=R,e[24]=v,e[25]=C):C=e[25];let T;e[26]!==u?(T=H=>{H&&j(!1),u(H)},e[26]=u,e[27]=T):T=e[27];let P;e[28]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=P):P=e[28];let L;e[29]!==S?(L=s.jsx(On,{align:"end",className:"w-fit min-w-20",children:S(mn)}),e[29]=S,e[30]=L):L=e[30];let O;e[31]!==m||e[32]!==T||e[33]!==L?(O=s.jsxs(Kn,{open:m,onOpenChange:T,children:[P,L]}),e[31]=m,e[32]=T,e[33]=L,e[34]=O):O=e[34];let A;e[35]!==C||e[36]!==O?(A=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,O]}),e[35]=C,e[36]=O,e[37]=A):A=e[37];let N;e[38]!==A||e[39]!==I?(N=s.jsx(Qa,{render:I,children:A}),e[38]=A,e[39]=I,e[40]=N):N=e[40];let M;e[41]!==S?(M=s.jsx(Ga,{className:"w-fit min-w-20",children:S(Ja)}),e[41]=S,e[42]=M):M=e[42];let F;return e[43]!==h||e[44]!==N||e[45]!==M?(F=s.jsxs(Ya,{open:h,onOpenChange:j,children:[N,M]}),e[43]=h,e[44]=N,e[45]=M,e[46]=F):F=e[46],F};function lh(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function ch(t){return t.loadSkills}function dh(t){return t.name}function uh(t){return!Ba(t)}function mh(t,e){return t.name.localeCompare(e.name)}function ph(t,e){return t.name.localeCompare(e.name)}const gh=()=>{const{t}=_e(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:i,commandDraft:o,setCommandDraft:r,setSelectedCommand:c}=qa(Os(U=>({selectedCommandName:U.selectedCommandName,getCommandByName:U.getCommandByName,createCommand:U.createCommand,updateCommand:U.updateCommand,commandDraft:U.commandDraft,setCommandDraft:U.setCommandDraft,setSelectedCommand:U.setSelectedCommand}))),l=Zs(),m=qa(U=>Cd(U,l)),u=e?n(e,l):null,f=!!(o&&o.name===e&&!u),[p,g]=d.useState(""),[h,j]=d.useState("user"),[x,S]=d.useState(""),[b,w]=d.useState(""),[k,I]=d.useState(""),[y,E]=d.useState(""),[v,R]=d.useState(!1),[C,T]=d.useState(""),[P,L]=d.useState(!1),O=d.useRef(null),A=JSON.stringify([l,e]),N=d.useRef(null),M=d.useRef(null);d.useEffect(()=>{const U=N.current===A;if(N.current=A,f&&o){const _=o.name||"",V=o.scope||"user",Z=o.description||"",Y=o.agent||"",Q=ji(o.model),ue=Q?`${Q.providerID}/${Q.modelID}`:"",ge=Q?.variant||"",fe=o.subagent===!0,Ie=o.template||"";g(_),j(V),S(Z),w(Y),I(ue),E(ge),R(fe),T(Ie),O.current={draftName:_,draftScope:V,description:Z,agent:Y,model:ue,variant:ge,subagent:fe,template:Ie}}else if(u){const _=u.description||"",V=u.agent||"",Z=ji(u.model),Y=Z?`${Z.providerID}/${Z.modelID}`:"",Q=Z?.variant||"",ue=u.subagent===!0,ge=u.template||"",fe=M.current,Ie=[O.current,fe?.identity===A?fe.form:null];if(U&&Ie.some(te=>te&&te.description===_&&te.agent===V&&te.model===Y&&te.variant===Q&&te.subagent===ue&&te.template===ge))return;S(_),w(V),I(Y),E(Q),R(ue),T(ge),O.current={draftName:"",draftScope:"user",description:_,agent:V,model:Y,variant:Q,subagent:ue,template:ge}}},[u,f,e,m,o,A]);const F=d.useCallback(U=>{const _=b.trim(),V=En(k.trim()),Z=V?qd({providerID:V.providerId,modelID:V.modelId,variant:y.trim()||void 0}):null;return{name:U,description:x.trim()||void 0,agent:_===""?null:_,model:Z,subagent:v,template:C.trim(),scope:f?h:void 0}},[b,x,h,f,k,v,C,y]),H=d.useCallback(async()=>{const U=O.current,_=e?.trim();if(f||!U||!_||x.trim()===U.description.trim()&&b.trim()===U.agent.trim()&&k.trim()===U.model.trim()&&y.trim()===U.variant.trim()&&v===U.subagent&&C.trim()===U.template.trim())return Ls;if(!C.trim())return fs(t("settings.commands.page.toast.templateRequired"));const Z=F(_),Y=ji(Z.model),Q={identity:A,form:{...U,description:Z.description||"",agent:Z.agent||"",model:Y?`${Y.providerID}/${Y.modelID}`:"",variant:Y?.variant||"",subagent:Z.subagent===!0,template:Z.template||""}};M.current=Q;try{return await i(_,Z,l)?(N.current===A&&(O.current=Q.form),vn):fs(t("settings.commands.page.toast.updateFailed"))}finally{M.current===Q&&(M.current=null)}},[b,F,x,A,f,k,e,l,v,t,C,i,y]),W=ei(H),{requestSave:G}=W,$=async()=>{const U=p.trim().replace(/\s+/g,"-");if(!U){q.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){q.error(t("settings.commands.page.toast.templateRequired"));return}if(m.some(_=>_.name===U)){q.error(t("settings.commands.sidebar.toast.commandExists"));return}L(!0);try{await a(F(U),l)?(r(null),q.success(t("settings.commands.page.toast.created"))):q.error(t("settings.commands.page.toast.createFailed"))}catch(_){console.error("Error creating command:",_),q.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{L(!1)}},z=()=>{r(null),c(null)};return e?s.jsxs(es,{title:f?t("settings.commands.page.title.new"):`/${e}`,description:t(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),onBlurCapture:W.onBlurCapture,children:[!f&&u&&s.jsx(fl,{legacy:u.legacy===!0,path:u.path}),s.jsxs(qe,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[f&&s.jsxs(yt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:p,onChange:U=>g(U.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:h,onValueChange:U=>j(U),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Et,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{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(Ts,{value:x,onChange:U=>S(U.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(qe,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(yt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(sl,{agentName:b,onChange:U=>{w(U),G()},className:qs})}),s.jsx(yt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(fa,{providerId:En(k)?.providerId??"",modelId:En(k)?.modelId??"",onChange:(U,_)=>{I(U&&_?`${U}/${_}`:""),G()},className:qs})}),s.jsx(yt,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(He,{value:y,onChange:U=>E(U.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!k&&!y,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(yt,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(ha,{checked:v,onCheckedChange:U=>{R(U),G()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(qe,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ts,{value:C,onChange:U=>T(U.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(B,{onClick:()=>{$()},disabled:P||!p.trim()||!C.trim(),size:"xs",className:"!font-normal",children:t(P?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(B,{variant:"ghost",onClick:z,disabled:P,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(J,{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 Hs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function li(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function fn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ji(t,e,n){const a=hh(n),i=typeof n.url=="string"?n.url.trim():"",o=dc(n,"env","environment"),r=dc(n,"headers"),c=Hs(n.oauth)?n.oauth:null,l=ci(c,"client_id","clientId"),m=ci(c,"client_secret","clientSecret"),u=ci(c,"scope"),f=ci(c,"redirect_uri","redirectUri"),p=fh(c,"callback_port","callbackPort"),g=ci(c,"auth_server_metadata_url","authServerMetadataUrl"),h=n.oauth===!1||n.oauth===null||n.oauth===void 0?!1:!!c&&!!(l||m||u||f||p||g),j=xh(n);return{ok:!0,name:t,type:e,command:a,url:i,environment:o,headers:r,oauthEnabled:h,oauthClientId:l,oauthClientSecret:m,oauthScope:u,oauthRedirectUri:f,oauthCallbackPort:p,oauthAuthServerMetadataUrl:g,timeoutStartup:j.startup,timeoutCatalog:j.catalog,timeoutExecution:j.execution,codemode:n.codemode===!0?"on":n.codemode===!1?"off":"default",disabled:bh(n),protocol:Rr.find(x=>x===n.protocol)??"legacy"}}function ci(t,...e){if(!t)return"";for(const n of e){const a=t[n];if(typeof a=="string"&&a.trim())return a.trim()}return""}function fh(t,...e){if(!t)return"";for(const n of e){const a=hi(t[n]);if(a)return a}return""}function hi(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 hh(t){const e=t.command,n=t.args;if(li(e)&&li(n))return[...e,...n];if(li(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return li(n)?[...a,...n]:a}return li(n)?n:[]}function dc(t,...e){for(const n of e){const a=t[n];if(!Hs(a))continue;const i=Object.entries(a).filter(([o,r])=>o&&typeof r=="string");if(i.length>0)return i.map(([o,r])=>({key:o,value:String(r)}))}return[]}function xh(t){return Hs(t.timeout)?{startup:hi(t.timeout.startup),catalog:hi(t.timeout.catalog),execution:hi(t.timeout.execution)}:{startup:"",catalog:"",execution:hi(t.timeout)}}function bh(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function vh(t){const e=t.mcpServers;if(Hs(e)){const a=Object.keys(e);if(a.length===1){const i=a[0],o=e[i];if(Hs(o))return{name:i,entry:o}}if(a.length>1)return null}const n=Object.keys(t).filter(a=>{const i=t[a];return a!=="mcpServers"&&Hs(i)});if(n.length===1){const a=n[0],i=t[a];if(au(i))return{name:a,entry:i}}return null}function au(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function yh(t,e){let n;try{const l=t.trim();if(!l)return fn("No JSON content provided");n=JSON.parse(l)}catch(l){return fn(l instanceof Error?`Invalid JSON: ${l.message}`:"Invalid JSON")}if(!Hs(n))return fn("Expected a JSON object, not an array or primitive");const a=n,i=a.mcpServers;if(Hs(i)){const l=Object.keys(i);if(l.length===0)return fn("mcpServers object is empty",n);if(l.length>1)return fn("Paste one server at a time. Found "+l.length+" servers in mcpServers",n);const m=l[0],u=i[m];return Hs(u)?Ji(m,Qi(u),u):fn("Server entry is not a valid object",n)}const o=a.mcp,r=Hs(o)&&Hs(o.servers)?o.servers:o;if(Hs(r)){const l=Object.keys(r);if(l.length===0)return fn("mcp object is empty",n);if(l.length>1)return fn("Paste one server at a time. Found "+l.length+" servers in mcp",n);const m=l[0],u=r[m];return Hs(u)?Ji(m,Qi(u),u):fn("Server entry in mcp is not a valid object",n)}const c=vh(a);if(c)return Ji(c.name,Qi(c.entry),c.entry);if(au(a)){const l=Qi(a),m=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return Ji(m,l,a)}return fn("No recognizable MCP server configuration found in JSON",n)}function Qi(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 jh(t,e,n){const a=n?.isNewServer??!1,i=t.name,o=a&&i?i:e.name??"";return{...e,name:o,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 kh=(t,e)=>!!e&&t!=="claude-code",wh=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Sh=t=>wh.exec(t)?.[0]??void 0,Ti=t=>t.type!=="external",Yi=t=>t.title??t.key,Nh=(t,e)=>{if(e===void 0)return!1;const n=String(e),a=String(t.value);return t.op==="eq"?n===a:n!==a},Ch=(t,e)=>Ti(t)?(t.when??[]).every(n=>Nh(n,e[n.key])):!0,hl=(t,e)=>{const n={},a=[];for(const i of t){if(!Ch(i,n))continue;a.push(i);const o=e[i.key];Ti(i)&&o!==void 0&&(n[i.key]=o)}return a},Ih=t=>{const e={};for(const n of t)switch(n.type){case"external":break;case"boolean":e[n.key]=n.default??!1;break;case"number":case"integer":typeof n.default=="number"&&(e[n.key]=n.default);break;case"multiselect":e[n.key]=n.default??[];break;case"string":e[n.key]=n.default??n.options?.[0]?.value??"";break}return e},iu=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,Ph=(t,e)=>hl(t,e).find(n=>Ti(n)&&n.required===!0&&iu(e[n.key]))??null,Ah=(t,e)=>{const n={};for(const a of hl(t,e)){if(!Ti(a))continue;const i=e[a.key];iu(i)||i===void 0||(n[a.key]=typeof i=="string"?i.trim():i)}return n},uc=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),mc=t=>typeof t=="string"&&t.length>0?t:void 0,Th=(t,e,n)=>{const a=uc(t)?t:{},i=uc(a.data)?a.data:{};switch(a.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 mc(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return mc(a.message)??e(n)}},ur={phase:"idle"},Eh=1500,Br=({integrationId:t,methods:e,onConnected:n,directory:a,className:i})=>{const{t:o}=_e(),r=d.useCallback(()=>a?Ps.getScopedSdkClient(a):Ps.getSdkClient(),[a]),[c,l]=d.useState(ur),[m,u]=d.useState({}),[f,p]=d.useState(""),g=d.useRef(null),h=d.useCallback(P=>{g.current=null,r().integration.oauth.cancel({integrationID:t,attemptID:P}).catch(()=>{})},[t,r]);d.useEffect(()=>()=>{const P=g.current;P&&h(P)},[h]);const j=c.phase==="idle"?null:c.methodID,x=c.phase==="connecting"||c.phase==="waiting"||c.phase==="awaitingCode"&&c.submitting,S=async(P,L,O)=>{const A=await _a(P);if(A.ok){q.success(o(L));return}console.error("Failed to copy OAuth value:",A.error),q.error(o(O))},b=async()=>{g.current=null,l(ur),q.success(o("settings.providers.page.toast.oauthCompleted")),await n()},w=(P,L,O)=>{g.current=null,console.error("OAuth flow failed:",L),l({phase:"failed",methodID:P,message:Th(L,o,O)})},k=async(P,L)=>{const O=r();for(;g.current===L;){if(await new Promise(A=>setTimeout(A,Eh)),g.current!==L)return;try{const{data:A}=await O.integration.oauth.status({integrationID:t,attemptID:L});if(g.current!==L)return;if(A.status==="complete"){await b();return}if(A.status==="failed"){l({phase:"failed",methodID:P,message:A.message}),g.current=null;return}}catch(A){if(g.current!==L)return;w(P,A,"settings.providers.page.toast.oauthCompleteFailed");return}}},I=async(P,L)=>{l({phase:"connecting",methodID:P.id});let O;try{const{data:A}=await r().integration.oauth.connect({integrationID:t,methodID:P.id,...Object.keys(L).length>0?{answer:L}:{}});O={attemptID:A.attemptID,mode:A.mode,url:A.url,instructions:A.instructions}}catch(A){w(P.id,A,"settings.providers.page.toast.oauthStartFailed");return}if(g.current=O.attemptID,kh(t,O.url)&&Ss(O.url),O.mode==="code"){p(""),l({phase:"awaitingCode",methodID:P.id,attempt:O,submitting:!1});return}l({phase:"waiting",methodID:P.id,attempt:O}),await k(P.id,O.attemptID)},y=P=>{const L=(P.form??[]).filter(Ti);if(L.length===0){I(P,{});return}u(Ih(L)),l({phase:"prompting",methodID:P.id,fields:L,error:null})},E=P=>{if(c.phase!=="prompting")return;const L=Ph(c.fields,m);if(L){l({...c,error:o("settings.providers.page.auth.oauth.promptRequired",{field:Yi(L)})});return}I(P,Ah(c.fields,m))},v=async()=>{if(c.phase!=="awaitingCode")return;const P=f.trim();if(!P)return;const{methodID:L,attempt:O}=c;l({...c,submitting:!0});try{await r().integration.oauth.complete({integrationID:t,attemptID:O.attemptID,code:P}),await b()}catch(A){w(L,A,"settings.providers.page.toast.oauthCompleteFailed")}},R=()=>{(c.phase==="waiting"||c.phase==="awaitingCode")&&h(c.attempt.attemptID),l(ur)},C=P=>{if(P.type==="external")return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Yi(P)}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(P.url)},children:o("settings.providers.page.actions.open")})]},P.key);const L=m[P.key],O=typeof L=="string"?L:"",A=M=>u(F=>({...F,[P.key]:M})),N=P.type==="string"||P.type==="multiselect"?P.options??[]:[];return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Yi(P)}),P.description&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:P.description}),N.length>0?s.jsxs(Dt,{value:O,onValueChange:A,children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{children:M=>N.find(F=>F.value===M)?.label??null})}),s.jsx(Et,{children:N.map(M=>s.jsx(dt,{value:M.value,children:M.description?`${M.label} · ${M.description}`:M.label},M.value))})]}):P.type==="boolean"?s.jsx("input",{type:"checkbox",checked:L===!0,onChange:M=>A(M.target.checked),"aria-label":Yi(P)}):s.jsx(He,{value:O,onChange:M=>A(M.target.value),placeholder:P.type==="string"?P.placeholder:void 0,className:"max-w-[24rem] text-xs"})]},P.key)},T=P=>{const L=Sh(P.instructions);return s.jsxs(s.Fragment,{children:[P.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:P.instructions}),L&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:L,readOnly:!0,"aria-label":o("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{S(L,"settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:o("settings.providers.page.actions.copyCode")})]}),P.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:P.url,readOnly:!0,"aria-label":o("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(P.url)},children:o("settings.providers.page.actions.open")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{S(P.url,"settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:o("settings.providers.page.actions.copy")})]})]})]})};return s.jsx("div",{className:je("space-y-4",i),children:e.map(P=>{const L=j===P.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:P.label}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>y(P),disabled:x,children:o("settings.providers.page.actions.connect")})]}),L&&c.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[hl(c.fields,m).map(C),c.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:c.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>E(P),children:o("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:R,children:o("settings.providers.page.actions.cancel")})]})]}),L&&c.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(J,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),o("settings.providers.page.auth.oauth.starting")]}),L&&c.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[T(c.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(J,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),o("settings.providers.page.auth.oauth.waiting")]}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,children:o("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:o("settings.providers.page.auth.oauth.waitingHint")})]}),L&&c.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[T(c.attempt),s.jsx("p",{className:"typography-meta text-muted-foreground",children:o("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:f,onChange:O=>p(O.target.value),placeholder:o("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:c.submitting}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{v()},disabled:c.submitting||f.trim().length===0,children:c.submitting?o("settings.providers.page.actions.saving"):o("settings.providers.page.actions.complete")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,disabled:c.submitting,children:o("settings.providers.page.actions.cancel")})]})]}),L&&c.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:c.message}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>y(P),children:o("settings.providers.page.actions.tryAgain")})]})]},P.id)})})},Dh=(t,e)=>t.find(n=>n.id.startsWith("mcp_")&&n.metadata?.source==="mcp"&&n.name===e),Mh=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Rh=({serverName:t,directory:e,onConnected:n})=>{const[a,i]=d.useState(null);d.useEffect(()=>{let r=!1;i(null);const c=e?Ps.getScopedSdkClient(e):Ps.getSdkClient();return(async()=>{try{const{data:m}=await c.integration.list();r||i(Dh(m,t)??null)}catch(m){console.error("Failed to load MCP integrations:",m)}})(),()=>{r=!0}},[e,t]);const o=Mh(a??void 0);return!a||o.length===0?null:s.jsx(Br,{integrationId:a.id,methods:o,directory:e,onConnected:n},a.id)},bo={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},Lh=t=>t===!1?{...bo,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)}:bo,xl="grid grid-cols-1 gap-3 @xl:grid-cols-2 @3xl:grid-cols-3",Vr=je("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)]"),Oh={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"},hn=t=>{const e=$e.c(5),{tone:n,children:a}=t,i=Oh[n];let o;e[0]!==i?(o=je("max-w-40 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",i),e[0]=i,e[1]=o):o=e[1];let r;return e[2]!==a||e[3]!==o?(r=s.jsx("span",{className:o,children:a}),e[2]=a,e[3]=o,e[4]=r):r=e[4],r},vo=t=>{const e=$e.c(2),{children:n}=t;let a;return e[0]!==n?(a=s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-px text-[10px] font-medium",children:n}),e[0]=n,e[1]=a):a=e[1],a},ou=t=>{const e=$e.c(5),{action:n}=t;let a;e[0]!==n.icon?(a=n.icon?s.jsx(J,{name:n.icon,className:"size-4"}):null,e[0]=n.icon,e[1]=a):a=e[1];let i;return e[2]!==n.label||e[3]!==a?(i=s.jsxs(s.Fragment,{children:[a,n.label]}),e[2]=n.label,e[3]=a,e[4]=i):i=e[4],i},Ci=t=>{const e=$e.c(57),{icon:n,title:a,subtitle:i,badges:o,footer:r,muted:c,onOpen:l,actions:m,actionsLabel:u}=t,f=(m?.length??0)>0,p=c&&"opacity-60";let g;e[0]!==p?(g=je("flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",p),e[0]=p,e[1]=g):g=e[1];let h;e[2]!==n||e[3]!==g?(h=s.jsx("span",{className:g,children:n}),e[2]=n,e[3]=g,e[4]=h):h=e[4];let j;e[5]!==o?(j=o?s.jsx("span",{className:"flex min-w-0 flex-wrap justify-end gap-1",children:o}):null,e[5]=o,e[6]=j):j=e[6];let x;e[7]!==h||e[8]!==j?(x=s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[h,j]}),e[7]=h,e[8]=j,e[9]=x):x=e[9];const S=c&&"opacity-60";let b;e[10]!==S?(b=je("mt-3 min-w-0",S),e[10]=S,e[11]=b):b=e[11];let w;e[12]!==a?(w=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",title:a,children:a}),e[12]=a,e[13]=w):w=e[13];let k;e[14]!==i?(k=i?s.jsx("div",{className:"mt-0.5 truncate font-mono typography-micro text-muted-foreground",title:i,children:i}):null,e[14]=i,e[15]=k):k=e[15];let I;e[16]!==b||e[17]!==w||e[18]!==k?(I=s.jsxs("div",{className:b,children:[w,k]}),e[16]=b,e[17]=w,e[18]=k,e[19]=I):I=e[19];const y=f&&"pr-8";let E;e[20]!==y?(E=je("mt-auto flex min-w-0 items-center gap-2 pt-3 typography-micro text-muted-foreground",y),e[20]=y,e[21]=E):E=e[21];let v;e[22]!==f||e[23]!==l?(v=l&&!f?s.jsx(J,{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[22]=f,e[23]=l,e[24]=v):v=e[24];let R;e[25]!==r||e[26]!==E||e[27]!==v?(R=s.jsxs("div",{className:E,children:[r,v]}),e[25]=r,e[26]=E,e[27]=v,e[28]=R):R=e[28];let C;e[29]!==I||e[30]!==R||e[31]!==x?(C=s.jsxs(s.Fragment,{children:[x,I,R]}),e[29]=I,e[30]=R,e[31]=x,e[32]=C):C=e[32];const T=C;let P;e[33]!==T||e[34]!==l?(P=l?s.jsx("button",{type:"button",onClick:l,className:je(Vr,"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:T}):s.jsx("div",{className:je(Vr,"h-full border-[var(--interactive-border)] bg-[var(--surface-elevated)]"),children:T}),e[33]=T,e[34]=l,e[35]=P):P=e[35];const L=P;if(!f||!m)return L;let O;e[36]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx("div",{className:"group relative"}),e[36]=O):O=e[36];let A;e[37]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(J,{name:"more-2",className:"size-4"}),e[37]=A):A=e[37];let N;e[38]!==u?(N=s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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":u,title:u,children:A})}),e[38]=u,e[39]=N):N=e[39];let M;e[40]!==m?(M=m.map(Fh),e[40]=m,e[41]=M):M=e[41];let F;e[42]!==M?(F=s.jsx(On,{align:"end",className:"w-fit min-w-32",children:M}),e[42]=M,e[43]=F):F=e[43];let H;e[44]!==N||e[45]!==F?(H=s.jsxs(Kn,{children:[N,F]}),e[44]=N,e[45]=F,e[46]=H):H=e[46];let W;e[47]!==L||e[48]!==H?(W=s.jsxs(Qa,{render:O,children:[L,H]}),e[47]=L,e[48]=H,e[49]=W):W=e[49];let G;e[50]!==m?(G=m.map(Kh),e[50]=m,e[51]=G):G=e[51];let $;e[52]!==G?($=s.jsx(Ga,{className:"w-fit min-w-32",children:G}),e[52]=G,e[53]=$):$=e[53];let z;return e[54]!==W||e[55]!==$?(z=s.jsxs(Ya,{children:[W,$]}),e[54]=W,e[55]=$,e[56]=z):z=e[56],z},bl=t=>{const e=$e.c(11),{label:n,hint:a,onClick:i,settingsItem:o}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=je(Vr,"items-center justify-center gap-2 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 c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx("span",{className:"flex size-10 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(J,{name:"add",className:"size-5"})}),e[1]=c):c=e[1];let l;e[2]!==n?(l=s.jsx("span",{className:"typography-ui-label font-medium",children:n}),e[2]=n,e[3]=l):l=e[3];let m;e[4]!==a?(m=a?s.jsx("span",{className:"typography-micro",children:a}):null,e[4]=a,e[5]=m):m=e[5];let u;return e[6]!==i||e[7]!==o||e[8]!==l||e[9]!==m?(u=s.jsxs("button",{type:"button",onClick:i,"data-settings-item":o,className:r,children:[c,l,m]}),e[6]=i,e[7]=o,e[8]=l,e[9]=m,e[10]=u):u=e[10],u},vl=t=>{const e=$e.c(7),{value:n,onChange:a,placeholder:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(J,{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]=o):o=e[0];let r;e[1]!==a?(r=l=>a(l.target.value),e[1]=a,e[2]=r):r=e[2];let c;return e[3]!==i||e[4]!==r||e[5]!==n?(c=s.jsxs("div",{className:"relative mb-4 max-w-[24rem]",children:[o,s.jsx(He,{value:n,onChange:r,placeholder:i,"aria-label":i,className:"h-9 pl-8"})]}),e[3]=i,e[4]=r,e[5]=n,e[6]=c):c=e[6],c},yl=t=>{const e=$e.c(4),{label:n,onClick:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(J,{name:"arrow-left-s",className:"size-4"}),e[0]=i):i=e[0];let o;return e[1]!==n||e[2]!==a?(o=s.jsx(B,{variant:"ghost",size:"icon",className:"-ml-2 h-7 w-7 shrink-0",onClick:a,"aria-label":n,title:n,children:i}),e[1]=n,e[2]=a,e[3]=o):o=e[3],o},Hr=t=>{const e=$e.c(2),{name:n}=t;let a;return e[0]!==n?(a=s.jsx(J,{name:n,className:"size-5 text-muted-foreground"}),e[0]=n,e[1]=a):a=e[1],a};function Fh(t){return s.jsx(mn,{variant:t.destructive?"destructive":"default",onClick:t.onSelect,children:s.jsx(ou,{action:t})},t.label)}function Kh(t){return s.jsx(Ja,{className:je(t.destructive&&"text-destructive focus:text-destructive"),onClick:t.onSelect,children:s.jsx(ou,{action:t})},t.label)}const zh=t=>{const e="new-mcp-server";let n=e,a=1;for(;t.some(i=>i.name===n);)n=`${e}-${a}`,a+=1;return n},Uh=t=>{const e=$e.c(9),{status:n,enabled:a}=t,{t:i}=_e();if(!a){let l;e[0]!==i?(l=i("settings.mcp.grid.status.disabled"),e[0]=i,e[1]=l):l=e[1];let m;return e[2]!==l?(m=s.jsx(hn,{tone:"neutral",children:l}),e[2]=l,e[3]=m):m=e[3],m}let o;e[4]!==n||e[5]!==i?(o=n==="connected"?{tone:"success",label:i("settings.mcp.page.status.label.connected")}:n==="failed"?{tone:"error",label:i("settings.mcp.page.status.label.failed")}:n==="needs_auth"?{tone:"warning",label:i("settings.mcp.page.status.label.needsAuth")}:n==="pending"?{tone:"neutral",label:i("settings.mcp.grid.status.pending")}:null,e[4]=n,e[5]=i,e[6]=o):o=e[6];const r=o;let c;return e[7]!==r?(c=r?s.jsx(hn,{tone:r.tone,children:r.label}):null,e[7]=r,e[8]=c):c=e[8],c},$h=()=>{const t=$e.c(130),{t:e}=_e(),n=Zs(),{setSelectedMcp:a,setMcpDraft:i,loadMcpConfigs:o,deleteMcp:r}=Tn(Os(_h)),[c,l]=d.useState(null),[m,u]=d.useState(!1);let f;t[0]!==n?(f=Te=>el(Te,n),t[0]=n,t[1]=f):f=t[1];const p=Tn(f);let g;t[2]!==n?(g=Te=>Te.getStatusForDirectory(n),t[2]=n,t[3]=g):g=t[3];const h=ln(g),j=ln(Bh),x=ln(Vh),[S,b]=d.useState(!1),[w,k]=d.useState("");let I,y;t[4]!==o||t[5]!==n?(I=()=>{o({directory:n})},y=[o,n],t[4]=o,t[5]=n,t[6]=I,t[7]=y):(I=t[6],y=t[7]),d.useEffect(I,y);let E;t[8]!==x||t[9]!==S||t[10]!==j||t[11]!==n?(E=()=>{if(S)return;b(!0);const Te=new Promise(Hh);Promise.all([j({directory:n,silent:!0}),Te]).then(()=>{const de=x(n);de&&q.error(de)}).finally(()=>b(!1))},t[8]=x,t[9]=S,t[10]=j,t[11]=n,t[12]=E):E=t[12];const v=E;let R;t[13]!==p||t[14]!==i||t[15]!==a?(R=()=>{const Te=zh(p),de={name:Te,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...bo,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1};i(de),a(Te)},t[13]=p,t[14]=i,t[15]=a,t[16]=R):R=t[16];const C=R;let T;t[17]!==r||t[18]!==c||t[19]!==n||t[20]!==e?(T=async()=>{if(!c)return;const Te=c;u(!0);const de=await r(Te,n);de.ok?(de.reloadFailed?q.warning(de.message||e("settings.mcp.page.toast.serverDeletedReloadFailed",{name:Te}),{description:de.warning||e("settings.mcp.page.toast.refreshListIfStale")}):q.success(de.message||e("settings.mcp.page.toast.serverDeleted",{name:Te})),l(null)):q.error(e("settings.mcp.page.toast.deleteFailed")),u(!1)},t[17]=r,t[18]=c,t[19]=n,t[20]=e,t[21]=T):T=t[21];const P=T;let L,O,A,N,M,F,H,W,G;if(t[22]!==C||t[23]!==v||t[24]!==S||t[25]!==h||t[26]!==w||t[27]!==p||t[28]!==i||t[29]!==a||t[30]!==e){const Te=Wn([...p],w,qh);let de;t[40]!==w?(de=w.trim(),t[40]=w,t[41]=de):de=t[41];const Me=de.length>0;L=es,t[42]!==e?(O=e("settings.page.mcp.title"),t[42]=e,t[43]=O):O=t[43],t[44]!==e?(A=e("settings.mcp.grid.description"),t[44]=e,t[45]=A):A=t[45];let Se;t[46]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(Ai,{className:"min-w-0 flex-1 @xl:w-56 @xl:flex-none"}),t[46]=Se):Se=t[46];let Le;t[47]!==e?(Le=e("settings.mcp.sidebar.actions.refreshStatusAria"),t[47]=e,t[48]=Le):Le=t[48];let Ke;t[49]!==e?(Ke=e("settings.mcp.sidebar.actions.refreshStatusTitle"),t[49]=e,t[50]=Ke):Ke=t[50];const oe=S&&"animate-spin";let le;t[51]!==oe?(le=je("size-4",oe),t[51]=oe,t[52]=le):le=t[52];let xe;t[53]!==le?(xe=s.jsx(J,{name:"refresh",className:le}),t[53]=le,t[54]=xe):xe=t[54],t[55]!==v||t[56]!==S||t[57]!==Le||t[58]!==Ke||t[59]!==xe?(N=s.jsxs("div",{className:"flex w-full items-center gap-2 @xl:w-auto",children:[Se,s.jsx(B,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",disabled:S,onClick:v,"aria-label":Le,title:Ke,children:xe})]}),t[55]=v,t[56]=S,t[57]=Le,t[58]=Ke,t[59]=xe,t[60]=N):N=t[60],t[61]!==w||t[62]!==p.length||t[63]!==e?(M=p.length>0?s.jsx(vl,{value:w,onChange:k,placeholder:e("settings.mcp.grid.searchPlaceholder")}):null,t[61]=w,t[62]=p.length,t[63]=e,t[64]=M):M=t[64],F=p.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.empty")}):Te.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.noMatches",{query:w.trim()})}):null,H=xl,t[65]!==C||t[66]!==Me||t[67]!==e?(W=Me?null:s.jsx(bl,{label:e("settings.mcp.sidebar.actions.addServerTitle"),hint:e("settings.mcp.grid.addHint"),onClick:C,settingsItem:"mcp.create"}),t[65]=C,t[66]=Me,t[67]=e,t[68]=W):W=t[68];let De;t[69]!==h||t[70]!==i||t[71]!==a||t[72]!==e?(De=Ve=>{const Be=Ve.disabled!==!0,Ne=Ve.type==="local"?Ve.command?.join(" "):Ve.url;return s.jsx(Ci,{icon:s.jsx(Hr,{name:Ve.type==="local"?"server":"global"}),title:Ve.name,subtitle:Ne||void 0,badges:s.jsx(Uh,{status:h[Ve.name]?.status.status,enabled:Be}),muted:!Be,footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ve.type==="local"?e("settings.mcp.sidebar.serverType.localTitle"):e("settings.mcp.sidebar.serverType.remoteTitle")}),Ve.scope==="project"?s.jsx(vo,{children:e("settings.mcp.grid.scope.project")}):null]}),onOpen:()=>{i(null),a(Ve.name)},actionsLabel:e("settings.mcp.grid.actionsAria",{name:Ve.name}),actions:[{label:e("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>l(Ve.name)}]},Ve.name)},t[69]=h,t[70]=i,t[71]=a,t[72]=e,t[73]=De):De=t[73],G=Te.map(De),t[22]=C,t[23]=v,t[24]=S,t[25]=h,t[26]=w,t[27]=p,t[28]=i,t[29]=a,t[30]=e,t[31]=L,t[32]=O,t[33]=A,t[34]=N,t[35]=M,t[36]=F,t[37]=H,t[38]=W,t[39]=G}else L=t[31],O=t[32],A=t[33],N=t[34],M=t[35],F=t[36],H=t[37],W=t[38],G=t[39];let $;t[74]!==H||t[75]!==W||t[76]!==G?($=s.jsxs("div",{className:H,children:[W,G]}),t[74]=H,t[75]=W,t[76]=G,t[77]=$):$=t[77];const z=c!==null;let U;t[78]!==m?(U=Te=>{!Te&&!m&&l(null)},t[78]=m,t[79]=U):U=t[79];const _=c??"";let V;t[80]!==e||t[81]!==_?(V=e("settings.mcp.page.deleteDialog.title",{name:_}),t[80]=e,t[81]=_,t[82]=V):V=t[82];let Z;t[83]!==V?(Z=s.jsx(Vt,{children:V}),t[83]=V,t[84]=Z):Z=t[84];let Y;t[85]!==e?(Y=e("settings.mcp.page.deleteDialog.descriptionPrefix"),t[85]=e,t[86]=Y):Y=t[86];let Q;t[87]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),t[87]=Q):Q=t[87];let ue;t[88]!==e?(ue=e("settings.mcp.page.deleteDialog.descriptionSuffix"),t[88]=e,t[89]=ue):ue=t[89];let ge;t[90]!==Y||t[91]!==ue?(ge=s.jsxs(Ht,{children:[Y," ",Q,"."," ",ue]}),t[90]=Y,t[91]=ue,t[92]=ge):ge=t[92];let fe;t[93]!==Z||t[94]!==ge?(fe=s.jsxs(Bt,{children:[Z,ge]}),t[93]=Z,t[94]=ge,t[95]=fe):fe=t[95];let Ie;t[96]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>l(null),t[96]=Ie):Ie=t[96];let te;t[97]!==e?(te=e("settings.common.actions.cancel"),t[97]=e,t[98]=te):te=t[98];let Ce;t[99]!==m||t[100]!==te?(Ce=s.jsx(B,{variant:"outline",size:"sm",onClick:Ie,disabled:m,children:te}),t[99]=m,t[100]=te,t[101]=Ce):Ce=t[101];let ie;t[102]!==P?(ie=()=>{P()},t[102]=P,t[103]=ie):ie=t[103];let ae;t[104]!==m||t[105]!==e?(ae=e(m?"settings.mcp.page.actions.deleting":"settings.common.actions.delete"),t[104]=m,t[105]=e,t[106]=ae):ae=t[106];let re;t[107]!==m||t[108]!==ie||t[109]!==ae?(re=s.jsx(B,{variant:"destructive",size:"sm",onClick:ie,disabled:m,children:ae}),t[107]=m,t[108]=ie,t[109]=ae,t[110]=re):re=t[110];let ye;t[111]!==Ce||t[112]!==re?(ye=s.jsxs(ns,{children:[Ce,re]}),t[111]=Ce,t[112]=re,t[113]=ye):ye=t[113];let Ee;t[114]!==fe||t[115]!==ye?(Ee=s.jsxs(Ut,{className:"max-w-md",children:[fe,ye]}),t[114]=fe,t[115]=ye,t[116]=Ee):Ee=t[116];let Pe;t[117]!==z||t[118]!==U||t[119]!==Ee?(Pe=s.jsx(zt,{open:z,onOpenChange:U,children:Ee}),t[117]=z,t[118]=U,t[119]=Ee,t[120]=Pe):Pe=t[120];let ke;return t[121]!==L||t[122]!==O||t[123]!==A||t[124]!==N||t[125]!==M||t[126]!==F||t[127]!==$||t[128]!==Pe?(ke=s.jsxs(L,{title:O,description:A,headerEnd:N,children:[M,F,$,Pe]}),t[121]=L,t[122]=O,t[123]=A,t[124]=N,t[125]=M,t[126]=F,t[127]=$,t[128]=Pe,t[129]=ke):ke=t[129],ke};function _h(t){return{setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Bh(t){return t.refresh}function Vh(t){return t.getErrorForDirectory}function Hh(t){return setTimeout(t,500)}function qh(t){return[t.name,t.type==="local"?t.command?.join(" ")??"":t.url??""]}const mr=t=>t===void 0?"":String(t),pr=t=>{const e=t.trim();if(!e)return null;const n=Number(e);return!Number.isFinite(n)||n<=0?null:n%1e3===0?`${n/1e3}s`:`${n}ms`},gr={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},pc={default:"settings.mcp.page.advanced.codemodeOption.default",on:"settings.mcp.page.advanced.codemodeOption.on",off:"settings.mcp.page.advanced.codemodeOption.off"},Wh=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},di=t=>t?.status.status,fr=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function ru(t){const e=[];let n="",a=!1,i=!1;for(let o=0;o<t.length;o++){const r=t[o];if(r==="'"&&!i){a=!a;continue}if(r==='"'&&!a){i=!i;continue}if((r===" "||r===" ")&&!a&&!i){n&&(e.push(n),n="");continue}n+=r}return n&&e.push(n),e}const Gh=t=>{const e=$e.c(27),{value:n,onChange:a,preview:i,onDetectUrl:o}=t;let r;e[0]!==n?(r=()=>n.join(`
5
- `),e[0]=n,e[1]=r):r=e[1];const[c,l]=d.useState(r),m=d.useRef(n);let u,f;e[2]!==n?(u=()=>{JSON.stringify(m.current)!==JSON.stringify(n)&&(m.current=n,l(n.join(`
6
- `)))},f=[n],e[2]=n,e[3]=u,e[4]=f):(u=e[3],f=e[4]),d.useEffect(u,f);let p;e[5]!==a||e[6]!==o?(p=y=>{const E=y.split(`
7
- `).filter(tx);if(o&&E.length===1&&/^https?:\/\/\S+$/i.test(E[0].trim())){o(E[0].trim());return}a(E)},e[5]=a,e[6]=o,e[7]=p):p=e[7];const g=p;let h;e[8]!==a?(h=y=>{const v=y.clipboardData.getData("text").trim();if(!v||v.includes(`
8
- `)||!/\s/.test(v))return;const R=y.currentTarget;if(R.selectionStart!==0||R.selectionEnd!==R.value.length)return;y.preventDefault();const C=ru(v);l(C.join(`
9
- `)),a(C)},e[8]=a,e[9]=h):h=e[9];const j=h;let x;e[10]!==g?(x=y=>{l(y.target.value),g(y.target.value)},e[10]=g,e[11]=x):x=e[11];let S;e[12]!==g||e[13]!==c?(S=()=>{const y=c.split(`
10
- `).map(sx).join(`
11
- `);l(y),g(y)},e[12]=g,e[13]=c,e[14]=S):S=e[14];const b=Math.max(4,n.length+1);let w;e[15]!==j||e[16]!==x||e[17]!==S||e[18]!==b||e[19]!==c?(w=s.jsx(Ts,{onPaste:j,value:c,onChange:x,onBlur:S,placeholder:`npx
12
- -y
13
- @modelcontextprotocol/server-postgres
14
- postgresql://user:pass@host/db`,rows:b,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=j,e[16]=x,e[17]=S,e[18]=b,e[19]=c,e[20]=w):w=e[20];let k;e[21]!==i||e[22]!==n?(k=n.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(n.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:n.map(nx)})})]}),e[21]=i,e[22]=n,e[23]=k):k=e[23];let I;return e[24]!==k||e[25]!==w?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[w,k]}),e[24]=k,e[25]=w,e[26]=I):I=e[26],I},Jh=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),gc=({value:t,onChange:e,onCommit:n,keyTransform:a=Jh,keyPlaceholder:i="API_KEY",keyInputClassName:o="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:c="Paste KEY=VALUE lines from clipboard",noPairsFoundError:l,importSuccess:m,clipboardReadFailed:u,keyLabel:f,valueLabel:p,valuePlaceholder:g,hideValueTitle:h,showValueTitle:j,addVariable:x,plainTextWarning:S,removeVariableAria:b})=>{const[w,k]=d.useState(new Set),I=()=>e([...t,{key:"",value:""}]),y=T=>{e(t.filter((P,L)=>L!==T)),n?.(),k(P=>{const L=new Set(P);return L.delete(T),L})},E=(T,P,L)=>{const O=[...t];O[T]={...O[T],[P]:L},e(O)},v=T=>{k(P=>{const L=new Set(P);return L.has(T)?L.delete(T):L.add(T),L})},R=async()=>{try{const T=await navigator.clipboard.readText(),P=[];for(const O of T.split(`
15
- `)){const A=O.trim();if(!A||A.startsWith("#"))continue;const N=A.indexOf("=");if(N===-1)continue;const M=A.slice(0,N).trim();let F=A.slice(N+1).trim();(F.startsWith('"')&&F.endsWith('"')||F.startsWith("'")&&F.endsWith("'"))&&(F=F.slice(1,-1)),M&&P.push({key:M,value:F})}if(P.length===0){q.error(l);return}const L=[...t];for(const O of P){const A=L.findIndex(N=>N.key===O.key);A!==-1?L[A]=O:L.push(O)}e(L),n?.(),q.success(m(P.length))}catch{q.error(u)}},C=t.some(T=>T.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:f}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:R,type:"button",title:c,children:[s.jsx(J,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:T.key,onChange:L=>E(P,"key",a(L.target.value)),placeholder:i,className:o,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:w.has(P)?"text":"password",value:T.value,onChange:L=>E(P,"value",L.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:()=>v(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(P)?h:j,children:w.has(P)?s.jsx(J,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(P),"aria-label":b,children:s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},P))}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:I,type:"button",children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),x]}),C&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:S})]})},fc=t=>{const e=$e.c(14),{status:n,enabled:a,getStatusLabel:i,variant:o}=t,r=o===void 0?"compact":o;if(!a||!n)return null;let c,l;if(e[0]!==i||e[1]!==n||e[2]!==r){l=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"}}[n]??{text:"text-muted-foreground",bg:""};if(r==="pill"){const g=je("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let h;e[5]!==i||e[6]!==n?(h=i(n),e[5]=i,e[6]=n,e[7]=h):h=e[7],l=s.jsxs("span",{className:g,children:["● ",h]});break e}c=je("typography-micro font-medium",p.text)}e[0]=i,e[1]=n,e[2]=r,e[3]=c,e[4]=l}else c=e[3],l=e[4];if(l!==Symbol.for("react.early_return_sentinel"))return l;let m;e[8]!==i||e[9]!==n?(m=i(n),e[8]=i,e[9]=n,e[10]=m):m=e[10];let u;return e[11]!==c||e[12]!==m?(u=s.jsxs("span",{className:c,children:["● ",m]}),e[11]=c,e[12]=m,e[13]=u):u=e[13],u},Qh=(t,e,n)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return n?.trim()||e("settings.mcp.page.status.description.needsAuth");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Yh=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Zh=t=>t==="failed"||t==="needs_auth",Xh=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},ex=()=>{const{t}=_e(),e=d.useCallback((se,Ae)=>t(se,Ae),[t]),{selectedMcpName:n,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:r,createMcp:c,updateMcp:l,deleteMcp:m}=Tn(Os(se=>({selectedMcpName:se.selectedMcpName,mcpDraft:se.mcpDraft,setMcpDraft:se.setMcpDraft,setSelectedMcp:se.setSelectedMcp,getMcpByName:se.getMcpByName,createMcp:se.createMcp,updateMcp:se.updateMcp,deleteMcp:se.deleteMcp}))),u=Zs();d.useEffect(()=>()=>{const se=Tn.getState();se.setSelectedMcp(null),se.setMcpDraft(null)},[]);const f=ln(se=>se.getStatusForDirectory(u)),p=ln(se=>se.getDiagnosticForDirectory(u)),g=ln(se=>se.refresh),h=ln(se=>se.connect),j=ln(se=>se.disconnect),x=ln(se=>se.testConnection),S=Tn(se=>el(se,u)),b=n?r(n,u):null,w=!!(a&&a.name===n&&!b),[k,I]=d.useState(""),[y,E]=d.useState("user"),[v,R]=d.useState("local"),[C,T]=d.useState([]),[P,L]=d.useState(""),[O,A]=d.useState([]),[N,M]=d.useState([]),[F,H]=d.useState(""),[W,G]=d.useState(""),[$,z]=d.useState(""),[U,_]=d.useState("default"),[V,Z]=d.useState("legacy"),[Y,Q]=d.useState(""),[ue,ge]=d.useState(bo),[fe,Ie]=d.useState(!0),[te,Ce]=d.useState(!1),[ie,ae]=d.useState(!1),[re,ye]=d.useState(!1),[Ee,Pe]=d.useState(!1),[ke,Te]=d.useState(!1),[de,Me]=d.useState(!1),[Se,Le]=d.useState(!1),[Ke,oe]=d.useState(""),[le,xe]=d.useState(null),De=d.useMemo(()=>Xh(n,u),[u,n]),Ve=d.useRef(De),Be=d.useRef(null),Ne=JSON.stringify([n,u,w]),Je=d.useRef(Ne);Je.current=Ne;const ut=d.useRef(null),ht={mcpType:v,command:C,url:P,envEntries:O,headerEntries:N,timeoutStartup:F,timeoutCatalog:W,timeoutExecution:$,codemode:U,protocol:V,oauthAuthServerMetadataUrl:v==="remote"?Y:"",enabled:fe},st=d.useRef(ht);st.current=ht;const jt=d.useCallback(()=>{oe(""),xe(null),Le(!0)},[]),St=d.useCallback(async()=>{try{const se=await navigator.clipboard.readText();oe(se),xe(null)}catch{q.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ze=d.useCallback(()=>{const se=yh(Ke,{fallbackName:k});if(!se.ok){xe(se.error);return}const tt=jh(se,{name:k,scope:y,type:v,command:C,url:P,environment:O,headers:N,timeoutStartup:F,timeoutCatalog:W,timeoutExecution:$,codemode:U,disabled:!fe,protocol:V,oauthAuthServerMetadataUrl:Y},{isNewServer:w});I(tt.name),R(tt.type),T(tt.command??[]),L(tt.url??""),A(tt.environment??[]),M(tt.headers??[]),H(tt.timeoutStartup??""),G(tt.timeoutCatalog??""),z(tt.timeoutExecution??""),_(tt.codemode??"default"),Ie(tt.disabled!==!0),Z(tt.protocol??"legacy"),Q(tt.oauthAuthServerMetadataUrl??""),Le(!1),oe(""),xe(null),q.success(t("settings.mcp.page.toast.configImported"))},[Ke,k,y,v,C,P,O,N,V,Y,F,W,$,U,fe,w,t]);d.useEffect(()=>{if(w&&a){ut.current=null,I(a.name),E(a.scope||"user"),R(a.type),T(a.command),L(a.url),A(a.environment),M(a.headers),H(a.timeoutStartup),G(a.timeoutCatalog),z(a.timeoutExecution),_(a.codemode),Z(a.protocol),Q(a.oauthAuthServerMetadataUrl),ge({oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,oauthCallbackPort:a.oauthCallbackPort}),Ie(!a.disabled),Me(!1),Be.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,timeoutStartup:a.timeoutStartup,timeoutCatalog:a.timeoutCatalog,timeoutExecution:a.timeoutExecution,codemode:a.codemode,protocol:a.protocol,oauthAuthServerMetadataUrl:a.oauthAuthServerMetadataUrl,enabled:!a.disabled};return}if(b){E(b.scope==="project"?"project":"user");const se=El(b.environment),Ae=b.type==="remote"?b:null,tt=El(Ae?.headers),ot=b.type,At=ot==="local"?b.command??[]:[],pe=Ae?.url??"",we=mr(b.timeout?.startup),ze=mr(b.timeout?.catalog),pt=mr(b.timeout?.execution),Ct=ym(b.codemode),Gt=b.protocol??"legacy",Zt=Lh(Ae?.oauth),as=Ae&&Ae.oauth?Ae.oauth.auth_server_metadata_url??"":"",Jt=b.disabled!==!0;ge(Zt);const Es=Be.current!==null&&JSON.stringify(Be.current)!==JSON.stringify(st.current);if(ut.current===Ne&&Es)return;ut.current=Ne,R(ot),T(At),L(pe),A(se),M(tt),H(we),G(ze),z(pt),_(Ct),Z(Gt),Q(as),Ie(Jt),Me(!1),Be.current={mcpType:ot,command:At,url:pe,envEntries:se,headerEntries:tt,timeoutStartup:we,timeoutCatalog:ze,timeoutExecution:pt,codemode:Ct,protocol:Gt,oauthAuthServerMetadataUrl:as,enabled:Jt}}},[b,n,u,w,a,Ne]);const it=d.useMemo(()=>{const se=Y.trim();return!se||Wh(se)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[Y,t]),et=d.useMemo(()=>{const se=[];v==="remote"&&N.length>0&&se.push(`${N.length} ${t("settings.mcp.page.advanced.headers")}`);const Ae=v==="local"?pr(F):null;Ae&&se.push(t("settings.mcp.page.advanced.summary.startup",{value:Ae}));const tt=pr(W);tt&&se.push(t("settings.mcp.page.advanced.summary.catalog",{value:tt}));const ot=pr($);return ot&&se.push(t("settings.mcp.page.advanced.summary.execution",{value:ot})),U==="on"&&se.push(t("settings.mcp.page.advanced.summary.codemodeOn")),U==="off"&&se.push(t("settings.mcp.page.advanced.summary.codemodeOff")),V!=="legacy"&&se.push(t(gr[V])),se.join(" · ")},[U,N.length,v,V,t,W,$,F]),mt=d.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(J,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(J,{name:"global",className:"h-3.5 w-3.5"})}],[t]),ft=d.useCallback(se=>{R("remote"),L(se),T([])},[]),be=d.useCallback(se=>{L(se);const Ae=se.trim();Ae&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(Ae)&&/\s/.test(Ae)&&(R("local"),T(ru(Ae)),L(""))},[]),Re=se=>({name:se,scope:y,type:v,command:C,url:P,environment:O,headers:N,...ue,oauthAuthServerMetadataUrl:v==="remote"?Y:"",protocol:V,timeoutStartup:F,timeoutCatalog:W,timeoutExecution:$,codemode:U,disabled:!fe}),ce=ei(async()=>{const se=Be.current;if(w||!se||!n||JSON.stringify(se)===JSON.stringify({mcpType:v,command:C,url:P,envEntries:O,headerEntries:N,timeoutStartup:F,timeoutCatalog:W,timeoutExecution:$,codemode:U,protocol:V,oauthAuthServerMetadataUrl:v==="remote"?Y:"",enabled:fe}))return Ls;if(v==="local"&&C.filter(Boolean).length===0)return fs(t("settings.mcp.page.toast.localCommandRequired"));if(v==="remote"&&!P.trim())return fs(t("settings.mcp.page.toast.remoteUrlRequired"));if(v==="remote"&&it)return fs(it);const Ae=await l(n,Re(n),u);return Ae.ok?Je.current!==Ne?vn:(Be.current={mcpType:v,command:C,url:P,envEntries:O,headerEntries:N,timeoutStartup:F,timeoutCatalog:W,timeoutExecution:$,codemode:U,protocol:V,oauthAuthServerMetadataUrl:v==="remote"?Y:"",enabled:fe},await g({directory:u,silent:!0}),Ae.reloadFailed?fs(Ae.warning||Ae.message||t("settings.mcp.page.toast.savedReloadFailed")):vn):fs(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:Oe}=ce,We=async()=>{const se=k.trim();if(!se){q.error(t("settings.mcp.page.toast.nameRequired"));return}if(S.some(Ae=>Ae.name===se)){q.error(t("settings.mcp.page.toast.serverNameExists"));return}if(v==="local"&&C.filter(Boolean).length===0){q.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(v==="remote"&&!P.trim()){q.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(v==="remote"&&it){q.error(it);return}Ce(!0);try{const Ae=await c(Re(se),u);Ae.ok?(i(null),o(se),await g({directory:u,silent:!0}),Ae.reloadFailed?q.warning(Ae.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:Ae.warning||t("settings.mcp.page.toast.retryRefreshHint")}):q.success(Ae.message||t("settings.mcp.page.toast.serverCreatedReloading"))):q.error(t("settings.mcp.page.toast.saveFailed"))}catch(Ae){q.error(Ae instanceof Error?Ae.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ce(!1)}},nt=()=>{i(null),o(null)},at=async()=>{if(!n)return;ye(!0);const se=await m(n,u);se.ok?(se.reloadFailed?q.warning(se.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:se.warning||t("settings.mcp.page.toast.refreshListIfStale")}):q.success(se.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ae(!1)):q.error(t("settings.mcp.page.toast.deleteFailed")),ye(!1)},vt=async()=>{if(n)try{await h(n,u),q.success(t("settings.mcp.page.toast.connected"))}catch(se){q.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionTestFailed"))}},kt=async()=>{if(n){Pe(!0);try{if(di(f[n])==="connected")await j(n,u),q.success(t("settings.mcp.page.toast.disconnected"));else{await h(n,u),await g({directory:u,silent:!0});const Ae=ln.getState().getStatusForDirectory(u)[n],tt=di(Ae);tt==="connected"?q.success(t("settings.mcp.page.toast.connected")):tt==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):tt==="failed"?q.error(fr(Ae)||t("settings.mcp.page.toast.connectionFailed")):q.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await g({directory:u,silent:!0})}catch(se){q.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Pe(!1)}}},xt=d.useCallback(()=>w?(q.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[w,t]),It=d.useCallback(async(se=!1)=>{try{await g({directory:u,silent:se})}catch(Ae){se||q.error(Ae instanceof Error?Ae.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,g,t]);d.useEffect(()=>{It(!0)},[It]),d.useEffect(()=>{Ve.current=De,Pe(!1),Te(!1)},[De]);const _t=d.useCallback(async()=>{if(!(!n||!xt())){if(!fe){q.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Te(!0);try{const se=await x(n,u),Ae=di(se.status);se.warning?q.warning(se.warning):Ae==="connected"?q.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Ae==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Ae==="failed"?q.error(fr(se.status)||se.error||t("settings.mcp.page.toast.connectionTestFailed")):se.error?q.error(se.error):q.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(se){q.error(se instanceof Error?se.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Te(!1)}}},[u,fe,xt,n,t,x]);if(!n)return s.jsx($h,{});const Ye=f[n],Xe=n?p[n]:void 0,gt=Ye?di(Ye):Xe?.status,Ue=Ye?fr(Ye):Xe?.error,ee=di(Ye)==="connected",ve=Qh(gt,e,Ue),Fe=se=>{switch(se){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");default:return se}};return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:w?t("settings.mcp.page.header.newServer"):n,titleLeading:s.jsx(yl,{label:t("settings.mcp.page.back"),onClick:()=>{i(null),o(null)}}),titleAccessory:w?void 0:s.jsx(fc,{status:gt,enabled:fe,getStatusLabel:Fe,variant:"pill"}),description:w?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(v==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:w?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:ee?"outline":"default",size:"xs",className:"!font-normal",onClick:kt,disabled:Ee||!fe,children:t(Ee?"settings.mcp.page.actions.working":ee?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),ee&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{_t()},disabled:ke||!fe,children:t(ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:ce.onBlurCapture,children:[!w&&b&&s.jsx(fl,{legacy:b.legacy===!0,path:b.path}),!w&&Zh(gt)&&s.jsx(qe,{divider:!1,children:s.jsx("div",{className:je("rounded-lg border p-3",Yh(gt)),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:Pt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(fc,{status:gt,enabled:fe,getStatusLabel:Fe})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ve}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:y==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),gt==="needs_auth"&&n&&s.jsx(Rh,{serverName:n,directory:u,onConnected:vt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!ee&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_t()},disabled:ke||!fe,children:t(ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(qe,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:w?s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:jt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(J,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[w&&s.jsxs(yt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:k,onChange:se=>I(se.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Dt,{value:y,onValueChange:se=>E(se),children:[s.jsxs(Tt,{size:qt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(J,{name:y==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(y==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Et,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(ct,{checked:fe,onChange:se=>{Ie(se),Oe()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(qe,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(nl,{items:mt,activeId:v,onSelect:se=>{R(se),Oe()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),v==="local"?s.jsx(Gh,{value:C,onChange:T,preview:se=>t("settings.mcp.page.connection.previewArgs",{count:se}),onDetectUrl:ft}):s.jsx(He,{value:P,onChange:se=>be(se.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(v==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),s.jsx(qe,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Js,{open:de,onOpenChange:Me,children:[s.jsxs(Qs,{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")}),et&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",et,")"]})]}),de?s.jsx(J,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(J,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ys,{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:Pt,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(Wt,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Dt,{value:V,onValueChange:se=>{const Ae=Rr.find(tt=>tt===se);Ae&&(Z(Ae),Oe())},children:[s.jsx(Tt,{size:qt,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(gr[V])})}),s.jsx(Et,{children:Rr.map(se=>s.jsx(dt,{value:se,children:t(gr[se])},se))})]})]}),s.jsxs("div",{className:"space-y-2",children:[v==="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:Pt,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(Wt,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(He,{type:"number",min:"1",step:"1",value:F,onChange:se=>H(se.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(Wt,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(He,{type:"number",min:"1",step:"1",value:W,onChange:se=>G(se.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(Wt,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(He,{type:"number",min:"1",step:"1",value:$,onChange:se=>z(se.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.codemode")}),s.jsxs(Wt,{children:[t("settings.mcp.page.advanced.codemodeHint")," ",t("settings.mcp.page.advanced.codemodeDefaultHint")]})]}),s.jsxs(Dt,{value:U,onValueChange:se=>{const Ae=Dl.find(tt=>tt===se);Ae&&(_(Ae),Oe())},children:[s.jsx(Tt,{size:qt,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(pc[U])})}),s.jsx(Et,{children:Dl.map(se=>s.jsx(dt,{value:se,children:t(pc[se])},se))})]})]}),v==="remote"&&s.jsxs("div",{children:[s.jsxs(Ln,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),N.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",N.length,")"]})]}),s.jsx(gc,{value:N,onChange:M,onCommit:Oe,keyTransform:se=>se.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:se=>t("settings.mcp.page.toast.importedVariablesCount",{count:se}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),v==="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:Pt,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(Wt,{children:t("settings.mcp.page.advanced.oauthMetadataUrlHint")})]}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx(He,{type:"url",value:Y,onChange:se=>Q(se.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":it?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),it&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:it})]})]})]})]})})]})}),s.jsx(qe,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:O.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",O.length,")"]}):null,settingsItem:"mcp.environment",children:O.length===0?s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>A([{key:"",value:""}]),children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(gc,{value:O,onChange:A,onCommit:Oe,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:se=>t("settings.mcp.page.toast.importedVariablesCount",{count:se}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[w&&s.jsxs(s.Fragment,{children:[s.jsx(B,{onClick:()=>{We()},disabled:te||!k.trim(),size:"xs",className:"!font-normal",children:t(te?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(B,{variant:"ghost",onClick:nt,disabled:te,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!w&&s.jsx(B,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ae(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(zt,{open:Se,onOpenChange:se=>{se||(Le(!1),oe(""),xe(null))},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ht,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ts,{value:Ke,onChange:se=>{oe(se.target.value),xe(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"}),le&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:le}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:St,type:"button",children:[s.jsx(J,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ns,{children:[s.jsx(B,{variant:"outline",onClick:()=>{Le(!1),oe(""),xe(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:Ze,disabled:!Ke.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(zt,{open:ie,onOpenChange:se=>{!se&&!re&&ae(!1)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Ht,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ns,{children:[s.jsx(B,{variant:"outline",onClick:()=>ae(!1),disabled:re,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:at,disabled:re,children:t(re?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function tx(t){return t.trim().length>0}function sx(t){return t.trimEnd()}function nx(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 ax=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function ix(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}const ox=({open:t,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=_e(),i=Ft(A=>A.createEntry),o=Ft(A=>A.createFile),[r,c]=d.useState("npm"),[l,m]=d.useState(""),[u,f]=d.useState(""),[p,g]=d.useState(""),[h,j]=d.useState(""),[x,S]=d.useState(n),[b,w]=d.useState(!1),k=d.useCallback(()=>{m(""),f(""),g(""),j(""),S(n)},[n]);d.useEffect(()=>{t&&(c("npm"),k())},[t,k]);const I=A=>{A!==r&&(c(A),k())},y=d.useMemo(()=>ix(u),[u]),E=!y.ok,v=r==="file"&&p.trim()!==""&&!ax.test(p.trim()),R=(r==="npm"||r==="path")&&l.trim()==="",C=r==="file"&&h.trim()==="",T=r==="file"&&p.trim()==="",P=b||E||r==="npm"&&R||r==="path"&&R||r==="file"&&(T||v||C),L=async()=>{if(!P){w(!0);try{let A;r==="file"?A=await o({fileName:p.trim(),content:h,scope:x}):A=await i({spec:l.trim(),options:y.ok?y.value:void 0,scope:x}),A.ok?(q.success(A.message||a("settings.plugins.toast.created")),A.reloadFailed&&q.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):q.error(A.message||a("settings.plugins.sidebar.toast.deleteFailed"))}finally{w(!1)}}},O=d.useMemo(()=>[{id:"npm",label:a("settings.plugins.dialog.add.tab.npm")},{id:"path",label:a("settings.plugins.dialog.add.tab.path")},{id:"file",label:a("settings.plugins.dialog.add.tab.file")}],[a]);return s.jsx(zt,{open:t,onOpenChange:A=>{!A&&b||e(A)},children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:a("settings.plugins.dialog.add.title")}),s.jsx(Ht,{children:a("settings.plugins.sidebar.empty.description")})]}),s.jsx(nl,{items:O,activeId:r,onSelect:A=>I(A),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:a("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:l,onChange:A=>m(A.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":R?!1:void 0,disabled:b}),R&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("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:a("settings.plugins.page.field.options")}),s.jsx(Ts,{id:"plugin-options",value:u,onChange:A=>f(A.target.value),rows:5,className:"font-mono",hasError:E,disabled:b}),E&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("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:a("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:p,onChange:A=>g(A.target.value),placeholder:"my-plugin.ts","aria-invalid":v||void 0,disabled:b}),v&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("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:a("settings.plugins.page.field.content")}),s.jsx(Ts,{id:"plugin-content",value:h,onChange:A=>j(A.target.value),rows:16,className:"font-mono",disabled:b})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(A=>{const N=x===A,M=a(A==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>S(A),disabled:b,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(al,{checked:N,onChange:()=>S(A),ariaLabel:M}),s.jsx("span",{className:je("typography-ui-label font-normal",N?"text-foreground":"text-foreground/60"),children:M})]},A)})})]})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:b,children:a("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{L()},disabled:P,children:[b?s.jsx(J,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},rx=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),Ha=t=>{const e=t.replace(/\\/g,"/"),n=[],[a,...i]=e.split("/");for(const r of i)if(!(r===""||r===".")){if(r===".."){n.pop();continue}n.push(r)}return`${/^[A-Za-z]:$/.test(a)?`${a.toUpperCase()}/`:"/"}${n.join("/")}`},lx=t=>Ha(`${t.replace(/\\/g,"/")}/..`),cx=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function lu(t,e){if(t.startsWith("file://")){const n=cx(t);return n?{kind:"local",path:Ha(n)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:Ha(`${lx(e)}/${t}`)}:null:rx(t)?{kind:"local",path:Ha(t)}:{kind:"package",target:t}}function cu(t){return t?{kind:"local",path:Ha(t)}:null}const dx=(t,e)=>{if(t.kind==="package")return e.source.kind==="package"&&e.source.target===t.target;if(e.source.kind!=="local")return!1;const n=Ha(e.source.path);return n===t.path||n.startsWith(`${t.path}/`)};function du(t,e){return e.filter(n=>dx(t,n))}function ux(t){const e=t.find(a=>a.state.kind==="failed");if(e&&e.state.kind==="failed")return{kind:"failed",error:e.state.error,ref:e.state.ref};const n=t[0];return n?{kind:"active",version:n.source.kind==="package"?n.source.version:null}:{kind:"notReported"}}function uu(t){const e=t.flatMap(n=>n.source.kind==="package"?[n.source]:[]);return e.some(n=>n.updating)?"updating":e.some(n=>n.outdated)?"available":"none"}function mu(t){const e=$e.c(12),n=Ft(mx),a=il(ua());let i;e:{if(n.kind==="idle"||n.scope!==a){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={kind:"loading"},e[0]=m):m=e[0],i=m;break e}if(n.kind==="failed"||!t){let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m={kind:"unknown"},e[1]=m):m=e[1],i=m;break e}let o,r,c;if(e[2]!==n.plugins||e[3]!==t){const m=du(t,n.plugins);o="known",r=ux(m),c=uu(m),e[2]=n.plugins,e[3]=t,e[4]=o,e[5]=r,e[6]=c}else o=e[4],r=e[5],c=e[6];let l;e[7]!==o||e[8]!==r||e[9]!==c||e[10]!==t?(l={kind:o,load:r,update:c,target:t},e[7]=o,e[8]=r,e[9]=c,e[10]=t,e[11]=l):l=e[11],i=l}return i}function mx(t){return t.runtime}function pu(t){const e=$e.c(4);let n;if(e[0]!==t){const o=il(ua());n=t?.kind==="package"?Id(o,t.target):null,e[0]=t,e[1]=n}else n=e[1];const a=n;let i;return e[2]!==a?(i=o=>a?o.packageUpdates[a]??null:null,e[2]=a,e[3]=i):i=e[3],Ft(i)}const hc=t=>{const e=$e.c(18),{target:n,spec:a}=t,{t:i}=_e(),o=mu(n),r=pu(n);let c;e[0]!==a?(c=x=>a?x.registryInfo[a]:void 0,e[0]=a,e[1]=c):c=e[1];const l=Ft(c),m=l?.kind==="npm-missing-package"||l?.kind==="npm-missing-version"||l?.kind==="npm-malformed"||l?.kind==="path-missing"||l?.kind==="path-unreadable",u=o.kind==="known"&&(o.update==="updating"||r?.kind==="running"),f=!u&&(l?.kind==="npm-ok"&&l.hasUpdate||o.kind==="known"&&o.update==="available");let p;e[2]!==m||e[3]!==i?(p=m?s.jsx(hn,{tone:"error",children:i("settings.plugins.registry.banner.invalid.title")}):null,e[2]=m,e[3]=i,e[4]=p):p=e[4];let g;e[5]!==m||e[6]!==o.kind||e[7]!==o.load||e[8]!==i||e[9]!==u?(g=o.kind==="known"&&!m?u?s.jsx(hn,{tone:"neutral",children:i("settings.plugins.update.running")}):o.load.kind==="failed"?s.jsx(hn,{tone:"error",children:i("settings.plugins.status.failed.title")}):o.load.kind==="notReported"?s.jsx(hn,{tone:"neutral",children:i("settings.plugins.status.notReported.title")}):s.jsx(hn,{tone:"success",children:i("settings.plugins.status.loaded")}):null,e[5]=m,e[6]=o.kind,e[7]=o.load,e[8]=i,e[9]=u,e[10]=g):g=e[10];let h;e[11]!==i||e[12]!==f?(h=f?s.jsx(hn,{tone:"info",children:i("settings.plugins.update.available.title")}):null,e[11]=i,e[12]=f,e[13]=h):h=e[13];let j;return e[14]!==p||e[15]!==g||e[16]!==h?(j=s.jsxs(s.Fragment,{children:[p,g,h]}),e[14]=p,e[15]=g,e[16]=h,e[17]=j):j=e[17],j},px=t=>{const e=$e.c(54),{onAdd:n,onDelete:a}=t,{t:i}=_e(),{entries:o,files:r,setSelected:c,loadPlugins:l}=Ft(Os(gx)),m=Ft(fx),u=Ft(hx),f=Ft(xx),p=Ft(bx),g=Ft(vx),h=Ft(yx),j=Ft(jx),x=Ft(kx),S=Ft(wx),b=il(ua()),w=g.kind==="failed"&&g.scope===b,k=g.kind==="ready"&&g.scope===b?g.plugins:null,[I,y]=d.useState("");let E,v;e[0]!==l?(E=()=>{l()},v=[l],e[0]=l,e[1]=E,e[2]=v):(E=e[1],v=e[2]),d.useEffect(E,v);let R;e[3]!==p||e[4]!==u||e[5]!==i?(R=async()=>{q.info(i("settings.plugins.toast.refreshing"));const[ye,Ee]=await Promise.all([u({force:!0}),p()]);ye||q.error(i("settings.plugins.toast.refreshFailed")),Ee||q.error(i("settings.plugins.toast.checkFailed"))},e[3]=p,e[4]=u,e[5]=i,e[6]=R):R=e[6];const C=R;let T;if(e[7]!==o||e[8]!==r){T=new Map;for(const ye of o)T.set(ye.id,lu(ye.spec,ye.sourcePath));for(const ye of r)T.set(ye.id,cu(ye.absolutePath));e[7]=o,e[8]=r,e[9]=T}else T=e[9];const P=T,L=ye=>{const Ee=P.get(ye);return!k||Ee?.kind!=="package"||j[Id(b,Ee.target)]?.kind==="running"?null:uu(du(Ee,k))==="available"?Ee.target:null},O=ye=>{const Ee=[],Pe=h[ye.spec],ke=L(ye.id);if(Pe?.kind==="npm-ok"&&Pe.hasUpdate&&Pe.latestVersion){const Te=Pe.latestVersion;Ee.push({label:i("settings.plugins.registry.banner.updateAvailable.action",{latest:Te}),icon:"arrow-up-s",onSelect:()=>{x(ye.id).then(de=>{de.ok?q.success(i("settings.plugins.toast.updatedToLatest",{version:Te})):q.error(i("settings.plugins.toast.refreshFailed"))})}})}else ke&&Ee.push({label:i("settings.plugins.update.action"),icon:"arrow-up-s",onSelect:()=>{S(ke).then(Te=>{Te?q.success(i("settings.plugins.update.toast.done",{name:ye.spec})):q.error(i("settings.plugins.update.toast.failed",{name:ye.spec}))})}});return Ee.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>a({kind:"entry",id:ye.id,label:ye.spec})}),Ee},A=[...o.map(Sx),...r.map(Nx)],N=Wn(A,I,Cx);let M;e[10]!==I?(M=I.trim(),e[10]=I,e[11]=M):M=e[11];const F=M.length>0,H=m||f,W=es;let G;e[12]!==i?(G=i("settings.page.plugins.title"),e[12]=i,e[13]=G):G=e[13];let $;e[14]!==i?($=i("settings.plugins.grid.description"),e[14]=i,e[15]=$):$=e[15];let z;e[16]!==w||e[17]!==i?(z=w?s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsx(J,{name:"question",className:"size-3.5"}),i("settings.plugins.status.sidebar.unavailable")]}):null,e[16]=w,e[17]=i,e[18]=z):z=e[18];let U;e[19]!==C?(U=()=>{C()},e[19]=C,e[20]=U):U=e[20];let _;e[21]!==i?(_=i("settings.plugins.sidebar.actions.refresh"),e[21]=i,e[22]=_):_=e[22];let V;e[23]!==i?(V=i("settings.plugins.sidebar.actions.refresh"),e[23]=i,e[24]=V):V=e[24];const Z=H&&"animate-spin";let Y;e[25]!==Z?(Y=je("size-4",Z),e[25]=Z,e[26]=Y):Y=e[26];let Q;e[27]!==Y?(Q=s.jsx(J,{name:"refresh",className:Y}),e[27]=Y,e[28]=Q):Q=e[28];let ue;e[29]!==H||e[30]!==V||e[31]!==Q||e[32]!==U||e[33]!==_?(ue=s.jsx(B,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",onClick:U,disabled:H,"aria-label":_,title:V,children:Q}),e[29]=H,e[30]=V,e[31]=Q,e[32]=U,e[33]=_,e[34]=ue):ue=e[34];let ge;e[35]!==ue||e[36]!==z?(ge=s.jsxs("div",{className:"flex items-center gap-2",children:[z,ue]}),e[35]=ue,e[36]=z,e[37]=ge):ge=e[37];const fe=A.length>0?s.jsx(vl,{value:I,onChange:y,placeholder:i("settings.plugins.grid.searchPlaceholder")}):null,Ie=A.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:i("settings.plugins.grid.empty")}):N.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:i("settings.plugins.grid.noMatches",{query:I.trim()})}):null,te=xl;let Ce;e[38]!==F||e[39]!==n||e[40]!==i?(Ce=F?null:s.jsx(bl,{label:i("settings.plugins.sidebar.actions.addTitle"),hint:i("settings.plugins.grid.addHint"),onClick:n,settingsItem:"plugins.create"}),e[38]=F,e[39]=n,e[40]=i,e[41]=Ce):Ce=e[41];const ie=N.map(ye=>{if(ye.kind==="entry"){const{entry:ke}=ye;return s.jsx(Ci,{icon:s.jsx(Hr,{name:ke.parsedKind==="npm"?"code-box":"folder"}),title:ke.spec,badges:s.jsx(hc,{target:P.get(ke.id)??null,spec:ke.spec}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:ke.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path")}),ke.scope==="project"?s.jsx(vo,{children:i("settings.plugins.grid.scope.project")}):null]}),onOpen:()=>c(ke.id),actionsLabel:i("settings.plugins.grid.actionsAria",{name:ke.spec}),actions:O(ke)},ke.id)}const{file:Ee}=ye,Pe=Ee.kind==="package";return s.jsx(Ci,{icon:s.jsx(Hr,{name:Pe?"folder":"file-text"}),title:Ee.fileName,badges:s.jsx(hc,{target:P.get(Ee.id)??null}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:i(Pe?"settings.plugins.sidebar.kind.package":"settings.plugins.sidebar.kind.file")}),Ee.scope==="project"?s.jsx(vo,{children:i("settings.plugins.grid.scope.project")}):null]}),onOpen:Pe?void 0:()=>c(Ee.id),actionsLabel:i("settings.plugins.grid.actionsAria",{name:Ee.fileName}),actions:Pe?void 0:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>a({kind:"file",id:Ee.id,label:Ee.fileName})}]},Ee.id)});let ae;e[42]!==te||e[43]!==Ce||e[44]!==ie?(ae=s.jsxs("div",{className:te,children:[Ce,ie]}),e[42]=te,e[43]=Ce,e[44]=ie,e[45]=ae):ae=e[45];let re;return e[46]!==W||e[47]!==ge||e[48]!==fe||e[49]!==Ie||e[50]!==ae||e[51]!==G||e[52]!==$?(re=s.jsxs(W,{title:G,description:$,headerEnd:ge,children:[fe,Ie,ae]}),e[46]=W,e[47]=ge,e[48]=fe,e[49]=Ie,e[50]=ae,e[51]=G,e[52]=$,e[53]=re):re=e[53],re};function gx(t){return{entries:t.entries,files:t.files,setSelected:t.setSelected,loadPlugins:t.loadPlugins}}function fx(t){return t.isLoadingRegistry}function hx(t){return t.loadRegistryInfo}function xx(t){return t.isCheckingUpdates}function bx(t){return t.checkUpdates}function vx(t){return t.runtime}function yx(t){return t.registryInfo}function jx(t){return t.packageUpdates}function kx(t){return t.updateToLatest}function wx(t){return t.updatePackage}function Sx(t){return{kind:"entry",entry:t}}function Nx(t){return{kind:"file",file:t}}function Cx(t){return t.kind==="entry"?[t.entry.spec]:[t.file.fileName,t.file.absolutePath??""]}const Ix=({entryId:t,spec:e})=>{const{t:n}=_e(),a=Ft(f=>f.registryInfo[e]),i=Ft(f=>f.updateToLatest),[o,r]=d.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const f=a.latestVersion,p=a.currentVersion??"",g=async()=>{r(!0);try{(await i(t)).ok?q.success(n("settings.plugins.toast.updatedToLatest",{version:f})):q.error(n("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(J,{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:n("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:n("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:f})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{g()},disabled:o,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:f})})]})}if(a.kind==="path-ok")return null;if(a.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(J,{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:n("settings.plugins.registry.badge.network.tooltip")})})]});const c=a.kind==="path-unreadable",l=c?"var(--status-warning)":"var(--status-error)",m=c?"alert":"error-warning",u=(()=>{switch(a.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("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(J,{name:m,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:l}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:l},children:n("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:u})]})]})},xc=t=>{const e=$e.c(68),{target:n,name:a}=t,{t:i}=_e(),o=mu(n),r=pu(n),c=Ft(Px),l=Ft(Ax);if(o.kind==="loading")return null;if(o.kind==="unknown"){let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(J,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=k):k=e[0];let I;e[1]!==i?(I=i("settings.plugins.status.unknown.title"),e[1]=i,e[2]=I):I=e[2];let y;e[3]!==I?(y=s.jsx("p",{className:"typography-label text-foreground",children:I}),e[3]=I,e[4]=y):y=e[4];let E;e[5]!==i?(E=i("settings.plugins.status.unknown.description"),e[5]=i,e[6]=E):E=e[6];let v;e[7]!==E?(v=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:E}),e[7]=E,e[8]=v):v=e[8];let R;e[9]!==y||e[10]!==v?(R=s.jsxs("div",{className:"flex-1 min-w-0",children:[y,v]}),e[9]=y,e[10]=v,e[11]=R):R=e[11];let C;e[12]!==c?(C=()=>{c()},e[12]=c,e[13]=C):C=e[13];let T;e[14]!==i?(T=i("settings.plugins.status.retry"),e[14]=i,e[15]=T):T=e[15];let P;e[16]!==C||e[17]!==T?(P=s.jsx(B,{variant:"outline",size:"sm",onClick:C,children:T}),e[16]=C,e[17]=T,e[18]=P):P=e[18];let L;return e[19]!==R||e[20]!==P?(L=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[k,R,P]}),e[19]=R,e[20]=P,e[21]=L):L=e[21],L}const{load:m,update:u}=o,f=o.target.kind==="package"?o.target.target:null,p=u==="updating"||r?.kind==="running";let g;e[22]!==a||e[23]!==f||e[24]!==i||e[25]!==l?(g=async()=>{if(!f)return;await l(f)?q.success(i("settings.plugins.update.toast.done",{name:a})):q.error(i("settings.plugins.update.toast.failed",{name:a}))},e[22]=a,e[23]=f,e[24]=i,e[25]=l,e[26]=g):g=e[26];const h=g;let j;e:{switch(m.kind){case"active":{let k;e[27]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(J,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=k):k=e[27];let I;e[28]!==m.version||e[29]!==i?(I=m.version?i("settings.plugins.status.loadedVersion",{version:m.version}):i("settings.plugins.status.loaded"),e[28]=m.version,e[29]=i,e[30]=I):I=e[30];let y;e[31]!==I?(y=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[k,I]}),e[31]=I,e[32]=y):y=e[32],j=y;break e}case"notReported":{let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(J,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=k):k=e[33];let I;e[34]!==i?(I=i("settings.plugins.status.notReported.title"),e[34]=i,e[35]=I):I=e[35];let y;e[36]!==I?(y=s.jsx("p",{className:"typography-label text-foreground",children:I}),e[36]=I,e[37]=y):y=e[37];let E;e[38]!==i?(E=i("settings.plugins.status.notReported.description"),e[38]=i,e[39]=E):E=e[39];let v;e[40]!==E?(v=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:E}),e[40]=E,e[41]=v):v=e[41];let R;e[42]!==y||e[43]!==v?(R=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[k,s.jsxs("div",{className:"flex-1 min-w-0",children:[y,v]})]}),e[42]=y,e[43]=v,e[44]=R):R=e[44],j=R;break e}case"failed":{let k;e[45]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(J,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=k):k=e[45];let I;e[46]!==i?(I=i("settings.plugins.status.failed.title"),e[46]=i,e[47]=I):I=e[47];let y;e[48]!==I?(y=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:I}),e[48]=I,e[49]=y):y=e[49];let E;e[50]!==m.error?(E=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]=E):E=e[51];let v;e[52]!==m.ref||e[53]!==i?(v=m.ref?s.jsx("p",{className:"typography-micro text-muted-foreground mt-1",children:i("settings.plugins.status.failed.ref",{ref:m.ref})}):null,e[52]=m.ref,e[53]=i,e[54]=v):v=e[54];let R;e[55]!==y||e[56]!==E||e[57]!==v?(R=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[k,s.jsxs("div",{className:"flex-1 min-w-0",children:[y,E,v]})]}),e[55]=y,e[56]=E,e[57]=v,e[58]=R):R=e[58],j=R;break e}}j=void 0}const x=j,S=f!==null&&(u!=="none"||r!==null);let b;e[59]!==h||e[60]!==p||e[61]!==r||e[62]!==S||e[63]!==i?(b=S?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(J,{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:i("settings.plugins.update.available.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:i("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:i("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(B,{variant:"default",size:"sm",onClick:()=>{h()},disabled:p,children:p?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),i("settings.plugins.update.running")]}):i("settings.plugins.update.action")})]}):null,e[59]=h,e[60]=p,e[61]=r,e[62]=S,e[63]=i,e[64]=b):b=e[64];let w;return e[65]!==x||e[66]!==b?(w=s.jsxs("div",{className:"flex flex-col gap-3",children:[x,b]}),e[65]=x,e[66]=b,e[67]=w):w=e[67],w};function Px(t){return t.loadRuntime}function Ax(t){return t.updatePackage}function yo(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}function jo(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function bc(t,e){if(t.trim()===e.trim())return!0;const n=yo(t),a=yo(e);return n.ok&&a.ok&&jo(n.value)===jo(a.value)}function Tx(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:jo(t.options),fileName:"",content:""}}function Ex(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const vc=t=>{const e=$e.c(4),{scope:n,label:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=je("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let o;return e[1]!==a||e[2]!==n?(o=s.jsx("span",{className:i,"data-scope":n,children:a}),e[1]=a,e[2]=n,e[3]=o):o=e[3],o},Dx=()=>{const t=$e.c(229),{t:e}=_e(),a=un(Mx)?.trim()||ua(),i=Ft(Rx),o=Ft(Lx),r=i===a&&o===Xt(),c=Ft(Ox),l=Ft(Fx),m=Ft(Kx),u=Ft(zx),f=Ft(Ux),p=Ft($x),g=Ft(_x),h=Ft(Bx),j=Ft(Vx),x=Ft(Hx),S=Ft(qx),[b,w]=d.useState(!1),[k,I]=d.useState(null),[y,E]=d.useState(!1);let v;t[0]!==w?(v=()=>{const Ze=()=>w(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Ze),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Ze)},t[0]=w,t[1]=v):v=t[1];let R;t[2]===Symbol.for("react.memo_cache_sentinel")?(R=[],t[2]=R):R=t[2],d.useEffect(v,R);let C;t[3]===Symbol.for("react.memo_cache_sentinel")?(C=[],t[3]=C):C=t[3],d.useEffect(Gx,C);let T;t[4]!==l||t[5]!==c?(T=c?l.find(Ze=>Ze.id===c)??null:null,t[4]=l,t[5]=c,t[6]=T):T=t[6];const P=T;let L;t[7]!==m||t[8]!==c?(L=c?m.find(Ze=>Ze.id===c)??null:null,t[7]=m,t[8]=c,t[9]=L):L=t[9];const O=L;let A;t[10]!==P?(A=P?lu(P.spec,P.sourcePath):null,t[10]=P,t[11]=A):A=t[11];const N=A;let M;t[12]!==O?(M=O?cu(O.absolutePath):null,t[12]=O,t[13]=M):M=t[13];const F=M,[H,W]=d.useState(!1);let G;t[14]===Symbol.for("react.memo_cache_sentinel")?(G=new Map,t[14]=G):G=t[14];const $=d.useRef(G),z=d.useRef(null),U=JSON.stringify([a,c]);let _;t[15]!==r||t[16]!==a||t[17]!==U||t[18]!==h||t[19]!==P||t[20]!==O||t[21]!==f||t[22]!==W?(_=()=>{let Ze=!1;if(!r){z.current=null,f(null);return}const it=(et,mt)=>{if(Ft.getState().selectedId!==et||ua()!==a)return;const ft=z.current,be=Ft.getState().draft,Re=ft?.id===et&&ft.directory===a&&be!==null&&(be.spec!==ft.value.spec||!bc(be.optionsJson,ft.value.optionsJson)||be.content!==ft.value.content);z.current={id:et,directory:a,value:mt},Re||f(mt)};return P?(it(P.id,Tx(P)),()=>{Ze=!0}):O?(W(z.current?.id!==O.id||z.current.directory!==a),(async()=>{const et=await h(O.id);if(Ze||ua()!==a)return;W(!1);const mt=et?.content??"";$.current.set(U,mt),it(O.id,Ex(O,mt))})(),()=>{Ze=!0}):(z.current=null,f(null),()=>{Ze=!0})},t[15]=r,t[16]=a,t[17]=U,t[18]=h,t[19]=P,t[20]=O,t[21]=f,t[22]=W,t[23]=_):_=t[23];let V;t[24]!==r||t[25]!==a||t[26]!==U||t[27]!==h||t[28]!==P||t[29]!==O||t[30]!==f?(V=[P,O,h,f,r,a,U],t[24]=r,t[25]=a,t[26]=U,t[27]=h,t[28]=P,t[29]=O,t[30]=f,t[31]=V):V=t[31],d.useEffect(_,V);let Z;t[32]!==r||t[33]!==a||t[34]!==u||t[35]!==U||t[36]!==P||t[37]!==O||t[38]!==e||t[39]!==p||t[40]!==g?(Z=async()=>{if(!u||!r||ua()!==a)return Ls;if(P&&u.mode==="entry"){const Ze=u.spec.trim();if(Ze===P.spec&&bc(u.optionsJson,jo(P.options)))return Ls;if(!Ze)return fs(e("settings.plugins.validation.specRequired"));const et=yo(u.optionsJson);if(!et.ok)return fs(e("settings.plugins.page.field.options.invalidJson"));const mt=await p(P.id,{spec:Ze,options:et.value});return mt.ok?mt.reloadFailed?fs(mt.warning||mt.message||e("settings.plugins.toast.reloadFailed")):vn:fs(mt.message||e("settings.plugins.toast.reloadFailed"))}if(O&&u.mode==="file"){const Ze=$.current.get(U)??"";if(u.content===Ze)return Ls;const it=await g(O.id,{content:u.content});return it.ok?($.current.set(U,u.content),it.reloadFailed?fs(it.warning||it.message||e("settings.plugins.toast.reloadFailed")):vn):fs(it.message||e("settings.plugins.toast.reloadFailed"))}return Ls},t[32]=r,t[33]=a,t[34]=u,t[35]=U,t[36]=P,t[37]=O,t[38]=e,t[39]=p,t[40]=g,t[41]=Z):Z=t[41];const Q=ei(Z);let ue;t[42]!==x||t[43]!==S||t[44]!==k||t[45]!==I||t[46]!==E||t[47]!==e?(ue=async()=>{if(!k)return;E(!0);const Ze=k.kind==="entry"?await x(k.id):await S(k.id);Ze.ok?q.success(Ze.message||e("settings.plugins.sidebar.toast.deleted",{name:k.label})):q.error(e("settings.plugins.sidebar.toast.deleteFailed")),I(null),E(!1)},t[42]=x,t[43]=S,t[44]=k,t[45]=I,t[46]=E,t[47]=e,t[48]=ue):ue=t[48];const ge=ue;let fe;t[49]!==b||t[50]!==w?(fe=s.jsx(ox,{open:b,onOpenChange:w}),t[49]=b,t[50]=w,t[51]=fe):fe=t[51];const Ie=k!==null;let te;t[52]!==y||t[53]!==I?(te=Ze=>{!Ze&&!y&&I(null)},t[52]=y,t[53]=I,t[54]=te):te=t[54];let Ce;t[55]!==e?(Ce=e("settings.plugins.sidebar.deleteDialog.title"),t[55]=e,t[56]=Ce):Ce=t[56];let ie;t[57]!==Ce?(ie=s.jsx(Vt,{children:Ce}),t[57]=Ce,t[58]=ie):ie=t[58];const ae=k?.label??"";let re;t[59]!==e||t[60]!==ae?(re=e("settings.plugins.sidebar.deleteDialog.description",{name:ae}),t[59]=e,t[60]=ae,t[61]=re):re=t[61];let ye;t[62]!==re?(ye=s.jsx(Ht,{children:re}),t[62]=re,t[63]=ye):ye=t[63];let Ee;t[64]!==ie||t[65]!==ye?(Ee=s.jsxs(Bt,{children:[ie,ye]}),t[64]=ie,t[65]=ye,t[66]=Ee):Ee=t[66];let Pe;t[67]!==I?(Pe=()=>I(null),t[67]=I,t[68]=Pe):Pe=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]!==Pe||t[73]!==ke?(Te=s.jsx(B,{size:"sm",variant:"ghost",onClick:Pe,disabled:y,children:ke}),t[71]=y,t[72]=Pe,t[73]=ke,t[74]=Te):Te=t[74];let de;t[75]!==ge?(de=()=>{ge()},t[75]=ge,t[76]=de):de=t[76];let Me;t[77]!==y||t[78]!==e?(Me=e(y?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),t[77]=y,t[78]=e,t[79]=Me):Me=t[79];let Se;t[80]!==y||t[81]!==de||t[82]!==Me?(Se=s.jsx(B,{size:"sm",variant:"destructive",onClick:de,disabled:y,children:Me}),t[80]=y,t[81]=de,t[82]=Me,t[83]=Se):Se=t[83];let Le;t[84]!==Te||t[85]!==Se?(Le=s.jsxs(ns,{children:[Te,Se]}),t[84]=Te,t[85]=Se,t[86]=Le):Le=t[86];let Ke;t[87]!==Ee||t[88]!==Le?(Ke=s.jsxs(Ut,{className:"max-w-md",children:[Ee,Le]}),t[87]=Ee,t[88]=Le,t[89]=Ke):Ke=t[89];let oe;t[90]!==Ie||t[91]!==te||t[92]!==Ke?(oe=s.jsx(zt,{open:Ie,onOpenChange:te,children:Ke}),t[90]=Ie,t[91]=te,t[92]=Ke,t[93]=oe):oe=t[93];let le;t[94]!==fe||t[95]!==oe?(le=s.jsxs(s.Fragment,{children:[fe,oe]}),t[94]=fe,t[95]=oe,t[96]=le):le=t[96];const xe=le;if(!c){let Ze;t[97]!==w?(Ze=()=>w(!0),t[97]=w,t[98]=Ze):Ze=t[98];let it;t[99]!==I||t[100]!==Ze?(it=s.jsx(px,{onAdd:Ze,onDelete:I}),t[99]=I,t[100]=Ze,t[101]=it):it=t[101];let et;return t[102]!==xe||t[103]!==it?(et=s.jsxs(s.Fragment,{children:[it,xe]}),t[102]=xe,t[103]=it,t[104]=et):et=t[104],et}let De;t[105]!==e?(De=e("settings.plugins.page.back"),t[105]=e,t[106]=De):De=t[106];let Ve;t[107]!==j?(Ve=()=>j(null),t[107]=j,t[108]=Ve):Ve=t[108];let Be;t[109]!==De||t[110]!==Ve?(Be=s.jsx(yl,{label:De,onClick:Ve}),t[109]=De,t[110]=Ve,t[111]=Be):Be=t[111];const Ne=Be;let Je;t[112]!==P||t[113]!==O||t[114]!==I?(Je=()=>{P?I({kind:"entry",id:P.id,label:P.spec}):O&&I({kind:"file",id:O.id,label:O.fileName})},t[112]=P,t[113]=O,t[114]=I,t[115]=Je):Je=t[115];let ut;t[116]===Symbol.for("react.memo_cache_sentinel")?(ut=s.jsx(J,{name:"delete-bin",className:"size-3.5"}),t[116]=ut):ut=t[116];let ht;t[117]!==e?(ht=e("settings.common.actions.delete"),t[117]=e,t[118]=ht):ht=t[118];let st;t[119]!==Je||t[120]!==ht?(st=s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:Je,children:[ut,ht]}),t[119]=Je,t[120]=ht,t[121]=st):st=t[121];const jt=st;if(P&&u&&u.mode==="entry"){let Ze;t[122]!==u.optionsJson?(Ze=yo(u.optionsJson),t[122]=u.optionsJson,t[123]=Ze):Ze=t[123];const et=Ze.ok;let mt;t[124]!==e?(mt=e("settings.plugins.page.header.entry"),t[124]=e,t[125]=mt):mt=t[125];let ft;t[126]!==P.scope||t[127]!==e?(ft=P.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[126]=P.scope,t[127]=e,t[128]=ft):ft=t[128];let be;t[129]!==P.scope||t[130]!==ft?(be=s.jsx(vc,{scope:P.scope,label:ft}),t[129]=P.scope,t[130]=ft,t[131]=be):be=t[131];const Re=Q.onBlurCapture;let X;t[132]!==P.spec||t[133]!==N?(X=s.jsx(xc,{target:N,name:P.spec}),t[132]=P.spec,t[133]=N,t[134]=X):X=t[134];let ce;t[135]!==P.id||t[136]!==P.spec?(ce=s.jsx(Ix,{entryId:P.id,spec:P.spec}),t[135]=P.id,t[136]=P.spec,t[137]=ce):ce=t[137];let Oe;t[138]!==X||t[139]!==ce?(Oe=s.jsx(qe,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[X,ce]})}),t[138]=X,t[139]=ce,t[140]=Oe):Oe=t[140];let We;t[141]!==e?(We=e("settings.plugins.page.field.spec"),t[141]=e,t[142]=We):We=t[142];const nt=u.spec;let at;t[143]!==u||t[144]!==f?(at=Ae=>f({...u,spec:Ae.target.value}),t[143]=u,t[144]=f,t[145]=at):at=t[145];let vt;t[146]!==e?(vt=e("settings.plugins.page.field.spec.placeholder"),t[146]=e,t[147]=vt):vt=t[147];let kt;t[148]!==u.spec||t[149]!==at||t[150]!==vt?(kt=s.jsx(He,{value:nt,onChange:at,placeholder:vt,className:"font-mono typography-meta",spellCheck:!1}),t[148]=u.spec,t[149]=at,t[150]=vt,t[151]=kt):kt=t[151];let xt;t[152]!==We||t[153]!==kt?(xt=s.jsx(qe,{title:We,settingsItem:"plugins.spec",children:kt}),t[152]=We,t[153]=kt,t[154]=xt):xt=t[154];let It;t[155]!==e?(It=e("settings.plugins.page.field.options"),t[155]=e,t[156]=It):It=t[156];const _t=u.optionsJson;let Ye;t[157]!==u||t[158]!==f?(Ye=Ae=>f({...u,optionsJson:Ae.target.value}),t[157]=u,t[158]=f,t[159]=Ye):Ye=t[159];const Xe=!et&&"border-[var(--status-error-border)]";let gt;t[160]!==Xe?(gt=je("font-mono typography-meta min-h-[200px]",Xe),t[160]=Xe,t[161]=gt):gt=t[161];let Ue;t[162]!==u.optionsJson||t[163]!==Ye||t[164]!==gt?(Ue=s.jsx(Ts,{value:_t,onChange:Ye,rows:10,className:gt,spellCheck:!1,placeholder:"{ }"}),t[162]=u.optionsJson,t[163]=Ye,t[164]=gt,t[165]=Ue):Ue=t[165];let ee;t[166]!==et||t[167]!==e?(ee=!et&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[166]=et,t[167]=e,t[168]=ee):ee=t[168];let ve;t[169]!==It||t[170]!==Ue||t[171]!==ee?(ve=s.jsxs(qe,{title:It,settingsItem:"plugins.options",children:[Ue,ee]}),t[169]=It,t[170]=Ue,t[171]=ee,t[172]=ve):ve=t[172];let Fe;t[173]!==Q.onBlurCapture||t[174]!==Ne||t[175]!==jt||t[176]!==mt||t[177]!==be||t[178]!==Oe||t[179]!==xt||t[180]!==ve?(Fe=s.jsxs(es,{title:mt,titleLeading:Ne,headerEnd:jt,titleAccessory:be,onBlurCapture:Re,children:[Oe,xt,ve]}),t[173]=Q.onBlurCapture,t[174]=Ne,t[175]=jt,t[176]=mt,t[177]=be,t[178]=Oe,t[179]=xt,t[180]=ve,t[181]=Fe):Fe=t[181];let se;return t[182]!==xe||t[183]!==Fe?(se=s.jsxs(s.Fragment,{children:[Fe,xe]}),t[182]=xe,t[183]=Fe,t[184]=se):se=t[184],se}if(O&&u&&u.mode==="file"){let Ze;t[185]!==e?(Ze=e("settings.plugins.page.header.file"),t[185]=e,t[186]=Ze):Ze=t[186];let it;t[187]!==O.scope||t[188]!==e?(it=O.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[187]=O.scope,t[188]=e,t[189]=it):it=t[189];let et;t[190]!==O.scope||t[191]!==it?(et=s.jsx(vc,{scope:O.scope,label:it}),t[190]=O.scope,t[191]=it,t[192]=et):et=t[192];let mt;t[193]===Symbol.for("react.memo_cache_sentinel")?(mt=je("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),t[193]=mt):mt=t[193];let ft;t[194]!==O.fileName?(ft=s.jsx("span",{className:mt,children:O.fileName}),t[194]=O.fileName,t[195]=ft):ft=t[195];let be;t[196]!==et||t[197]!==ft?(be=s.jsxs(s.Fragment,{children:[et,ft]}),t[196]=et,t[197]=ft,t[198]=be):be=t[198];const Re=Q.onBlurCapture;let X;t[199]!==O.fileName||t[200]!==F?(X=s.jsx(qe,{divider:!1,children:s.jsx(xc,{target:F,name:O.fileName})}),t[199]=O.fileName,t[200]=F,t[201]=X):X=t[201];let ce;t[202]!==e?(ce=e("settings.plugins.page.field.content"),t[202]=e,t[203]=ce):ce=t[203];let Oe;t[204]!==u||t[205]!==f?(Oe=xt=>f({...u,content:xt.target.value}),t[204]=u,t[205]=f,t[206]=Oe):Oe=t[206];let We;t[207]!==Q?(We=xt=>{xt.key==="Enter"&&(xt.metaKey||xt.ctrlKey)&&(xt.preventDefault(),Q.requestSave())},t[207]=Q,t[208]=We):We=t[208];let nt;t[209]!==u.content||t[210]!==H||t[211]!==Oe||t[212]!==We?(nt=s.jsx(Ts,{value:u.content,onChange:Oe,onKeyDown:We,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:H}),t[209]=u.content,t[210]=H,t[211]=Oe,t[212]=We,t[213]=nt):nt=t[213];let at;t[214]!==ce||t[215]!==nt?(at=s.jsx(qe,{title:ce,settingsItem:"plugins.content",children:nt}),t[214]=ce,t[215]=nt,t[216]=at):at=t[216];let vt;t[217]!==Q.onBlurCapture||t[218]!==Ne||t[219]!==jt||t[220]!==Ze||t[221]!==be||t[222]!==X||t[223]!==at?(vt=s.jsxs(es,{title:Ze,titleLeading:Ne,headerEnd:jt,titleAccessory:be,onBlurCapture:Re,children:[X,at]}),t[217]=Q.onBlurCapture,t[218]=Ne,t[219]=jt,t[220]=Ze,t[221]=be,t[222]=X,t[223]=at,t[224]=vt):vt=t[224];let kt;return t[225]!==xe||t[226]!==vt?(kt=s.jsxs(s.Fragment,{children:[vt,xe]}),t[225]=xe,t[226]=vt,t[227]=kt):kt=t[227],kt}let St;return t[228]===Symbol.for("react.memo_cache_sentinel")?(St=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(J,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[228]=St):St=t[228],St};function Mx(t){return t.getActiveProject()?.path}function Rx(t){return t.loadedDirectory}function Lx(t){return t.loadedRuntimeKey}function Ox(t){return t.selectedId}function Fx(t){return t.entries}function Kx(t){return t.files}function zx(t){return t.draft}function Ux(t){return t.setDraft}function $x(t){return t.updateEntry}function _x(t){return t.updateFile}function Bx(t){return t.readFile}function Vx(t){return t.setSelected}function Hx(t){return t.deleteEntry}function qx(t){return t.deleteFile}function Wx(){Ft.getState().setSelected(null)}function Gx(){return Wx}const Jx="<built-in>",ki=t=>t?.path===Jx,qr=t=>!!t&&!ki(t)&&t.renamable===!0,Qx=t=>{const e=$e.c(166),{onItemSelect:n}=t,{t:a}=_e(),[i,o]=d.useState(""),[r,c]=d.useState(null),[l,m]=d.useState(""),[u,f]=d.useState(null),[p,g]=d.useState(!1),[h,j]=d.useState(null),{selectedSkillName:x,setSelectedSkill:S,setSkillDraft:b,deleteSkill:w,renameSkill:k,getSkillDetail:I}=tn(Os(Yx)),y=Zs();let E;e[0]!==y?(E=Ue=>tl(Ue,y),e[0]=y,e[1]=E):E=e[1];const v=tn(E),R=tn(Zx);let C,T;e[2]!==R||e[3]!==y?(C=()=>{R(y)},T=[R,y],e[2]=R,e[3]=y,e[4]=C,e[5]=T):(C=e[4],T=e[5]),d.useEffect(C,T);let P;e[6]!==n||e[7]!==S||e[8]!==b||e[9]!==v?(P=()=>{let Ue="new-skill",ee=1;for(;v.some(ve=>ve.name===Ue);)Ue=`new-skill-${ee}`,ee++;b({name:Ue,scope:"user",source:"opencode",description:""}),S(Ue),n?.()},e[6]=n,e[7]=S,e[8]=b,e[9]=v,e[10]=P):P=e[10];const L=P;let O;e[11]===Symbol.for("react.memo_cache_sentinel")?(O=async Ue=>{ki(Ue)||f(Ue)},e[11]=O):O=e[11];const A=O;let N;e[12]!==u||e[13]!==w||e[14]!==y||e[15]!==a?(N=async()=>{if(!u)return;if(ki(u)){f(null);return}g(!0),await w(u.name,y)?(q.success(a("settings.skills.sidebar.toast.skillDeleted",{name:u.name})),f(null)):q.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),g(!1)},e[12]=u,e[13]=w,e[14]=y,e[15]=a,e[16]=N):N=e[16];const M=N;let F;e[17]!==I||e[18]!==S||e[19]!==b||e[20]!==y||e[21]!==v||e[22]!==a?(F=async Ue=>{if(ki(Ue))return;const ee=Ue.name;let ve=1,Fe=`${ee}-copy`;for(;v.some(Ae=>Ae.name===Fe);)ve++,Fe=`${ee}-copy-${ve}`;const se=await I(Ue.name,y);if(!se){q.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:Fe,scope:Ue.scope||"user",source:Ue.source||"opencode",description:(se.sources.md.fields.includes("description"),""),instructions:""}),S(Fe)},e[17]=I,e[18]=S,e[19]=b,e[20]=y,e[21]=v,e[22]=a,e[23]=F):F=e[23];const H=F;let W;e[24]===Symbol.for("react.memo_cache_sentinel")?(W=Ue=>{qr(Ue)&&(m(Ue.name),c(Ue))},e[24]=W):W=e[24];const G=W;let $;e[25]!==r||e[26]!==l||e[27]!==k||e[28]!==S||e[29]!==y||e[30]!==v||e[31]!==a?($=async()=>{if(!r)return;if(!qr(r)){c(null);return}const Ue=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ue){q.error(a("settings.skills.page.toast.skillNameRequired"));return}if(Ue===r.name){c(null);return}if(v.some(ve=>ve.name===Ue)){q.error(a("settings.skills.page.toast.skillExists"));return}await k(r.name,Ue,y)?(q.success(a("settings.skills.sidebar.toast.skillRenamed",{name:Ue})),S(Ue)):q.error(a("settings.skills.sidebar.toast.renameFailed")),c(null)},e[25]=r,e[26]=l,e[27]=k,e[28]=S,e[29]=y,e[30]=v,e[31]=a,e[32]=$):$=e[32];const z=$;let U,_,V;if(e[33]!==i||e[34]!==v){let Ue;e[38]!==i?(Ue=ee=>Co([ee.name,ee.description],i),e[38]=i,e[39]=Ue):Ue=e[39],_=v.filter(Ue),U=_.filter(Xx),V=_.filter(eb),e[33]=i,e[34]=v,e[35]=U,e[36]=_,e[37]=V}else U=e[35],_=e[36],V=e[37];const Z=V;let Y;e[40]===Symbol.for("react.memo_cache_sentinel")?(Y=function(ee){const ve={},Fe=[];for(const Ae of ee)Ae.group?(ve[Ae.group]||(ve[Ae.group]=[]),ve[Ae.group].push(Ae)):Fe.push(Ae);const se=Object.keys(ve).sort(tb).map(Ae=>({name:Ae,skills:[...ve[Ae]].sort(sb)}));return Fe.sort(nb),{sortedGroups:se,ungrouped:Fe}},e[40]=Y):Y=e[40];const Q=Y;let ue;e[41]!==U?(ue=Q(U),e[41]=U,e[42]=ue):ue=e[42];const ge=ue;let fe;e[43]!==Z?(fe=Q(Z),e[43]=Z,e[44]=fe):fe=e[44];const Ie=fe;let te;e[45]===Symbol.for("react.memo_cache_sentinel")?(te=je("flex h-full flex-col","bg-background"),e[45]=te):te=e[45];let Ce;e[46]!==a?(Ce=a("settings.skills.sidebar.title"),e[46]=a,e[47]=Ce):Ce=e[47];let ie;e[48]!==Ce?(ie=s.jsx("h2",{className:`${ya} mb-3`,children:Ce}),e[48]=Ce,e[49]=ie):ie=e[49];let ae;e[50]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(Ai,{className:"mb-3"}),e[50]=ae):ae=e[50];let re;e[51]!==v.length||e[52]!==a?(re=a("settings.skills.sidebar.total",{count:v.length}),e[51]=v.length,e[52]=a,e[53]=re):re=e[53];let ye;e[54]!==re?(ye=s.jsx("span",{className:"typography-meta text-muted-foreground",children:re}),e[54]=re,e[55]=ye):ye=e[55];let Ee;e[56]===Symbol.for("react.memo_cache_sentinel")?(Ee=s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),e[56]=Ee):Ee=e[56];let Pe;e[57]!==L?(Pe=s.jsx(B,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:L,children:Ee}),e[57]=L,e[58]=Pe):Pe=e[58];let ke;e[59]!==ye||e[60]!==Pe?(ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ye,Pe]}),e[59]=ye,e[60]=Pe,e[61]=ke):ke=e[61];let Te;e[62]!==i||e[63]!==v.length?(Te=v.length>0?s.jsx(pl,{value:i,onChange:o}):null,e[62]=i,e[63]=v.length,e[64]=Te):Te=e[64];let de;e[65]!==ie||e[66]!==ke||e[67]!==Te?(de=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ie,ae,ke,Te]}),e[65]=ie,e[66]=ke,e[67]=Te,e[68]=de):de=e[68];let Me;e[69]!==ge||e[70]!==Ie||e[71]!==H||e[72]!==n||e[73]!==h||e[74]!==U||e[75]!==i||e[76]!==x||e[77]!==S||e[78]!==_||e[79]!==v.length||e[80]!==a||e[81]!==Z?(Me=s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(J,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.sidebar.empty.description")})]}):_.length===0?s.jsx(gl,{query:i}):s.jsxs(s.Fragment,{children:[U.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.project")}),ge.sortedGroups.map(Ue=>{const{name:ee,skills:ve}=Ue;return s.jsx($r,{label:ee,count:ve.length,storageKey:"project-skills",children:ve.map(Fe=>s.jsx(Zi,{skill:Fe,isSelected:x===Fe.name,onSelect:()=>{S(Fe.name),n?.()},onRename:()=>G(Fe),onDelete:()=>A(Fe),onDuplicate:()=>H(Fe),isMenuOpen:h===Fe.name,onMenuOpenChange:se=>j(se?Fe.name:null)},Fe.name))},ee)}),ge.ungrouped.map(Ue=>s.jsx(Zi,{skill:Ue,isSelected:x===Ue.name,onSelect:()=>{S(Ue.name),n?.()},onRename:()=>G(Ue),onDelete:()=>A(Ue),onDuplicate:()=>H(Ue),isMenuOpen:h===Ue.name,onMenuOpenChange:ee=>j(ee?Ue.name:null)},Ue.name))]}),Z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.user")}),Ie.sortedGroups.map(Ue=>{const{name:ee,skills:ve}=Ue;return s.jsx($r,{label:ee,count:ve.length,storageKey:"user-skills",children:ve.map(Fe=>s.jsx(Zi,{skill:Fe,isSelected:x===Fe.name,onSelect:()=>{S(Fe.name),n?.()},onRename:()=>G(Fe),onDelete:()=>A(Fe),onDuplicate:()=>H(Fe),isMenuOpen:h===Fe.name,onMenuOpenChange:se=>j(se?Fe.name:null)},Fe.name))},ee)}),Ie.ungrouped.map(Ue=>s.jsx(Zi,{skill:Ue,isSelected:x===Ue.name,onSelect:()=>{S(Ue.name),n?.()},onRename:()=>G(Ue),onDelete:()=>A(Ue),onDuplicate:()=>H(Ue),isMenuOpen:h===Ue.name,onMenuOpenChange:ee=>j(ee?Ue.name:null)},Ue.name))]})]})}),e[69]=ge,e[70]=Ie,e[71]=H,e[72]=n,e[73]=h,e[74]=U,e[75]=i,e[76]=x,e[77]=S,e[78]=_,e[79]=v.length,e[80]=a,e[81]=Z,e[82]=Me):Me=e[82];const Se=u!==null;let Le;e[83]!==p?(Le=Ue=>{!Ue&&!p&&f(null)},e[83]=p,e[84]=Le):Le=e[84];let Ke;e[85]!==a?(Ke=a("settings.skills.sidebar.deleteDialog.title"),e[85]=a,e[86]=Ke):Ke=e[86];let oe;e[87]!==Ke?(oe=s.jsx(Vt,{children:Ke}),e[87]=Ke,e[88]=oe):oe=e[88];const le=u?.name??"";let xe;e[89]!==a||e[90]!==le?(xe=a("settings.skills.sidebar.deleteDialog.description",{name:le}),e[89]=a,e[90]=le,e[91]=xe):xe=e[91];let De;e[92]!==xe?(De=s.jsx(Ht,{children:xe}),e[92]=xe,e[93]=De):De=e[93];let Ve;e[94]!==oe||e[95]!==De?(Ve=s.jsxs(Bt,{children:[oe,De]}),e[94]=oe,e[95]=De,e[96]=Ve):Ve=e[96];let Be;e[97]===Symbol.for("react.memo_cache_sentinel")?(Be=()=>f(null),e[97]=Be):Be=e[97];let Ne;e[98]!==a?(Ne=a("settings.common.actions.cancel"),e[98]=a,e[99]=Ne):Ne=e[99];let Je;e[100]!==p||e[101]!==Ne?(Je=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Be,disabled:p,children:Ne}),e[100]=p,e[101]=Ne,e[102]=Je):Je=e[102];let ut;e[103]!==a?(ut=a("settings.common.actions.delete"),e[103]=a,e[104]=ut):ut=e[104];let ht;e[105]!==M||e[106]!==p||e[107]!==ut?(ht=s.jsx(B,{size:"sm",onClick:M,disabled:p,children:ut}),e[105]=M,e[106]=p,e[107]=ut,e[108]=ht):ht=e[108];let st;e[109]!==Je||e[110]!==ht?(st=s.jsxs(ns,{children:[Je,ht]}),e[109]=Je,e[110]=ht,e[111]=st):st=e[111];let jt;e[112]!==Ve||e[113]!==st?(jt=s.jsxs(Ut,{className:"max-w-md",children:[Ve,st]}),e[112]=Ve,e[113]=st,e[114]=jt):jt=e[114];let St;e[115]!==Se||e[116]!==Le||e[117]!==jt?(St=s.jsx(zt,{open:Se,onOpenChange:Le,children:jt}),e[115]=Se,e[116]=Le,e[117]=jt,e[118]=St):St=e[118];const Ze=r!==null;let it;e[119]===Symbol.for("react.memo_cache_sentinel")?(it=Ue=>!Ue&&c(null),e[119]=it):it=e[119];let et;e[120]!==a?(et=a("settings.skills.sidebar.renameDialog.title"),e[120]=a,e[121]=et):et=e[121];let mt;e[122]!==et?(mt=s.jsx(Vt,{children:et}),e[122]=et,e[123]=mt):mt=e[123];const ft=r?.name??"";let be;e[124]!==a||e[125]!==ft?(be=a("settings.skills.sidebar.renameDialog.description",{name:ft}),e[124]=a,e[125]=ft,e[126]=be):be=e[126];let Re;e[127]!==be?(Re=s.jsx(Ht,{children:be}),e[127]=be,e[128]=Re):Re=e[128];let X;e[129]!==mt||e[130]!==Re?(X=s.jsxs(Bt,{children:[mt,Re]}),e[129]=mt,e[130]=Re,e[131]=X):X=e[131];let ce;e[132]===Symbol.for("react.memo_cache_sentinel")?(ce=Ue=>m(Ue.target.value),e[132]=ce):ce=e[132];let Oe;e[133]!==a?(Oe=a("settings.skills.sidebar.renameDialog.placeholder"),e[133]=a,e[134]=Oe):Oe=e[134];let We;e[135]!==z?(We=Ue=>{Ue.key==="Enter"&&z()},e[135]=z,e[136]=We):We=e[136];let nt;e[137]!==l||e[138]!==Oe||e[139]!==We?(nt=s.jsx(He,{value:l,onChange:ce,placeholder:Oe,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:We}),e[137]=l,e[138]=Oe,e[139]=We,e[140]=nt):nt=e[140];let at;e[141]===Symbol.for("react.memo_cache_sentinel")?(at=()=>c(null),e[141]=at):at=e[141];let vt;e[142]!==a?(vt=a("settings.common.actions.cancel"),e[142]=a,e[143]=vt):vt=e[143];let kt;e[144]!==vt?(kt=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:at,children:vt}),e[144]=vt,e[145]=kt):kt=e[145];let xt;e[146]!==a?(xt=a("settings.common.actions.rename"),e[146]=a,e[147]=xt):xt=e[147];let It;e[148]!==z||e[149]!==xt?(It=s.jsx(B,{size:"sm",onClick:z,children:xt}),e[148]=z,e[149]=xt,e[150]=It):It=e[150];let _t;e[151]!==kt||e[152]!==It?(_t=s.jsxs(ns,{children:[kt,It]}),e[151]=kt,e[152]=It,e[153]=_t):_t=e[153];let Ye;e[154]!==X||e[155]!==nt||e[156]!==_t?(Ye=s.jsxs(Ut,{children:[X,nt,_t]}),e[154]=X,e[155]=nt,e[156]=_t,e[157]=Ye):Ye=e[157];let Xe;e[158]!==Ze||e[159]!==Ye?(Xe=s.jsx(zt,{open:Ze,onOpenChange:it,children:Ye}),e[158]=Ze,e[159]=Ye,e[160]=Xe):Xe=e[160];let gt;return e[161]!==de||e[162]!==Me||e[163]!==St||e[164]!==Xe?(gt=s.jsxs("div",{className:te,children:[de,Me,St,Xe]}),e[161]=de,e[162]=Me,e[163]=St,e[164]=Xe,e[165]=gt):gt=e[165],gt},Zi=t=>{const e=$e.c(41),{skill:n,isSelected:a,onSelect:i,onDelete:o,onRename:r,onDuplicate:c,isMenuOpen:l,onMenuOpenChange:m}=t,{t:u}=_e();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Xr(),e[0]=f):f=e[0];const p=f;let g;e[1]!==n?(g=ki(n),e[1]=n,e[2]=g):g=e[2];const h=g;let j;e[3]!==n?(j=qr(n),e[3]=n,e[4]=j):j=e[4];const x=j,[S,b]=d.useState(!1);let w;e[5]!==x||e[6]!==o||e[7]!==c||e[8]!==r||e[9]!==u?(w=M=>s.jsxs(s.Fragment,{children:[x?s.jsxs(M,{onClick:F=>{F.stopPropagation(),r()},children:[s.jsx(J,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}):null,s.jsxs(M,{onClick:F=>{F.stopPropagation(),c()},children:[s.jsx(J,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),s.jsxs(M,{onClick:F=>{F.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[5]=x,e[6]=o,e[7]=c,e[8]=r,e[9]=u,e[10]=w):w=e[10];const k=w,I=!h&&S,y=a?"bg-interactive-selection":"hover:bg-interactive-hover";let E;e[11]!==y?(E=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y),e[11]=y,e[12]=E):E=e[12];let v;e[13]!==h?(v=!p&&!h?M=>{M.preventDefault(),b(!0)}:void 0,e[13]=h,e[14]=v):v=e[14];let R;e[15]!==E||e[16]!==v?(R=s.jsx("div",{className:E,onContextMenu:v}),e[15]=E,e[16]=v,e[17]=R):R=e[17];let C;e[18]!==n.name?(C=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name})}),e[18]=n.name,e[19]=C):C=e[19];let T;e[20]!==i||e[21]!==C?(T=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:C}),e[20]=i,e[21]=C,e[22]=T):T=e[22];let P;e[23]!==h||e[24]!==l||e[25]!==m||e[26]!==k?(P=h?null:s.jsxs(Kn,{open:l,onOpenChange:M=>{M&&b(!1),m(M)},children:[s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(On,{align:"end",className:"w-fit min-w-20",children:k(mn)})]}),e[23]=h,e[24]=l,e[25]=m,e[26]=k,e[27]=P):P=e[27];let L;e[28]!==T||e[29]!==P?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,P]}),e[28]=T,e[29]=P,e[30]=L):L=e[30];let O;e[31]!==L||e[32]!==R?(O=s.jsx(Qa,{render:R,children:L}),e[31]=L,e[32]=R,e[33]=O):O=e[33];let A;e[34]!==h||e[35]!==k?(A=h?null:s.jsx(Ga,{className:"w-fit min-w-20",children:k(Ja)}),e[34]=h,e[35]=k,e[36]=A):A=e[36];let N;return e[37]!==O||e[38]!==A||e[39]!==I?(N=s.jsxs(Ya,{open:I,onOpenChange:b,children:[O,A]}),e[37]=O,e[38]=A,e[39]=I,e[40]=N):N=e[40],N};function Yx(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Zx(t){return t.loadSkills}function Xx(t){return t.scope==="project"}function eb(t){return t.scope==="user"}function tb(t,e){return t.localeCompare(e)}function sb(t,e){return t.name.localeCompare(e.name)}function nb(t,e){return t.name.localeCompare(e.name)}const ab=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,ib=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const a=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return a?`${a[1]}/${a[2].replace(/\.git$/i,"")}`:e},ob=({open:t,onOpenChange:e})=>{const{t:n}=_e(),a=Pn(A=>A.scanRepo),i=Pn(A=>A.loadCatalog),o=Pn(A=>A.loadSource),r=Pn(A=>A.setSelectedSource),c=Pn(A=>A.isScanning),l=pa(A=>A.defaultGitIdentityId),m=pa(A=>A.loadDefaultGitIdentityId),[u,f]=d.useState(""),[p,g]=d.useState(""),[h,j]=d.useState(""),[x,S]=d.useState(null),[b,w]=d.useState(null),[k,I]=d.useState(!1),[y,E]=d.useState([]),[v,R]=d.useState(null),C=d.useRef(0),T=d.useCallback(A=>{C.current+=1,I(!1),w(null),A?.clearIdentity&&(E([]),R(null))},[]);d.useEffect(()=>{t&&(C.current+=1,f(""),g(""),j(""),w(null),I(!1),E([]),R(null),m(),S(null),(async()=>{const A=await yn();S(A?A.skillCatalogs??[]:null)})())},[t,m]);const P=d.useMemo(()=>{const A=p.trim(),N=h.trim();return(x??[]).some(M=>{const F=(M.source||"").trim(),H=(M.subpath||"").trim();return F===A&&H===N})},[x,p,h]),L=async()=>{const A=p.trim();if(!A){q.error(n("settings.skills.catalog.add.toast.repositoryRequired"));return}u.trim()||f(ib(A)),I(!1),w(null);const N=C.current+1;C.current=N;const M=await a({source:A,subpath:h.trim()||void 0,gitIdentityId:v||void 0});if(C.current!==N)return;if(!M.ok){if(M.error?.kind==="authRequired"){if(os()){q.error(n("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const H=M.error.identities||[];if(E(H),!v&&H.length>0){const W=l&&l!=="global"&&H.some(G=>G.id===l)?l:H[0].id;R(W)}q.error(n("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}q.error(M.error?.message||n("settings.skills.catalog.add.toast.scanFailed"));return}const F=M.items?.length||0;if(w(F),F===0){q.error(n("settings.skills.catalog.add.toast.noSkillsFound")),I(!1);return}E([]),I(!0),q.success(n("settings.skills.catalog.shared.toast.foundSkills",{count:F}))},O=async()=>{const A=u.trim(),N=p.trim(),M=h.trim();if(!A){q.error(n("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!N){q.error(n("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!k){q.error(n("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(P){q.error(n("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const F={id:ab(),label:A,source:N,...M?{subpath:M}:{},...v?{gitIdentityId:v}:{}};if(x===null){q.error(n("settings.skills.catalog.add.toast.saveFailed"));return}const H=[...x,F];try{if(!(await bt({skillCatalogs:H})).ok)throw new Error(n("settings.skills.catalog.add.toast.saveFailed"));S(H),q.success(n("settings.skills.catalog.add.toast.catalogAdded")),await i({refresh:!0}),await o(F.id,{refresh:!0}),r(F.id),e(!1)}catch(W){q.error(W instanceof Error?W.message:n("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(zt,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:n("settings.skills.catalog.add.title")}),s.jsxs(Ht,{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(He,{value:u,onChange:A=>f(A.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(Wt,{children:n("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(He,{value:p,onChange:A=>{g(A.target.value),T({clearIdentity:!0})},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(He,{value:h,onChange:A=>{j(A.target.value),T({clearIdentity:!0})},placeholder:n("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),y.length>0&&!os()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:n("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:n("settings.skills.catalog.shared.auth.description")}),s.jsx(Wt,{className:"ml-1",children:n("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Dt,{value:v||"",onValueChange:A=>{R(A),T()},children:[s.jsx(Tt,{className:"w-fit",children:s.jsx("span",{children:y.find(A=>A.id===v)?.name||n("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Et,{align:"start",children:y.map(A=>s.jsx(dt,{value:A.id,children:A.name},A.id))})]})]}):null,b!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:n("settings.skills.catalog.add.scanResult",{count:b})}):null,P?s.jsx("div",{className:"typography-meta text-muted-foreground",children:n("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:n("settings.common.actions.cancel")}),s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{L()},disabled:c||!p.trim(),children:[s.jsx(J,{name:"git-repository",className:"h-4 w-4"}),n(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(B,{size:"sm",onClick:()=>{O()},disabled:!k||P||x===null||!u.trim()||!p.trim(),children:n("settings.skills.catalog.add.actions.addCatalog")})]})]})})},rb=t=>{const e=$e.c(85),{open:n,onOpenChange:a,conflicts:i,onConfirm:o}=t,{t:r}=_e();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[l,m]=d.useState(c);let u,f;e[1]!==i||e[2]!==n?(u=()=>{if(!n)return;const Y={};for(const Q of i)Y[Q.skillName]="skip";m(Y)},f=[n,i],e[1]=i,e[2]=n,e[3]=u,e[4]=f):(u=e[3],f=e[4]),d.useEffect(u,f);let p;e[5]!==i?(p=Y=>{const Q={};for(const ue of i)Q[ue.skillName]=Y;m(Q)},e[5]=i,e[6]=p):p=e[6];const g=p;let h;e[7]!==i||e[8]!==l?(h=i.length>0&&i.every(Y=>l[Y.skillName]),e[7]=i,e[8]=l,e[9]=h):h=e[9];const j=h;let x;e[10]!==r?(x=r("settings.skills.catalog.conflicts.title"),e[10]=r,e[11]=x):x=e[11];let S;e[12]!==x?(S=s.jsx(Vt,{children:x}),e[12]=x,e[13]=S):S=e[13];let b;e[14]!==r?(b=r("settings.skills.catalog.conflicts.description"),e[14]=r,e[15]=b):b=e[15];let w;e[16]!==b?(w=s.jsx(Ht,{children:b}),e[16]=b,e[17]=w):w=e[17];let k;e[18]!==S||e[19]!==w?(k=s.jsxs(Bt,{children:[S,w]}),e[18]=S,e[19]=w,e[20]=k):k=e[20];let I;e[21]!==i.length||e[22]!==r?(I=r("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=r,e[23]=I):I=e[23];let y;e[24]!==I?(y=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=y):y=e[25];let E;e[26]!==g?(E=()=>g("skip"),e[26]=g,e[27]=E):E=e[27];let v;e[28]!==r?(v=r("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=r,e[29]=v):v=e[29];let R;e[30]!==E||e[31]!==v?(R=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:E,children:v}),e[30]=E,e[31]=v,e[32]=R):R=e[32];let C;e[33]!==g?(C=()=>g("overwrite"),e[33]=g,e[34]=C):C=e[34];let T;e[35]!==r?(T=r("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=r,e[36]=T):T=e[36];let P;e[37]!==C||e[38]!==T?(P=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:T}),e[37]=C,e[38]=T,e[39]=P):P=e[39];let L;e[40]!==R||e[41]!==P?(L=s.jsxs("div",{className:"flex items-center gap-2",children:[R,P]}),e[40]=R,e[41]=P,e[42]=L):L=e[42];let O;e[43]!==y||e[44]!==L?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y,L]}),e[43]=y,e[44]=L,e[45]=O):O=e[45];let A;if(e[46]!==i||e[47]!==l||e[48]!==r){let Y;e[50]!==l||e[51]!==r?(Y=Q=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:Q.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.conflicts.installedIn",{scope:Q.scope==="project"?r("settings.skills.catalog.conflicts.scope.project"):r("settings.skills.catalog.conflicts.scope.user"),source:Q.source==="agents"?r("settings.skills.catalog.conflicts.source.agents"):r("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Dt,{value:l[Q.skillName]||"skip",onValueChange:ue=>m(ge=>({...ge,[Q.skillName]:ue})),children:[s.jsx(Tt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(l[Q.skillName]||"skip")==="overwrite"?r("settings.skills.catalog.conflicts.decision.overwrite"):r("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Et,{align:"end",children:[s.jsx(dt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(dt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},Q.skillName),e[50]=l,e[51]=r,e[52]=Y):Y=e[52],A=i.map(Y),e[46]=i,e[47]=l,e[48]=r,e[49]=A}else A=e[49];let N;e[53]!==A?(N=s.jsx("div",{className:"space-y-2",children:A}),e[53]=A,e[54]=N):N=e[54];let M;e[55]!==O||e[56]!==N?(M=s.jsxs("div",{className:"space-y-3",children:[O,N]}),e[55]=O,e[56]=N,e[57]=M):M=e[57];let F;e[58]!==a?(F=()=>a(!1),e[58]=a,e[59]=F):F=e[59];let H;e[60]!==r?(H=r("settings.common.actions.cancel"),e[60]=r,e[61]=H):H=e[61];let W;e[62]!==F||e[63]!==H?(W=s.jsx(B,{size:"sm",variant:"ghost",onClick:F,children:H}),e[62]=F,e[63]=H,e[64]=W):W=e[64];let G;e[65]!==l||e[66]!==o?(G=()=>o(l),e[65]=l,e[66]=o,e[67]=G):G=e[67];const $=!j;let z;e[68]!==r?(z=r("settings.skills.catalog.conflicts.actions.continue"),e[68]=r,e[69]=z):z=e[69];let U;e[70]!==G||e[71]!==$||e[72]!==z?(U=s.jsx(B,{size:"sm",onClick:G,disabled:$,children:z}),e[70]=G,e[71]=$,e[72]=z,e[73]=U):U=e[73];let _;e[74]!==W||e[75]!==U?(_=s.jsxs(ns,{children:[W,U]}),e[74]=W,e[75]=U,e[76]=_):_=e[76];let V;e[77]!==k||e[78]!==M||e[79]!==_?(V=s.jsxs(Ut,{className:"max-w-2xl",children:[k,M,_]}),e[77]=k,e[78]=M,e[79]=_,e[80]=V):V=e[80];let Z;return e[81]!==a||e[82]!==n||e[83]!==V?(Z=s.jsx(zt,{open:n,onOpenChange:a,children:V}),e[81]=a,e[82]=n,e[83]=V,e[84]=Z):Z=e[84],Z},jl=[{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 wi(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 gu(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=jl.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const lb=t=>{const e=$e.c(124),{open:n,onOpenChange:a,item:i}=t,{t:o}=_e(),r=Pn(cb),c=Pn(db),[l,m]=d.useState("user"),[u,f]=d.useState("opencode"),p=un(ub),g=un(mb),[h,j]=d.useState(null),[x,S]=d.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=[],e[0]=b):b=e[0];const[w,k]=d.useState(b),[I,y]=d.useState(null);let E,v;e[1]!==g||e[2]!==n?(E=()=>{n&&(m("user"),f("opencode"),j(g),S(!1),k([]),y(null))},v=[n,g],e[1]=g,e[2]=n,e[3]=E,e[4]=v):(E=e[3],v=e[4]),d.useEffect(E,v);let R;e[5]!==o?(R=Ne=>{switch(Ne){case"project-opencode":return o("settings.skills.location.option.projectOpencode.label");case"user-agents":return o("settings.skills.location.option.userAgents.label");case"project-agents":return o("settings.skills.location.option.projectAgents.label");default:return o("settings.skills.location.option.userOpencode.label")}},e[5]=o,e[6]=R):R=e[6];const C=R;let T;e[7]!==o?(T=Ne=>{switch(Ne){case"project-opencode":return o("settings.skills.location.option.projectOpencode.description");case"user-agents":return o("settings.skills.location.option.userAgents.description");case"project-agents":return o("settings.skills.location.option.projectAgents.description");default:return o("settings.skills.location.option.userOpencode.description")}},e[7]=o,e[8]=T):T=e[8];const P=T;let L;e:{if(p.length===0){L=null;break e}if(h&&p.some(Ne=>Ne.id===h)){L=h;break e}if(g&&p.some(Ne=>Ne.id===g)){L=g;break e}L=p[0]?.id??null}const O=L;let A;e:{if(l!=="project"){A=null;break e}const Ne=O;if(!Ne){A=null;break e}let Je;if(e[9]!==Ne||e[10]!==p){let ht;e[12]!==Ne?(ht=st=>st.id===Ne,e[12]=Ne,e[13]=ht):ht=e[13],Je=p.find(ht),e[9]=Ne,e[10]=p,e[11]=Je}else Je=e[11];A=Je?.path??null}const N=A;let M;e[14]!==r||e[15]!==i?.gitIdentityId||e[16]!==a||e[17]!==o?(M=async Ne=>{const Je=await r({source:Ne.source,subpath:Ne.subpath,gitIdentityId:i?.gitIdentityId,scope:Ne.scope,targetSource:Ne.targetSource,selections:[{skillDir:Ne.skillDir}],conflictPolicy:"prompt",conflictDecisions:Ne.conflictDecisions},{directory:Ne.directoryOverride??null});if(Je.ok){q.success(o("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(Je.error?.kind==="conflicts"){y({source:Ne.source,subpath:Ne.subpath,scope:Ne.scope,targetSource:Ne.targetSource,skillDir:Ne.skillDir,directoryOverride:Ne.directoryOverride??null}),k(Je.error.conflicts),S(!0);return}if(Je.error?.kind==="authRequired"){q.error(Je.error.message||o("settings.skills.catalog.installSkill.toast.authRequired"));return}q.error(Je.error?.message||o("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=r,e[15]=i?.gitIdentityId,e[16]=a,e[17]=o,e[18]=M):M=e[18];const F=M;if(!i)return null;let H;e[19]!==o?(H=o("settings.skills.catalog.installSkill.title"),e[19]=o,e[20]=H):H=e[20];let W;e[21]!==H?(W=s.jsx(Vt,{children:H}),e[21]=H,e[22]=W):W=e[22];let G;e[23]!==o?(G=o("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=o,e[24]=G):G=e[24];let $;e[25]!==i.skillName?($=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=$):$=e[26];let z;e[27]!==o?(z=o("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=o,e[28]=z):z=e[28];let U;e[29]!==G||e[30]!==$||e[31]!==z?(U=s.jsxs(Ht,{children:[G," ",$," ",z]}),e[29]=G,e[30]=$,e[31]=z,e[32]=U):U=e[32];let _;e[33]!==W||e[34]!==U?(_=s.jsxs(Bt,{children:[W,U]}),e[33]=W,e[34]=U,e[35]=_):_=e[35];let V;e[36]!==o?(V=o("settings.skills.catalog.installSkill.field.destination"),e[36]=o,e[37]=V):V=e[37];let Z;e[38]!==V?(Z=s.jsx("span",{className:"typography-ui-label text-foreground",children:V}),e[38]=V,e[39]=Z):Z=e[39];let Y;e[40]!==l||e[41]!==u?(Y=wi(l,u),e[40]=l,e[41]=u,e[42]=Y):Y=e[42];let Q;e[43]===Symbol.for("react.memo_cache_sentinel")?(Q=Ne=>{const Je=gu(Ne);m(Je.scope),f(Je.source==="agents"?"agents":"opencode")},e[43]=Q):Q=e[43];let ue;e[44]!==l?(ue=l==="user"?s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=l,e[45]=ue):ue=e[45];let ge;e[46]!==u?(ge=u==="agents"?s.jsx(J,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=u,e[47]=ge):ge=e[47];let fe;e[48]!==C||e[49]!==l||e[50]!==u?(fe=C(wi(l,u)),e[48]=C,e[49]=l,e[50]=u,e[51]=fe):fe=e[51];let Ie;e[52]!==fe?(Ie=s.jsx("span",{children:fe}),e[52]=fe,e[53]=Ie):Ie=e[53];let te;e[54]!==ue||e[55]!==ge||e[56]!==Ie?(te=s.jsxs(Tt,{className:"w-fit gap-1.5",children:[ue,ge,Ie]}),e[54]=ue,e[55]=ge,e[56]=Ie,e[57]=te):te=e[57];let Ce;e[58]!==P||e[59]!==C?(Ce=jl.map(Ne=>s.jsx(dt,{value:Ne.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:[Ne.scope==="user"?s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),Ne.source==="agents"?s.jsx(J,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:C(Ne.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:P(Ne.value)})]})},Ne.value)),e[58]=P,e[59]=C,e[60]=Ce):Ce=e[60];let ie;e[61]!==Ce?(ie=s.jsx(Et,{align:"start",children:Ce}),e[61]=Ce,e[62]=ie):ie=e[62];let ae;e[63]!==Y||e[64]!==te||e[65]!==ie?(ae=s.jsxs(Dt,{value:Y,onValueChange:Q,children:[te,ie]}),e[63]=Y,e[64]=te,e[65]=ie,e[66]=ae):ae=e[66];let re;e[67]!==Z||e[68]!==ae?(re=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Z,ae]}),e[67]=Z,e[68]=ae,e[69]=re):re=e[69];let ye;e[70]!==p||e[71]!==O||e[72]!==l||e[73]!==o?(ye=l==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:o("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Dt,{value:O??"",onValueChange:Ne=>j(Ne),disabled:p.length===1,children:[s.jsx(Tt,{className:"w-fit",children:s.jsx($t,{placeholder:o("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Et,{align:"start",children:p.map(pb)})]})]}),e[70]=p,e[71]=O,e[72]=l,e[73]=o,e[74]=ye):ye=e[74];let Ee;e[75]!==i.warnings?(Ee=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Ee):Ee=e[76];let Pe;e[77]!==re||e[78]!==ye||e[79]!==Ee?(Pe=s.jsxs("div",{className:"mt-2 space-y-3",children:[re,ye,Ee]}),e[77]=re,e[78]=ye,e[79]=Ee,e[80]=Pe):Pe=e[80];let ke;e[81]!==a?(ke=()=>a(!1),e[81]=a,e[82]=ke):ke=e[82];let Te;e[83]!==o?(Te=o("settings.common.actions.cancel"),e[83]=o,e[84]=Te):Te=e[84];let de;e[85]!==ke||e[86]!==Te?(de=s.jsx(B,{size:"sm",variant:"ghost",onClick:ke,children:Te}),e[85]=ke,e[86]=Te,e[87]=de):de=e[87];const Me=c||!i.installable||l==="project"&&!N;let Se;e[88]!==N||e[89]!==F||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==l||e[94]!==u?(Se=()=>{F({source:i.repoSource,subpath:i.repoSubpath,scope:l,targetSource:u,skillDir:i.skillDir,directoryOverride:N})},e[88]=N,e[89]=F,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=l,e[94]=u,e[95]=Se):Se=e[95];let Le;e[96]!==c||e[97]!==o?(Le=o(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=o,e[98]=Le):Le=e[98];let Ke;e[99]!==Me||e[100]!==Se||e[101]!==Le?(Ke=s.jsx(B,{size:"sm",disabled:Me,onClick:Se,children:Le}),e[99]=Me,e[100]=Se,e[101]=Le,e[102]=Ke):Ke=e[102];let oe;e[103]!==de||e[104]!==Ke?(oe=s.jsxs(ns,{children:[de,Ke]}),e[103]=de,e[104]=Ke,e[105]=oe):oe=e[105];let le;e[106]!==_||e[107]!==Pe||e[108]!==oe?(le=s.jsxs(Ut,{className:"max-w-md",children:[_,Pe,oe]}),e[106]=_,e[107]=Pe,e[108]=oe,e[109]=le):le=e[109];let xe;e[110]!==a||e[111]!==n||e[112]!==le?(xe=s.jsx(zt,{open:n,onOpenChange:a,children:le}),e[110]=a,e[111]=n,e[112]=le,e[113]=xe):xe=e[113];let De;e[114]!==I||e[115]!==F?(De=Ne=>{I&&(F({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:Ne,directoryOverride:I.directoryOverride??null}),S(!1))},e[114]=I,e[115]=F,e[116]=De):De=e[116];let Ve;e[117]!==w||e[118]!==x||e[119]!==De?(Ve=s.jsx(rb,{open:x,onOpenChange:S,conflicts:w,onConfirm:De}),e[117]=w,e[118]=x,e[119]=De,e[120]=Ve):Ve=e[120];let Be;return e[121]!==xe||e[122]!==Ve?(Be=s.jsxs(s.Fragment,{children:[xe,Ve]}),e[121]=xe,e[122]=Ve,e[123]=Be):Be=e[123],Be};function cb(t){return t.installSkills}function db(t){return t.isInstalling}function ub(t){return t.projects}function mb(t){return t.activeProjectId}function pb(t){return s.jsx(dt,{value:t.id,children:t.label||t.path},t.id)}const gb=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,fb=t=>{const e=t.trim();return gb.test(e)?`https://github.com/${e}`:null},hb=t=>{const e=fb(t.repoSource);if(!e)return null;const n=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return n?`${e}/tree/HEAD/${n}`:e};let Xi=null;const xb=t=>{const e=Io();return(!Xi||Xi.locale!==e)&&(Xi={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Xi.formatter.format(t)},bb=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const n=Date.now()-e;if(n<6e4)return{key:"common.relative.justNow",count:0};const a=Math.floor(n/6e4);if(a<60)return{key:"common.relative.minutesAgoShort",count:a};const i=Math.floor(a/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const o=Math.floor(i/24);if(o<7)return{key:"common.relative.daysAgoShort",count:o};const r=Math.floor(o/7);return r<52?{key:"common.relative.weeksAgoShort",count:r}:{key:"common.relative.yearsAgoShort",count:Math.floor(o/365)}},vb=t=>{const e=$e.c(50),{source:n,isActive:a,isLoading:i,skillsCount:o,onSelect:r,t:c}=t,l=n.stars??null;let m,u,f,p,g,h,j,x,S,b;if(e[0]!==a||e[1]!==i||e[2]!==r||e[3]!==o||e[4]!==n.label||e[5]!==n.repoUpdatedAt||e[6]!==n.source||e[7]!==l||e[8]!==c){const y=n.repoUpdatedAt?bb(n.repoUpdatedAt):null;x="button",S=r,b=a;const E=a?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==E?(u=je("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",E),e[19]=E,e[20]=u):u=e[20],g="min-w-0 flex-1 block";let v;e[21]!==n.label?(v=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:n.label}),e[21]=n.label,e[22]=v):v=e[22];let R;e[23]!==i||e[24]!==o||e[25]!==c?(R=i?s.jsx(J,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):o!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:c("settings.skills.catalog.page.source.skillsCount",{count:o})}),e[23]=i,e[24]=o,e[25]=c,e[26]=R):R=e[26],e[27]!==v||e[28]!==R?(h=s.jsxs("span",{className:"flex items-center gap-2",children:[v,R]}),e[27]=v,e[28]=R,e[29]=h):h=e[29],e[30]!==n.source?(j=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:n.source}),e[30]=n.source,e[31]=j):j=e[31],m="flex items-center gap-3 mt-1",e[32]!==l||e[33]!==c?(f=l!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:c("settings.skills.catalog.page.source.stars",{count:l}),children:[s.jsx(J,{name:"star",className:"h-3 w-3"}),xb(l)]}),e[32]=l,e[33]=c,e[34]=f):f=e[34],p=y&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:y.key==="common.relative.justNow"?c(y.key):c("settings.skills.catalog.page.source.updated",{time:c(y.key,{count:y.count})})}),e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=n.label,e[5]=n.repoUpdatedAt,e[6]=n.source,e[7]=l,e[8]=c,e[9]=m,e[10]=u,e[11]=f,e[12]=p,e[13]=g,e[14]=h,e[15]=j,e[16]=x,e[17]=S,e[18]=b}else m=e[9],u=e[10],f=e[11],p=e[12],g=e[13],h=e[14],j=e[15],x=e[16],S=e[17],b=e[18];let w;e[35]!==m||e[36]!==f||e[37]!==p?(w=s.jsxs("span",{className:m,children:[f,p]}),e[35]=m,e[36]=f,e[37]=p,e[38]=w):w=e[38];let k;e[39]!==w||e[40]!==g||e[41]!==h||e[42]!==j?(k=s.jsxs("span",{className:g,children:[h,j,w]}),e[39]=w,e[40]=g,e[41]=h,e[42]=j,e[43]=k):k=e[43];let I;return e[44]!==u||e[45]!==k||e[46]!==x||e[47]!==S||e[48]!==b?(I=s.jsx("button",{type:x,onClick:S,"aria-pressed":b,className:u,children:k}),e[44]=u,e[45]=k,e[46]=x,e[47]=S,e[48]=b,e[49]=I):I=e[49],I},yb=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=_e(),{sources:i,itemsBySource:o,selectedSourceId:r,setSelectedSource:c,loadCatalog:l,loadSource:m,isLoadingCatalog:u,isLoadingSource:f,loadedSourceIds:p,lastCatalogError:g}=Pn(Os(F=>({sources:F.sources,itemsBySource:F.itemsBySource,selectedSourceId:F.selectedSourceId,setSelectedSource:F.setSelectedSource,loadCatalog:F.loadCatalog,loadSource:F.loadSource,isLoadingCatalog:F.isLoadingCatalog,isLoadingSource:F.isLoadingSource,loadedSourceIds:F.loadedSourceIds,lastCatalogError:F.lastCatalogError}))),[h,j]=d.useState(""),[x,S]=d.useState(!1),[b,w]=d.useState(!1),[k,I]=d.useState(null),[y,E]=d.useState(!1),[v,R]=d.useState(!1),C=d.useRef(null);d.useEffect(()=>{l()},[l]),d.useEffect(()=>{const F=i.filter(G=>!p[G.id]);if(F.length===0)return;let H=!1;return(async()=>{for(const G of F){if(H)return;await m(G.id)}})(),()=>{H=!0}},[i,p,m]),d.useEffect(()=>{!r||p[r]||m(r)},[r,p,m]),d.useEffect(()=>{const F=H=>{(H.metaKey||H.ctrlKey)&&H.key.toLowerCase()==="k"&&(H.preventDefault(),C.current?.focus())};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const T=h.trim().length>0,P=d.useMemo(()=>T?Wn(i.flatMap(F=>o[F.id]||[]),h,F=>[F.skillName,F.frontmatterName,F.description]):r?o[r]||[]:[],[i,o,r,h,T]),L=d.useMemo(()=>i.find(F=>F.id===r)||null,[i,r]),O=!!(r&&r.startsWith("custom:")),A=async()=>{if(!(!r||!O)){E(!0);try{const F=await yn();if(!F)return;const W=(F.skillCatalogs??[]).filter(G=>G.id!==r);await bt({skillCatalogs:W}),await l({refresh:!0}),R(!1)}finally{E(!1)}}},N=T?a("settings.skills.catalog.page.list.searchTitle"):L?.label??"",M=!T&&r!==null&&!p[r]&&(f||u);return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:a("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[n&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(nl,{items:[{id:"manual",label:a("settings.skills.catalog.page.mode.manual")},{id:"external",label:a("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:F=>e(F),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:a("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(J,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{ref:C,value:h,onChange:F=>j(F.target.value),placeholder:a("settings.skills.catalog.page.searchAllPlaceholder"),className:je("h-8 pl-8 w-full",h&&"pr-8")}),h&&s.jsx("button",{type:"button",onClick:()=>{j(""),C.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:a("settings.skills.catalog.page.search.clear"),children:s.jsx(J,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(qe,{title:a("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(F=>s.jsx(vb,{source:F,isActive:F.id===r,isLoading:f&&!p[F.id],skillsCount:p[F.id]?(o[F.id]||[]).length:null,onSelect:()=>c(F.id),t:a},F.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>S(!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(J,{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:a("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:a("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),g&&s.jsx(qe,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:a("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:g.message})]})}),s.jsxs(qe,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:N}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:a("settings.skills.catalog.page.foundCount",{count:P.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{r&&!T?m(r,{refresh:!0}):l({refresh:!0})},disabled:u||f,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(J,{name:"refresh",className:je("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),O&&!T&&s.jsx(B,{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:y,title:a("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),M||f&&P.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(J,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:a("settings.skills.catalog.page.loading.skills")})]}):P.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:a("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:P.map(F=>{const H=F.installed?.isInstalled,W=F.installed?.scope,G=hb(F);return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:F.skillName}),H&&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:a("settings.skills.catalog.page.badge.installed",{scope:W||a("settings.skills.catalog.page.badge.unknown")})}),!F.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:a("settings.skills.catalog.page.badge.notInstallable")})]}),F.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:F.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:a("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:[G?s.jsxs("a",{href:G,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:a("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(J,{name:"github",className:"h-3 w-3 shrink-0"}),F.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:F.repoSource}),F.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:F.skillDir})]})]}),F.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:F.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[G&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(G,"_blank","noreferrer"),title:a("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(J,{name:"external-link",className:"h-3.5 w-3.5"})}),H?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:a("settings.skills.catalog.page.badge.installed",{scope:W||""}),children:s.jsx(J,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!F.installable,onClick:()=>{I(F),w(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})]})},`${F.sourceId}:${F.skillDir}`)})})]})]}),s.jsx(ob,{open:x,onOpenChange:S}),s.jsx(lb,{open:b,onOpenChange:w,item:k}),s.jsx(zt,{open:v,onOpenChange:F=>{y||R(F)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:a("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ht,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>R(!1),disabled:y,children:a("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{A()},disabled:y,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},jb=()=>{const t=$e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(yb,{mode:"external",onModeChange:Ib,showModeTabs:!1}),t[0]=e):e=t[0],e},kb="SKILL.md",wb="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",co=(t,e)=>{const n=$g({description:t}).trimEnd(),a=e.trimStart();return`---
23
- ${n}
24
- ---${a?`
25
-
26
- ${a}`:`
27
- `}`},Sb=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),fu=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let n=null;try{const a=_g(e[1]);if(Sb(a)){const i=a.description;typeof i=="string"&&(n=i)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Nb=(t,e)=>{const n=fu(t);return co(e,n.instructions)},Cb=()=>{const{t}=_e(),{currentTheme:e}=va(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:i,createSkill:o,updateSkill:r,skillDraft:c,setSkillDraft:l,setSelectedSkill:m}=tn(Os(ce=>({selectedSkillName:ce.selectedSkillName,getSkillByName:ce.getSkillByName,getSkillDetail:ce.getSkillDetail,createSkill:ce.createSkill,updateSkill:ce.updateSkill,skillDraft:ce.skillDraft,setSkillDraft:ce.setSkillDraft,setSelectedSkill:ce.setSelectedSkill}))),u=Zs(),f=tn(ce=>tl(ce,u)),p=n?a(n,u):null,g=!!(c&&c.name===n&&!p),h=!!(n&&!p&&!c),j=p?.path==="<built-in>";d.useEffect(()=>{h&&m(null)},[h,m]);const[x,S]=d.useState(""),[b,w]=d.useState("user"),[k,I]=d.useState("opencode"),[y,E]=d.useState(""),[v,R]=d.useState(""),[C,T]=d.useState(!1),[P,L]=d.useState(()=>co("","")),[O,A]=d.useState("edit"),[N,M]=d.useState([]),[F,H]=d.useState([]),[W,G]=d.useState(!1),[$,z]=d.useState(!1),[U,_]=d.useState(""),[V,Z]=d.useState(""),[Y,Q]=d.useState(!1),[ue,ge]=d.useState(!1),[fe,Ie]=d.useState(""),[te,Ce]=d.useState(""),[ie,ae]=d.useState(null),[re,ye]=d.useState(!1),[Ee,Pe]=d.useState(""),[ke,Te]=d.useState(null),[de,Me]=d.useState(!1),Se=ie?te!==Ee:fe.trim()!=="",Le=d.useCallback(ce=>{switch(ce){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]),Ke=d.useCallback(ce=>{switch(ce){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]),oe=JSON.stringify([u,n,p?.path,g]),le=d.useRef(null),xe=d.useRef({key:oe,markdown:P,disableModelInvocation:C});xe.current={key:oe,markdown:P,disableModelInvocation:C};const De=d.useRef(""),Ve=d.useRef(!1);d.useEffect(()=>{let ce=!1;const Oe=(nt,at,vt)=>{if(xe.current.key!==oe)return;const kt=co(nt,at),xt=le.current===oe,It=xt&&xe.current.markdown!==De.current,_t=xt&&xe.current.disableModelInvocation!==Ve.current;le.current=oe,De.current=kt,Ve.current=vt,It||(E(nt),R(at),L(kt)),_t||T(vt)};return(async()=>{if(g&&c){z(!1);const nt=c.description||"",at=c.instructions||"";S(c.name||""),w(c.scope||"user"),I(c.source==="agents"?"agents":"opencode"),Oe(nt,at,!1),_(""),Z(""),Q(!1),M([]),H(c.pendingFiles||[])}else if(n&&p){z(le.current!==oe);try{const nt=await i(n,u);if(!ce&&xe.current.key===oe&&nt){const at=nt.sources.md,vt=at.description||"",kt=at.instructions||"",xt=at.disableModelInvocation===!0;Oe(vt,kt,xt),_(vt),Z(kt),Q(xt),M(at.supportingFiles||[])}}catch(nt){console.error("Failed to load skill details:",nt)}finally{ce||z(!1)}}})(),()=>{ce=!0}},[p,g,n,u,f,c,i,oe]);const Be=ne(ce=>ce.editorFontSize),Ne=d.useMemo(()=>{const ce=[ec(e,{fontSize:Be})],Oe=Ml(kb);return Oe&&ce.push(Oe),ce.push(sc.lineWrapping),ce},[e,Be]),Je=d.useMemo(()=>{const ce=fe.trim()||"supporting-file.md",Oe=jm(ce),We=!!Oe&&Oe!=="markdown",nt=[ec(e,We?{syntaxColors:!1,fontSize:Be}:{fontSize:Be})],at=Ml(ce);return at&&nt.push(at),We&&Oe&&nt.push(Bg({language:Oe,themeName:e.metadata.id,theme:Hg(e)})),nt.push(sc.lineWrapping),nt},[e,fe,Be]),ut=d.useCallback(ce=>{E(ce),L(Oe=>Nb(Oe,ce))},[]),ht=d.useCallback(ce=>{L(ce);const Oe=fu(ce);E(Oe.description??""),R(Oe.instructions)},[]),st=ce=>ce?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ce)||ce.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),jt=d.useCallback(async()=>{const ce=n?.trim();return g||j||!ce||y===U&&v===V&&C===Y?Ls:y.trim()?await r(ce,{name:ce,description:y.trim(),instructions:v.trim()||void 0,targetPath:p?.path,disableModelInvocation:C},u)?(xe.current.key===oe&&(De.current=co(y,v),Ve.current=C,_(y),Z(v),Q(C)),vn):fs(t("settings.skills.page.toast.updateSkillFailed")):fs(t("settings.skills.page.toast.descriptionRequired"))},[y,v,C,g,j,U,V,Y,p?.path,n,u,oe,t,r]),St=ei(jt),Ze=ce=>{T(ce),g||St.requestSave()},it=async()=>{const ce=x.trim().replace(/\s+/g,"-").toLowerCase(),Oe=st(ce);if(Oe){q.error(Oe);return}if(!y.trim()){q.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f.some(We=>We.name===ce)){q.error(t("settings.skills.page.toast.skillExists"));return}G(!0);try{const We={name:ce,description:y.trim(),instructions:v.trim()||void 0,scope:b,source:k,supportingFiles:F.length>0?F:void 0,disableModelInvocation:C};await o(We,u)?(l(null),H([]),m(ce),q.success(t("settings.skills.page.toast.skillCreated"))):q.error(t("settings.skills.page.toast.createSkillFailed"))}catch(We){console.error("Error creating skill:",We),q.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{G(!1)}},et=()=>{l(null),m(null)},mt=()=>{ae(null),Ie(""),Ce(""),Pe(""),ge(!0)},ft=async ce=>{if(ae(ce),Ie(ce),g){const We=F.find(nt=>nt.path===ce)?.content||"";Ce(We),Pe(We),ge(!0);return}if(n){ye(!0),ge(!0);try{const{readSupportingFile:Oe}=tn.getState(),We=await Oe(n,ce,u);Ce(We||""),Pe(We||"")}catch{q.error(t("settings.skills.page.toast.loadFileContentFailed")),Ce(""),Pe("")}finally{ye(!1)}}},be=async()=>{if(!fe.trim()){q.error(t("settings.skills.page.toast.fileNameRequired"));return}const ce=fe.trim(),Oe=ie!==null;if(g){if(Oe)H(at=>at.map(vt=>vt.path===ie?{path:ce,content:te}:vt)),q.success(t("settings.skills.page.toast.fileUpdated",{path:ce}));else{if(F.some(at=>at.path===ce)){q.error(t("settings.skills.page.toast.fileExists"));return}H(at=>[...at,{path:ce,content:te}]),q.success(t("settings.skills.page.toast.fileAdded",{path:ce}))}ge(!1),ae(null);return}if(!n){q.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:We}=tn.getState();if(await We(n,ce,te,u)){q.success(Oe?t("settings.skills.page.toast.fileUpdated",{path:ce}):t("settings.skills.page.toast.fileCreated",{path:ce})),ge(!1),ae(null);const at=await i(n,u);at&&M(at.sources.md.supportingFiles||[])}else q.error(t(Oe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Re=ce=>{if(g){H(Oe=>Oe.filter(We=>We.path!==ce)),q.success(t("settings.skills.page.toast.fileRemoved",{path:ce}));return}n&&Te(ce)},X=async()=>{if(!ke||!n)return;Me(!0);const{deleteSupportingFile:ce}=tn.getState();if(await ce(n,ke,u)){q.success(t("settings.skills.page.toast.fileDeleted",{path:ke}));const We=await i(n,u);We&&M(We.sources.md.supportingFiles||[]),Te(null)}else q.error(t("settings.skills.page.toast.deleteFileFailed"));Me(!1)};return!n&&!c||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(J,{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")})]})}):$?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(es,{title:g?t("settings.skills.page.title.newSkill"):n,description:p?t("settings.skills.page.subtitle.skillLocation",{location:Le(wi(p.scope,p.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:St.onBlurCapture,children:[s.jsxs(qe,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[g&&s.jsxs(yt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:x,onChange:ce=>S(ce.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Dt,{value:wi(b,k),onValueChange:ce=>{const Oe=gu(ce);w(Oe.scope),I(Oe.source==="agents"?"agents":"opencode")},children:[s.jsxs(Tt,{size:qt,className:"w-fit gap-1.5",children:[b==="user"?s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),k==="agents"?s.jsx(J,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Le(wi(b,k))})]}),s.jsx(Et,{align:"start",children:jl.map(ce=>s.jsx(dt,{value:ce.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ce.scope==="user"?s.jsx(J,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"folder",className:"h-3.5 w-3.5"}),ce.source==="agents"?s.jsx(J,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Le(ce.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ke(ce.value)})]})},ce.value))})]})]}),s.jsx(Rt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Ts,{value:y,onChange:ce=>ut(ce.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:j})}),s.jsx(ct,{checked:C,onChange:Ze,label:t("settings.skills.page.field.disableModelInvocation"),info:t("settings.skills.page.field.disableModelInvocationHint"),disabled:j,className:"pt-2"})]}),s.jsx(qe,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Vg,{currentMode:O==="preview"?"preview":"edit",onToggle:()=>A(ce=>ce==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:je("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",wb),onKeyDown:ce=>{ce.key==="Enter"&&(ce.metaKey||ce.ctrlKey)&&(ce.preventDefault(),St.requestSave())},children:O==="preview"?s.jsx(js,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(km,{content:P,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(tc,{value:P,onChange:ht,readOnly:j,extensions:Ne,className:"h-full",enableSearch:!0})})}),s.jsx(qe,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:mt,disabled:j,children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const ce=g?F:N;return ce.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:ce.map(Oe=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ft(Oe.path),children:[s.jsx(J,{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:Oe.path}),g&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!j&&s.jsx(B,{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(),Re(Oe.path)},children:s.jsx(J,{name:"delete-bin",className:"h-3 w-3"})})]},Oe.path))})})()}),g&&s.jsx(qe,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{onClick:()=>{it()},disabled:W||!x.trim()||!y.trim(),size:"xs",className:"!font-normal",children:t(W?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(B,{variant:"ghost",onClick:et,disabled:W,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(zt,{open:ke!==null,onOpenChange:ce=>{!ce&&!de&&Te(null)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.description",{path:ke??""})})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>Te(null),disabled:de,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:X,disabled:de,children:t("settings.common.actions.delete")})]})]})}),s.jsx(zt,{open:ue,onOpenChange:ce=>{if(ce){ge(!0);return}if(ie!==null&&te!==Ee){be();return}ge(!1),ae(null)},children:s.jsxs(Ut,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Bt,{className:"flex-shrink-0",children:[s.jsx(Vt,{children:t(ie?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ht,{children:t(ie?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),re?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:Pt,children:t("settings.skills.page.fileDialog.field.filePath")}),!ie&&s.jsx(Wt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:fe,onChange:ce=>Ie(ce.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:ie!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Pt} 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(tc,{value:te,onChange:Ce,extensions:Je,className:"h-full",enableSearch:!0})})]})]}),s.jsx(ns,{className:"mt-4",children:ie?s.jsx(B,{size:"sm",onClick:()=>{be()},disabled:re,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{ge(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:()=>{be()},disabled:re||!Se,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},yc=t=>{const e=$e.c(2),{view:n}=t,a=n===void 0?"installed":n;let i;return e[0]!==a?(i=a==="catalog"?s.jsx(jb,{}):s.jsx(Cb,{}),e[0]=a,e[1]=i):i=e[1],i};function Ib(){}const Pb=t=>{const e=$e.c(26),{header:n,footer:a,children:i,className:o,variant:r}=t,c=r===void 0?"sidebar":r,l=os(),m=d.useRef(null),[u,f]=d.useState(!1),[p,g]=d.useState(!1),h=c==="background"||l?"bg-background":"bg-sidebar",j=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const P=m.current;if(!P){f(!1),g(!1);return}if(!(P.scrollHeight>P.clientHeight+1)){f(!1),g(!1);return}f(P.scrollTop>1),g(P.scrollTop+P.clientHeight<P.scrollHeight-1)},e[0]=x):x=e[0];const S=x;let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{S()},e[1]=b):b=e[1];let w;e[2]!==i?(w=[i,S],e[2]=i,e[3]=w):w=e[3],d.useEffect(b,w);let k,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const P=m.current;if(!P)return;const L=()=>S();return P.addEventListener("scroll",L,{passive:!0}),()=>P.removeEventListener("scroll",L)},I=[S],e[4]=k,e[5]=I):(k=e[4],I=e[5]),d.useEffect(k,I);let y;e[6]!==h||e[7]!==o?(y=je("flex h-full flex-col",h,o),e[6]=h,e[7]=o,e[8]=y):y=e[8];let E;e[9]!==i?(E=s.jsx(js,{ref:m,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=E):E=e[10];let v;e[11]!==j||e[12]!==u?(v=u&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${j} 0%, transparent 100%)`}}),e[11]=j,e[12]=u,e[13]=v):v=e[13];let R;e[14]!==j||e[15]!==p?(R=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${j} 0%, transparent 100%)`}}),e[14]=j,e[15]=p,e[16]=R):R=e[16];let C;e[17]!==R||e[18]!==E||e[19]!==v?(C=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[E,v,R]}),e[17]=R,e[18]=E,e[19]=v,e[20]=C):C=e[20];let T;return e[21]!==a||e[22]!==n||e[23]!==C||e[24]!==y?(T=s.jsxs("div",{className:y,children:[n,C,a]}),e[21]=a,e[22]=n,e[23]=C,e[24]=y,e[25]=T):T=e[25],T},Ab=t=>{const e=$e.c(23),{title:n,metadata:a,selected:i,onSelect:o,icon:r,actions:c,className:l}=t,m=i===void 0?!1:i,u=c&&c.length>0,f=m?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==l||e[1]!==f?(p=je("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",f,l),e[0]=l,e[1]=f,e[2]=p):p=e[2];let g;e[3]!==n?(g=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,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 j;e[8]!==a?(j=a&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=j):j=e[9];let x;e[10]!==o||e[11]!==h||e[12]!==j?(x=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:[h,j]}),e[10]=o,e[11]=h,e[12]=j,e[13]=x):x=e[13];let S;e[14]!==c||e[15]!==u?(S=u&&s.jsxs(Kn,{children:[s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(On,{align:"end",className:"w-fit min-w-20",children:c.map(Tb)})]}),e[14]=c,e[15]=u,e[16]=S):S=e[16];let b;e[17]!==x||e[18]!==S?(b=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,S]}),e[17]=x,e[18]=S,e[19]=b):b=e[19];let w;return e[20]!==p||e[21]!==b?(w=s.jsx("div",{className:p,children:b}),e[20]=p,e[21]=b,e[22]=w):w=e[22],w};function Tb(t){const e=t.icon;return s.jsxs(mn,{onClick:n=>{n.stopPropagation(),t.onClick()},className:je(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(J,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Eb=t=>{const e=$e.c(38),{onItemSelect:n}=t,{t:a}=_e(),i=un(Db),o=ne(Mb),r=ne(Rb),{currentTheme:c}=va();let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=os(),e[0]=l):l=e[0];const m=l,u=Lb;let f,p;e[1]!==i||e[2]!==o||e[3]!==r?(f=()=>{if(i.length===0){o!==null&&r(null);return}o&&i.some(E=>E.id===o)||r(i[0].id)},p=[i,o,r],e[1]=i,e[2]=o,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=je("border-b px-3","pt-4 pb-3"),e[6]=g):g=e[6];let h;e[7]!==a?(h=a("settings.page.projects.title"),e[7]=a,e[8]=h):h=e[8];let j;e[9]!==h?(j=s.jsx("h2",{className:`${ya} mb-3`,children:h}),e[9]=h,e[10]=j):j=e[10];let x;e[11]!==i.length||e[12]!==a?(x=a("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=a,e[13]=x):x=e[13];let S;e[14]!==x?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=S):S=e[15];let b;e[16]!==a?(b=!m&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:u,"aria-label":a("settings.projects.sidebar.actions.addProject"),children:s.jsx(J,{name:"add",className:"size-4"})}),e[16]=a,e[17]=b):b=e[17];let w;e[18]!==S||e[19]!==b?(w=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,b]}),e[18]=S,e[19]=b,e[20]=w):w=e[20];let k;e[21]!==w||e[22]!==j?(k=s.jsxs("div",{className:g,children:[j,w]}),e[21]=w,e[22]=j,e[23]=k):k=e[23];let I;if(e[24]!==c||e[25]!==n||e[26]!==i||e[27]!==o||e[28]!==r){let E;e[30]!==c||e[31]!==n||e[32]!==o||e[33]!==r?(E=v=>{const R=v.id===o,C=v.icon?Sm[v.icon]:null,T=v.color?Nm[v.color]??null:null,P=C?s.jsx(J,{name:C,className:je("h-4 w-4",R?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}):s.jsx(J,{name:"folder",className:je("h-4 w-4",R?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}),L=v.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:v.iconBackground?{backgroundColor:v.iconBackground}:void 0,children:s.jsx(Cm,{project:v,options:{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground},className:"h-full w-full object-contain",fallback:P})}):P;return s.jsx(Ab,{title:v.label||v.path,icon:L,selected:R,onSelect:()=>{r(v.id),n?.()}},v.id)},e[30]=c,e[31]=n,e[32]=o,e[33]=r,e[34]=E):E=e[34],I=i.map(E),e[24]=c,e[25]=n,e[26]=i,e[27]=o,e[28]=r,e[29]=I}else I=e[29];let y;return e[35]!==k||e[36]!==I?(y=s.jsx(Pb,{variant:"background",header:k,children:I}),e[35]=k,e[36]=I,e[37]=y):y=e[37],y};function Db(t){return t.projects}function Mb(t){return t.settingsProjectsSelectedId}function Rb(t){return t.setSettingsProjectsSelectedId}function Lb(){wm.requestDirectoryDialog()}const Ob=()=>{const t=$e.c(30),{t:e}=_e(),n=un(Fb),a=un(Kb),i=ne(zb),o=ne(Ub);let r;e:{if(!i){r=null;break e}let x;t[0]!==n||t[1]!==i?(x=n.find(S=>S.id===i)??null,t[0]=n,t[1]=i,t[2]=x):x=t[2],r=x}const c=r;let l,m;t[3]!==n||t[4]!==i||t[5]!==o?(l=()=>{if(n.length===0){o(null);return}i&&n.some(x=>x.id===i)||o(n[0].id)},m=[n,i,o],t[3]=n,t[4]=i,t[5]=o,t[6]=l,t[7]=m):(l=t[6],m=t[7]),d.useEffect(l,m);let u;t[8]!==c||t[9]!==a?(u=async x=>{c&&a(c.id,{label:x.label,icon:x.icon,color:x.color,iconBackground:x.iconBackground,defaultAgent:x.defaultAgent??null,defaultModel:x.defaultModel??null,defaultVariant:x.defaultVariant??null})},t[8]=c,t[9]=a,t[10]=u):u=t[10];const f=u;if(!c){let x;t[11]!==e?(x=e("settings.page.projects.title"),t[11]=e,t[12]=x):x=t[12];let S;t[13]!==e?(S=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=S):S=t[14];let b;t[15]!==S?(b=s.jsx("p",{className:"typography-meta text-muted-foreground",children:S}),t[15]=S,t[16]=b):b=t[16];let w;return t[17]!==x||t[18]!==b?(w=s.jsx(es,{title:x,showSaveStatus:!0,children:b}),t[17]=x,t[18]=b,t[19]=w):w=t[19],w}let p;t[20]!==c.label||t[21]!==e?(p=c.label??e("settings.projects.page.title.default"),t[20]=c.label,t[21]=e,t[22]=p):p=t[22];const g=p;let h;t[23]!==f||t[24]!==c?(h=s.jsx(Mg,{project:c,onIdentitySave:f}),t[23]=f,t[24]=c,t[25]=h):h=t[25];let j;return t[26]!==g||t[27]!==c.path||t[28]!==h?(j=s.jsx(es,{title:g,description:c.path,showSaveStatus:!0,outerClassName:"bg-background",children:h}),t[26]=g,t[27]=c.path,t[28]=h,t[29]=j):j=t[29],j};function Fb(t){return t.projects}function Kb(t){return t.updateProjectMeta}function zb(t){return t.settingsProjectsSelectedId}function Ub(t){return t.setSettingsProjectsSelectedId}const $b=rs({clientToken:Nt().trim().min(1)}),_b=rs({error:Pg("Invalid or expired pairing session")}),Bb=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&_b.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const n=$b.safeParse(e);return n.success?{kind:"success",token:n.data.clientToken}:{kind:"invalid-response"}};function Vb(t){const e=$e.c(42),{t:n}=_e(),[a,i]=Ge.useState(null),o=Ge.useRef(null),r=Ge.useRef(null);let c,l;e[0]!==t?(c=()=>(r.current=t,i(null),()=>{r.current=null;const A=o.current;o.current=null,A?.(null)}),l=[t],e[0]=t,e[1]=c,e[2]=l):(c=e[1],l=e[2]),Ge.useEffect(c,l);let m;e[3]!==t?(m=(A,N)=>{const M=N===void 0?"settings.common.actions.saveChanges":N;return!t||r.current!==t||o.current?Promise.resolve(null):new Promise(F=>{o.current=F,i({messageKey:A,actionKey:M})})},e[3]=t,e[4]=m):m=e[4];const u=m;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=A=>{const N=o.current;o.current=null,i(null),N?.(A)},e[5]=f):f=e[5];const p=f,g=a!==null;let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=A=>{A||p(!1)},e[6]=h):h=e[6];let j;e[7]!==n?(j=n("settings.remoteInstances.page.title"),e[7]=n,e[8]=j):j=e[8];let x;e[9]!==j?(x=s.jsx(Vt,{children:j}),e[9]=j,e[10]=x):x=e[10];let S;e[11]!==a||e[12]!==n?(S=a?n(a.messageKey):null,e[11]=a,e[12]=n,e[13]=S):S=e[13];let b;e[14]!==S?(b=s.jsx(Ht,{children:S}),e[14]=S,e[15]=b):b=e[15];let w;e[16]!==x||e[17]!==b?(w=s.jsxs(Bt,{children:[x,b]}),e[16]=x,e[17]=b,e[18]=w):w=e[18];let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=()=>p(!1),e[19]=k):k=e[19];let I;e[20]!==n?(I=n("settings.common.actions.cancel"),e[20]=n,e[21]=I):I=e[21];let y;e[22]!==I?(y=s.jsx(B,{variant:"outline",autoFocus:!0,onClick:k,children:I}),e[22]=I,e[23]=y):y=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=()=>p(!0),e[24]=E):E=e[24];let v;e[25]!==a||e[26]!==n?(v=a?n(a.actionKey):null,e[25]=a,e[26]=n,e[27]=v):v=e[27];let R;e[28]!==v?(R=s.jsx(B,{onClick:E,children:v}),e[28]=v,e[29]=R):R=e[29];let C;e[30]!==y||e[31]!==R?(C=s.jsxs(ns,{children:[y,R]}),e[30]=y,e[31]=R,e[32]=C):C=e[32];let T;e[33]!==w||e[34]!==C?(T=s.jsxs(Ut,{children:[w,C]}),e[33]=w,e[34]=C,e[35]=T):T=e[35];let P;e[36]!==T||e[37]!==g?(P=s.jsx(zt,{open:g,onOpenChange:h,children:T}),e[36]=T,e[37]=g,e[38]=P):P=e[38];const L=P;let O;return e[39]!==u||e[40]!==L?(O={confirm:u,dialog:L},e[39]=u,e[40]=L,e[41]=O):O=e[41],O}const uo=()=>Math.floor(2e4+Math.random()*3e4),Hb=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")},qb=()=>{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"},jc=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}},kc=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"}},Wb=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),kl=t=>!!(t&&Wb.has(t)),wc=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||kl(t)?"connecting":"idle",Sc=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"}},Gb=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},Nc={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Jb=t=>t==="noRuntime"?Nc.noRuntime:t==="noOpencode"?Nc.noOpencode:null,Cc=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",Qb=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}`,Yb=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:uo(),remoteHost:"127.0.0.1",remotePort:80}),Zb=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",en=t=>{const e=$e.c(7),{label:n,hint:a}=t;let i;e[0]!==n?(i=s.jsx("span",{children:n}),e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a?(o=s.jsx(Wt,{contentClassName:"max-w-xs",children:a}),e[2]=a,e[3]=o):o=e[3];let r;return e[4]!==i||e[5]!==o?(r=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Pt}`,children:[i,o]}),e[4]=i,e[5]=o,e[6]=r):r=e[6],r},Xb=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"}},Ic=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},ev=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},tv=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const n=Number(e[1]),a=Number.isFinite(n)?new Date(n).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),o=e[3]||"";return`[${a}] [${i}] ${o}`},Wr=(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}),sv=t=>t.trim().toLowerCase()==="authorization",hr=t=>{const e={};for(const n of t){const a=n.name.trim(),i=n.value.trim();a&&i&&!sv(a)&&(e[a]=i)}return Object.keys(e).length>0?e:void 0},nv=t=>Object.entries(t||{}).map(([e,n])=>Wr(e,n)),hu=()=>{if(typeof window>"u")return null;const e=Ii()||window.location.href;try{const n=Number(new URL(e).port||window.location.port);return Number.isFinite(n)&&n>0?n:null}catch{const n=Number(window.location.port);return Number.isFinite(n)&&n>0?n:null}},Pc=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},av=async()=>{const t=da(Ii())||window.location.origin;if(!cs()||!Xa()||(await yn())?.desktopLanAccessActive!==!0)return t;const n=await Wd(),a=hu();return!n||!a?t:`http://${n}:${a}`},Ac=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},iv=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),a=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...n?{nickname:n}:{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:a}},ov=()=>{const{t}=_e(),e=ne(K=>K.timeFormatPreference),{clientAuth:n}=Za(),a=cs(),i=Is(K=>K.instances),o=Is(K=>K.statusesById),r=Is(K=>K.importCandidates),c=Is(K=>K.isLoading),l=Is(K=>K.isImportsLoading),m=Is(K=>K.isSaving),u=Is(K=>K.error),f=Is(K=>K.load),p=Is(K=>K.loadImports),g=Is(K=>K.refreshStatuses),h=Is(K=>K.upsertInstance),j=Is(K=>K.createFromCommand),x=Is(K=>K.removeInstance),S=Is(K=>K.connect),b=Is(K=>K.disconnect),w=Is(K=>K.retry),k=ne(K=>K.settingsRemoteInstancesSelectedId),I=ne(K=>K.setSettingsRemoteInstancesSelectedId),y=ne(K=>K.setSettingsDialogOpen),{confirm:E,dialog:v}=Vb(k),R=d.useMemo(()=>k&&i.find(K=>K.id===k)||null,[i,k]),[C,T]=d.useState(null),[P,L]=d.useState(!1),[O,A]=d.useState(!1),[N,M]=d.useState(null),[F,H]=d.useState([]),[W,G]=d.useState(null),[$,z]=d.useState(""),[U,_]=d.useState(!1),[V,Z]=d.useState({}),[Y,Q]=d.useState(!1),[ue,ge]=d.useState(!1),[fe,Ie]=d.useState(()=>Date.now()),[te,Ce]=d.useState([]),[ie,ae]=d.useState({}),[re,ye]=d.useState("local"),[Ee,Pe]=d.useState(!1),[ke,Te]=d.useState(!1),[de,Me]=d.useState(""),[Se,Le]=d.useState(""),[Ke,oe]=d.useState(""),[le,xe]=d.useState([]),[De,Ve]=d.useState(""),[Be,Ne]=d.useState(null),[Je,ut]=d.useState(!1),[ht,st]=d.useState(!1),[jt,St]=d.useState(!1),[Ze,it]=d.useState(null),[et,mt]=d.useState(""),[ft,be]=d.useState(""),[Re,X]=d.useState(""),[ce,Oe]=d.useState([]),[We,nt]=d.useState([]),[at,vt]=d.useState([]),[kt,xt]=d.useState(!1),[It,_t]=d.useState(""),[Ye,Xe]=d.useState(null),[gt,Ue]=d.useState(null),[ee,ve]=d.useState(null),[Fe,se]=d.useState(null),[Ae,tt]=d.useState(!1),[ot,At]=d.useState(!1),[pe,we]=d.useState("configure"),[ze,pt]=d.useState(!1),[Ct,Gt]=d.useState("relay"),[Zt,as]=d.useState(!0),[Jt,Es]=d.useState(null),pn=Ni(K=>K.networkAccessBlocked),Un=!Jt||Jt.lanUrl?t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"):cs()?Xa()?t(pn?"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"),Ro=d.useMemo(()=>We.filter(K=>!!K.revokedAt).length,[We]),[Lo,$n]=d.useState(!1),[Ei,ti]=d.useState("saved"),[ja,Di]=d.useState(""),[Yn,Mi]=d.useState(""),[si,Ri]=d.useState(""),[Zn,jn]=d.useState(!1);d.useEffect(()=>{f(),p()},[f,p]);const Li=d.useCallback(async()=>{Pe(!0),Ne(null);try{const K=await cr();Ce(K.hosts||[]),ye(K.defaultHostId||"local")}catch(K){Ne(K instanceof Error?K.message:String(K))}finally{Pe(!1)}},[]);d.useEffect(()=>{Li()},[Li]);const Fs=d.useCallback(async(K,me=re)=>{Te(!0),Ne(null);try{return await $l({hosts:K,defaultHostId:me,initialHostChoiceCompleted:!0}),Ce(K),ye(me),!0}catch(Qe){return Ne(Qe instanceof Error?Qe.message:String(Qe)),!1}finally{Te(!1)}},[re]),Oi=d.useCallback(async()=>{const K=_l(Se);if(!K){Ne(t("desktopHostSwitcher.error.invalidUrl"));return}const me=K.persistedUrl,lt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:de.trim()||ri(me),url:me,apiUrl:me,...Ke.trim()?{clientToken:Ke.trim()}:{},...hr(le)?{requestHeaders:hr(le)}:{}};await Fs([lt,...te],re)&&(Me(""),Le(""),oe(""),xe([]),ut(!1),K.redeemUrl&&Ac(K.redeemUrl))},[re,le,te,de,Ke,Se,Fs,t]),Oo=d.useCallback(async()=>{Ne(null);const K=Gp(De);if(!K){Ne(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const me=await Jp().catch(()=>""),Qe=JSON.stringify({pairingId:K.pairingId,secret:K.secret,clientLabel:K.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:qb(),...me?{dedupeKey:`desktop:${me}`}:{}}),lt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Qe};let Kt=null;const Ns=async Yt=>{const Cs=await Bb(Yt);switch(Cs.kind){case"success":return Cs.token;case"rejected":Kt=t("desktopHostSwitcher.error.pairingRejected");break;case"http-error":Kt??=t("desktopHostSwitcher.error.pairingFailed",{status:Cs.status});break;case"invalid-response":Kt??=t("desktopHostSwitcher.error.pairingInvalidResponse");break}return null},_s=[...K.candidates].sort((Yt,Cs)=>(Yt.type==="relay"?1:0)-(Cs.type==="relay"?1:0));let us=null;for(const Yt of _s){if(Yt.type==="relay"){const Da=Qp({relayUrl:Yt.relayUrl,serverId:Yt.serverId,hostEncPubJwk:Yt.hostEncPubJwk,...Yt.grant?{grant:Yt.grant}:{}});try{const Ma=await Da.fetch("/api/client-auth/pairing/redeem",{...lt,signal:AbortSignal.timeout(15e3)}),Vi=await Ns(Ma);if(Vi){us={kind:"relay",relay:{relayUrl:Yt.relayUrl,serverId:Yt.serverId,hostEncPubJwk:Yt.hostEncPubJwk},token:Vi};break}}catch{}finally{Da.close()}continue}const Cs=da(Yt.url);if(Cs)try{const Da=await fetch(`${Cs}/api/client-auth/pairing/redeem`,{...lt,signal:AbortSignal.timeout(15e3)}),Ma=await Ns(Da);if(Ma){us={kind:"direct",url:Cs,token:Ma};break}}catch{}}if(!us){Ne(Kt||t("mobile.connect.error.unreachable"));return}const Ds=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,wn=K.candidates.find(Yt=>Yt.type==="relay"),Bs=us.kind==="relay"?us.relay:wn?{relayUrl:wn.relayUrl,serverId:wn.serverId,hostEncPubJwk:wn.hostEncPubJwk}:void 0,an=K.candidates.filter(Yt=>Yt.type!=="relay").map(Yt=>da(Yt.url)).find(Yt=>!!Yt),on=us.kind==="direct"?us.url:an,{token:Ot}=us,ts=on||(Bs?Yp(Bs.serverId):null);if(!ts){Ne(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const Sn={url:ts,apiUrl:on||void 0,clientToken:Ot,...Bs?{relay:Bs}:{}},Bn=te.find(Yt=>Bs?Yt.relay?.serverId===Bs.serverId:!Yt.relay&&da(Yt.apiUrl||Yt.url)===ts);if(Bn){const Yt=te.map(Cs=>Cs.id===Bn.id?{...Cs,label:K.label||Cs.label,...Sn}:Cs);if(!await Fs(Yt,re))return}else if(!await Fs([{id:Ds(),label:K.label||ri(ts),...Sn},...te],re))return;Ve(""),Ne(null),st(!1)},[De,re,te,Fs,t]),Fo=d.useCallback(async K=>{const me=te.filter(lt=>lt.id!==K);await Fs(me,re===K?"local":re)&&Ze===K&&it(null)},[re,Ze,te,Fs]),ni=d.useCallback(K=>{it(K.id),mt(K.label),be(K.apiUrl||K.url),X(K.clientToken||""),Oe(nv(K.requestHeaders)),Ne(null)},[]),ai=d.useCallback(async()=>{if(!Ze)return;const K=_l(ft);if(!K){Ne(t("desktopHostSwitcher.error.invalidUrl"));return}const me=K.persistedUrl,Qe=te.map(lt=>lt.id===Ze?{...lt,label:et.trim()||ri(me),url:me,apiUrl:me,clientToken:Re.trim()||void 0,requestHeaders:hr(ce)}:lt);await Fs(Qe,re)&&(it(null),K.redeemUrl&&Ac(K.redeemUrl))},[re,ce,et,Re,ft,Ze,te,Fs,t]),Ko=d.useCallback(async()=>{const K=Yn.trim();if(!K){q.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const me=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await j(me,K,si.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(me),$n(!1),Mi(""),Ri(""),q.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Qe){q.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)})}},[j,I,Yn,si,t]),zo=d.useCallback(()=>{Di(""),ti(r.length>0?"saved":"manual"),$n(!0)},[r.length]),Uo=d.useCallback(async K=>{await Fs(te,K)},[te,Fs]);d.useEffect(()=>{if(!a||te.length===0)return;let K=!1;return Promise.all(te.map(async me=>{const Qe=()=>sg(me.relay,{clientToken:me.clientToken||null,requestHeaders:me.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(me.relay&&!me.apiUrl)return[me.id,await Qe()];const lt=da(Bl(me));if(!lt)return[me.id,me.relay?await Qe():{status:"unreachable",latencyMs:0}];const Kt=await Zp(lt,{clientToken:me.clientToken||null,requestHeaders:me.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Kt.status==="unreachable"&&me.relay){const Ns=await Qe();if(Ns.status==="ok")return[me.id,Ns]}return[me.id,Kt]})).then(me=>{K||ae(Object.fromEntries(me))}),()=>{K=!0}},[te,a]);const $s=d.useCallback(async K=>{if(n){K?.silent||xt(!0),K?.silent||Xe(null);try{const[me,Qe]=await Promise.all([n.listClients(),n.listPendingPairings().catch(()=>null)]);nt(me),Qe&&vt(Qe)}catch(me){K?.silent||Xe(me instanceof Error?me.message:String(me))}finally{K?.silent||xt(!1)}}},[n]),ii=d.useRef(!1);d.useEffect(()=>{if(!(!ot||pe!=="result"||!ee)){if(at.some(K=>K.id===ee)){ii.current=!0;return}ii.current&&(ve(null),At(!1),We.some(K=>K.pairingId===ee)&&q.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[ot,pe,ee,at,We,t]);const $o=d.useCallback(async K=>{if(n)try{await n.cancelPairing(K),vt(me=>me.filter(Qe=>Qe.id!==K)),await $s({silent:!0})}catch(me){Xe(me instanceof Error?me.message:String(me))}},[n,$s]);d.useEffect(()=>{if(!n)return;$s();const K=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||$s({silent:!0})},5e3);return()=>window.clearInterval(K)},[n,$s]);const Fi=d.useCallback(async()=>{if(n?.getPairingTransports)try{const lt=await n.getPairingTransports();return{localUrl:lt.local,lanUrl:lt.lan,relayAvailable:lt.relayAvailable}}catch{}const K=hu(),me=K?`http://127.0.0.1:${K}`:Pc(window.location.origin)?window.location.origin:null;let Qe=null;try{const lt=da(await av());Qe=lt&&!Pc(lt)?lt:null}catch{}return{localUrl:me,lanUrl:Qe,relayAvailable:!0}},[n]),Ki=d.useCallback(async()=>{Xe(null),Ue(null),se(null),tt(!1),ve(null),we("configure"),as(!0),At(!0);const K=await Fi();Es(K),Gt(K.relayAvailable?"relay":K.lanUrl?"lan":"local")},[Fi]),_o=d.useCallback(async()=>{if(!(!n?.createPairingSession||!Jt)){Xe(null),pt(!0);try{const K=It.trim()||void 0;let me,Qe,lt=!0;Ct==="local"?(me=Jt.localUrl??void 0,Qe=!1):Ct==="lan"?(me=Jt.lanUrl??void 0,Qe=Zt):Zt&&Jt.lanUrl?(me=Jt.lanUrl,Qe=!0):(lt=!1,Qe=!0);const{pairing:Kt,server:Ns}=await n.createPairingSession({label:K,allowedClientKinds:["mobile","desktop"],serverUrl:me,includeRelay:Qe,includeDirect:lt}),_s=Xp({pairingId:Kt.id,secret:Kt.secret,label:Ns.label,fingerprint:Kt.fingerprint??void 0,expiresAt:Kt.expiresAt,candidates:Ns.candidates}),us=eg(_s);Ue(us),se(await tu.toDataURL(us,{width:1024,margin:2,errorCorrectionLevel:"L"})),tt(!1),ii.current=!1,ve(Kt.id),we("result"),await $s({silent:!0})}catch(K){Xe(K instanceof Error?K.message:String(K))}finally{pt(!1)}}},[n,Jt,Ct,Zt,It,$s]),zi=d.useCallback(()=>{gt&&_a(gt).then(K=>{K.ok&&(tt(!0),window.setTimeout(()=>tt(!1),2e3))})},[gt]),Bo=d.useCallback(async K=>{if(!n)return;const me=K.clientKind==="desktop-local";Xe(null);try{if(await n.revokeClient(K.id),me&&cs()){const Qe=await cr();await $l({hosts:Qe.hosts,defaultHostId:Qe.defaultHostId,initialHostChoiceCompleted:Qe.initialHostChoiceCompleted,localClientToken:null}),nt(lt=>lt.map(Kt=>Kt.id===K.id?{...Kt,revokedAt:new Date().toISOString()}:Kt)),Vl({apiBaseUrl:Ii(),clientToken:null,runtimeKey:"local"});return}await $s()}catch(Qe){Xe(Qe instanceof Error?Qe.message:String(Qe))}},[n,$s]),Vo=d.useCallback(async()=>{if(n){Xe(null);try{await n.purgeRevokedClients(),await $s()}catch(K){Xe(K instanceof Error?K.message:String(K))}}},[n,$s]);d.useEffect(()=>{T(R)},[R]),d.useEffect(()=>{jn(!1)},[k]),d.useEffect(()=>{if(!k)return;const K=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||g()},2e3);return()=>{window.clearInterval(K)}},[g,k]),d.useEffect(()=>{let K=null,me=Date.now();const Qe=()=>{const Kt=Date.now();Kt-me>=1e3&&(Ie(Kt),me=Kt),K=requestAnimationFrame(Qe)};(typeof document>"u"||document.visibilityState==="visible")&&(K=requestAnimationFrame(Qe));const lt=()=>{document.visibilityState==="visible"&&K===null?K=requestAnimationFrame(Qe):document.visibilityState!=="visible"&&K!==null&&(cancelAnimationFrame(K),K=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),K!==null&&cancelAnimationFrame(K)}},[]);const Ks=k?o[k]:null,Xs=Ks?.phase,ka=Xs==="ready",kn=Xs==="degraded",_n=kl(Xs),nn=ka||(_n||kn),Ho=Ks?Math.max(0,fe-Ks.updatedAtMs):0,wa=kn&&Ho>12e3,Sa=wc(Xs),Xn=Sa==="error"?Gb(Ks?.detail):null,oi=Jb(Xn),qo=d.useMemo(()=>!C||!R?!1:JSON.stringify(C)!==JSON.stringify(R),[C,R]),ps=d.useCallback(K=>{T(me=>me&&K(me))},[]),Wo=d.useCallback(async()=>{if(!C)return;const K=iv(C);if(!K.sshCommand.trim()){q.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(K.remoteOpenchamber.mode==="external"&&!K.remoteOpenchamber.preferredPort){q.error(t("settings.remoteInstances.page.validation.externalPortRequired")),jn(!0);return}if(K.remoteOpenchamber.mode==="managed"&&K.remoteOpenchamber.bindHost==="0.0.0.0"&&!K.auth.openchamberPassword?.value?.trim()){q.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),jn(!0),window.setTimeout(()=>Ia.current?.focus(),0);return}if(!(K.localForward.bindHost==="0.0.0.0"&&!await E("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(K.auth.sshPassword?.enabled&&K.auth.sshPassword.value?.trim()&&K.auth.sshPassword.store!=="settings"){const me=await E("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext");if(me===null)return;K.auth.sshPassword.store=me?"settings":"never",me||(K.auth.sshPassword.value=void 0)}if(K.auth.openchamberPassword?.enabled&&K.auth.openchamberPassword.value?.trim()&&K.auth.openchamberPassword.store!=="settings"){const me=await E("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext");if(me===null)return;K.auth.openchamberPassword.store=me?"settings":"never",me||(K.auth.openchamberPassword.value=void 0)}try{await h(K),q.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(me){q.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:me instanceof Error?me.message:String(me)})}}},[E,C,t,h]),ea=d.useCallback(async(K,me)=>{const Qe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await j(Qe,`ssh ${me}`,K),I(Qe),q.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(lt){return q.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:lt instanceof Error?lt.message:String(lt)}),!1}},[j,I,t]),Na=d.useCallback(()=>{U||(G(null),z(""))},[U]),Go=d.useCallback((K,me)=>{if($n(!1),me){G(K),z(Zb(K));return}ea(K,K)},[ea]),Ui=d.useMemo(()=>Wn(r,ja,K=>[K.host,K.sshCommand]),[r,ja]),$i=d.useCallback(async K=>{const Qe=(await cr().catch(()=>null))?.hosts.find(Kt=>Kt.id===K),lt=Qe?da(Bl(Qe)):null;if(!Qe||!lt){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Vl({apiBaseUrl:lt,clientToken:Qe.clientToken||null,requestHeaders:Qe.requestHeaders||null,runtimeKey:tg(Qe)}),y(!1)},[y,t]),_i=d.useCallback(async()=>{const K=W,me=$.trim();if(K){if(!me){q.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}_(!0);try{await ea(K,me)&&(G(null),z(""))}finally{_(!1)}}},[ea,$,W,t]),Ca=d.useCallback(async()=>{if(R)try{await S(R.id);return}catch(K){if(!Hb(K)||!await E("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw K;const Qe={...R,localForward:{...R.localForward,preferredLocalPort:uo()}};await h(Qe),await S(Qe.id),q.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[E,S,R,t,h]),Ia=d.useRef(null),Bi=d.useRef(null),Jo=d.useCallback(async K=>{if(R){if(K==="localPort"){const me={...R,localForward:{...R.localForward,preferredLocalPort:uo()}};try{await h(me),await S(me.id),q.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Qe){q.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)})}return}jn(!0),window.setTimeout(()=>{if(K==="uiPassword"){Ia.current?.focus();return}Bi.current?.scrollIntoView({block:"center"})},0)}},[S,R,t,h]),Pa=d.useCallback(async K=>(await Im(K,600)).map(Qe=>tv(Qe)),[]),Qo=d.useCallback(async()=>{if(C){L(!0),A(!0),M(null);try{const K=await Pa(C.id);H(K)}catch(K){H([]),M(K instanceof Error?K.message:String(K))}finally{A(!1)}}},[C,Pa]);d.useEffect(()=>{if(!P||!C)return;let K=!1;const me=async()=>{try{const lt=await Pa(C.id);K||(H(lt),M(null))}catch(lt){K||M(lt instanceof Error?lt.message:String(lt))}};me();const Qe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||me()},1e3);return()=>{K=!0,window.clearInterval(Qe)}},[C,P,Pa]);const Aa=d.useMemo(()=>F.join(`
28
- `),[F]),Yo=d.useCallback(()=>{if(!Aa.trim()){q.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}_a(Aa).then(K=>{K.ok&&q.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Aa,t]),ta=d.useCallback(async()=>{if(C)try{await Pm(C.id),H([]),q.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(K){q.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:K instanceof Error?K.message:String(K)})}},[C,t]),sa=d.useCallback(()=>{if(!C)return;if(!nn&&C.remoteOpenchamber.mode==="external"&&!C.remoteOpenchamber.preferredPort){q.error(t("settings.remoteInstances.page.validation.externalPortRequired")),jn(!0);return}if(!nn&&C.remoteOpenchamber.mode==="managed"&&C.remoteOpenchamber.bindHost==="0.0.0.0"&&!C.auth.openchamberPassword?.value?.trim()){q.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),jn(!0),window.setTimeout(()=>Ia.current?.focus(),0);return}Q(!0),(nn?b(C.id):Ca()).catch(me=>{const Qe=nn?ka?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";q.error(t(Qe),{description:me instanceof Error?me.message:String(me)})}).finally(()=>{Q(!1)})},[nn,Ca,b,C,ka,t]),Zo=d.useCallback(()=>{if(!C||_n)return;ge(!0),(kn?b(C.id).then(()=>Ca()):w(C.id)).catch(me=>{q.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:me instanceof Error?me.message:String(me)})}).finally(()=>{ge(!1)})},[Ca,b,C,_n,kn,w,t]),Xo=t(_n?"settings.remoteInstances.page.actions.connecting":kn?wa?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ta=!Y&&!ue&&(Xs==="error"||Xs==="idle"||!Xs||kn&&wa)&&!_n,er=t(ka?"settings.remoteInstances.sidebar.actions.disconnect":nn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!C)return s.jsxs(es,{title:t("settings.page.remoteInstances.title"),children:[n?s.jsxs(qe,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ki()},children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[Ro>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Vo()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,kt&&We.length===0&&at.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):We.length===0&&at.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[at.map(K=>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:K.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),K.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(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$o(K.id)},children:t("settings.common.actions.cancel")})]},`pending-${K.id}`)),We.map(K=>{const me=K.clientKind==="desktop-local",Qe=K.lastUsedAt?Date.parse(K.lastUsedAt):Number.NaN,lt=!K.revokedAt&&(me||Number.isFinite(Qe)&&Date.now()-Qe<9e4),Kt=K.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):lt?K.lastTransport==="relay"&&!me?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Qe)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Am(Qe,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:je("h-2 w-2 shrink-0 rounded-full",K.revokedAt?"bg-muted-foreground/20":lt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:K.label}),jc(K.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:jc(K.devicePlatform)}):null,me?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:je("typography-micro truncate",lt&&!K.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Kt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Bo(K)},disabled:!!K.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},K.id)})]})]}),Ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):null]}):null,a?s.jsxs(qe,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ne(null),st(!0)},disabled:ke,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ne(null),ut(!0)},disabled:ke,children:[s.jsx(J,{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:Ee?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):te.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):te.map(K=>{const me=ie[K.id],Qe=me?me.status==="ok"?"desktopHostSwitcher.status.connected":me.status==="auth"?"desktopHostSwitcher.status.authRequired":me.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":me.status==="incompatible"?"desktopHostSwitcher.status.incompatible":me.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",lt=me?.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:je("h-2 w-2 shrink-0 rounded-full",me?lt?"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:ri(K.label)}),re===K.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:je("typography-micro shrink-0",lt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Qe),lt&&typeof me?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(me.latencyMs))}):""]})]}),s.jsx("p",{className:je("typography-micro text-muted-foreground truncate",K.apiUrl&&"font-mono"),children:K.relay&&!K.apiUrl?t("mobile.connect.relay.badge"):ri(K.apiUrl||K.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Uo(K.id)},disabled:ke||re===K.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:re===K.id?s.jsx(J,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"star",className:"h-3.5 w-3.5"})}),K.relay&&!K.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ni(K),disabled:ke,children:[s.jsx(J,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Fo(K.id)},disabled:ke,children:[s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},K.id)})}),Be&&!ht&&!Je&&!Ze?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Be}):null]}):null,a?s.jsx(zt,{open:Je,onOpenChange:ut,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Oi()},children:[s.jsx(He,{className:"h-8",value:de,onChange:K=>Me(K.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ke}),s.jsx(He,{className:"h-8",value:Se,onChange:K=>Le(K.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ke,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:Ke,onChange:K=>oe(K.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(Wt,{children:t("settings.remoteInstances.direct.headers.description")})]}),le.map(K=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:K.name,onChange:me=>xe(Qe=>Qe.map(lt=>lt.id===K.id?{...lt,name:me.target.value}:lt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ke}),s.jsx(He,{className:"h-8 font-mono text-xs",value:K.value,onChange:me=>xe(Qe=>Qe.map(lt=>lt.id===K.id?{...lt,value:me.target.value}:lt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ke}),s.jsx("button",{type:"button",onClick:()=>xe(me=>me.filter(Qe=>Qe.id!==K.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(J,{name:"close",className:"h-4 w-4"})})]},K.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>xe(K=>[...K,Wr()]),disabled:ke,children:[s.jsx(J,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ut(!1),disabled:ke,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:ke||!Se.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),Be?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null]})]})}):null,a?s.jsx(zt,{open:!!Ze,onOpenChange:K=>{K||it(null)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),ai()},children:[s.jsx(He,{className:"h-8",value:et,onChange:K=>mt(K.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ke}),s.jsx(He,{className:"h-8",value:ft,onChange:K=>be(K.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ke,autoFocus:!0}),s.jsx(He,{className:"h-8",value:Re,onChange:K=>X(K.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(Wt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ce.map(K=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:K.name,onChange:me=>Oe(Qe=>Qe.map(lt=>lt.id===K.id?{...lt,name:me.target.value}:lt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ke}),s.jsx(He,{className:"h-8 font-mono text-xs",value:K.value,onChange:me=>Oe(Qe=>Qe.map(lt=>lt.id===K.id?{...lt,value:me.target.value}:lt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ke}),s.jsx("button",{type:"button",onClick:()=>Oe(me=>me.filter(Qe=>Qe.id!==K.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(J,{name:"close",className:"h-4 w-4"})})]},K.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Oe(K=>[...K,Wr()]),disabled:ke,children:[s.jsx(J,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>it(null),disabled:ke,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:ke,children:t("settings.common.actions.saveChanges")})]}),Be?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null]})]})}):null,a?s.jsx(zt,{open:ht,onOpenChange:K=>{jt||st(K)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":jt,onSubmit:async K=>{if(K.preventDefault(),!(jt||ke)){St(!0);try{await Oo()}catch{Ne(t("mobile.connect.error.unreachable"))}finally{St(!1)}}},children:[s.jsx(He,{className:"h-8",value:De,onChange:K=>{Ve(K.target.value),Ne(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:ke||jt,"aria-describedby":Be?"direct-import-error":void 0,autoFocus:!0}),Be?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:Be}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>st(!1),disabled:ke||jt,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:ke||jt||!De.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(zt,{open:ot,onOpenChange:At,children:s.jsxs(Ut,{className:pe==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t(pe==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Ht,{children:t(pe==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),pe==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:K=>{K.preventDefault(),_o()},children:[s.jsx(He,{className:"h-8",value:It,onChange:K=>_t(K.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:Un,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(K=>{const me=Ct===K.key;return s.jsxs("div",{className:je("flex items-start gap-2 py-0.5",K.available?"cursor-pointer":"opacity-45"),onClick:()=>{K.available&&Gt(K.key)},role:"presentation",children:[s.jsx(al,{checked:me,disabled:!K.available,onChange:()=>Gt(K.key),ariaLabel:K.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:je("typography-ui-label font-normal",me?"text-foreground":"text-foreground/70"),children:K.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:K.hint})]})]},K.key)})}),Ct==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Lr,{checked:Zt,onChange:as,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Ct==="relay"&&Jt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Lr,{checked:Zt,onChange:as,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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>At(!1),disabled:ze,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:ze||!Jt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Fe?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Fe,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,gt?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:gt}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:zi,children:[s.jsx(J,{name:Ae?"check":"file-copy",className:je("h-3.5 w-3.5",Ae&&"text-[var(--status-success)]")}),t(Ae?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>At(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),a?s.jsx(qe,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(B,{type:"button",size:"xs",className:"!font-normal",onClick:zo,children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children: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")}):i.map(K=>{const me=o[K.id],Qe=K.nickname?.trim()||K.sshParsed?.destination||K.id,lt=me?.phase,Kt=lt==="ready",Ns=wc(lt),_s=Ns==="error"?me?.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 ${Cc(lt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Qe})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Sc(Ns)),Ns==="connecting"?` · ${t(kc(lt))}`:"",Kt&&me?.localUrl?` · ${me.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Kt?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$i(K.id)},children:[s.jsx(J,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Kt?b(K.id):S(K.id)).catch(Ds=>q.error(t(Kt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Ds instanceof Error?Ds.message:String(Ds)}))},children:[Kt?s.jsx(J,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Kt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>I(K.id),children:[s.jsx(J,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&x(K.id).catch(Ds=>q.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Ds instanceof Error?Ds.message:String(Ds)}))},children:[s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),_s?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:_s}):null]},K.id)})}):null,a?s.jsx(zt,{open:Lo,onOpenChange:$n,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Ht,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Ws,{value:Ei,onChange:ti,"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")}]}),Ei==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(He,{className:"h-8",value:ja,onChange:K=>Di(K.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),l?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")}):Ui.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:Ui.map(K=>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:[K.host,K.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:K.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Go(K.host,K.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${K.source}:${K.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Ko()},children:[s.jsx(He,{className:"h-8",value:si,onChange:K=>Ri(K.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:m}),s.jsx(He,{className:"h-8",value:Yn,onChange:K=>Mi(K.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$n(!1),disabled:m,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:m||!Yn.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(zt,{open:!!W,onOpenChange:K=>{K||Na()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),_i()},children:[s.jsx(He,{value:$,onChange:K=>z(K.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Na,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const na=C.remoteOpenchamber.mode==="managed",he=na&&C.remoteOpenchamber.bindHost==="0.0.0.0",hs=he&&!C.auth.openchamberPassword?.value?.trim(),Ea=C.nickname?.trim()||C.sshParsed?.destination||C.id;return s.jsx(zt,{open:!!C,onOpenChange:K=>{K||I(null)},children:s.jsxs(Ut,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Mr} truncate`,children:Ea}),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 ${Cc(Xs)}`}),s.jsx("span",{className:"text-foreground",children:t(Sc(Sa))}),Sa==="connecting"?s.jsx("span",{children:t(kc(Xs))}):null,Ks?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Ks.localUrl}):null,wa?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{type:"button",variant:nn?"outline":"default",size:"xs",className:"!font-normal",onClick:sa,disabled:Y||ue,children:[nn?s.jsx(J,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"plug-2",className:"h-3.5 w-3.5"}),er]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Zo,disabled:!Ta,children:[s.jsx(J,{name:"refresh",className:`h-3.5 w-3.5 ${_n||kn&&!wa?"animate-spin":""}`}),Xo]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qo()},children:[s.jsx(J,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&x(C.id).then(()=>{I(null),q.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(me=>{q.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:me instanceof Error?me.message:String(me)})})},children:[s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),Sa==="error"&&Ks?.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:Ks.detail}),oi?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(oi)}):null,Xn&&!oi?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Jo(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,Ks?.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:Ks.localUrl})]}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:C.sshCommand,onChange:K=>ps(me=>({...me,sshCommand:K.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:C.nickname||"",onChange:K=>ps(me=>({...me,nickname:K.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Dt,{value:C.remoteOpenchamber.mode,onValueChange:K=>ps(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,mode:K==="external"?"external":"managed"}})),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(dt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Js,{open:Zn,onOpenChange:jn,children:[s.jsxs(Qs,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:Pd,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(J,{name:Zn?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Ys,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(gs,{containerClassName:"w-fit",min:5,max:240,step:1,className:je(bs,"tabular-nums"),value:C.connectionTimeoutSec,onValueChange:K=>{ps(me=>({...me,connectionTimeoutSec:Number.isFinite(K)?K:me.connectionTimeoutSec}))}})]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",ref:Bi,children:s.jsx(en,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:je(bs,"tabular-nums"),value:C.remoteOpenchamber.preferredPort,onValueChange:K=>{ps(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,preferredPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{ps(K=>({...K,remoteOpenchamber:{...K.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),na?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Dt,{value:C.remoteOpenchamber.installMethod,onValueChange:K=>ps(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,installMethod:K==="npm"||K==="bun"?K:"auto"}})),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(dt,{value:"bun",children:"bun"}),s.jsx(dt,{value:"npm",children:"npm"})]})]})]}):null,na?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(ha,{checked:he,onCheckedChange:K=>ps(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,bindHost:K?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),he?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,na?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(ha,{checked:C.remoteOpenchamber.keepRunning,onCheckedChange:K=>ps(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,keepRunning:K}}))})})]}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Dt,{value:C.localForward.bindHost,onValueChange:K=>{K==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ps(me=>({...me,localForward:{...me.localForward,bindHost:K==="localhost"||K==="0.0.0.0"?K:"127.0.0.1"}}))},children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[240px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(dt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(dt,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:je(bs,"tabular-nums"),value:C.localForward.preferredLocalPort,onValueChange:K=>{ps(me=>({...me,localForward:{...me.localForward,preferredLocalPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{ps(K=>({...K,localForward:{...K.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ps(K=>({...K,localForward:{...K.localForward,preferredLocalPort:uo()}})),children:s.jsx(J,{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(qe,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:C.auth.sshPassword?.value||"",onChange:K=>ps(me=>({...me,auth:{...me.auth,sshPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:me.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t(he?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(na?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(He,{className:je("h-7 md:max-w-sm",hs&&"border-[var(--status-error)]"),type:"password",ref:Ia,"aria-invalid":hs,value:C.auth.openchamberPassword?.value||"",onChange:K=>ps(me=>({...me,auth:{...me.auth,openchamberPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:me.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),hs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(qe,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[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((K,me)=>{const Qe=Ot=>{ps(ts=>({...ts,portForwards:ts.portForwards.map((Sn,Bn)=>Bn===me?Ot(Sn):Sn)}))},lt=K.type==="remote"?"Local target":"Local listen",Kt=K.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.",Ns=K.type==="remote"?"Remote listen":"Remote target",_s=K.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",us=Ic(K.localHost||"localhost",K.localPort),Ds=Ic(K.remoteHost||"localhost",K.remotePort),wn=K.type==="local"&&typeof K.localPort=="number"&&K.localPort>0,Bs=wn?`http://${ev(K.localHost)}:${K.localPort}`:"",an=!!V[K.id],on=K.type==="local"?t("settings.remoteInstances.page.forwardType.local"):K.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Js,{open:an,onOpenChange:Ot=>{Z(ts=>({...ts,[K.id]:Ot}))},className:`${me>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(Qs,{className:"flex items-center gap-2 group",children:[s.jsx(J,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${an?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Qb(K)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:on})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ha,{checked:K.enabled,onCheckedChange:Ot=>Qe(ts=>({...ts,enabled:Ot})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(B,{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:()=>ps(Ot=>({...Ot,portForwards:Ot.portForwards.filter(ts=>ts.id!==K.id)})),children:s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ys,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Xb(K.type))})]})})}),s.jsxs(Dt,{value:K.type,onValueChange:Ot=>Qe(ts=>({...ts,type:Ot==="dynamic"||Ot==="remote"?Ot:"local"})),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(dt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(dt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:lt,hint:Kt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:K.localHost||"127.0.0.1",onChange:Ot=>Qe(ts=>({...ts,localHost:Ot.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:je(bs,"tabular-nums"),value:K.localPort,onValueChange:Ot=>{Qe(ts=>({...ts,localPort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{Qe(Ot=>({...Ot,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),K.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(en,{label:Ns,hint:_s})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:K.remoteHost||"",onChange:Ot=>Qe(ts=>({...ts,remoteHost:Ot.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(gs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:je(bs,"tabular-nums"),value:K.remotePort,onValueChange:Ot=>{Qe(ts=>({...ts,remotePort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{Qe(Ot=>({...Ot,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:K.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):K.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ds}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(J,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(J,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:us}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(J,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(J,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ds}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),wn?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ss(Bs).then(Ot=>{Ot||q.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(J,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},K.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const K=Yb();ps(me=>({...me,portForwards:[...me.portForwards,K]})),Z(me=>({...me,[K.id]:!0}))},children:[s.jsx(J,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Wo()},disabled:!qo||m,children:t("settings.common.actions.saveChanges")}),Ks?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_a(Ks.localUrl||"").then(K=>{K.ok&&q.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(J,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{C&&$i(C.id)},children:[s.jsx(J,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,u?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:u}):null]})}),v,s.jsx(zt,{open:P,onOpenChange:L,children:s.jsxs(Ut,{className:"sm:max-w-2xl",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ht,{children: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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Yo,disabled:O||!Aa.trim(),children:[s.jsx(J,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ta()},disabled:O,children:[s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):N?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:N}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:F.length>0?F.join(`
29
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(zt,{open:!!W,onOpenChange:K=>{K||Na()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ht,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),_i()},children:[s.jsx(He,{value:$,onChange:K=>z(K.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Na,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.common.actions.create")})]})]})]})})]})})},rv=t=>t,lv=(t,e,n)=>t&&!e&&!n,cv=Nt(),Gr=t=>cv.safeParse(t?.settings?.apiKey).data??null,In=(t,e)=>t.find(n=>n.id===e),xi=t=>t==="opencode-go"?"opencode":t,mo=(t,e)=>{const n=In(t,e)?.connections,a=xi(e);if(a===e)return n;const i=In(t,a)?.connections;if(!(!n&&!i))return[...n??[],...i??[]]},Tc=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),dv=t=>(t?.methods??[]).find(e=>e.type==="key"),Ec=t=>t===void 0||dv(t)!==void 0,Dc=t=>(t?.connections??[]).filter(e=>e.type==="credential"),Mc=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,wl=t=>t.status?.status==="needs_auth",uv=t=>{if(t.integrations===null)return null;const e=mo(t.integrations,t.providerId);if((e??[]).some(wl))return{kind:"reauthNeeded"};const n=(e??[]).filter(a=>a.type==="credential").length;return n>1?{kind:"accounts",count:n}:n===1||(t.optionsApiKey?.trim().length??0)>0?{kind:"connected"}:(e??[]).some(a=>a.type==="env")?{kind:"environment"}:e===void 0?null:{kind:"signInNeeded"}},mv=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),pv=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,To=t=>{const e=$e.c(12),{t:n}=_e();if(t==="zen-promo"){let a;return e[0]!==n?(a=n("settings.classification.source.zenPromo.name"),e[0]=n,e[1]=a):a=e[1],a}if(t==="zen-key"){let a;return e[2]!==n?(a=n("settings.classification.source.zenKey.name"),e[2]=n,e[3]=a):a=e[3],a}if(t==="openrouter"){let a;return e[4]!==n?(a=n("settings.classification.source.openrouter.name"),e[4]=n,e[5]=a):a=e[5],a}if(t==="vercel"){let a;return e[6]!==n?(a=n("settings.classification.source.vercel.name"),e[6]=n,e[7]=a):a=e[7],a}if(t==="typesafe"){let a;return e[8]!==n?(a=n("settings.classification.source.typesafe.name"),e[8]=n,e[9]=a):a=e[9],a}if(t==="custom"){let a;return e[10]!==n?(a=n("settings.classification.source.custom.name"),e[10]=n,e[11]=a):a=e[11],a}return null},ko=()=>{const t=ne.getState();t.setSettingsProvidersClassificationRequested(!0),t.requestSettingsJump("providers","providers.classification")},Mn=t=>{const e=$e.c(3),{onClick:n,children:a}=t;let i;return e[0]!==a||e[1]!==n?(i=s.jsx("button",{type:"button",onClick:n,className:"cursor-pointer text-[var(--primary-text)] underline-offset-4 hover:underline focus-visible:underline focus-visible:outline-none",children:a}),e[0]=a,e[1]=n,e[2]=i):i=e[2],i},Eo=()=>{const t=$e.c(16),{t:e}=_e(),n=Qt(gv),a=Qt(fv),i=Qt(hv),o=To(i),r=zn();if(!n)return null;if(r&&!a){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 c;t[4]!==a||t[5]!==o||t[6]!==e?(c=a&&o?e("settings.jevAccess.via",{provider:o}):e("settings.jevAccess.missing"),t[4]=a,t[5]=o,t[6]=e,t[7]=c):c=t[7];let l;t[8]!==a||t[9]!==e?(l=e(a?"settings.jevAccess.manage":"settings.jevAccess.setUp"),t[8]=a,t[9]=e,t[10]=l):l=t[10];let m;t[11]!==l?(m=s.jsx(Mn,{onClick:ko,children:l}),t[11]=l,t[12]=m):m=t[12];let u;return t[13]!==c||t[14]!==m?(u=s.jsxs("p",{className:Mt,children:[c," ",m]}),t[13]=c,t[14]=m,t[15]=u):u=t[15],u};function gv(t){return t.available}function fv(t){return t.jevAvailable}function hv(t){return t.classifier?.effective??null}const xv="https://opencode.ai/v2/docs/policies/",bv=t=>{const e=$e.c(3),[n,a]=d.useState(null);let i,o;return e[0]!==t?(i=()=>{let r=!1;return a(null),Ps.configDeniesAnyProvider(t).then(c=>{r||a(c)}).catch(c=>{console.warn("[providers] could not read OpenCode provider policies:",c instanceof Error?c.message:String(c)),r||a(null)}),()=>{r=!0}},o=[t],e[0]=t,e[1]=i,e[2]=o):(i=e[1],o=e[2]),d.useEffect(i,o),n},vv=t=>{const e=$e.c(44),{directory:n,integrations:a}=t,{t:i}=_e(),o=bv(n),r=Ni(Sv),c=Ni(Nv),l=a===null?null:(In(a,"opencode")?.connections?.length??0)>0,m=o!==!1||l===null?null:l?"console":"open",u=m==="open";let f;e[0]!==i?(f=i("settings.providers.enterprisePolicyLink"),e[0]=i,e[1]=f):f=e[1];let p;e[2]!==f?(p=s.jsx(Mn,{onClick:Cv,children:f}),e[2]=f,e[3]=p):p=e[3];const g=p,h=u?"border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5":"border-[var(--status-info-border)] bg-[var(--status-info-background)]/30";let j;e[4]!==h?(j=je("mb-4 flex items-start gap-2 rounded-lg border p-3",h),e[4]=h,e[5]=j):j=e[5];const x=u?"error-warning":"information",S=u?"text-[var(--status-warning)]":"text-[var(--status-info)]";let b;e[6]!==S?(b=je("mt-0.5 size-4 shrink-0",S),e[6]=S,e[7]=b):b=e[7];let w;e[8]!==x||e[9]!==b?(w=s.jsx(J,{name:x,className:b}),e[8]=x,e[9]=b,e[10]=w):w=e[10];let k;e[11]!==i?(k=i("settings.providers.enterpriseTitle"),e[11]=i,e[12]=k):k=e[12];let I;e[13]!==k?(I=s.jsx("p",{className:Or,children:k}),e[13]=k,e[14]=I):I=e[14];let y;e[15]!==r||e[16]!==i?(y=r?s.jsx("p",{className:"typography-meta text-foreground",children:i("settings.providers.enterpriseManagedBy",{organization:r})}):null,e[15]=r,e[16]=i,e[17]=y):y=e[17];let E;e[18]!==c||e[19]!==i?(E=c?s.jsx("p",{className:"typography-meta text-foreground",children:i("settings.providers.enterprisePolicyUnreadable")}):null,e[18]=c,e[19]=i,e[20]=E):E=e[20];let v;e[21]!==i?(v=i("settings.providers.enterpriseMode"),e[21]=i,e[22]=v):v=e[22];let R;e[23]!==v?(R=s.jsx("p",{className:"typography-meta text-muted-foreground",children:v}),e[23]=v,e[24]=R):R=e[24];let C;e[25]!==m||e[26]!==g||e[27]!==i?(C=m==="open"?s.jsxs("p",{className:"typography-meta text-foreground",children:[i("settings.providers.enterprisePolicyMissing")," ",g]}):null,e[25]=m,e[26]=g,e[27]=i,e[28]=C):C=e[28];let T;e[29]!==m||e[30]!==g||e[31]!==i?(T=m==="console"?s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[i("settings.providers.enterprisePolicyConsole")," ",g]}):null,e[29]=m,e[30]=g,e[31]=i,e[32]=T):T=e[32];let P;e[33]!==I||e[34]!==y||e[35]!==E||e[36]!==R||e[37]!==C||e[38]!==T?(P=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[I,y,E,R,C,T]}),e[33]=I,e[34]=y,e[35]=E,e[36]=R,e[37]=C,e[38]=T,e[39]=P):P=e[39];let L;return e[40]!==P||e[41]!==j||e[42]!==w?(L=s.jsxs("div",{className:j,children:[w,P]}),e[40]=P,e[41]=j,e[42]=w,e[43]=L):L=e[43],L},yv=t=>{const e=$e.c(19),{onOpen:n}=t,{t:a}=_e(),i=Qt(Iv),o=Qt(Pv),r=Qt(Av);if(!i)return null;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(bn,{providerId:"typesafe",className:"size-5"}),e[0]=c):c=e[0];let l;e[1]!==a?(l=a("settings.classification.page.title"),e[1]=a,e[2]=l):l=e[2];const m=o?"success":r?"neutral":"warning";let u;e[3]!==o||e[4]!==r||e[5]!==a?(u=a(o?"settings.classification.card.ready":r?"settings.classification.card.off":"settings.classification.card.notSetUp"),e[3]=o,e[4]=r,e[5]=a,e[6]=u):u=e[6];let f;e[7]!==m||e[8]!==u?(f=s.jsx(hn,{tone:m,children:u}),e[7]=m,e[8]=u,e[9]=f):f=e[9];let p;e[10]!==a?(p=a("settings.classification.card.usedFor"),e[10]=a,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]!==n||e[15]!==l||e[16]!==f||e[17]!==g?(h=s.jsx(Ci,{icon:c,title:l,subtitle:"jev",badges:f,footer:g,onOpen:n}),e[14]=n,e[15]=l,e[16]=f,e[17]=g,e[18]=h):h=e[18],h},jv=(t,e)=>{const[n,a]=d.useState(()=>new Set);return d.useEffect(()=>{let i=!1;const o=e?`?directory=${encodeURIComponent(e)}`:"";return Promise.all(t.map(async r=>{try{const c=await Lt(`/api/provider/${encodeURIComponent(r.id)}/source${o}`,{method:"GET",headers:{Accept:"application/json"}});if(!c.ok)return null;const l=await c.json().catch(()=>null);return(l?.sources??l?.data?.sources)?.project?.exists===!0?r.id:null}catch{return null}})).then(r=>{i||a(new Set(r.filter(c=>c!==null)))}),()=>{i=!0}},[e,t]),n},kv=t=>{const e=$e.c(14),{status:n}=t,{t:a}=_e();let i;e:switch(n.kind){case"reauthNeeded":{let c;e[0]!==a?(c=a("settings.providers.card.status.reauthNeeded"),e[0]=a,e[1]=c):c=e[1],i=c;break e}case"accounts":{let c;e[2]!==n.count||e[3]!==a?(c=a("settings.providers.card.status.accounts",{count:n.count}),e[2]=n.count,e[3]=a,e[4]=c):c=e[4],i=c;break e}case"connected":{let c;e[5]!==a?(c=a("settings.providers.card.status.connected"),e[5]=a,e[6]=c):c=e[6],i=c;break e}case"environment":{let c;e[7]!==a?(c=a("settings.providers.card.status.environment"),e[7]=a,e[8]=c):c=e[8],i=c;break e}case"signInNeeded":{let c;e[9]!==a?(c=a("settings.providers.card.status.signInNeeded"),e[9]=a,e[10]=c):c=e[10],i=c}}const o=n.kind==="signInNeeded"||n.kind==="reauthNeeded"?"warning":n.kind==="environment"?"neutral":"success";let r;return e[11]!==i||e[12]!==o?(r=s.jsx(hn,{tone:o,children:i}),e[11]=i,e[12]=o,e[13]=r):r=e[13],r},wv=t=>{const e=$e.c(44),{providers:n,integrations:a,directory:i,onSelect:o,onConnect:r,onOpenClassification:c}=t,{t:l}=_e(),[m,u]=d.useState(""),f=jv(n,i);let p;e[0]!==n?(p=[...n].sort(Tv),e[0]=n,e[1]=p):p=e[1];const h=Wn(p,m,Ev);let j;e[2]!==m?(j=m.trim(),e[2]=m,e[3]=j):j=e[3];const x=j.length>0,S=zn(),b=es;let w;e[4]!==l?(w=l("settings.page.providers.title"),e[4]=l,e[5]=w):w=e[5];let k;e[6]!==l?(k=l("settings.providers.grid.description"),e[6]=l,e[7]=k):k=e[7];let I;e[8]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Ai,{className:"w-full min-w-0 @xl:w-56"}),e[8]=I):I=e[8];let y;e[9]!==i||e[10]!==a||e[11]!==S?(y=S?s.jsx(vv,{directory:i,integrations:a}):null,e[9]=i,e[10]=a,e[11]=S,e[12]=y):y=e[12];let E;e[13]!==n.length||e[14]!==m||e[15]!==l?(E=n.length>0?s.jsx(vl,{value:m,onChange:u,placeholder:l("settings.providers.grid.searchPlaceholder")}):null,e[13]=n.length,e[14]=m,e[15]=l,e[16]=E):E=e[16];const v=n.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:l("settings.providers.grid.empty")}):h.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:l("settings.providers.grid.noMatches",{query:m.trim()})}):null,R=xl;let C;e[17]!==x||e[18]!==S||e[19]!==r||e[20]!==l?(C=x||S?null:s.jsx(bl,{label:l("settings.providers.grid.connect"),hint:l("settings.providers.grid.connectHint"),onClick:r}),e[17]=x,e[18]=S,e[19]=r,e[20]=l,e[21]=C):C=e[21];let T;e[22]!==x||e[23]!==c?(T=x?null:s.jsx(yv,{onOpen:c}),e[22]=x,e[23]=c,e[24]=T):T=e[24];let P;e[25]!==a||e[26]!==o||e[27]!==f||e[28]!==l?(P=N=>{const M=uv({integrations:a,providerId:N.id,optionsApiKey:Gr(N)});return s.jsx(Ci,{icon:s.jsx(bn,{providerId:N.id,className:"size-5"}),title:N.name||N.id,subtitle:N.id,badges:M?s.jsx(kv,{status:M}):null,footer:s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"inline-flex items-center gap-1","aria-label":l("settings.providers.card.models",{count:N.models.length}),children:[s.jsx(J,{name:"stack",className:"size-3.5 opacity-70","aria-hidden":!0}),s.jsx("span",{className:"tabular-nums",children:N.models.length})]}),f.has(N.id)?s.jsx(vo,{children:l("settings.providers.card.source.project")}):null]}),onOpen:()=>o(N.id)},N.id)},e[25]=a,e[26]=o,e[27]=f,e[28]=l,e[29]=P):P=e[29];const L=h.map(P);let O;e[30]!==C||e[31]!==T||e[32]!==L||e[33]!==R?(O=s.jsxs("div",{className:R,children:[C,T,L]}),e[30]=C,e[31]=T,e[32]=L,e[33]=R,e[34]=O):O=e[34];let A;return e[35]!==b||e[36]!==O||e[37]!==w||e[38]!==k||e[39]!==I||e[40]!==y||e[41]!==E||e[42]!==v?(A=s.jsxs(b,{title:w,description:k,headerEnd:I,children:[y,E,v,O]}),e[35]=b,e[36]=O,e[37]=w,e[38]=k,e[39]=I,e[40]=y,e[41]=E,e[42]=v,e[43]=A):A=e[43],A};function Sv(t){return t.organization}function Nv(t){return t.policyError!==null}function Cv(){Ss(xv)}function Iv(t){return t.available}function Pv(t){return t.jevAvailable}function Av(t){return t.classifier?.selected==="off"}function Tv(t,e){return(t.name||t.id).localeCompare(e.name||e.id,void 0,{sensitivity:"base"})}function Ev(t){return[t.name||t.id,t.id]}const xu=t=>{const e=$e.c(38),{disabled:n,draft:a}=t,i=n===void 0?!1:n,{t:o}=_e();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"idle"},e[0]=r):r=e[0];const[c,l]=d.useState(r),m=c.kind==="done"?c.result:null,u=To(m&&"source"in m?m.source:null)??"";let f;e[1]!==a?(f=async()=>{const v=a?a():void 0;if(v!==null){l({kind:"running"});try{l({kind:"done",result:await Tm(v)})}catch(R){const C=R;l({kind:"failed",error:C instanceof Error?C.message:String(C)})}}},e[1]=a,e[2]=f):f=e[2];const p=f;let g;e[3]!==u||e[4]!==m||e[5]!==c.error||e[6]!==c.kind||e[7]!==o?(g=()=>{if(c.kind==="failed")return{text:o("settings.classification.test.failed",{error:c.error}),ok:!1};if(!m)return null;if(m.ok)return{text:o("settings.classification.test.ok",{provider:u,model:m.model,ms:m.ms}),ok:!0};if(m.reason==="unavailable")return{text:o("settings.classification.test.unavailable"),ok:!1};if(m.reason==="timeout")return{text:o("settings.classification.test.timeout",{provider:u}),ok:!1};if(m.reason==="unparsable")return{text:o("settings.classification.test.unparsable",{provider:u}),ok:!1};if(m.reason==="network")return{text:o("settings.classification.test.network",{provider:u,error:m.message??""}),ok:!1};const v=m.status??0;return v===401||v===403?{text:o("settings.classification.test.keyRejected",{provider:u,status:v}),ok:!1}:v===404?{text:o("settings.classification.test.notFound",{provider:u}),ok:!1}:{text:o("settings.classification.test.http",{provider:u,status:v}),ok:!1}},e[3]=u,e[4]=m,e[5]=c.error,e[6]=c.kind,e[7]=o,e[8]=g):g=e[8];const h=g;let j,x,S,b,w,k;if(e[9]!==h||e[10]!==i||e[11]!==p||e[12]!==c.kind||e[13]!==o){j=h(),w="flex min-w-0 flex-col gap-1.5";let v;e[20]!==p?(v=()=>{p()},e[20]=p,e[21]=v):v=e[21];const R=i||c.kind==="running";let C;e[22]!==c.kind||e[23]!==o?(C=c.kind==="running"?o("settings.classification.test.running"):o("settings.classification.test.button"),e[22]=c.kind,e[23]=o,e[24]=C):C=e[24],e[25]!==v||e[26]!==R||e[27]!==C?(k=s.jsx(B,{size:"sm",variant:"outline",className:"self-start",onClick:v,disabled:R,children:C}),e[25]=v,e[26]=R,e[27]=C,e[28]=k):k=e[28],x="status",S="polite",b=je(Mt,j&&!j.ok&&"text-[var(--status-error)]"),e[9]=h,e[10]=i,e[11]=p,e[12]=c.kind,e[13]=o,e[14]=j,e[15]=x,e[16]=S,e[17]=b,e[18]=w,e[19]=k}else j=e[14],x=e[15],S=e[16],b=e[17],w=e[18],k=e[19];const I=j?.text??"";let y;e[29]!==I||e[30]!==x||e[31]!==S||e[32]!==b?(y=s.jsx("p",{role:x,"aria-live":S,className:b,children:I}),e[29]=I,e[30]=x,e[31]=S,e[32]=b,e[33]=y):y=e[33];let E;return e[34]!==y||e[35]!==w||e[36]!==k?(E=s.jsxs("div",{className:w,children:[k,y]}),e[34]=y,e[35]=w,e[36]=k,e[37]=E):E=e[37],E},xr="flex w-full min-w-0 items-center gap-2",br="h-8 rounded-md px-3 min-w-0 flex-1",Dv=()=>{const{t}=_e(),e=Qt(w=>w.customEndpoint),n=Qt(w=>w.setCustomEndpoint),a=Qt(w=>w.clearCustomEndpoint),[i,o]=d.useState(e?.url??""),[r,c]=d.useState(e?.model??""),[l,m]=d.useState(""),[u,f]=d.useState(!1),[p,g]=d.useState(null);d.useEffect(()=>{o(e?.url??""),c(e?.model??"")},[e?.url,e?.model]);const h=async w=>{f(!0),g(null);try{await w(),m("")}catch(k){g(k instanceof Error?k.message:String(k))}finally{f(!1)}},j=i.trim().length>0&&r.trim().length>0,x=()=>{if(!j)return;const w={url:i.trim(),model:r.trim()},k=l.trim();k&&(w.key=k),h(()=>n(w))},S=()=>{if(!j)return null;const w=l.trim();return w?{url:i.trim(),model:r.trim(),key:w}:{url:i.trim(),model:r.trim()}},b=w=>{w.key==="Enter"&&x()};return e?.pinned?s.jsx(qe,{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(qe,{title:t("settings.classification.custom.title"),info:t("settings.classification.custom.info"),children:s.jsxs("div",{className:ws,children:[s.jsx(yt,{label:t("settings.classification.custom.url.label"),info:t("settings.classification.custom.url.info"),children:s.jsx("div",{className:xr,children:s.jsx(He,{type:"url",autoComplete:"off",spellCheck:!1,value:i,onChange:w=>o(w.target.value),onKeyDown:b,placeholder:"https://example.com/v1/systemone","aria-label":t("settings.classification.custom.url.label"),className:br,disabled:u})})}),s.jsx(yt,{label:t("settings.classification.custom.model.label"),children:s.jsx("div",{className:xr,children:s.jsx(He,{autoComplete:"off",spellCheck:!1,value:r,onChange:w=>c(w.target.value),onKeyDown:b,placeholder:"jev-latest","aria-label":t("settings.classification.custom.model.label"),className:br,disabled:u})})}),s.jsx(yt,{label:t("settings.classification.custom.key.label"),info:t("settings.classification.custom.key.info"),children:s.jsx("div",{className:xr,children:s.jsx(He,{type:"password",autoComplete:"off",value:l,onChange:w=>m(w.target.value),onKeyDown:b,placeholder:e?.keyPresent?t("settings.classification.custom.key.replacePlaceholder"):t("settings.classification.custom.key.placeholder"),"aria-label":t("settings.classification.custom.key.label"),className:br,disabled:u})})}),s.jsxs(yt,{label:null,children:[s.jsx(B,{size:"sm",variant:"outline",onClick:x,disabled:u||!j,children:t("settings.classification.custom.save")}),e?s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{h(a)},disabled:u,children:t("settings.classification.custom.remove")}):null]}),p?s.jsx("p",{className:xn,children:p}):null,s.jsx(yt,{label:null,children:s.jsx(xu,{disabled:u||!j,draft:S})})]})})},Mv="https://docs.openchamber.dev/classification-providers/",vr=t=>{const e=$e.c(6),{text:n,linkLabel:a,onOpen:i}=t;let o;e[0]!==a||e[1]!==i?(o=s.jsx("span",{onClick:Lv,onKeyDown:Ov,children:s.jsx(Mn,{onClick:i,children:a})}),e[0]=a,e[1]=i,e[2]=o):o=e[2];let r;return e[3]!==o||e[4]!==n?(r=s.jsxs(s.Fragment,{children:[n," ",o]}),e[3]=o,e[4]=n,e[5]=r):r=e[5],r},Rv=({titleLeading:t,onOpenProvider:e})=>{const{t:n}=_e(),a=Qt(A=>A.available),i=Qt(A=>A.loaded),o=Qt(A=>A.loadError),r=Qt(A=>A.classifier),c=Qt(A=>A.tokenPresent),l=Qt(A=>A.customEndpoint),m=Qt(A=>A.enterpriseMode),u=Qt(A=>A.load),f=Qt(A=>A.setClassifierSource),p=Qt(A=>A.setToken),g=Qt(A=>A.clearToken),h=To(r?.effective??null),[j,x]=d.useState(""),[S,b]=d.useState(!1),[w,k]=d.useState(null);d.useEffect(()=>{u()},[u]);const I=A=>r?.sources.find(N=>N.id===A)?.usable===!0,y=async A=>{ss("saving");try{await f(A),ss("saved")}catch{ss("error")}},E=async()=>{const A=j.trim();if(A){b(!0),k(null);try{await p(A),x("")}catch(N){k(N instanceof Error?N.message:String(N))}finally{b(!1)}}},v=async()=>{b(!0),k(null);try{await g()}catch(A){k(A instanceof Error?A.message:String(A))}finally{b(!1)}},R=m?l?.pinned?n("settings.classification.status.enterprisePinned"):n("settings.classification.status.enterprise"):!r||r.selected==="off"?null:r.effective===null?n("settings.classification.status.none"):r.effective!==r.selected&&h?n("settings.classification.status.fallback",{provider:h}):null,C=I("zen-promo"),T=I("zen-key"),P=I("openrouter"),L=I("vercel"),O=I("custom");return s.jsxs(es,{title:n("settings.classification.page.title"),titleLeading:t,description:s.jsxs("p",{className:xn,children:[n("settings.classification.page.description")," ",s.jsx(Mn,{onClick:()=>{Ss(Mv)},children:n("settings.classification.page.docsLink")})]}),showSaveStatus:!0,children:[o?s.jsx("p",{className:xn,children:n("settings.routing.loadError",{error:o})}):null,i?!a||!r?s.jsx("p",{className:xn,children:n("settings.classification.unavailable")}):s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(bn,{providerId:"typesafe",className:"size-4 shrink-0"}),n("settings.classification.jev.title")]}),info:n("settings.classification.jev.info"),divider:!1,settingsItem:"providers.classification",children:s.jsxs("div",{className:ws,children:[R?s.jsx("p",{className:Mt,children:R}):null,s.jsxs(Vs,{"aria-label":n("settings.classification.jev.title"),children:[s.jsx(is,{selected:r.selected==="off",onSelect:()=>{y("off")},label:n("settings.classification.source.off.name"),description:n("settings.classification.source.off.description")}),m?null:s.jsxs(s.Fragment,{children:[C||r.selected==="zen-promo"?s.jsx(is,{selected:r.selected==="zen-promo",onSelect:()=>{y("zen-promo")},disabled:!C,label:n("settings.classification.source.zenPromo.name"),description:n(C?"settings.classification.source.zenPromo.description":"settings.classification.source.zenPromo.ended")}):null,s.jsx(is,{selected:r.selected==="zen-key",onSelect:()=>{y("zen-key")},disabled:!T,label:n("settings.classification.source.zenKey.name"),description:T?n("settings.classification.source.zenKey.description"):s.jsx(vr,{text:n("settings.classification.source.zenKey.missing"),linkLabel:n("settings.classification.source.openProvider",{provider:"OpenCode Zen"}),onOpen:()=>e("opencode")})}),s.jsx(is,{selected:r.selected==="openrouter",onSelect:()=>{y("openrouter")},disabled:!P,label:n("settings.classification.source.openrouter.name"),description:P?n("settings.classification.source.openrouter.description"):s.jsx(vr,{text:n("settings.classification.source.openrouter.missing"),linkLabel:n("settings.classification.source.openProvider",{provider:"OpenRouter"}),onOpen:()=>e("openrouter")})}),s.jsx(is,{selected:r.selected==="vercel",onSelect:()=>{y("vercel")},disabled:!L,label:n("settings.classification.source.vercel.name"),description:L?n("settings.classification.source.vercel.description"):s.jsx(vr,{text:n("settings.classification.source.vercel.missing"),linkLabel:n("settings.classification.source.openProvider",{provider:"Vercel AI Gateway"}),onOpen:()=>e("vercel")})}),s.jsx(is,{selected:r.selected==="typesafe",onSelect:()=>{y("typesafe")},disabled:!c,label:n("settings.classification.source.typesafe.name"),description:n(c?"settings.classification.source.typesafe.description":"settings.classification.source.typesafe.missing")})]}),!m||l?.pinned?s.jsx(is,{selected:r.selected==="custom",onSelect:()=>{y("custom")},disabled:!O,label:n("settings.classification.source.custom.name"),description:l&&O?n("settings.classification.source.custom.description",{url:l.url}):n("settings.classification.source.custom.missing")}):null]}),m?null:s.jsx(yt,{label:n("settings.routing.token.label"),info:n("settings.routing.token.info"),children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(He,{type:"password",autoComplete:"off",value:j,onChange:A=>x(A.target.value),onKeyDown:A=>{A.key==="Enter"&&E()},placeholder:n(c?"settings.routing.token.replacePlaceholder":"settings.routing.token.placeholder"),"aria-label":n("settings.routing.token.label"),className:"h-8 rounded-md px-3 min-w-0 flex-1",disabled:S}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>{E()},disabled:S||j.trim().length===0,children:n("settings.routing.token.save")}),c?s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{v()},disabled:S,children:n("settings.routing.token.remove")}):null]})}),w?s.jsx("p",{className:xn,children:w}):null,s.jsx(yt,{label:null,children:s.jsx(xu,{disabled:r.effective===null})})]})}),!m||l?.pinned?s.jsx(Dv,{}):null]}):null]})};function Lv(t){return t.stopPropagation()}function Ov(t){return t.stopPropagation()}const Rc=t=>{const e=$e.c(2),{icon:n}=t;let a;return e[0]!==n?(a=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(J,{name:n,className:"size-4"})}),e[0]=n,e[1]=a):a=e[1],a},Lc=t=>{const e=$e.c(3),{connection:n,fallback:a}=t;let i;return e[0]!==n||e[1]!==a?(i=wl(n)&&n.status?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] break-words",children:n.status.message}):s.jsx("div",{className:"typography-micro text-muted-foreground",children:a}),e[0]=n,e[1]=a,e[2]=i):i=e[2],i},Oc=t=>{const e=$e.c(11),{connection:n,account:a}=t,{t:i}=_e(),o=wl(n)?n.status?.url:void 0;if(!o)return null;let r;e[0]!==o?(r=()=>{Ss(o)},e[0]=o,e[1]=r):r=e[1];let c;e[2]!==a||e[3]!==i?(c=i("settings.providers.accounts.signInAria",{account:a}),e[2]=a,e[3]=i,e[4]=c):c=e[4];let l;e[5]!==i?(l=i("settings.providers.accounts.signIn"),e[5]=i,e[6]=l):l=e[6];let m;return e[7]!==r||e[8]!==c||e[9]!==l?(m=s.jsx(B,{variant:"outline",size:"xs",onClick:r,"aria-label":c,children:l}),e[7]=r,e[8]=c,e[9]=l,e[10]=m):m=e[10],m},Fv=t=>{const e=$e.c(32),{initial:n,onSave:a,onCancel:i}=t,{t:o}=_e(),[r,c]=d.useState(n);let l;e[0]!==r?(l=r.trim(),e[0]=r,e[1]=l):l=e[1];const m=l;let u;e[2]!==n||e[3]!==i||e[4]!==a||e[5]!==m?(u=()=>{if(m.length===0||m===n){i();return}a(m)},e[2]=n,e[3]=i,e[4]=a,e[5]=m,e[6]=u):u=e[6];const f=u;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=>c(y.target.value),e[9]=g):g=e[9];let h;e[10]!==i?(h=y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),i())},e[10]=i,e[11]=h):h=e[11];let j;e[12]!==o?(j=o("settings.providers.accounts.nameAria"),e[12]=o,e[13]=j):j=e[13];let x;e[14]!==h||e[15]!==j||e[16]!==r?(x=s.jsx(He,{autoFocus:!0,value:r,onChange:g,onKeyDown:h,"aria-label":j,className:"h-8 max-w-[18rem]"}),e[14]=h,e[15]=j,e[16]=r,e[17]=x):x=e[17];let S;e[18]!==o?(S=o("settings.providers.accounts.save"),e[18]=o,e[19]=S):S=e[19];let b;e[20]!==S?(b=s.jsx(B,{type:"submit",size:"xs",children:S}),e[20]=S,e[21]=b):b=e[21];let w;e[22]!==o?(w=o("settings.providers.page.actions.cancel"),e[22]=o,e[23]=w):w=e[23];let k;e[24]!==i||e[25]!==w?(k=s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:i,children:w}),e[24]=i,e[25]=w,e[26]=k):k=e[26];let I;return e[27]!==k||e[28]!==p||e[29]!==x||e[30]!==b?(I=s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-2",onSubmit:p,children:[x,b,k]}),e[27]=k,e[28]=p,e[29]=x,e[30]=b,e[31]=I):I=e[31],I},Kv=t=>{const e=$e.c(32),{connections:n,activeId:a,unusedIds:i,busyId:o,onActivate:r,onRename:c,onRemove:l}=t,{t:m}=_e(),[u,f]=d.useState(null);let p;if(e[0]!==n||e[1]!==i){let w;e[3]!==i?(w=k=>k.type==="credential"&&!i.has(k.id),e[3]=i,e[4]=w):w=e[4],p=n.filter(w),e[0]=n,e[1]=i,e[2]=p}else p=e[2];const h=p.length>1;let j;e[5]!==n?(j=n.filter(zv),e[5]=n,e[6]=j):j=e[6];const x=j.length>1;let S;if(e[7]!==a||e[8]!==o||e[9]!==h||e[10]!==n||e[11]!==r||e[12]!==l||e[13]!==c||e[14]!==u||e[15]!==x||e[16]!==m||e[17]!==i){let w;e[19]!==a||e[20]!==o||e[21]!==h||e[22]!==r||e[23]!==l||e[24]!==c||e[25]!==u||e[26]!==x||e[27]!==m||e[28]!==i?(w=k=>{if(k.type==="env")return s.jsxs("div",{className:"flex min-w-0 items-center gap-3 py-2.5",children:[s.jsx(Rc,{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:k.name}),s.jsx(Lc,{connection:k,fallback:m("settings.providers.accounts.environment")})]}),s.jsx(Oc,{connection:k,account:k.name})]},`env:${k.name}`);const I=k.id===a,y=i.has(k.id),E=o!==null,v=k.method==="oauth"?m(y?"settings.providers.accounts.method.oauthUnused":"settings.providers.accounts.method.oauth"):m(y?"settings.providers.accounts.method.keyUnused":"settings.providers.accounts.method.key");return s.jsxs("div",{className:je("flex min-w-0 items-center gap-3 py-2.5",y&&"opacity-60"),children:[s.jsx(Rc,{icon:k.method==="oauth"?"user-3":"key"}),u===k.id?s.jsx(Fv,{initial:k.label,onCancel:()=>f(null),onSave:R=>{f(null),c(k,R)}}):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:k.label}),x&&I?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(Lc,{connection:k,fallback:v})]}),s.jsx(Oc,{connection:k,account:k.label}),h&&!I&&!y?s.jsxs(B,{variant:"outline",size:"xs",disabled:E,onClick:()=>r(k),"aria-label":m("settings.providers.accounts.useAria",{account:k.label}),children:[o===k.id?s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):null,m("settings.providers.accounts.use")]}):null,s.jsxs(Kn,{children:[s.jsx(Fn,{asChild:!0,children:s.jsx(B,{variant:"ghost",size:"icon",disabled:E,className:je(ls,"shrink-0"),"aria-label":m("settings.providers.accounts.menuAria",{account:k.label}),children:s.jsx(J,{name:"more-2",className:"size-4"})})}),s.jsxs(On,{align:"end",children:[s.jsxs(mn,{onSelect:()=>f(k.id),children:[s.jsx(J,{name:"pencil",className:"size-4"}),m("settings.providers.accounts.rename")]}),s.jsxs(mn,{variant:"destructive",onSelect:()=>l(k),children:[s.jsx(J,{name:"delete-bin",className:"size-4"}),m("settings.providers.accounts.remove")]})]})]})]})]},k.id)},e[19]=a,e[20]=o,e[21]=h,e[22]=r,e[23]=l,e[24]=c,e[25]=u,e[26]=x,e[27]=m,e[28]=i,e[29]=w):w=e[29],S=n.map(w),e[7]=a,e[8]=o,e[9]=h,e[10]=n,e[11]=r,e[12]=l,e[13]=c,e[14]=u,e[15]=x,e[16]=m,e[17]=i,e[18]=S}else S=e[18];let b;return e[30]!==S?(b=s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:S}),e[30]=S,e[31]=b):b=e[31],b};function zv(t){return t.type==="credential"}const Sl={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},ra="__custom_provider__",Uv=/^[a-z0-9][a-z0-9-_]*$/,bu=/^https?:\/\//,$v=/^\{env:([^}]+)\}$/,wo=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 _v=0;const So=()=>`row-${_v++}`,Do=()=>({row:So(),id:"",name:"",contextWindow:"",maxOutputTokens:"",inputCapabilities:["text"],outputCapabilities:["text"],tools:!0,capabilitiesKnown:!1,variants:""}),Fc=rs({context:xo().optional(),output:xo().optional()}),Kc=rs({tools:Pi(),input:sn(Nt()),output:sn(Nt())}),Bv=rs({id:Nt(),name:Nt(),limit:Fc.optional(),capabilities:Kc.optional(),metadata:rs({providerID:Nt(),modelID:Nt(),name:Nt().optional(),limit:Fc.optional(),capabilities:Kc.optional()}).optional()}),Vv=rs({models:sn(Bv)}),Hv=rs({error:Nt()}),qv=t=>{const e=t.metadata,n=t.limit?.context??e?.limit?.context,a=t.limit?.output??e?.limit?.output,i=t.capabilities??e?.capabilities,o=!!(t.limit||t.capabilities);return{...Do(),id:t.id,name:t.name!==t.id?t.name:e?.name??t.id,contextWindow:n?String(n):"",maxOutputTokens:a?String(a):"",inputCapabilities:i?.input??["text"],outputCapabilities:i?.output??["text"],tools:i?.tools??!0,capabilitiesKnown:!!i,...o?{metadataSource:"provider-api"}:e?{metadataSource:"models.dev"}:{}}};function Wv(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 Gv(t){const e=t.split(/[,\s]+/).map(n=>n.trim()).filter(Boolean);return e.filter((n,a)=>e.indexOf(n)===a)}function Jv(t){return Object.fromEntries((t??[]).map(({id:e,...n})=>[e,n]))}const Nl=()=>({row:So(),key:"",value:""}),Qv=()=>({providerID:"",name:"",icon:null,protocol:"openai-chat",baseURL:"",apiKey:"",models:[Do()],headers:[Nl()]}),yu={"@opencode/ai/providers/openai-compatible":"openai-chat","@opencode/ai/providers/openai":"openai-responses","@opencode/ai/providers/anthropic":"anthropic-messages"};function Yv(t){const e=t?yu[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 Zv(t){const e=t.trim();if(!e)return{};const a=e.match($v)?.[1]?.trim();return a?{env:a}:{key:e}}function Xv(t){const e=vu(t),n=typeof e.baseURL=="string"?e.baseURL.trim():"";if(n&&bu.test(n))return!0;const a=new Set([...Object.values(Sl),...Object.keys(yu)]);return a.has(wo(t)??"")?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(o=>!o||typeof o!="object"?!1:a.has(wo(o)??""))}function zc(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&Xv(t):!1}function Uc(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function $c(t){const e=vu(t),n=typeof e.baseURL=="string"?e.baseURL:"",a=t.headers&&typeof t.headers=="object"?t.headers:e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(a).filter(m=>typeof m[0]=="string"&&typeof m[1]=="string").map(([m,u])=>({row:So(),key:m,value:u})),o=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([m,u])=>{const f=u&&typeof u=="object"?u:{};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:ju.safeParse(f.variants).data,limit:ku.safeParse(f.limit).data,capabilities:wu.safeParse(f.capabilities).data}}):[],r=o.length>0?o.map(m=>{const u=typeof m?.modelID=="string"&&m.modelID?m.modelID:typeof m?.id=="string"?m.id:"",f=Jv(m?.variants);return{row:So(),id:u,name:typeof m?.name=="string"?m.name:u,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}}):[Do()],c=Array.isArray(t.env)?t.env.find(m=>typeof m=="string"&&m.trim().length>0)?.trim():void 0,l=o.map(m=>wo(m)).find(m=>!!m);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,icon:null,protocol:Yv(wo(t)??l),baseURL:n,apiKey:c?`{env:${c}}`:"",models:r,headers:i.length>0?i:[Nl()]}}const ju=sn(rs({id:Nt(),settings:Dn(Nt(),Fr()).optional(),headers:Dn(Nt(),Nt()).optional(),body:Dn(Nt(),Fr()).optional()})),ku=rs({context:xo().optional(),output:xo().optional()}),wu=rs({tools:Pi().optional(),input:sn(Nt()).optional(),output:sn(Nt()).optional()}),ey=rs({name:Nt().optional(),package:Nt().optional(),env:sn(Nt()).optional(),settings:Dn(Nt(),Fr()).optional(),headers:Dn(Nt(),Nt()).optional(),models:Dn(Nt(),rs({modelID:Nt().optional(),name:Nt().optional(),package:Nt().optional(),variants:ju.optional(),limit:ku.optional(),capabilities:wu.optional()})).optional()});function ty(t,e,n=null){const a=Array.isArray(t.models)?t.models.map(r=>({...r,variants:void 0})):t.models,i=$c({...t,models:a});if(!e)return{...i,icon:n,models:i.models.map(r=>({...r,savedVariants:void 0}))};const o=$c({...e,id:t.id});return{providerID:t.id,name:e.name?.trim()?o.name:i.name,icon:n,protocol:e.package?o.protocol:i.protocol,baseURL:o.baseURL||i.baseURL,apiKey:o.apiKey,models:e.models&&Object.keys(e.models).length>0?o.models:i.models.map(r=>({...r,savedVariants:void 0})),headers:o.headers}}function sy(t){const e=t.form.providerID.trim(),n=t.form.name.trim(),a=t.form.baseURL.trim(),{env:i,key:o}=Zv(t.form.apiKey),r=t.disabledProviders??[],c=t.editingProviderID?.trim(),l=e?Uv.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),m=n?void 0:t.t("settings.providers.page.custom.error.name.required"),u=a?bu.test(a)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(i||o||c&&t.allowExistingAuth&&c===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),g=r.includes(e),j=l||!!(c&&c===e)?void 0:t.existingProviderIDs.has(e)&&!g?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,x=new Set,S=t.form.models.map(C=>{const T=C.id.trim(),P=T?x.has(T)?t.t("settings.providers.page.custom.error.duplicate"):void x.add(T):t.t("settings.providers.page.custom.error.required"),L=C.name.trim()?void 0:t.t("settings.providers.page.custom.error.required"),O=C.contextWindow.trim()&&!eo(C.contextWindow)?t.t("settings.providers.page.custom.error.positiveInteger"):void 0,A=C.maxOutputTokens.trim()&&!eo(C.maxOutputTokens)?t.t("settings.providers.page.custom.error.positiveInteger"):void 0;return{id:P,name:L,contextWindow:O,maxOutputTokens:A}}),b=S.every(C=>!C.id&&!C.name&&!C.contextWindow&&!C.maxOutputTokens),w=Object.fromEntries(t.form.models.map(C=>{const T=C.id.trim(),P={modelID:T,name:C.name.trim()},L=eo(C.contextWindow),O=eo(C.maxOutputTokens);(L||O)&&(P.limit={...L?{context:L}:{},...O?{output:O}:{}}),C.capabilitiesKnown&&(P.capabilities={tools:C.tools,input:C.inputCapabilities,output:C.outputCapabilities});const A=Gv(C.variants);return(A.length>0||C.savedVariants!==void 0)&&(P.variants=A.map(N=>({id:N,...C.savedVariants?.[N]??Wv(t.form.protocol,N)}))),[T,P]})),k=new Set,I=t.form.headers.map(C=>{const T=C.key.trim(),P=C.value.trim();if(!T&&!P)return{};const L=T?k.has(T.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void k.add(T.toLowerCase()):t.t("settings.providers.page.custom.error.required"),O=P?void 0:t.t("settings.providers.page.custom.error.required");return{key:L,value:O}}),y=I.every(C=>!C.key&&!C.value),E=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])),v={providerID:l??j,name:m,baseURL:u,apiKey:p};return!l&&!j&&!m&&!u&&!p&&b&&y?{err:v,models:S,headers:I,result:{providerID:e,name:n,icon:t.form.icon,apiKey:o,...!i&&!o?{keepsStoredCredential:!0}:{},config:ny({protocol:t.form.protocol,name:n,env:i,baseURL:a,headers:E,models:w})}}:{err:v,models:S,headers:I}}function eo(t){const e=t.trim();if(!/^\d+$/.test(e))return;const n=Number(e);return Number.isSafeInteger(n)&&n>0?n:void 0}function ny(t){const e={package:Sl[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 ay(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function iy(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user",hasCredential:!!(t.apiKey||t.keepsStoredCredential)}}const oy=[250,500,1e3,2e3];async function ry(t,e=n=>new Promise(a=>setTimeout(a,n))){for(let n=0;;n+=1)try{await t();return}catch(a){const i=oy[n];if(!(a instanceof Error&&/not found/i.test(a.message))||i===void 0)throw a;await e(i)}}const ly=8,cy=t=>{const e=$e.c(78),{models:n,existingIds:a,onAdd:i,onCancel:o}=t,{t:r}=_e(),[c,l]=d.useState("");let m;e[0]!==a||e[1]!==n?(m=()=>new Set(n.filter(z=>!a.has(z.id)).map(dy)),e[0]=a,e[1]=n,e[2]=m):m=e[2];const[u,f]=d.useState(m);let p,g,h,j,x,S,b,w,k,I;if(e[3]!==a||e[4]!==n||e[5]!==c||e[6]!==u||e[7]!==r){const z=c.trim().toLocaleLowerCase();I=z?n.filter(V=>[V.id,V.name,V.metadata?.name].some(Z=>Z?.toLocaleLowerCase().includes(z))):n;let U;e[18]!==a?(U=V=>!a.has(V.id),e[18]=a,e[19]=U):U=e[19],g=I.filter(U),p=g.length>0&&g.every(V=>u.has(V.id)),k=()=>f(V=>{const Z=new Set(V);for(const Y of g)p?Z.delete(Y.id):Z.add(Y.id);return Z}),w="space-y-2",b="flex items-end justify-between gap-2",x="min-w-0";let _;e[20]!==r?(_=r("settings.providers.page.custom.discovery.review"),e[20]=r,e[21]=_):_=e[21],e[22]!==_?(S=s.jsx("p",{className:Pt,children:_}),e[22]=_,e[23]=S):S=e[23],h=Mt,j=r("settings.providers.page.custom.discovery.counts",{matching:I.length,total:n.length,selected:u.size}),e[3]=a,e[4]=n,e[5]=c,e[6]=u,e[7]=r,e[8]=p,e[9]=g,e[10]=h,e[11]=j,e[12]=x,e[13]=S,e[14]=b,e[15]=w,e[16]=k,e[17]=I}else p=e[8],g=e[9],h=e[10],j=e[11],x=e[12],S=e[13],b=e[14],w=e[15],k=e[16],I=e[17];let y;e[24]!==h||e[25]!==j?(y=s.jsx("p",{className:h,children:j}),e[24]=h,e[25]=j,e[26]=y):y=e[26];let E;e[27]!==x||e[28]!==S||e[29]!==y?(E=s.jsxs("div",{className:x,children:[S,y]}),e[27]=x,e[28]=S,e[29]=y,e[30]=E):E=e[30];const v=g.length===0;let R;e[31]!==p||e[32]!==r?(R=r(p?"settings.providers.page.custom.discovery.deselectAll":"settings.providers.page.custom.discovery.selectAll"),e[31]=p,e[32]=r,e[33]=R):R=e[33];let C;e[34]!==v||e[35]!==R||e[36]!==k?(C=s.jsx(B,{type:"button",variant:"ghost",size:"xs",disabled:v,onClick:k,children:R}),e[34]=v,e[35]=R,e[36]=k,e[37]=C):C=e[37];let T;e[38]!==C||e[39]!==b||e[40]!==E?(T=s.jsxs("div",{className:b,children:[E,C]}),e[38]=C,e[39]=b,e[40]=E,e[41]=T):T=e[41];let P;e[42]!==n.length||e[43]!==c||e[44]!==r?(P=n.length>ly?s.jsxs("div",{className:"relative",children:[s.jsx(J,{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(He,{value:c,onChange:z=>l(z.target.value),onKeyDown:z=>{z.key==="Escape"&&c&&(z.preventDefault(),z.stopPropagation(),l(""))},placeholder:r("settings.agents.modelSelector.searchPlaceholder"),"aria-label":r("settings.agents.modelSelector.searchPlaceholder"),className:"h-8 rounded-md pl-8"})]}):null,e[42]=n.length,e[43]=c,e[44]=r,e[45]=P):P=e[45];let L;e[46]!==a||e[47]!==u||e[48]!==r||e[49]!==I?(L=I.length>0?I.map(z=>{const U=a.has(z.id),_=z.limit?.context??z.metadata?.limit?.context,V=z.limit?.output??z.metadata?.limit?.output,Z=[_?r("settings.providers.page.custom.discovery.contextValue",{value:go(_)}):null,V?r("settings.providers.page.custom.discovery.outputValue",{value:go(V)}):null].filter(Boolean).join(" · ");return s.jsx(ct,{checked:U||u.has(z.id),disabled:U,onChange:Y=>f(Q=>{const ue=new Set(Q);return Y?ue.add(z.id):ue.delete(z.id),ue}),label:s.jsx("span",{className:"block truncate font-mono text-xs",children:z.id}),description:U?r("settings.providers.page.custom.discovery.alreadyAdded"):Z||void 0,ariaLabel:z.id,className:"py-1.5"},z.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]=a,e[47]=u,e[48]=r,e[49]=I,e[50]=L):L=e[50];let O;e[51]!==L?(O=s.jsx(js,{outerClassName:"max-h-[min(18rem,45dvh)] rounded-md border border-border/60",className:"px-2 py-1",disableHorizontal:!0,preventOverscroll:!0,useScrollShadow:!0,children:L}),e[51]=L,e[52]=O):O=e[52];const A=u.size===0;let N;e[53]!==n||e[54]!==i||e[55]!==u?(N=()=>i(n.filter(z=>u.has(z.id))),e[53]=n,e[54]=i,e[55]=u,e[56]=N):N=e[56];let M;e[57]!==u.size||e[58]!==r?(M=r("settings.providers.page.custom.discovery.importSelected",{count:u.size}),e[57]=u.size,e[58]=r,e[59]=M):M=e[59];let F;e[60]!==A||e[61]!==N||e[62]!==M?(F=s.jsx(B,{type:"button",size:"xs",className:"!font-normal",disabled:A,onClick:N,children:M}),e[60]=A,e[61]=N,e[62]=M,e[63]=F):F=e[63];let H;e[64]!==r?(H=r("settings.providers.page.custom.discovery.cancel"),e[64]=r,e[65]=H):H=e[65];let W;e[66]!==o||e[67]!==H?(W=s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:o,children:H}),e[66]=o,e[67]=H,e[68]=W):W=e[68];let G;e[69]!==F||e[70]!==W?(G=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[F,W]}),e[69]=F,e[70]=W,e[71]=G):G=e[71];let $;return e[72]!==T||e[73]!==P||e[74]!==O||e[75]!==G||e[76]!==w?($=s.jsxs("div",{className:w,children:[T,P,O,G]}),e[72]=T,e[73]=P,e[74]=O,e[75]=G,e[76]=w,e[77]=$):$=e[77],$};function dy(t){return t.id}const uy=["text","image","audio","video","pdf"],_c=t=>{const e=Number(t.trim());return Number.isSafeInteger(e)&&e>0?e:null},my=t=>{const e=$e.c(70),{model:n,errors:a,expanded:i,onToggle:o,onChange:r,onToggleCapability:c,onToolsChange:l,onRemove:m}=t,{t:u}=_e(),f=d.useId();let p;e[0]!==n.id?(p=n.id.trim(),e[0]=n.id,e[1]=p):p=e[1];const g=p;let h;e[2]!==n.name?(h=n.name.trim(),e[2]=n.name,e[3]=h):h=e[3];const j=h;let x;e[4]!==g||e[5]!==j||e[6]!==u?(x=j||g||u("settings.providers.page.custom.models.untitled"),e[4]=g,e[5]=j,e[6]=u,e[7]=x):x=e[7];const S=x;let b,w,k;if(e[8]!==n.contextWindow||e[9]!==n.inputCapabilities||e[10]!==n.maxOutputTokens||e[11]!==u){const U=_c(n.contextWindow),_=_c(n.maxOutputTokens),V=n.inputCapabilities.filter(py);b=U?u("settings.providers.page.custom.discovery.contextValue",{value:go(U)}):null,w=_?u("settings.providers.page.custom.discovery.outputValue",{value:go(_)}):null,k=V.length>0?V.join(", "):null,e[8]=n.contextWindow,e[9]=n.inputCapabilities,e[10]=n.maxOutputTokens,e[11]=u,e[12]=b,e[13]=w,e[14]=k}else b=e[12],w=e[13],k=e[14];let I;e[15]!==n.tools||e[16]!==u?(I=n.tools?null:u("settings.providers.page.custom.models.toolsOff"),e[15]=n.tools,e[16]=u,e[17]=I):I=e[17];let y;e[18]!==b||e[19]!==w||e[20]!==k||e[21]!==I?(y=[b,w,k,I].filter(Boolean),e[18]=b,e[19]=w,e[20]=k,e[21]=I,e[22]=y):y=e[22];const E=y.join(" · "),v=gy,R=i&&"rotate-90";let C;e[23]!==R?(C=je("size-4 shrink-0 text-muted-foreground transition-transform",R),e[23]=R,e[24]=C):C=e[24];let T;e[25]!==C?(T=s.jsx(J,{name:"arrow-right-s",className:C,"aria-hidden":!0}),e[25]=C,e[26]=T):T=e[26];const P=!j&&!g&&"text-muted-foreground";let L;e[27]!==P?(L=je("truncate",Pt,P),e[27]=P,e[28]=L):L=e[28];let O;e[29]!==L||e[30]!==S?(O=s.jsx("span",{className:L,children:S}),e[29]=L,e[30]=S,e[31]=O):O=e[31];let A;e[32]!==g||e[33]!==j?(A=j&&g&&j!==g?s.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:g}):null,e[32]=g,e[33]=j,e[34]=A):A=e[34];let N;e[35]!==O||e[36]!==A?(N=s.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[O,A]}),e[35]=O,e[36]=A,e[37]=N):N=e[37];let M;e[38]!==E?(M=E?s.jsx("span",{className:je("truncate",Mt),children:E}):null,e[38]=E,e[39]=M):M=e[39];let F;e[40]!==N||e[41]!==M?(F=s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[N,M]}),e[40]=N,e[41]=M,e[42]=F):F=e[42];let H;e[43]!==f||e[44]!==i||e[45]!==o||e[46]!==T||e[47]!==F?(H=s.jsxs("button",{type:"button",onClick:o,"aria-expanded":i,"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:[T,F]}),e[43]=f,e[44]=i,e[45]=o,e[46]=T,e[47]=F,e[48]=H):H=e[48];let W;e[49]!==m||e[50]!==u?(W=m?s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:ls,onClick:m,"aria-label":u("settings.providers.page.custom.models.remove"),children:s.jsx(J,{name:"delete-bin",className:"size-4"})}):null,e[49]=m,e[50]=u,e[51]=W):W=e[51];let G;e[52]!==H||e[53]!==W?(G=s.jsxs("div",{className:"flex items-center gap-1 py-1",children:[H,W]}),e[52]=H,e[53]=W,e[54]=G):G=e[54];let $;e[55]!==f||e[56]!==a?.contextWindow||e[57]!==a?.id||e[58]!==a?.maxOutputTokens||e[59]!==a?.name||e[60]!==i||e[61]!==n||e[62]!==r||e[63]!==c||e[64]!==l||e[65]!==u?($=i?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:Pt,children:u("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:n.id,onChange:U=>r("id",U.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!a?.id,"aria-label":u("settings.providers.page.custom.models.idLabel")}),v(a?.id)]}),s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:n.name,onChange:U=>r("name",U.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-invalid":!!a?.name,"aria-label":u("settings.providers.page.custom.models.nameLabel")}),v(a?.name)]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 @xl:grid-cols-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.contextWindow")}),s.jsx(He,{inputMode:"numeric",value:n.contextWindow,onChange:U=>r("contextWindow",U.target.value),placeholder:"128000",className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!a?.contextWindow,"aria-label":u("settings.providers.page.custom.models.contextWindow")}),v(a?.contextWindow)]}),s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.maxOutputTokens")}),s.jsx(He,{inputMode:"numeric",value:n.maxOutputTokens,onChange:U=>r("maxOutputTokens",U.target.value),placeholder:"16384",className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!a?.maxOutputTokens,"aria-label":u("settings.providers.page.custom.models.maxOutputTokens")}),v(a?.maxOutputTokens)]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.variantsLabel")}),s.jsx(Wt,{children:u("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(He,{value:n.variants,onChange:U=>r("variants",U.target.value),placeholder:u("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.variantsLabel")})]}),["inputCapabilities","outputCapabilities"].map(U=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("span",{className:Pt,children:u(U==="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:uy.map(_=>s.jsx(ct,{checked:n[U].includes(_),onChange:()=>c(U,_),label:_,ariaLabel:_},_))})]},U)),s.jsx(ct,{checked:n.tools,onChange:l,label:u("settings.providers.page.custom.models.tools"),ariaLabel:u("settings.providers.page.custom.models.tools")}),n.metadataSource==="models.dev"||n.metadataSource==="provider-api"?s.jsx("p",{className:Mt,children:n.metadataSource==="models.dev"?u("settings.providers.page.custom.discovery.source.models.dev"):u("settings.providers.page.custom.discovery.source.provider-api")}):null]}):null,e[55]=f,e[56]=a?.contextWindow,e[57]=a?.id,e[58]=a?.maxOutputTokens,e[59]=a?.name,e[60]=i,e[61]=n,e[62]=r,e[63]=c,e[64]=l,e[65]=u,e[66]=$):$=e[66];let z;return e[67]!==G||e[68]!==$?(z=s.jsxs("div",{className:"border-b border-border/50 last:border-b-0",children:[G,$]}),e[67]=G,e[68]=$,e[69]=z):z=e[69],z};function py(t){return t!=="text"}function gy(t){return t?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:t}):null}const Bc=({existingProviderIDs:t,disabledProviders:e=[],busy:n=!1,mode:a="create",initialValues:i,allowExistingAuth:o=!1,authFailureHint:r=null,onSubmit:c,onCancel:l,onDisconnect:m})=>{const{t:u}=_e(),f=a==="edit",[p,g]=d.useState(()=>i??Qv()),[h,j]=d.useState({}),[x,S]=d.useState([]),[b,w]=d.useState([]),[k,I]=d.useState(!1),[y,E]=d.useState(null),[v,R]=d.useState(null),[C,T]=d.useState(()=>new Set(i?[]:p.models.map(z=>z.row))),P=d.useRef(null),L=p.providerID.trim()||"custom",{hasLogo:O}=Em(L);d.useEffect(()=>{i&&(f&&P.current===i.providerID||(P.current=f?i.providerID:null,g(i),j({}),S([]),w([]),T(new Set),R(null)))},[i,f]);const A=(z,U)=>{g(_=>({..._,[z]:U})),j(_=>({..._,[z]:void 0}))},N=(z,U,_)=>{g(V=>({...V,models:V.models.map((Z,Y)=>Y===z?{...Z,[U]:_,metadataSource:"manual"}:Z)})),S(V=>{const Z=[...V];return Z[z]={...Z[z]??{},[U]:void 0},Z})},M=(z,U,_)=>{g(V=>({...V,headers:V.headers.map((Z,Y)=>Y===z?{...Z,[U]:_}:Z)})),w(V=>{const Z=[...V];return Z[z]={...Z[z]??{},[U]:void 0},Z})},F=async()=>{I(!0),E(null);try{const z=Object.fromEntries(p.headers.map(Z=>[Z.key.trim(),Z.value.trim()]).filter(([Z,Y])=>Z&&Y)),U=await Lt("/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:z,enrich:!0,metadataProviderID:p.providerID})}),_=await U.json().catch(()=>null),V=Vv.safeParse(_);if(!U.ok||!V.success)throw new Error(Hv.safeParse(_).data?.error||u("settings.providers.page.custom.discovery.failed"));R(V.data.models)}catch(z){E(z instanceof Error?z.message:u("settings.providers.page.custom.discovery.failed"))}finally{I(!1)}},H=z=>{g(U=>{const _=new Set(U.models.map(Y=>Y.id.trim()).filter(Boolean)),V=z.filter(Y=>!_.has(Y.id)).map(qv),Z=U.models.filter(Y=>Y.id.trim()||Y.name.trim());return{...U,models:[...Z,...V]}}),S([]),R(null)},W=z=>T(U=>{const _=new Set(U);return _.has(z)?_.delete(z):_.add(z),_}),G=(z,U,_)=>{g(V=>({...V,models:V.models.map((Z,Y)=>{if(Y!==z)return Z;const Q=Z[U],ue=Q.includes(_)?Q.filter(ge=>ge!==_):[...Q,_];return{...Z,[U]:ue,capabilitiesKnown:!0,metadataSource:"manual"}})}))},$=async z=>{if(z.preventDefault(),n)return;const U=sy({form:p,t:((V,Z)=>u(V,Z)),existingProviderIDs:t,disabledProviders:e,editingProviderID:f?p.providerID:void 0,allowExistingAuth:f&&o});j(U.err),S(U.models),w(U.headers);const _=p.models.filter((V,Z)=>Object.values(U.models[Z]??{}).some(Boolean)).map(V=>V.row);_.length>0&&T(V=>new Set([...V,..._])),U.result&&await c(U.result)};return s.jsxs("form",{onSubmit:$,className:"space-y-0",children:[s.jsxs(qe,{title:u(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:u("settings.providers.page.custom.description")}),r?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:r}):null,s.jsxs(Rt,{label:u("settings.providers.page.custom.field.providerID.label"),info:u("settings.providers.page.custom.field.providerID.info"),children:[s.jsx(He,{value:p.providerID,onChange:z=>A("providerID",z.target.value),placeholder:u("settings.providers.page.custom.field.providerID.placeholder"),className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:!f,disabled:f||n,"aria-invalid":!!h.providerID,"aria-label":u("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(Rt,{label:u("settings.providers.page.custom.field.protocol.label"),info:u("settings.providers.page.custom.field.protocol.info"),children:s.jsxs(Dt,{value:p.protocol,onValueChange:z=>{z in Sl&&g(U=>({...U,protocol:z,models:U.models.map(_=>_.savedVariants?{..._,savedVariants:{}}:_)}))},disabled:n,children:[s.jsx(Tt,{"aria-label":u("settings.providers.page.custom.field.protocol.label"),className:"w-full",children:s.jsx($t,{})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"openai-chat",children:u("settings.providers.page.custom.field.protocol.openaiChat")}),s.jsx(dt,{value:"openai-responses",children:u("settings.providers.page.custom.field.protocol.openaiResponses")}),s.jsx(dt,{value:"anthropic-messages",children:u("settings.providers.page.custom.field.protocol.anthropicMessages")})]})]})}),s.jsxs(Rt,{label:u("settings.providers.page.custom.field.name.label"),info:u("settings.providers.page.custom.field.name.info"),children:[s.jsx(He,{value:p.name,onChange:z=>A("name",z.target.value),placeholder:u("settings.providers.page.custom.field.name.placeholder"),className:"h-8 rounded-md px-3","aria-invalid":!!h.name,"aria-label":u("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(Rt,{label:u("settings.providers.page.custom.field.icon.label"),info:u("settings.providers.page.custom.field.icon.info"),children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",role:"group","aria-label":u("settings.providers.page.custom.field.icon.label"),children:[s.jsx(B,{type:"button",variant:p.icon===null?"chip":"ghost",size:"icon",className:je(ls,p.icon===null&&"text-foreground"),"aria-label":u("settings.providers.page.custom.field.icon.option.default"),title:u("settings.providers.page.custom.field.icon.option.default"),"aria-pressed":p.icon===null,onClick:()=>g(z=>({...z,icon:null})),children:O?s.jsx(bn,{providerId:L,className:"size-4",ignoreCustomIcon:!0}):s.jsx(J,{name:"checkbox-blank-circle",className:"size-4 text-muted-foreground"})}),ng.map(z=>s.jsx(B,{type:"button",variant:p.icon===z.id?"chip":"ghost",size:"icon",className:je(ls,p.icon===z.id&&"text-foreground"),"aria-label":u(`settings.providers.page.custom.field.icon.option.${z.id}`),title:u(`settings.providers.page.custom.field.icon.option.${z.id}`),"aria-pressed":p.icon===z.id,onClick:()=>g(U=>({...U,icon:z.id})),children:s.jsx(J,{name:z.icon,className:"size-4"})},z.id))]})}),s.jsxs(Rt,{label:u("settings.providers.page.custom.field.baseURL.label"),info:u("settings.providers.page.custom.field.baseURL.info"),children:[s.jsx(He,{value:p.baseURL,onChange:z=>A("baseURL",z.target.value),placeholder:u("settings.providers.page.custom.field.baseURL.placeholder"),className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":!!h.baseURL,"aria-label":u("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(Rt,{label:u("settings.providers.page.custom.field.apiKey.label"),info:u(f&&o?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),children:[s.jsx(He,{type:"password",value:p.apiKey,onChange:z=>A("apiKey",z.target.value),placeholder:u(f&&o?"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":u("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(qe,{title:u("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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{F()},disabled:n||k||!p.baseURL.trim(),children:[s.jsx(J,{name:"search",className:"size-3.5"}),u(k?"settings.providers.page.custom.discovery.fetching":"settings.providers.page.custom.discovery.fetch")]}),s.jsx(Wt,{children:u("settings.providers.page.custom.discovery.info")})]}),y?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",role:"alert",children:y}):null,v?s.jsx(cy,{models:v,existingIds:new Set(p.models.map(z=>z.id.trim()).filter(Boolean)),onAdd:H,onCancel:()=>R(null)}):null]}),s.jsx("div",{className:ks,children:p.models.map((z,U)=>s.jsx(my,{model:z,errors:x[U],expanded:C.has(z.row),onToggle:()=>W(z.row),onChange:(_,V)=>N(U,_,V),onToggleCapability:(_,V)=>G(U,_,V),onToolsChange:_=>g(V=>({...V,models:V.models.map((Z,Y)=>Y===U?{...Z,tools:_,capabilitiesKnown:!0,metadataSource:"manual"}:Z)})),onRemove:p.models.length>1?()=>{g(_=>({..._,models:_.models.filter((V,Z)=>Z!==U)})),S(_=>_.filter((V,Z)=>Z!==U))}:void 0},z.row))}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const z=Do();g(U=>({...U,models:[...U.models,z]})),S(U=>[...U,{}]),T(U=>new Set([...U,z.row]))},children:u("settings.providers.page.custom.models.add")})]}),s.jsxs(qe,{title:u("settings.providers.page.custom.headers.title"),contentClassName:ws,children:[s.jsx("p",{className:Mt,children:u("settings.providers.page.custom.headers.description")}),p.headers.map((z,U)=>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:Pt,children:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:z.key,onChange:_=>M(U,"key",_.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),b[U]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b[U]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:z.value,onChange:_=>M(U,"value",_.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),b[U]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b[U]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:ls,disabled:p.headers.length<=1,onClick:()=>{p.headers.length<=1||(g(_=>({..._,headers:_.headers.filter((V,Z)=>Z!==U)})),w(_=>_.filter((V,Z)=>Z!==U)))},"aria-label":u("settings.providers.page.custom.headers.remove"),children:s.jsx(J,{name:"delete-bin",className:"size-4"})})]})},z.row)),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{g(z=>({...z,headers:[...z.headers,Nl()]})),w(z=>[...z,{}])},children:u("settings.providers.page.custom.headers.add")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[l?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:l,disabled:n,children:u("settings.providers.page.custom.actions.back")}):null,m?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:n,children:u("settings.providers.page.actions.disconnect")}):null,s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:n,children:u(n?"settings.providers.page.actions.saving":f?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save")})]})]})},fy=t=>new Intl.NumberFormat(Io(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Vc=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=fy(t);return e.endsWith(".0")?e.slice(0,-2):e},Nn="__add_provider__",za="__classification__",Su=t=>typeof t=="object"&&t!==null,hy=t=>{if(typeof t=="string")return{id:t};if(!Su(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const n=typeof t.name=="string"?t.name:void 0;return{id:e,name:n}},xy=t=>{let e=[];Array.isArray(t)?e=t:Su(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(i=>hy(i)).filter(i=>!!i),a=new Set;return n.filter(i=>a.has(i.id)?!1:(a.add(i.id),!0))},by=()=>{const{t}=_e(),{isMobile:e}=Qn(),n=Zs(),a=rt(pe=>Ad(pe,n)),i=ne(pe=>pe.settingsProvidersConnectRequested),o=ne(pe=>pe.setSettingsProvidersConnectRequested),r=ne(pe=>pe.settingsProvidersClassificationRequested),c=ne(pe=>pe.setSettingsProvidersClassificationRequested),l=ne(pe=>pe.settingsProvidersOpenRequested),m=ne(pe=>pe.setSettingsProvidersOpenRequested),[u,f]=d.useState(()=>i?Nn:r?za:l??"");d.useEffect(()=>{i&&(f(Nn),o(!1))},[i,o]),d.useEffect(()=>{r&&(f(za),c(!1))},[r,c]),d.useEffect(()=>{l&&(f(l),m(null))},[l,m]);const p=rt(pe=>pe.getModelMetadata),g=ne(pe=>pe.hiddenModels),h=ne(pe=>pe.customProviderIcons),j=ne(pe=>pe.setCustomProviderIcon),x=ne(pe=>pe.toggleHiddenModel),S=ne(pe=>pe.hideAllModels),b=ne(pe=>pe.showAllModels),w=rt(pe=>pe.loadProviders);d.useEffect(()=>{n&&w({directory:n,source:"settings:providers"})},[w,n]);const[k,I]=d.useState(null),[y,E]=d.useState(!1),[v,R]=d.useState({}),[C,T]=d.useState(null),[P,L]=d.useState(null),[O,A]=d.useState(""),[N,M]=d.useState([]),[F,H]=d.useState(!1),[W,G]=d.useState(null),[$,z]=d.useState(""),[U,_]=d.useState(""),[V,Z]=d.useState(!1),[Y,Q]=d.useState({}),[ue,ge]=d.useState({}),[fe,Ie]=d.useState(0),[te,Ce]=d.useState(0),[ie,ae]=d.useState(!1),re=zn(),[ye,Ee]=d.useState(null),[Pe,ke]=d.useState(null),[Te,de]=d.useState(null),[Me,Se]=d.useState(null),[Le,Ke]=d.useState(null),[oe,le]=d.useState(null),xe=u===Nn,De=xe&&$===ra,Ve=!!(Pe&&u&&Pe===u&&!xe);d.useEffect(()=>{let pe=!0;return(async()=>{E(!0);try{const{data:ze}=await Ps.getSdkClient().integration.list();if(!pe)return;I(ze)}catch(ze){if(!pe)return;console.error("Failed to load provider integrations:",ze),q.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{pe&&E(!1)}})(),()=>{pe=!1}},[te,t]),d.useEffect(()=>{if(!rv(xe))return;let pe=!0;return(async()=>{H(!0),G(null);try{const[{data:ze},pt]=await Promise.all([Ps.getSdkClient().integration.list(),Dm(Ps.getDirectory()??null).catch(()=>null)]);if(!pe)return;const Ct=new Set((pt??[]).map(Gt=>Gt.id));M(xy(ze.filter(Gt=>!Gt.id.startsWith("mcp_")&&!Ct.has(Gt.id)&&Gt.connections.length===0)))}catch(ze){if(!pe)return;console.error("Failed to load available providers:",ze),G(t("settings.providers.page.state.unableToLoadProviderList"))}finally{pe&&H(!1)}})(),()=>{pe=!1}},[xe,t]);const Be=d.useMemo(()=>new Set(a.map(pe=>pe.id)),[a]),Ne=d.useMemo(()=>N.filter(pe=>!Be.has(pe.id)).sort((pe,we)=>{const ze=(pe.name||pe.id).toLowerCase(),pt=(we.name||we.id).toLowerCase();return ze.localeCompare(pt)}),[N,Be]);d.useEffect(()=>{u!==Nn||F||N.length===0||$&&$!==ra&&!Ne.some(pe=>pe.id===$)&&z("")},[u,$,Ne,F,N.length]),d.useEffect(()=>{if(u===Nn){ae(!0),Ee(null),ke(null),de(null),Se(null),Ke(null);return}ae(!1),Ee(null),Pe&&Pe!==u&&(ke(null),de(null),Se(null),Ke(null))},[u,Pe]),d.useEffect(()=>{if(!u||u===Nn||u===za)return;const pe=Y[u];if(!pe||k===null)return;const we=a.find(Ct=>Ct.id===u),ze=Mc({connections:mo(k,u),optionsApiKey:Gr(we)}),pt=!!(we&&zc(we,pe));pv({hasCredentials:ze,userDismissed:ye===u,isEditableCustomProvider:pt})&&ae(!0)},[u,Y,a,k,ye]),d.useEffect(()=>{if(!u||u===Nn||u===za)return;let pe=!1;return(async()=>{try{const ze=n?`?directory=${encodeURIComponent(n)}`:"",pt=await Lt(`/api/provider/${encodeURIComponent(u)}/source${ze}`,{method:"GET",headers:{Accept:"application/json"}}),Ct=await pt.json().catch(()=>null);if(!pt.ok)throw new Error(Ct?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Gt=Ct?.sources??Ct?.data?.sources;!pe&&Gt&&(Q(Zt=>({...Zt,[u]:Gt})),ge(Zt=>({...Zt,[u]:ey.safeParse(Ct?.config??Ct?.data?.config).data??null})))}catch(ze){pe||console.error("Failed to load provider sources:",ze)}})(),()=>{pe=!0}},[u,fe,n,t]);const Je=d.useCallback(()=>{Ie(pe=>pe+1)},[]),ut=d.useCallback(()=>{Ce(pe=>pe+1)},[]),ht=d.useCallback(pe=>{I(we=>(we??[]).map(ze=>ze.id===pe&&ze.connections.length===0?{...ze,connections:[{type:"credential",id:`pending:${pe}`,label:pe,method:"key"}]}:ze)),Ee(null),ae(!1),f(pe),Je(),ut()},[ut,Je,f]),st=a.find(pe=>pe.id===u),jt=u?Y[u]:void 0,St=async pe=>{const we=v[pe]?.trim()??"";if(!we){q.error(t("settings.providers.page.toast.apiKeyRequired"));return}const ze=`api:${pe}`;T(ze);try{await Ps.getSdkClient().integration.connect.key({integrationID:pe,key:we}),q.success(t("settings.providers.page.toast.apiKeySaved")),R(pt=>({...pt,[pe]:""})),ht(pe)}catch(pt){console.error("Failed to save API key:",pt),q.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{T(null)}},Ze=async pe=>{const we=`custom:${pe.providerID}`;T(we),le(pe.providerID),Ke(null);try{const ze=ay(pe),pt=iy(pe,{scope:Pe?Me??Uc(Y[Pe]):"user"}),Ct=await Lt(`/api/provider${n?`?directory=${encodeURIComponent(n)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(pt)}),Gt=await Ct.json().catch(()=>null);if(!Ct.ok)throw new Error(Gt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));if(ze)try{await ry(()=>Ps.getSdkClient().integration.connect.key(ze))}catch(as){throw Ke(t("settings.providers.page.custom.authFailure.keyAfterConfig")),as}const Zt={...ne.getState().customProviderIcons};pe.icon?Zt[pe.providerID]=pe.icon:delete Zt[pe.providerID],await bt({customProviderIcons:Zt}),j(pe.providerID,pe.icon),q.success(t("settings.providers.page.toast.customProviderSaved",{provider:pe.name})),z(""),ke(null),de(null),Se(null),Ke(null),le(null),ht(pe.providerID)}catch(ze){console.error("Failed to save custom provider:",ze),q.error(ze instanceof Error&&ze.message?ze.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{T(null)}},it=pe=>{ae(!1),ht(pe)},et=async pe=>{const we=`disconnect:${pe}`;T(we);try{const ze=Dc(In(k??[],pe)),pt=Ps.getSdkClient();for(const Ct of ze)await pt.credential.remove({credentialID:Ct.id});q.success(t("settings.providers.page.toast.providerDisconnected")),Ee(null),Je(),ut()}catch(ze){console.error("Failed to disconnect provider:",ze),q.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{T(null)}},mt=async pe=>{pe&&(await et(pe),ke(null),de(null),Se(null),Ke(null),le(null),z(""))},ft=async(pe,we,ze)=>{L(pe.id);try{await we(),ze.success&&q.success(ze.success)}catch(pt){console.error("Provider account action failed:",pt),q.error(ze.failure)}finally{L(null),ut()}},be=pe=>ft(pe,async()=>{await Ps.getSdkClient().credential.activate({credentialID:pe.id})},{success:t("settings.providers.accounts.toast.switched",{account:pe.label}),failure:t("settings.providers.accounts.toast.switchFailed")}),Re=(pe,we)=>ft(pe,async()=>{await Ps.getSdkClient().credential.update({credentialID:pe.id,label:we})},{failure:t("settings.providers.accounts.toast.renameFailed")}),X=pe=>ft(pe,async()=>{await Ps.getSdkClient().credential.remove({credentialID:pe.id}),Je()},{success:t("settings.providers.accounts.toast.removed"),failure:t("settings.providers.accounts.toast.removeFailed")}),ce=()=>f(""),Oe=s.jsx(yl,{label:t("settings.providers.page.back"),onClick:ce}),We=pe=>{if(a.some(we=>we.id===pe)){f(pe);return}z(pe),f(Nn)};if(u===za)return s.jsx(Rv,{titleLeading:Oe,onOpenProvider:We});if(xe&&!re)return s.jsxs(es,{title:t("settings.providers.page.connect.title"),titleLeading:Oe,showSaveStatus:!1,children:[s.jsx(qe,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),F?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):W?s.jsx("p",{className:"typography-meta text-muted-foreground",children:W}):s.jsxs(Kn,{open:V,onOpenChange:pe=>{Z(pe),pe||_("")},children:[s.jsx(Fn,{asChild:!0,children:s.jsxs("button",{type:"button",className:qs,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[$&&$!==ra?s.jsx(bn,{providerId:$,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:je("truncate typography-ui-label font-normal",$?"text-foreground":"text-muted-foreground"),children:$===ra?t("settings.providers.page.custom.optionLabel"):$?Ne.find(pe=>pe.id===$)?.name||$:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(J,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(On,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:pe=>pe.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:pe=>pe.stopPropagation(),children:[s.jsx(J,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:U,onChange:pe=>_(pe.target.value),onKeyDown:pe=>pe.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(js,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const pe=t("settings.providers.page.custom.optionLabel"),we=Co([pe,"other","custom"],U),ze=Wn(Ne,U,pt=>[pt.name||pt.id,pt.id]);return ze.length===0&&!we?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[ze.map(pt=>s.jsxs(mn,{onSelect:()=>{z(pt.id),Z(!1),_("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(bn,{providerId:pt.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:pt.name||pt.id})]}),$===pt.id&&s.jsx(J,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},pt.id)),we?s.jsxs(mn,{onSelect:()=>{z(ra),Z(!1),_("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(J,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:pe})]}),$===ra&&s.jsx(J,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ra):null]})})()})]})]})]})}),De?s.jsx(Bc,{mode:"create",existingProviderIDs:Be,busy:C?.startsWith("custom:")??!1,authFailureHint:Le,onCancel:()=>{z(""),Ke(null),le(null)},onDisconnect:Le&&oe?()=>{mt(oe)}:void 0,onSubmit:Ze}):$?s.jsx(qe,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:y?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const pe=In(k??[],$),we=Tc(In(k??[],xi($))),ze=Ec(pe);return s.jsxs(s.Fragment,{children:[ze?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Wt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:v[$]??"",onChange:pt=>R(Ct=>({...Ct,[$]:pt.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>St($),disabled:C===`api:${$}`,children:C===`api:${$}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,we.length>0?s.jsx(Br,{integrationId:xi($),methods:we,onConnected:()=>it($),className:je(ze&&"border-t border-[var(--surface-subtle)] pt-2")},$):null]})})()})}):null]});if(!st)return s.jsx(wv,{providers:a,integrations:k,directory:n,onSelect:f,onConnect:()=>f(Nn),onOpenClassification:()=>f(za)});const nt=Array.isArray(st.models)?st.models:[],at=In(k??[],st.id),vt=Tc(In(k??[],xi(st.id))),kt=Ec(at),xt=k!==null,It=!!jt,_t=It&&zc(st,jt),Ye=Mc({connections:mo(k??[],st.id),optionsApiKey:Gr(st)}),Xe=lv(xt,Ye,_t),gt=mv({modelCount:nt.length,integrationsLoaded:xt,hasCredentials:Ye,isEditableCustomProvider:_t}),Ue=mo(k??[],st.id)??[],ee=st.integrationID??st.id,ve=Dc(In(k??[],ee)),Fe=ve[0]?.id??null,se=new Set(Ue.flatMap(pe=>pe.type==="credential"&&!ve.some(we=>we.id===pe.id)?[pe.id]:[])),Ae=[jt?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,jt?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,jt?.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(pe=>pe!==null),tt=s.jsxs("span",{className:"flex items-center gap-2",children:[Oe,s.jsx(bn,{providerId:st.id,className:"h-5 w-5 shrink-0"})]}),ot=s.jsxs("span",{className:"typography-settings-description text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:st.id}),Ae.length>0?s.jsxs(s.Fragment,{children:[" · ",t("settings.providers.page.configuredIn",{sources:Ae.join(", ")})]}):null]}),At=Wn(nt,O,pe=>[typeof pe?.name=="string"?pe.name:"",typeof pe?.id=="string"?pe.id:""]);return Ve&&_t&&Te?s.jsx(es,{title:st.name||st.id,titleLeading:tt,description:ot,showSaveStatus:!1,children:s.jsx(Bc,{mode:"edit",existingProviderIDs:Be,initialValues:Te,allowExistingAuth:Ye||!It,busy:C?.startsWith("custom:")??!1,authFailureHint:Le,onCancel:()=>{ke(null),de(null),Se(null),Ke(null),le(null)},onDisconnect:()=>{mt(st.id)},onSubmit:Ze})}):s.jsxs(es,{title:st.name||st.id,titleLeading:tt,description:ot,showSaveStatus:!1,children:[s.jsxs(qe,{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:[_t&&!re?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ke(null),de(ty(st,ue[st.id]??null,h[st.id])),Se(Uc(jt)),ke(st.id)},children:t("settings.providers.page.actions.edit")}):null,re?null:s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const pe=!ie;ae(pe),Ee(pe?null:st.id)},children:ie?t("settings.providers.page.actions.cancel"):s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"add",className:"size-3.5"}),Ue.length>0?t("settings.providers.accounts.add"):t("settings.providers.page.actions.connect")]})})]}),settingsItem:"providers.auth",contentClassName:"space-y-4",children:[Ue.length>0?s.jsx(Kv,{connections:Ue,activeId:Fe,unusedIds:se,busyId:P,onActivate:pe=>{be(pe)},onRename:(pe,we)=>{Re(pe,we)},onRemove:pe=>{X(pe)}}):!ie&&Xe?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(J,{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")}),kt?s.jsx(Wt,{children:t("settings.providers.page.auth.incompleteHint")}):null]}):null,re?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.enterpriseMode")}):null,!ie||re?null:y?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:je("space-y-4",Ue.length>0&&"rounded-xl border border-[var(--interactive-border)] p-4"),children:[kt?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Wt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:v[st.id]??"",onChange:pe=>R(we=>({...we,[st.id]:pe.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>St(st.id),disabled:C===`api:${st.id}`,children:C===`api:${st.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,vt.length>0&&s.jsx(Br,{integrationId:xi(st.id),methods:vt,onConnected:()=>it(st.id),className:je(kt&&"border-t border-[var(--surface-subtle)] pt-2")},st.id)]})]}),gt?s.jsxs(qe,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",nt.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const pe=nt.map(we=>typeof we?.id=="string"?we.id:"").filter(we=>we.length>0);S(st.id,pe)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>b(st.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(J,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:O,onChange:pe=>A(pe.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),At.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:At.map(pe=>{const we=typeof pe?.id=="string"?pe.id:"",ze=typeof pe?.name=="string"?pe.name:we,pt=we?p(st.id,we):void 0,Ct=g.some(Es=>Es.providerID===st.id&&Es.modelID===we),Gt=Vc(pt?.limit?.context),Zt=Vc(pt?.limit?.output),as=[Gt?`${Gt} ${t("settings.providers.page.models.tokenBadge.context")}`:null,Zt?`${Zt} ${t("settings.providers.page.models.tokenBadge.output")}`:null].filter(Boolean).join(" · "),Jt=[];return pt?.tool_call&&Jt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),pt?.reasoning&&Jt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),pt?.attachment&&Jt.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:je("flex items-center gap-3",Ct&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ze}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e?as||Jt.length>0?s.jsx(Wt,{className:"h-6 w-6",children:s.jsxs("div",{className:"space-y-1.5",children:[as?s.jsx("div",{className:"font-medium",children:as}):null,Jt.map(({key:Es,icon:pn,label:Un})=>s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(J,{name:pn,className:"h-3.5 w-3.5"}),Un]},Es))]})}):null:s.jsxs(s.Fragment,{children:[as?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:as}):null,Jt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Jt.map(({key:Es,icon:pn,label:Un})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Un,"aria-label":Un,children:s.jsx(J,{name:pn,className:"h-3 w-3"})},Es))})]}),s.jsx("button",{type:"button",onClick:()=>x(st.id,we),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(Ct?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ct?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ct?s.jsx(J,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(J,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},we)})})]}):null]})},vy=t=>{const e=t?.windows??{},n=Object.values(e).map(a=>a.usedPercent).filter(a=>typeof a=="number");return n.length===0?null:Math.max(...n)},yy=t=>{const e=$e.c(75),{onItemSelect:n}=t,{t:a}=_e(),i=ds(jy),o=ds(ky),r=ds(wy),c=ds(Sy),l=ds(Ny),m=ds(Cy),u=ds(Iy),f=ds(Py);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=Ay;let j;e[3]!==u?(j=Q=>{Q!=="usage"&&Q!=="remaining"||(u(Q),h({usageDisplayMode:Q}))},e[3]=u,e[4]=j):j=e[4];const x=j;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=je("flex h-full flex-col","bg-background"),e[5]=S):S=e[5];let b;e[6]!==a?(b=a("settings.usage.sidebar.title"),e[6]=a,e[7]=b):b=e[7];let w;e[8]!==b?(w=s.jsx("h2",{className:`${ya} mb-3`,children:b}),e[8]=b,e[9]=w):w=e[9];let k;e[10]!==a?(k=a("settings.usage.sidebar.total",{count:fo.length}),e[10]=a,e[11]=k):k=e[11];let I;e[12]!==k?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[12]=k,e[13]=I):I=e[13];let y;e[14]!==c?(y=()=>c(),e[14]=c,e[15]=y):y=e[15];let E;e[16]!==a?(E=a("settings.usage.sidebar.actions.refreshAria"),e[16]=a,e[17]=E):E=e[17];let v;e[18]!==a?(v=a("settings.usage.sidebar.actions.refreshTitle"),e[18]=a,e[19]=v):v=e[19];const R=l&&"animate-spin";let C;e[20]!==R?(C=je("h-3.5 w-3.5",R),e[20]=R,e[21]=C):C=e[21];let T;e[22]!==C?(T=s.jsx(J,{name:"refresh",className:C}),e[22]=C,e[23]=T):T=e[23];let P;e[24]!==l||e[25]!==E||e[26]!==v||e[27]!==T||e[28]!==y?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:y,"aria-label":E,title:v,disabled:l,children:T})}),e[24]=l,e[25]=E,e[26]=v,e[27]=T,e[28]=y,e[29]=P):P=e[29];let L;e[30]!==P||e[31]!==I?(L=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,P]}),e[30]=P,e[31]=I,e[32]=L):L=e[32];let O;e[33]!==a?(O=a("settings.usage.sidebar.field.display"),e[33]=a,e[34]=O):O=e[34];let A;e[35]!==O?(A=s.jsx("span",{className:"typography-micro text-muted-foreground",children:O}),e[35]=O,e[36]=A):A=e[36];let N;e[37]!==a?(N=a("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=a,e[38]=N):N=e[38];let M;e[39]!==N?(M=s.jsx(Tt,{className:"w-fit",children:s.jsx($t,{placeholder:N})}),e[39]=N,e[40]=M):M=e[40];let F;e[41]!==a?(F=a("settings.usage.sidebar.field.displayModeUsage"),e[41]=a,e[42]=F):F=e[42];let H;e[43]!==F?(H=s.jsx(dt,{value:"usage",children:F}),e[43]=F,e[44]=H):H=e[44];let W;e[45]!==a?(W=a("settings.usage.sidebar.field.displayModeRemaining"),e[45]=a,e[46]=W):W=e[46];let G;e[47]!==W?(G=s.jsx(dt,{value:"remaining",children:W}),e[47]=W,e[48]=G):G=e[48];let $;e[49]!==H||e[50]!==G?($=s.jsxs(Et,{children:[H,G]}),e[49]=H,e[50]=G,e[51]=$):$=e[51];let z;e[52]!==x||e[53]!==M||e[54]!==$||e[55]!==m?(z=s.jsxs(Dt,{value:m,onValueChange:x,children:[M,$]}),e[52]=x,e[53]=M,e[54]=$,e[55]=m,e[56]=z):z=e[56];let U;e[57]!==A||e[58]!==z?(U=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[A,z]}),e[57]=A,e[58]=z,e[59]=U):U=e[59];let _;e[60]!==L||e[61]!==U||e[62]!==w?(_=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[w,L,U]}),e[60]=L,e[61]=U,e[62]=w,e[63]=_):_=e[63];let V;e[64]!==n||e[65]!==i||e[66]!==o||e[67]!==r||e[68]!==a?(V=fo.map(Q=>{const ue=i.find(ie=>ie.providerId===Q.id),ge=vy(ue?.usage),fe=Td(ge),Ie=Q.id===o,te=ue?.configured,Ce=te?fe==="critical"?{backgroundColor:"var(--status-error)"}:fe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Ie?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{r(Q.id),n?.()},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:Ce}),s.jsx(bn,{providerId:Q.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:Q.name}),te===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},Q.id)}),e[64]=n,e[65]=i,e[66]=o,e[67]=r,e[68]=a,e[69]=V):V=e[69];let Z;e[70]!==V?(Z=s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:V}),e[70]=V,e[71]=Z):Z=e[71];let Y;return e[72]!==_||e[73]!==Z?(Y=s.jsxs("div",{className:S,children:[_,Z]}),e[72]=_,e[73]=Z,e[74]=Y):Y=e[74],Y};function jy(t){return t.results}function ky(t){return t.selectedProviderId}function wy(t){return t.setSelectedProvider}function Sy(t){return t.fetchAllQuotas}function Ny(t){return t.isLoading}function Cy(t){return t.displayMode}function Iy(t){return t.setDisplayMode}function Py(t){return t.loadSettings}async function Ay(t){try{await bt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ty=t=>{const e=$e.c(17),{percent:n,tonePercent:a,className:i}=t;let o;e[0]!==n?(o=Mm(n)??0,e[0]=n,e[1]=o):o=e[1];const r=o,c=a??n;let l;e[2]!==c?(l=Td(c),e[2]=c,e[3]=l):l=e[3];const m=l;let u;e[4]!==m?(u=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=u):u=e[5];const f=u;let p;e[6]!==i?(p=je("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,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 j;e[11]!==r||e[12]!==h?(j=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]=j):j=e[13];let x;return e[14]!==p||e[15]!==j?(x=s.jsx("div",{className:p,children:j}),e[14]=p,e[15]=j,e[16]=x):x=e[16],x},yr=t=>{const e=$e.c(49),{title:n,window:a,subtitle:i,showToggle:o,toggleEnabled:r,onToggle:c,providerId:l}=t,m=o===void 0?!1:o,u=r===void 0?!1:r,{t:f}=_e(),p=ds(Ey),g=ne(Dy),h=p==="remaining"?a.remainingPercent:a.usedPercent,j=h!==null;let x;e[0]!==p||e[1]!==f?(x=f(p==="remaining"?"settings.usage.card.bar.remaining":"settings.usage.card.bar.used"),e[0]=p,e[1]=f,e[2]=x):x=e[2];const S=x;let b;e[3]!==h||e[4]!==a.valueLabel?(b=Rm(a.valueLabel,h),e[3]=h,e[4]=a.valueLabel,e[5]=b):b=e[5];const w=b;let k;if(e[6]!==f||e[7]!==g||e[8]!==a.resetAfterFormatted||e[9]!==a.resetAt||e[10]!==a.resetAtFormatted){const W=Lm(a.resetAt,a.resetAfterFormatted??a.resetAtFormatted,g);k=W?f("settings.usage.card.resetsAt",{time:W}):"",e[6]=f,e[7]=g,e[8]=a.resetAfterFormatted,e[9]=a.resetAt,e[10]=a.resetAtFormatted,e[11]=k}else k=e[11];const I=k;let y;e[12]!==n?(y=Om(n),e[12]=n,e[13]=y):y=e[13];const E=y;let v;e[14]!==c||e[15]!==m||e[16]!==f||e[17]!==u?(v=m&&s.jsx(Lr,{checked:u,onChange:W=>c?.(W),ariaLabel:f("settings.usage.card.showInHeaderAria")}),e[14]=c,e[15]=m,e[16]=f,e[17]=u,e[18]=v):v=e[18];let R;e[19]!==E?(R=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E}),e[19]=E,e[20]=R):R=e[20];let C;e[21]!==i?(C=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[21]=i,e[22]=C):C=e[22];let T;e[23]!==R||e[24]!==C?(T=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[R,C]}),e[23]=R,e[24]=C,e[25]=T):T=e[25];let P;e[26]!==T||e[27]!==v?(P=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[v,T]}),e[26]=T,e[27]=v,e[28]=P):P=e[28];let L;e[29]!==l||e[30]!==a?(L=l&&s.jsx(Fm,{window:a,providerId:l}),e[29]=l,e[30]=a,e[31]=L):L=e[31];const O=w==="-"?"":w;let A;e[32]!==O?(A=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums",children:O}),e[32]=O,e[33]=A):A=e[33];let N;e[34]!==L||e[35]!==A?(N=s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[L,A]}),e[34]=L,e[35]=A,e[36]=N):N=e[36];let M;e[37]!==P||e[38]!==N?(M=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[P,N]}),e[37]=P,e[38]=N,e[39]=M):M=e[39];let F;e[40]!==S||e[41]!==h||e[42]!==j||e[43]!==I||e[44]!==a.usedPercent?(F=j?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(Ty,{percent:h,tonePercent:a.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:I}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:S})]})]}):I?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:I}):null,e[40]=S,e[41]=h,e[42]=j,e[43]=I,e[44]=a.usedPercent,e[45]=F):F=e[45];let H;return e[46]!==M||e[47]!==F?(H=s.jsxs("div",{className:"py-3",children:[M,F]}),e[46]=M,e[47]=F,e[48]=H):H=e[48],H};function Ey(t){return t.displayMode}function Dy(t){return t.timeFormatPreference}const My=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,Ry=({providerId:t,providerName:e})=>{const{t:n}=_e(),[a,i]=d.useState(null),[o,r]=d.useState({}),[c,l]=d.useState(!1),m=`/api/quota/credentials/${t}`;d.useEffect(()=>{Lt(m).then(async p=>{if(!p.ok)throw new Error;const g=await p.json();i(g),r({})}).catch(()=>i({configured:!1}))},[m]);const u=async(p,g,h)=>{l(!0);try{const j=await Lt(p,{method:g,headers:h?{"Content-Type":"application/json"}:void 0,body:h?JSON.stringify(h):void 0}),x=await j.json().catch(()=>null);if(!j.ok)throw new Error(x?.error);x?.configured!==void 0&&i(x),r({}),q.success(n("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(j){q.error(j instanceof Error&&j.message?j.message:n("settings.providers.page.openCodeGo.saveFailed"))}finally{l(!1)}},f=(p,g,h)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[g,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:o[p]??"",onChange:j=>r(x=>({...x,[p]:j.target.value})),placeholder:a?.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:n("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:My})]}),t==="zenmux"&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.providers.page.quotaCredentials.zenmuxInstructions")}),t==="ollama-cloud"&&f("cookie",n("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&f("usageToken",n("settings.providers.page.quotaCredentials.usageToken"),n("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="zenmux"&&f("platformApiKey",n("settings.providers.page.quotaCredentials.platformApiKey"),n("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("accessToken",n("settings.providers.page.quotaCredentials.accessToken"),n("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&f("refreshToken",n("settings.providers.page.quotaCredentials.refreshToken"),n("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(B,{size:"xs",disabled:c,onClick:()=>u(m,"PUT",o),children:a?.configured?n("settings.providers.page.openCodeGo.replace"):n("settings.providers.page.openCodeGo.save")}),a?.configured&&s.jsx(B,{variant:"outline",size:"xs",disabled:c,onClick:()=>u(`${m}/validate`,"POST"),children:n("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:c,onClick:()=>u(`${m}/import`,"POST"),children:n("settings.providers.page.actions.connect")}),a?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:c,onClick:()=>u(m,"DELETE"),children:n("settings.providers.page.openCodeGo.delete")})]})]})]})},Hc=(t,e)=>{if(!t)return"-";try{return Ed(t,e,{fallback:"-"})}catch{return"-"}},Ly=()=>{const{t}=_e(),e=ne(M=>M.timeFormatPreference),n=ds(M=>M.results),a=ds(M=>M.selectedProviderId),i=ds(M=>M.setSelectedProvider),o=ds(M=>M.loadSettings),r=ds(M=>M.fetchAllQuotas),c=ds(M=>M.isLoading),l=ds(M=>M.lastUpdated),m=ds(M=>M.refreshErrors),u=ds(M=>M.dropdownProviderIds),f=ds(M=>M.setDropdownProviderIds),p=ds(M=>M.selectedModels),g=ds(M=>M.toggleModelSelected),h=ds(M=>M.applyDefaultSelections);Km(),d.useEffect(()=>{o(),r()},[o,r]),d.useEffect(()=>{if(a||n.length===0)return;const M=n.find(F=>F.configured)?.providerId;i(M??fo[0]?.id??null)},[n,a,i]);const j=n.find(M=>M.providerId===a)??null,S=fo.find(M=>M.id===a)?.name??a??t("settings.usage.sidebar.title"),b=j?.usage,w=a?m[a]:void 0,k=w?b?t("header.services.usageRefreshFailedStale",{error:w}):w:j?.configured&&!j.ok?j.error:null,I=a?u.includes(a):!1,y=a==="exe-dev"||a==="ollama-cloud"||a==="cursor"||a==="zenmux"?a:null,E=y!==null,v=d.useCallback(M=>{if(!a)return;const F=M?Array.from(new Set([...u,a])):u.filter(H=>H!==a);f(F),bt({usageDropdownProviders:F})},[u,a,f]),R=d.useMemo(()=>b?.models?Object.entries(b.models).map(([M,F])=>({name:M,windows:F})).filter(M=>Object.keys(M.windows.windows).length>0):[],[b?.models]);d.useEffect(()=>{a&&R.length>0&&h(a,R.map(M=>M.name))},[a,R,h]);const C=d.useMemo(()=>!a||R.length===0?new Map:zm(R,M=>M.name,a),[R,a]),T=d.useMemo(()=>{if(!a)return[];const M=$m(a);return Um(M)},[a]),[P,L]=d.useState(()=>({})),O=d.useCallback(M=>{L(F=>({...F,[M]:!F[M]}))},[]),A=d.useCallback(M=>{if(!a)return;g(a,M);const F=p[a]??[],W=F.includes(M)?F.filter($=>$!==M):[...F,M],G={...p,[a]:W};bt({usageSelectedModels:G})},[a,p,g]),N=a?p[a]??[]:[];return a?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:S}),titleLeading:s.jsx(bn,{providerId:a,className:"h-5 w-5 shrink-0"}),description:c?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):j?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:j.planLabel,time:Hc(l,e)}):t("settings.usage.page.header.lastUpdated",{time:Hc(l,e)}),showSaveStatus:!0,children:[s.jsx(qe,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(ct,{checked:I,onChange:v,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!j&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),k&&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:k})]}),j&&!j.configured&&!E&&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(Ry,{providerId:y,providerName:S}),b?.windows&&Object.keys(b.windows).length>0&&s.jsx(qe,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(b.windows).map(([M,F])=>s.jsx(yr,{title:M,window:F,providerId:a},M))})}),R.length>0&&s.jsxs(qe,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[T.map(M=>{const F=C.get(M.id)??[];if(F.length===0)return null;const H=P[M.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Js,{open:!H,onOpenChange:()=>O(M.id),children:[s.jsxs(Qs,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:M.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",F.length,")"]})]}),H?s.jsx(J,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(J,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ys,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:F.map(W=>{const G=Object.entries(W.windows.windows);if(G.length===0)return null;const[$,z]=G[0],U=N.includes(W.name);return s.jsx(yr,{title:$,subtitle:Rl(W.name),window:z,showToggle:!0,toggleEnabled:U,onToggle:()=>A(W.name)},W.name)})})})]})},M.id)}),(()=>{const M=C.get(null)??[];if(M.length===0)return null;const F=P.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Js,{open:!F,onOpenChange:()=>O("other"),children:[s.jsxs(Qs,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",M.length,")"]})]}),F?s.jsx(J,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(J,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ys,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(H=>{const W=Object.entries(H.windows.windows);if(W.length===0)return null;const[G,$]=W[0],z=N.includes(H.name);return s.jsx(yr,{title:G,subtitle:Rl(H.name),window:$,showToggle:!0,toggleEnabled:z,onToggle:()=>A(H.name)},H.name)})})})]})})})()]}),j?.configured&&b&&Object.keys(b.windows??{}).length===0&&R.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")})})},Oy="git.commit.generate",Jr=Ig(t=>({selectedPromptId:Oy,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),Fy=t=>{const e=$e.c(23),{onItemSelect:n}=t,{t:a}=_e(),i=Jr(Ky),o=Jr(zy);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 c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[1]=c):c=e[1];let l;e[2]===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[2]=l):l=e[2];let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=[r,c,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[3]=m):m=e[3];const u=m;let f;e[4]!==a?(f=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=f):f=e[5];let p;e[6]!==f?(p=s.jsx("h2",{className:ya,children:f}),e[6]=f,e[7]=p):p=e[7];let g;e[8]!==a?(g=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=g):g=e[9];let h;e[10]!==g?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:g}),e[10]=g,e[11]=h):h=e[11];let j;e[12]!==p||e[13]!==h?(j=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[p,h]}),e[12]=p,e[13]=h,e[14]=j):j=e[14];let x;e[15]!==n||e[16]!==i||e[17]!==o||e[18]!==a?(x=s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:u.map(b=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(b.groupKey)}),b.items.map(w=>{const k=i===w.id;return s.jsx("button",{type:"button",onClick:()=>{o(w.id),n?.()},className:je("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",k?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:a(w.titleKey)})},w.id)})]},b.groupKey))}),e[15]=n,e[16]=i,e[17]=o,e[18]=a,e[19]=x):x=e[19];let S;return e[20]!==x||e[21]!==j?(S=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[j,x]}),e[20]=x,e[21]=j,e[22]=S):S=e[22],S};function Ky(t){return t.selectedPromptId}function zy(t){return t.setSelectedPromptId}const qc={"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"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"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"}]}},Wc=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),jr=t=>t.endsWith(".visible"),Uy=()=>{const{t}=_e(),e=d.useCallback(y=>t(y),[t]),n=Jr(y=>y.selectedPromptId),[a,i]=d.useState(!0),[o,r]=d.useState({}),[c,l]=d.useState({}),[m,u]=d.useState({}),[f,p]=d.useState({}),[g,h]=d.useState(!1);d.useEffect(()=>{let y=!0;return(async()=>{i(!0);try{const v=await Hm();if(!y)return;r(v)}catch(v){console.warn("Failed to load magic prompts:",v),q.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{y&&i(!1)}})(),()=>{y=!1}},[t]);const j=qc[n]??qc["git.commit.generate"],x=d.useCallback(y=>Wc(o,y)?o[y]:ir(y),[o]),S=d.useCallback(y=>c[y]??x(y),[c,x]),b=d.useCallback((y,E)=>{l(v=>v[y]===E?v:{...v,[y]:E})},[]),w=d.useCallback(async y=>{const E=S(y);if(jr(y)&&E.trim().length===0){q.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}u(v=>({...v,[y]:!0}));try{const v=E===ir(y)?await Ll(y):await _m(y,E);r(v.overrides),q.success(t("settings.magicPrompts.page.toast.saved"))}catch(v){const R=v instanceof Error?v.message:String(v);q.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:R})}finally{u(v=>({...v,[y]:!1}))}},[S,t]),k=d.useCallback(async y=>{p(E=>({...E,[y]:!0}));try{const E=await Ll(y);r(E.overrides),l(v=>({...v,[y]:ir(y)})),q.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(E){const v=E instanceof Error?E.message:String(E);q.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:v})}finally{p(E=>({...E,[y]:!1}))}},[t]),I=d.useCallback(async()=>{h(!0);try{const y=await Bm();r(y.overrides),l({}),q.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(y){const E=y instanceof Error?y.message:String(y);q.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:E})}finally{h(!1)}},[t]);return a?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(es,{title:e(j.titleKey),titleAccessory:s.jsx(Wt,{contentClassName:"max-w-xs",children:e(j.descriptionKey)}),headerEnd:s.jsx(B,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{I()},disabled:g||Object.keys(o).length===0,children:t(g?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:j.blocks.map((y,E)=>{const v=Vm(y.id),R=x(y.id),C=S(y.id),T=Wc(o,y.id),P=C!==R,L=jr(y.id)&&C.trim().length===0,O=m[y.id]===!0,A=f[y.id]===!0;return s.jsxs(qe,{title:e(y.titleKey),info:v.description,description:v.placeholders&&v.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${v.placeholders.map(N=>`{{${N.key}}}`).join(", ")}`:void 0,divider:E>0,settingsItem:jr(y.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:C,onChange:N=>b(y.id,N.target.value),className:"min-h-[220px] font-mono text-sm"}),L&&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(P?"settings.magicPrompts.page.status.unsavedChanges":T?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"outline",size:"sm",onClick:()=>{k(y.id)},disabled:!T||O||A,children:t(A?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{w(y.id)},disabled:!P||O||A||L,children:t(O?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},y.id)})})},$y=t=>{const e=$e.c(89),{onItemSelect:n}=t,{t:a}=_e(),[i,o]=d.useState(null),[r,c]=d.useState(null),[l,m]=d.useState(null),{selectedSnippetName:u,snippets:f,setSelectedSnippet:p,setSnippetDraft:g,deleteSnippet:h,loadSnippets:j}=ho(Os(_y));let x,S;e[0]!==j?(x=()=>{j()},S=[j],e[0]=j,e[1]=x,e[2]=S):(x=e[1],S=e[2]),d.useEffect(x,S);let b;e[3]!==n||e[4]!==p||e[5]!==g||e[6]!==f?(b=async()=>{const ae=new Set(f.map(By));let re="new-snippet",ye=1;for(;ae.has(re);)re=`new-snippet-${ye++}`;g({name:re,scope:"global"}),p(re),n?.()},e[3]=n,e[4]=p,e[5]=g,e[6]=f,e[7]=b):b=e[7];const w=b;let k;e[8]!==i||e[9]!==h||e[10]!==a?(k=async()=>{if(!i)return;await h(i.name)?(q.success(a("settings.snippets.sidebar.toast.deleted")),o(null)):q.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=h,e[10]=a,e[11]=k):k=e[11];const I=k;let y;e[12]!==f?(y=[...f].sort(Vy),e[12]=f,e[13]=y):y=e[13];const E=y;let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=je("flex h-full flex-col","bg-background"),e[14]=v):v=e[14];let R;e[15]!==a?(R=a("settings.snippets.sidebar.title"),e[15]=a,e[16]=R):R=e[16];let C;e[17]!==R?(C=s.jsx("h2",{className:`${ya} mb-3`,children:R}),e[17]=R,e[18]=C):C=e[18];let T;e[19]!==f.length||e[20]!==a?(T=a("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=a,e[21]=T):T=e[21];let P;e[22]!==T?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:T}),e[22]=T,e[23]=P):P=e[23];let L;e[24]!==a?(L=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=L):L=e[25];let O;e[26]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),e[26]=O):O=e[26];let A;e[27]!==w||e[28]!==L?(A=s.jsx(B,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,"aria-label":L,children:O}),e[27]=w,e[28]=L,e[29]=A):A=e[29];let N;e[30]!==P||e[31]!==A?(N=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,A]}),e[30]=P,e[31]=A,e[32]=N):N=e[32];let M;e[33]!==N||e[34]!==C?(M=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,N]}),e[33]=N,e[34]=C,e[35]=M):M=e[35];let F;if(e[36]!==n||e[37]!==r||e[38]!==l||e[39]!==u||e[40]!==p||e[41]!==E||e[42]!==a){let ae;e[44]!==n||e[45]!==r||e[46]!==l||e[47]!==u||e[48]!==p||e[49]!==a?(ae=re=>s.jsxs(Ya,{open:l===re.name,onOpenChange:ye=>m(ye?re.name:null),children:[s.jsxs(Qa,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u===re.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ye=>{ye.preventDefault(),m(re.name)}}),children:[s.jsxs("button",{onClick:()=>{p(re.name),n?.()},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:["#",re.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:a(`snippets.source.${re.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:re.description||re.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Kn,{open:r===re.name,onOpenChange:ye=>{ye&&m(null),c(ye?re.name:null)},children:[s.jsx(Fn,{asChild:!0,children:s.jsx(B,{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":a("settings.snippets.sidebar.actions.more",{name:re.name}),children:s.jsx(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(On,{align:"end",className:"w-fit min-w-20",children:s.jsxs(mn,{onClick:ye=>{ye.stopPropagation(),o(re)},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]}),s.jsx(Ga,{className:"w-fit min-w-20",children:s.jsxs(Ja,{onClick:ye=>{ye.stopPropagation(),o(re)},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]},`${re.source}:${re.filePath}`),e[44]=n,e[45]=r,e[46]=l,e[47]=u,e[48]=p,e[49]=a,e[50]=ae):ae=e[50],F=E.map(ae),e[36]=n,e[37]=r,e[38]=l,e[39]=u,e[40]=p,e[41]=E,e[42]=a,e[43]=F}else F=e[43];let H;e[51]!==F?(H=s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:F}),e[51]=F,e[52]=H):H=e[52];const W=i!==null;let G;e[53]===Symbol.for("react.memo_cache_sentinel")?(G=ae=>{ae||o(null)},e[53]=G):G=e[53];let $;e[54]!==a?($=a("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=a,e[55]=$):$=e[55];let z;e[56]!==$?(z=s.jsx(Vt,{children:$}),e[56]=$,e[57]=z):z=e[57];const U=i?.name??"";let _;e[58]!==a||e[59]!==U?(_=a("settings.snippets.sidebar.dialog.deleteDescription",{name:U}),e[58]=a,e[59]=U,e[60]=_):_=e[60];let V;e[61]!==_?(V=s.jsx(Ht,{children:_}),e[61]=_,e[62]=V):V=e[62];let Z;e[63]!==z||e[64]!==V?(Z=s.jsxs(Bt,{children:[z,V]}),e[63]=z,e[64]=V,e[65]=Z):Z=e[65];let Y;e[66]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>o(null),e[66]=Y):Y=e[66];let Q;e[67]!==a?(Q=a("settings.common.actions.cancel"),e[67]=a,e[68]=Q):Q=e[68];let ue;e[69]!==Q?(ue=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,children:Q}),e[69]=Q,e[70]=ue):ue=e[70];let ge;e[71]!==a?(ge=a("settings.common.actions.delete"),e[71]=a,e[72]=ge):ge=e[72];let fe;e[73]!==I||e[74]!==ge?(fe=s.jsx(B,{size:"sm",onClick:I,children:ge}),e[73]=I,e[74]=ge,e[75]=fe):fe=e[75];let Ie;e[76]!==ue||e[77]!==fe?(Ie=s.jsxs(ns,{children:[ue,fe]}),e[76]=ue,e[77]=fe,e[78]=Ie):Ie=e[78];let te;e[79]!==Z||e[80]!==Ie?(te=s.jsxs(Ut,{className:"max-w-md",children:[Z,Ie]}),e[79]=Z,e[80]=Ie,e[81]=te):te=e[81];let Ce;e[82]!==W||e[83]!==te?(Ce=s.jsx(zt,{open:W,onOpenChange:G,children:te}),e[82]=W,e[83]=te,e[84]=Ce):Ce=e[84];let ie;return e[85]!==M||e[86]!==H||e[87]!==Ce?(ie=s.jsxs("div",{className:v,children:[M,H,Ce]}),e[85]=M,e[86]=H,e[87]=Ce,e[88]=ie):ie=e[88],ie};function _y(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function By(t){return t.name}function Vy(t,e){return t.name.localeCompare(e.name)}const Hy=()=>{const{t}=_e(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:i,updateSnippet:o,createSnippet:r}=ho(Os(v=>({selectedSnippetName:v.selectedSnippetName,snippets:v.snippets,snippetDraft:v.snippetDraft,setSnippetDraft:v.setSnippetDraft,updateSnippet:v.updateSnippet,createSnippet:v.createSnippet}))),c=d.useMemo(()=>e?n.find(v=>v.name===e||v.aliases.includes(e))??null:null,[e,n]),l=!!(a&&a.name===e&&!c),[m,u]=d.useState(""),[f,p]=d.useState("global"),[g,h]=d.useState(""),[j,x]=d.useState(""),[S,b]=d.useState(""),[w,k]=d.useState(!1),I=d.useRef(null);d.useEffect(()=>{if(l&&a){const v={draftName:a.name||"",draftScope:a.scope||"global",description:a.description||"",aliases:(a.aliases||[]).join(", "),content:a.content||""};u(v.draftName),p(v.draftScope),h(v.description),x(v.aliases),b(v.content),I.current=v}else if(c){const v={draftName:"",draftScope:"global",description:c.description??"",aliases:c.aliases.join(", "),content:c.content};h(v.description),x(v.aliases),b(v.content),I.current=v}},[c,l,e,a]);const y=d.useMemo(()=>{const v=I.current;return v?l&&m!==v.draftName||l&&f!==v.draftScope?!0:g!==v.description||j!==v.aliases||S!==v.content:!1},[j,S,g,m,f,l]),E=async()=>{const v=l?m.trim().replace(/\s+/g,"-"):e?.trim();if(!v){q.error(t("settings.snippets.page.toast.nameRequired"));return}if(!S.trim()){q.error(t("settings.snippets.page.toast.contentRequired"));return}const R=j.split(",").map(C=>C.trim()).filter(Boolean);k(!0);try{if(!(l?await r(v,S,{aliases:R,description:g,scope:f}):await o(v,{content:S,aliases:R,description:g}))){q.error(t("settings.snippets.page.toast.saveFailed"));return}q.success(t("settings.snippets.page.toast.saved")),l&&i(null)}finally{k(!1)}};return e?s.jsxs(es,{title:l?t("settings.snippets.page.title.new"):`#${e}`,description:c?c.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(qe,{divider:!1,contentClassName:"space-y-0",children:[l?s.jsxs(yt,{label:"#",children:[s.jsx(He,{value:m,onChange:v=>u(v.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Dt,{value:f,onValueChange:v=>p(v),children:[s.jsx(Tt,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{})}),s.jsxs(Et,{align:"end",children:[s.jsx(dt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(dt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Rt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:g,onChange:v=>h(v.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Rt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:j,onChange:v=>x(v.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(qe,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Wt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ts,{value:S,onChange:v=>b(v.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(B,{onClick:E,disabled:w||!y,size:"xs",className:"!font-normal",children:t(w?"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(J,{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")})]})})},Nu=()=>{const{t}=_e(),e=rt(f=>f.settingsGitmojiEnabled),n=rt(f=>f.setSettingsGitmojiEnabled),a=ag(),i=ne(f=>f.gitChangesViewMode),o=ne(f=>f.setGitChangesViewMode),[r,c]=d.useState(!0),l=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 yn();p&&(p.gitmojiEnabled!==void 0&&n(p.gitmojiEnabled),p.gitChangesViewMode!==void 0&&o(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{c(!1)}})()},[o,n]);const m=d.useCallback(async f=>{n(f);try{await bt({gitmojiEnabled:f})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[n]),u=d.useCallback(f=>{f!==i&&(o(f),bt({gitChangesViewMode:f}))},[i,o]);return r?null:s.jsx(qe,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:xs,children:[s.jsx(vs,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(Vs,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:l.map(f=>s.jsx(is,{selected:i===f.id,onSelect:()=>{u(f.id)},label:f.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:f.label})},f.id))})}),s.jsx(ct,{settingsItem:"git.gitmoji",checked:e,onChange:f=>{m(f)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(ct,{settingsItem:"git.gitignored-files",checked:a,onChange:ig,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},kr=()=>({status:"idle",credentials:[],candidates:[],truncated:!1,discoveryAttempted:!1});function qy({selection:t,disabled:e=!1}){const{t:n}=_e(),{git:a}=Za(),[i,o]=d.useState(kr),[r,c]=d.useState(!1),[l,m]=d.useState(""),u=d.useRef(0),f=t?.onChange;d.useLayoutEffect(()=>{const y=()=>{u.current+=1,o(kr()),c(!1),m("")};y();const E=dl(()=>{y(),f?.("")});return()=>{u.current+=1,E()}},[a,f]);const p=async y=>{if(!a.managedSshCredentials||e||i.status==="loading")return;const E=++u.current,v=Xt();o(R=>({...R,status:"loading",rejection:void 0,imported:!1}));try{const R=await a.managedSshCredentials(y);if(E!==u.current||v!==Xt())return;if(R.status==="unsupported"){c(!0),o(kr());return}if(c(!1),R.status==="available"){t?.value&&!R.credentials.some(T=>T.credentialId===t.value&&T.capability.status==="ready")&&t.onChange(""),m(""),o({status:"ready",credentials:R.credentials,candidates:[],truncated:!1,discoveryAttempted:!1});return}if(R.status==="discovered"){m(""),o(T=>({...T,status:"ready",candidates:R.candidates,truncated:R.truncated,discoveryAttempted:!0}));return}if(R.status==="rejected"){m(""),o(T=>({...T,status:"ready",rejection:R.reason}));return}m(""),t?.onChange(R.selectedCredential.credentialId);const C=y.operation==="import"?y.candidateId:"";o(T=>({...T,status:"ready",credentials:R.credentials,candidates:T.candidates.filter(P=>!("candidateId"in P)||P.candidateId!==C),truncated:!1,discoveryAttempted:!1,imported:!0}))}catch{E===u.current&&v===Xt()&&o(R=>({...R,status:"error",imported:!1}))}},g=d.useRef(p);g.current=p,d.useEffect(()=>{g.current({operation:"inventory"})},[a]);const h=y=>y.capability.status==="ready"?"":y.capability.reason==="unreadable"?n("settings.sourceControl.ssh.unreadable"):y.capability.reason==="fingerprint-mismatch"?n("settings.sourceControl.ssh.changed"):n("settings.sourceControl.ssh.unverifiable"),j=y=>y.capability.status==="ready"?"":y.capability.reason==="unreadable"?n("settings.sourceControl.ssh.unreadable"):y.capability.reason==="insecure-permissions"?n("settings.sourceControl.ssh.insecurePermissions"):n("settings.sourceControl.ssh.unverifiable"),x=()=>i.rejection?i.rejection==="candidate-expired"?n("settings.sourceControl.ssh.candidateExpired"):i.rejection==="candidate-changed"?n("settings.sourceControl.ssh.candidateChanged"):i.rejection==="fingerprint-mismatch"?n("settings.sourceControl.ssh.confirmationMismatch"):i.rejection==="inventory-full"?n("settings.sourceControl.ssh.inventoryFull"):n("settings.sourceControl.ssh.candidateUnavailable"):"",S=y=>[y.label,y.fingerprint,h(y)].filter(Boolean).join(" · "),b=i.credentials.find(y=>y.credentialId===t.value)??null,w=x(),k=e||i.status==="loading"||!a.managedSshCredentials,I=s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:t.value,onValueChange:t.onChange,disabled:e||i.status!=="ready",children:[s.jsx(Tt,{size:qt,className:"w-full","aria-label":n("settings.sourceControl.ssh.title"),children:s.jsx($t,{placeholder:n("settings.sourceControl.ssh.title"),children:b?S(b):void 0})}),s.jsx(Et,{children:i.credentials.map(y=>s.jsx(dt,{value:y.credentialId,disabled:y.capability.status!=="ready",children:S(y)},y.credentialId))})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[i.status==="idle"||i.status==="error"?s.jsx(B,{size:"sm",variant:"outline",disabled:k,onClick:()=>{p({operation:"inventory"})},children:n("settings.sourceControl.ssh.load")}):null,s.jsx(B,{size:"sm",variant:"outline",disabled:k,onClick:()=>{p({operation:"discover"})},children:n("settings.sourceControl.ssh.discover")})]}),i.candidates.length?s.jsx("div",{className:"space-y-4",children:i.candidates.map((y,E)=>"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:je(Mt,"break-all"),children:y.fingerprint}),s.jsx(ct,{checked:l===y.candidateId,onChange:v=>m(v?y.candidateId:""),disabled:e||i.status==="loading",className:"min-w-0 break-all",label:n("settings.sourceControl.ssh.confirmFingerprint",{fingerprint:y.fingerprint}),ariaLabel:n("settings.sourceControl.ssh.confirmFingerprint",{fingerprint:y.fingerprint})}),s.jsx(B,{size:"sm",variant:"default",disabled:e||i.status==="loading"||l!==y.candidateId,onClick:()=>{p({operation:"import",candidateId:y.candidateId,expectedFingerprint:y.fingerprint,confirmed:!0})},children:n("settings.sourceControl.ssh.import")})]},y.candidateId):s.jsx("p",{className:Mt,children:[y.label,j(y)].filter(Boolean).join(" · ")},`${y.label}-${E}`))}):null,i.status==="loading"?s.jsx("p",{role:"status",className:Mt,children:n("settings.sourceControl.transport.loading")}):null,i.status==="error"?s.jsx("p",{role:"alert",className:je(Mt,"text-[var(--status-error)]"),children:n("settings.sourceControl.ssh.operationFailed")}):null,w?s.jsx("p",{role:"alert",className:je(Mt,"text-[var(--status-error)]"),children:w}):null,i.imported?s.jsx("p",{role:"status",className:je(Mt,"text-[var(--status-success)]"),children:n("settings.sourceControl.ssh.imported")}):null,i.status==="ready"&&!i.credentials.length?s.jsx("p",{className:Mt,children:n("settings.sourceControl.ssh.empty")}):null,i.status==="ready"&&i.discoveryAttempted&&!i.candidates.length?s.jsx("p",{className:Mt,children:n("settings.sourceControl.ssh.discoveredEmpty")}):null,i.truncated?s.jsx("p",{role:"status",className:je(Mt,"text-[var(--status-warning)]"),children:n("settings.sourceControl.ssh.discoveryTruncated")}):null,r||!a.managedSshCredentials?s.jsx("p",{role:"status",className:Mt,children:n("settings.sourceControl.ssh.hostSetup")}):null]});return s.jsx(Rt,{className:"min-w-0 w-full",controlClassName:"max-w-none flex-col items-stretch gap-3",label:n("settings.sourceControl.ssh.title"),info:n("settings.sourceControl.ssh.hostSetup"),children:I})}const to="__none__",Gc=t=>JSON.stringify([t.provider,t.instance,t.accountId]),Jc=[{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"}],Qc=[{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)"}],Wy=[{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"}],Gy=({open:t,onOpenChange:e,profileId:n})=>{const{t:a}=_e(),i=pa(te=>te.getProfileById),o=pa(te=>te.createProfile),r=pa(te=>te.updateProfile),c=pa(te=>te.deleteProfile),l=d.useMemo(()=>n&&n!=="new"?i(n):null,[n,i]),m=n==="new",u=n==="global",[f,p]=d.useState(""),[g,h]=d.useState(""),[j,x]=d.useState(""),[S,b]=d.useState(!1),[w,k]=d.useState(""),[I,y]=d.useState("keyword"),[E,v]=d.useState("branch"),[R,C]=d.useState(to),[T,P]=d.useState("system"),[L,O]=d.useState(""),[A,N]=d.useState(!1),[M,F]=d.useState(!1),[H,W]=d.useState(!1),{sourceControl:G}=Za(),$=Gs(te=>te.identities),z=Gs(te=>te.entries),U=Gs(te=>te.refreshAll);d.useEffect(()=>{t&&!u&&U(G)},[t,u,U,G]);const _=d.useMemo(()=>$.flatMap(te=>{const Ce=z[ol(te)];return!Ce?.hasChecked||Ce.status?.status!=="connected"?[]:qm(te,Ce.status.accounts,ie=>a(Dd(ie.source)))}),[z,$,a]),V=_.find(te=>te.key===R)??null,Z=l?.account&&R===Gc(l.account)?l.account:null,Y=V?.reference??Z,Q=T;d.useEffect(()=>{if(t){if(m)p(""),h(""),x(""),b(!1),k(""),y("keyword"),v("branch"),C(to),P("system"),O("");else if(l)p(l.name),h(l.userName),x(l.userEmail),b(l.signCommits===!0),k(l.signingKey||""),y(l.color||"keyword"),v(l.icon||"branch"),C(l.account?Gc(l.account):to),P(l.transport??"system"),O(l.sshCredentialId??"");else if(u){const te=i("global");te&&(p(te.name),h(te.userName),x(te.userEmail),b(!1),k(""),y(te.color||"keyword"),v(te.icon||"branch"))}}},[t,n,l,m,u,i]);const ue=async()=>{if(!g.trim()||!j.trim()){q.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(S&&!w.trim()){q.error(a("settings.gitIdentities.editor.toast.signingKeyRequired"));return}if(Q==="account"&&!Y){q.error(a("settings.gitIdentities.editor.toast.accountRequired"));return}if(Q==="ssh"&&!L.trim()){q.error(a("settings.gitIdentities.editor.toast.sshKeyRequired"));return}N(!0);try{const te={name:f.trim()||g.trim(),userName:g.trim(),userEmail:j.trim(),account:Y,transport:Q,signCommits:S,signingKey:w.trim()||null,color:I,icon:E};Q==="ssh"&&(te.sshCredentialId=L.trim());let Ce;if(m)Ce=await o(te);else if(n)Ce=await r(n,te);else return;Ce?(q.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):q.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(te){console.error("Error saving profile:",te),q.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{N(!1)}},ge=async()=>{if(!(!n||m)){W(!0);try{await c(n)?(q.success(a("settings.gitIdentities.editor.toast.profileDeleted")),F(!1),e(!1)):q.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(te){console.error("Error deleting profile:",te),q.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{W(!1)}}},fe=d.useMemo(()=>Qc.find(Ce=>Ce.key===I)?.cssVar||"var(--syntax-keyword)",[I]),Ie=m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):l?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(zt,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:Ie}),s.jsx(Ht,{children:a(u?"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:[!u&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Pt} block mb-1.5`,children:a("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:f,onChange:te=>p(te.target.value),placeholder:a("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:a("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Qc.map(te=>s.jsx("button",{type:"button",onClick:()=>y(te.key),className:je("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===te.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:te.cssVar},title:te.label},te.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:Wy.map(te=>{const Ce=te.Icon;return s.jsx("button",{type:"button",onClick:()=>v(te.key),className:je("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",E===te.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:te.label,children:s.jsx(J,{name:Ce,className:"w-3.5 h-3.5",style:{color:E===te.key?fe:"var(--surface-muted-foreground)"}})},te.key)})})]})]}),!u&&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:Pt,children:a("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Wt,{contentClassName:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:g,onChange:te=>h(te.target.value),placeholder:a("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,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:Pt,children:a("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Wt,{contentClassName:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:j,onChange:te=>x(te.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&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:`${Pt} block mb-1.5`,children:a("settings.gitIdentities.editor.field.account")}),s.jsxs(Dt,{value:R,onValueChange:C,children:[s.jsx(Tt,{className:"w-full","aria-label":a("settings.gitIdentities.editor.field.account"),children:s.jsx($t,{children:V?.label??Z?.instance??a("settings.gitIdentities.editor.field.accountNone")})}),s.jsxs(Et,{children:[_.map(te=>s.jsx(dt,{value:te.key,children:te.label},te.key)),s.jsx(dt,{value:to,children:a("settings.gitIdentities.editor.field.accountNone")})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:`${Pt} block mb-1.5`,children:a("settings.gitIdentities.editor.auth.label")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Jc.map(te=>s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":T===te.method,onClick:()=>{P(te.method),te.method!=="ssh"&&O("")},children:[s.jsx(J,{name:te.icon,className:"w-3.5 h-3.5 mr-1"})," ",a(te.labelKey)]},te.method))})]}),Q==="ssh"?s.jsx(qy,{selection:{value:L,onChange:O}}):s.jsx("p",{className:Mt,children:a(Jc.find(te=>te.method===T)?.hintKey??"settings.gitIdentities.editor.auth.systemHint")})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(ct,{checked:S,onChange:b,label:a("settings.gitIdentities.editor.field.signCommits"),info:a("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:a("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:Pt,children:a("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:w,onChange:te=>k(te.target.value),placeholder:a("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!S,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ns,{className:"gap-2",children:[!u&&!m&&s.jsxs(B,{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(J,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(B,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(B,{size:"sm",onClick:ue,disabled:A,children:a(A?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(zt,{open:M,onOpenChange:te=>{H||F(te)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ht,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:l?.name||f})})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:H,children:a("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{ge()},disabled:H,children:a("settings.common.actions.delete")})]})]})})]})},Jy={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",github:"github",gitlab:"gitlab"},Qy={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Yy=()=>{const t=$e.c(103),{t:e}=_e(),{sourceControl:n}=Za(),a=Gs(Zy),{profiles:i,globalIdentity:o,defaultGitIdentityId:r,deleteProfile:c,loadProfiles:l,loadGlobalIdentity:m,loadDefaultGitIdentityId:u,setDefaultGitIdentityId:f}=pa(Os(Xy));let p,g;t[0]!==i||t[1]!==a||t[2]!==n?(p=()=>{a(n,i.map(e1))},g=[a,n,i],t[0]=i,t[1]=a,t[2]=n,t[3]=p,t[4]=g):(p=t[3],g=t[4]),d.useEffect(p,g);const[h,j]=d.useState(!1),[x,S]=d.useState(null),[b,w]=d.useState(null),[k,I]=d.useState(!1);let y,E;t[5]!==u||t[6]!==m||t[7]!==l?(y=()=>{l(),m(),u()},E=[l,m,u],t[5]=u,t[6]=m,t[7]=l,t[8]=y,t[9]=E):(y=t[8],E=t[9]),d.useEffect(y,E);let v;t[10]===Symbol.for("react.memo_cache_sentinel")?(v=Se=>{S(Se),j(!0)},t[10]=v):v=t[10];const R=v;let C;t[11]!==r||t[12]!==f||t[13]!==e?(C=async Se=>{const Le=r===Se?null:Se;if(!await f(Le)){q.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}q.success(e(Le?"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 T=C;let P;t[15]!==b||t[16]!==c||t[17]!==e?(P=async()=>{if(!b)return;I(!0),await c(b.id)?(q.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:b.name})),w(null)):q.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[15]=b,t[16]=c,t[17]=e,t[18]=P):P=t[18];const L=P;let O;t[19]!==e?(O=e("settings.page.git.title"),t[19]=e,t[20]=O):O=t[20];let A;t[21]!==e?(A=e("settings.gitIdentities.page.section.title"),t[21]=e,t[22]=A):A=t[22];let N,M;t[23]===Symbol.for("react.memo_cache_sentinel")?(M=()=>R("new"),N=s.jsx(J,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[23]=N,t[24]=M):(N=t[23],M=t[24]);let F;t[25]!==e?(F=e("settings.common.badge.new"),t[25]=e,t[26]=F):F=t[26];let H;t[27]!==F?(H=s.jsxs(B,{size:"sm",variant:"outline",onClick:M,children:[N," ",F]}),t[27]=F,t[28]=H):H=t[28];let W;t[29]!==r||t[30]!==o||t[31]!==T||t[32]!==i.length?(W=o&&s.jsx(Yc,{profile:o,isDefault:r==="global",onEdit:()=>R("global"),onToggleDefault:()=>T("global"),isReadOnly:!0,hasBorder:i.length>0}),t[29]=r,t[30]=o,t[31]=T,t[32]=i.length,t[33]=W):W=t[33];let G;if(t[34]!==r||t[35]!==T||t[36]!==i){let Se;t[38]!==r||t[39]!==T||t[40]!==i.length?(Se=(Le,Ke)=>s.jsx(Yc,{profile:Le,isDefault:r===Le.id,onEdit:()=>R(Le.id),onToggleDefault:()=>T(Le.id),onDelete:()=>w(Le),hasBorder:Ke<i.length-1},Le.id),t[38]=r,t[39]=T,t[40]=i.length,t[41]=Se):Se=t[41],G=i.map(Se),t[34]=r,t[35]=T,t[36]=i,t[37]=G}else G=t[37];let $;t[42]!==o||t[43]!==i.length||t[44]!==e?($=!o&&i.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(J,{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]=o,t[43]=i.length,t[44]=e,t[45]=$):$=t[45];let z;t[46]!==W||t[47]!==G||t[48]!==$?(z=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[W,G,$]}),t[46]=W,t[47]=G,t[48]=$,t[49]=z):z=t[49];let U;t[50]!==H||t[51]!==z||t[52]!==A?(U=s.jsx(qe,{title:A,headerAction:H,settingsItem:"git.identities",children:z}),t[50]=H,t[51]=z,t[52]=A,t[53]=U):U=t[53];let _;t[54]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Nu,{}),t[54]=_):_=t[54];let V;t[55]!==U||t[56]!==O?(V=s.jsxs(es,{title:O,showSaveStatus:!0,className:"px-4 @xl:px-6 @3xl:px-12",children:[U,_]}),t[55]=U,t[56]=O,t[57]=V):V=t[57];let Z;t[58]!==h||t[59]!==x?(Z=s.jsx(Gy,{open:h,onOpenChange:j,profileId:x}),t[58]=h,t[59]=x,t[60]=Z):Z=t[60];const Y=b!==null;let Q;t[61]!==k?(Q=Se=>{!Se&&!k&&w(null)},t[61]=k,t[62]=Q):Q=t[62];let ue;t[63]!==e?(ue=e("settings.gitIdentities.page.deleteDialog.title"),t[63]=e,t[64]=ue):ue=t[64];let ge;t[65]!==ue?(ge=s.jsx(Vt,{children:ue}),t[65]=ue,t[66]=ge):ge=t[66];const fe=b?.name??"";let Ie;t[67]!==e||t[68]!==fe?(Ie=e("settings.gitIdentities.page.deleteDialog.description",{name:fe}),t[67]=e,t[68]=fe,t[69]=Ie):Ie=t[69];let te;t[70]!==Ie?(te=s.jsx(Ht,{children:Ie}),t[70]=Ie,t[71]=te):te=t[71];let Ce;t[72]!==ge||t[73]!==te?(Ce=s.jsxs(Bt,{children:[ge,te]}),t[72]=ge,t[73]=te,t[74]=Ce):Ce=t[74];let ie;t[75]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>w(null),t[75]=ie):ie=t[75];let ae;t[76]!==e?(ae=e("settings.common.actions.cancel"),t[76]=e,t[77]=ae):ae=t[77];let re;t[78]!==k||t[79]!==ae?(re=s.jsx(B,{size:"sm",variant:"ghost",onClick:ie,disabled:k,children:ae}),t[78]=k,t[79]=ae,t[80]=re):re=t[80];let ye;t[81]!==L?(ye=()=>{L()},t[81]=L,t[82]=ye):ye=t[82];let Ee;t[83]!==e?(Ee=e("settings.common.actions.delete"),t[83]=e,t[84]=Ee):Ee=t[84];let Pe;t[85]!==k||t[86]!==ye||t[87]!==Ee?(Pe=s.jsx(B,{size:"sm",variant:"destructive",onClick:ye,disabled:k,children:Ee}),t[85]=k,t[86]=ye,t[87]=Ee,t[88]=Pe):Pe=t[88];let ke;t[89]!==re||t[90]!==Pe?(ke=s.jsxs(ns,{children:[re,Pe]}),t[89]=re,t[90]=Pe,t[91]=ke):ke=t[91];let Te;t[92]!==Ce||t[93]!==ke?(Te=s.jsxs(Ut,{className:"max-w-md",children:[Ce,ke]}),t[92]=Ce,t[93]=ke,t[94]=Te):Te=t[94];let de;t[95]!==Y||t[96]!==Q||t[97]!==Te?(de=s.jsx(zt,{open:Y,onOpenChange:Q,children:Te}),t[95]=Y,t[96]=Q,t[97]=Te,t[98]=de):de=t[98];let Me;return t[99]!==V||t[100]!==Z||t[101]!==de?(Me=s.jsxs(s.Fragment,{children:[V,Z,de]}),t[99]=V,t[100]=Z,t[101]=de,t[102]=Me):Me=t[102],Me},Yc=t=>{const e=$e.c(58),{profile:n,isDefault:a,onEdit:i,onToggleDefault:o,onDelete:r,isReadOnly:c,hasBorder:l}=t,{t:m}=_e(),u=Wm(),[f,p]=d.useState(!1),g=Jy[n.icon||"branch"]||"git-branch",h=og(n)?Gm(n,u)?null:"settings.gitIdentities.page.accountGone":"settings.gitIdentities.page.incomplete",j=h!==null,x=Qy[n.color||""];let S;e[0]!==i?(S=U=>{U.currentTarget===U.target&&(U.key!=="Enter"&&U.key!==" "||(U.preventDefault(),i()))},e[0]=i,e[1]=S):S=e[1];const b=S;let w;e[2]!==a||e[3]!==c||e[4]!==r||e[5]!==o||e[6]!==m?(w=U=>s.jsxs(s.Fragment,{children:[s.jsx(U,{onClick:_=>{_.stopPropagation(),o()},children:m(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!c&&r&&s.jsxs(U,{onClick:_=>{_.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(J,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[2]=a,e[3]=c,e[4]=r,e[5]=o,e[6]=m,e[7]=w):w=e[7];const k=w,I=l&&"border-b border-[var(--surface-subtle)]";let y;e[8]!==I?(y=je("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",I),e[8]=I,e[9]=y):y=e[9];let E;e[10]===Symbol.for("react.memo_cache_sentinel")?(E=U=>{U.preventDefault(),p(!0)},e[10]=E):E=e[10];let v;e[11]!==b||e[12]!==i||e[13]!==y?(v=s.jsx("div",{className:y,onClick:i,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:E}),e[11]=b,e[12]=i,e[13]=y,e[14]=v):v=e[14];let R;e[15]!==x?(R={color:x},e[15]=x,e[16]=R):R=e[16];let C;e[17]!==g||e[18]!==R?(C=s.jsx(J,{name:g,className:"w-4 h-4 shrink-0",style:R}),e[17]=g,e[18]=R,e[19]=C):C=e[19];let T;e[20]!==n||e[21]!==m?(T=Jm(n,m),e[20]=n,e[21]=m,e[22]=T):T=e[22];let P;e[23]!==T?(P=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:T}),e[23]=T,e[24]=P):P=e[24];let L;e[25]!==a||e[26]!==m?(L=a&&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]=a,e[26]=m,e[27]=L):L=e[27];let O;e[28]!==P||e[29]!==L?(O=s.jsxs("div",{className:"flex items-center gap-1.5",children:[P,L]}),e[28]=P,e[29]=L,e[30]=O):O=e[30];let A;e[31]!==c||e[32]!==j||e[33]!==h||e[34]!==n.userEmail||e[35]!==m?(A=!c&&h?s.jsx("span",{className:j?"text-[var(--status-warning)]":void 0,children:m(h)}):n.userEmail,e[31]=c,e[32]=j,e[33]=h,e[34]=n.userEmail,e[35]=m,e[36]=A):A=e[36];let N;e[37]!==A?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:A}),e[37]=A,e[38]=N):N=e[38];let M;e[39]!==O||e[40]!==N?(M=s.jsxs("div",{className:"min-w-0",children:[O,N]}),e[39]=O,e[40]=N,e[41]=M):M=e[41];let F;e[42]!==M||e[43]!==C?(F=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[C,M]}),e[42]=M,e[43]=C,e[44]=F):F=e[44];let H;e[45]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Fn,{asChild:!0,children:s.jsx(B,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:t1,children:s.jsx(J,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[45]=H):H=e[45];let W;e[46]!==k?(W=s.jsxs(Kn,{children:[H,s.jsx(On,{align:"end",className:"w-fit min-w-28",children:k(mn)})]}),e[46]=k,e[47]=W):W=e[47];let G;e[48]!==F||e[49]!==W||e[50]!==v?(G=s.jsxs(Qa,{render:v,children:[F,W]}),e[48]=F,e[49]=W,e[50]=v,e[51]=G):G=e[51];let $;e[52]!==k?($=s.jsx(Ga,{className:"w-fit min-w-28",children:k(Ja)}),e[52]=k,e[53]=$):$=e[53];let z;return e[54]!==f||e[55]!==G||e[56]!==$?(z=s.jsxs(Ya,{open:f,onOpenChange:p,children:[G,$]}),e[54]=f,e[55]=G,e[56]=$,e[57]=z):z=e[57],z};function Zy(t){return t.refreshIdentityAccounts}function Xy(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 e1(t){return t.account}function t1(t){return t.stopPropagation()}const Cu=({guest:t})=>{const{t:e}=_e(),n=t.integration,a=or(Y=>Y.byId[t.id]),i=or(Y=>Y.setStatus),o=d.useMemo(()=>Md(t.id,t.icon,Gd().authenticatedAsset),[t.id,t.icon]),r=or(Y=>Y.refresh),[c,l]=d.useState(!1),[m,u]=d.useState(!1),[f,p]=d.useState(!1),[g,h]=d.useState(""),[j,x]=d.useState(""),[S,b]=d.useState(""),[w,k]=d.useState(""),[I,y]=d.useState({}),[E,v]=d.useState(!1),R=d.useRef(null),[C]=d.useState(Xt),T=d.useRef(!0),P=()=>T.current&&Xt()===C,L=d.useCallback(()=>{R.current!=null&&(window.clearInterval(R.current),R.current=null),p(!1)},[]);if(d.useEffect(()=>(T.current=!0,r(t.id),()=>{T.current=!1,L()}),[t.id,r,L]),d.useEffect(()=>{a&&y(a.settings)},[a]),!n)return null;const O=n.auth,A=O==="token"&&n.token?.scheme==="basic",N=!!a?.connection.connected,M=a?.connection.account.trim()||"",F=f?e("settings.integrations.guests.status.waiting"):N?M||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),H=f?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":N?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",W=f||c,G=n.name,$=async()=>{if(!P())return!1;const Y=g.trim();if(!Y)return a?.hasClient?!0:(q.error(e("settings.integrations.guests.toast.clientRequired")),!1);ss("saving");const Q=await np(t.id,Y,j.trim()||void 0);return P()?Q?(i(t.id,Q),x(""),ss("saved"),!0):(ss("error"),q.error(e("settings.integrations.guests.toast.saveFailed",{name:G})),!1):!1},z=async(Y=I)=>{if(!P())return!1;const Q=a?.settings??{};if((n.settings??[]).every(Ie=>(Y[Ie.id]??"").trim()===(Q[Ie.id]??"")))return!0;ss("saving");const fe=await Qm(t.id,Y);return P()?fe?(i(t.id,fe),ss("saved"),!0):(ss("error"),q.error(e("settings.integrations.guests.toast.saveFailed",{name:G})),!1):!1},U=async()=>{if(!P())return!1;const Y=S.trim();if(!Y)return N?!0:(q.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const Q=w.trim();if(A&&!Q)return q.error(e("settings.integrations.guests.toast.usernameRequired")),!1;ss("saving");const ue=await sp(t.id,Y,A?Q:void 0);return P()?ue?(i(t.id,ue),b(""),k(""),ss("saved"),!0):(ss("error"),q.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},_=async()=>{if(!P())return;L(),u(!0);const Y=a?.connection??{connected:!1,account:""};try{if(O==="token"){if(await U()){if((n.settings??[]).length>0&&!await z()||!P())return;q.success(e("settings.integrations.guests.toast.connected",{name:G}))}return}if(O==="oauth"&&!a?.hasClient&&!await $())return;const Q=await Zm(t.id);if(!P())return;if(!Q){q.error(e("settings.integrations.guests.toast.startFailed",{name:G}));return}p(!0),l(!0),Ss(Q);const ue=Date.now()+Xm;R.current=window.setInterval(()=>{(async()=>{if(!P()){L();return}if(Date.now()>ue){L(),q.error(e("settings.integrations.guests.toast.authorizationFailed",{name:G}));return}const ge=await r(t.id);P()&&ge&&ep(Y,ge.connection)&&(L(),q.success(e("settings.integrations.guests.toast.connected",{name:G})),cs()&&Jd())})()},tp)}catch(Q){if(!P())return;console.error("Failed to start guest connect:",Q),q.error(e("settings.integrations.guests.toast.startFailed",{name:G})),L()}finally{P()&&u(!1)}},V=async()=>{if(P()){u(!0);try{L();const Y=await Ym(t.id);if(!P())return;if(!Y){q.error(e("settings.integrations.guests.toast.disconnectFailed",{name:G}));return}i(t.id,Y),q.success(e("settings.integrations.guests.toast.disconnected",{name:G}))}catch(Y){if(!P())return;console.error("Failed to disconnect guest:",Y),q.error(e("settings.integrations.guests.toast.disconnectFailed",{name:G}))}finally{P()&&u(!1)}}},Z=async()=>{const Y=a?.redirectUri??"";!Y||!(await _a(Y)).ok||(v(!0),window.setTimeout(()=>v(!1),1500))};return s.jsx(Js,{open:W,onOpenChange:Y=>{if(f){l(!0);return}l(Y)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Qs,{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(Rd,{icon:Ld(t.icon),iconSrc:o,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:G}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n.description})]}),s.jsx("span",{"aria-live":"polite",className:je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",H),children:F}),s.jsx(J,{name:"arrow-down-s",className:je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",W&&"rotate-180")})]}),s.jsx(Ys,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[O==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Rt,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(He,{value:g,onChange:Y=>h(Y.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}),s.jsx(Rt,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(He,{type:"password",value:j,onChange:Y=>x(Y.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})})]}):null,A?s.jsx(Rt,{label:n.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(He,{value:w,onChange:Y=>k(Y.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}):null,O==="token"?s.jsx(Rt,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(He,{type:"password",value:S,onChange:Y=>b(Y.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})}):null,(n.settings??[]).map(Y=>s.jsx(Rt,{label:Y.label,controlClassName:"w-full max-w-none",children:s.jsx(He,{value:I[Y.id]??"",onChange:Q=>{y(ue=>({...ue,[Y.id]:Q.target.value}))},onBlur:()=>{z()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:m})},Y.id)),O==="oauth"?s.jsxs(Rt,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(He,{value:a?.redirectUri??"",readOnly:!0,className:"h-8 min-w-0 flex-1 rounded-md px-3"}),s.jsx(B,{type:"button",size:"sm",variant:"outline",disabled:!a?.redirectUri,onClick:()=>{Z()},children:e(E?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:N?s.jsx(B,{type:"button",size:"sm",variant:"destructive",disabled:m,onClick:()=>{V()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(B,{type:"button",size:"sm",disabled:m||f,onClick:()=>{_()},children:[m?s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},s1=t=>{const e=$e.c(27),{divider:n}=t,a=n===void 0?!0:n,{t:i}=_e(),o=As(n1),r=As(a1);let c;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0],d.useEffect(i1,c),os()||Qd())return null;let l,m,u,f,p,g,h,j;if(e[1]!==a||e[2]!==o||e[3]!==r||e[4]!==i){j=Symbol.for("react.early_return_sentinel");e:{const S=o.filter(o1);if(S.length===0){j=null;break e}l=qe,e[13]!==i?(m=i("settings.integrations.guests.title"),e[13]=i,e[14]=m):m=e[14],e[15]!==i?(u=i("settings.integrations.guests.info"),e[15]=i,e[16]=u):u=e[16],f=a,p="integrations.guests",g="space-y-3";let b;e[17]!==r?(b=w=>s.jsx(Cu,{guest:w},`${r}:${w.id}`),e[17]=r,e[18]=b):b=e[18],h=S.map(b)}e[1]=a,e[2]=o,e[3]=r,e[4]=i,e[5]=l,e[6]=m,e[7]=u,e[8]=f,e[9]=p,e[10]=g,e[11]=h,e[12]=j}else l=e[5],m=e[6],u=e[7],f=e[8],p=e[9],g=e[10],h=e[11],j=e[12];if(j!==Symbol.for("react.early_return_sentinel"))return j;let x;return e[19]!==l||e[20]!==m||e[21]!==u||e[22]!==f||e[23]!==p||e[24]!==g||e[25]!==h?(x=s.jsx(l,{title:m,info:u,divider:f,settingsItem:p,contentClassName:g,children:h}),e[19]=l,e[20]=m,e[21]=u,e[22]=f,e[23]=p,e[24]=g,e[25]=h,e[26]=x):x=e[26],x};function n1(t){return t.guests}function a1(t){return t.runtimeKey}function i1(){cn()}function o1(t){return t.source!=="bundled"&&t.integration&&rl(t)}const r1=t=>{const e=new Map;for(const n of t){const a=JSON.stringify([n.user.provider,n.user.instance,n.user.id]),i=e.get(a);i?i.accounts.push(n):e.set(a,{key:a,accounts:[n]})}return Array.from(e.values())},l1=t=>/[0-9a-f]{8}(?=-[0-9a-f]{4}-)/i.exec(t)?.[0]??null,Iu=t=>{const e=$e.c(15),{accounts:n,avatarAlt:a,sourceLabel:i,statusLabel:o,currentLabel:r,renderActions:c}=t;let l;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==c||e[4]!==i||e[5]!==o){let u;e[7]!==a||e[8]!==r||e[9]!==c||e[10]!==i||e[11]!==o?(u=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:a(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(J,{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=i(g),j=o(g),x=f.accounts.some(S=>S!==g&&i(S)===h)?l1(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}),j?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx("span",{className:"text-[var(--status-warning)]",children:j})]}):null,x?s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",children:"·"}),s.jsx("span",{className:"font-mono",children:x})]}):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:c(g)})]},g.id)})})]},f.key)},e[7]=a,e[8]=r,e[9]=c,e[10]=i,e[11]=o,e[12]=u):u=e[12],l=r1(n).map(u),e[0]=n,e[1]=a,e[2]=r,e[3]=c,e[4]=i,e[5]=o,e[6]=l}else l=e[6];let m;return e[13]!==l?(m=s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:l}),e[13]=l,e[14]=m):m=e[14],m},Pu=t=>{const e=$e.c(34),{code:n,description:a,openLabel:i,onOpen:o,onCancel:r,disabled:c}=t,l=c===void 0?!1:c,{t:m}=_e();let u;e[0]!==m?(u=m("settings.github.page.flow.title"),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f=s.jsx(Ln,{children:u}),e[2]=u,e[3]=f):f=e[3];let p;e[4]!==a?(p=s.jsx("p",{className:"typography-meta text-muted-foreground",children:a}),e[4]=a,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]!==n?(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:n}),e[9]=n,e[10]=h):h=e[10];let j;e[11]!==o||e[12]!==i?(j=s.jsx(B,{size:"sm",onClick:o,children:i}),e[11]=o,e[12]=i,e[13]=j):j=e[13];let x;e[14]!==h||e[15]!==j?(x=s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[h,j]}),e[14]=h,e[15]=j,e[16]=x):x=e[16];let S;e[17]!==m?(S=m("settings.github.page.flow.waiting"),e[17]=m,e[18]=S):S=e[18];let b;e[19]!==S?(b=s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:S}),e[19]=S,e[20]=b):b=e[20];let w;e[21]!==m?(w=m("settings.common.actions.cancel"),e[21]=m,e[22]=w):w=e[22];let k;e[23]!==l||e[24]!==r||e[25]!==w?(k=s.jsx(B,{size:"sm",variant:"ghost",disabled:l,onClick:r,children:w}),e[23]=l,e[24]=r,e[25]=w,e[26]=k):k=e[26];let I;e[27]!==b||e[28]!==k?(I=s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[b,k]}),e[27]=b,e[28]=k,e[29]=I):I=e[29];let y;return e[30]!==I||e[31]!==g||e[32]!==x?(y=s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] p-3",children:[g,x,I]}),e[30]=I,e[31]=g,e[32]=x,e[33]=y):y=e[33],y},c1=()=>{const{t}=_e(),e=xa()?.sourceControl,n=ol(rn),a=Gs(A=>A.entries[n]),i=a?.status??null,o=a?.isLoading??!1,r=a?.hasChecked??!1,c=Gs(A=>A.refreshStatus),l=Gs(A=>A.refreshInstances),m=d.useCallback(async A=>{await Ss(A)},[]),[u,f]=d.useState(!1),[p,g]=d.useState(null),[h,j]=d.useState(null),[x,S]=d.useState(0),b=d.useRef(null),w=d.useRef(""),k=d.useRef(0),I=d.useCallback(()=>{const A=Xt(),N=k.current;return()=>N===k.current&&A===Xt()},[]),y=d.useCallback(()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null),j(null)},[]),E=d.useCallback(()=>{w.current="",g(null),y()},[y]);d.useEffect(()=>{const A=dl(()=>{k.current+=1,f(!1),E()});return()=>{k.current+=1,A()}},[E]),d.useEffect(()=>((async()=>{try{!r&&e&&await c(e,rn)}catch(A){console.warn("Failed to load GitHub auth status:",A)}})(),()=>{y()}),[r,c,e,y]);const v=d.useCallback(async()=>{const A=I();f(!0);try{if(!e)return;const N=await e.authStart(rn);if(!A())return;w.current=Xt(),g(N),S(0),j(Math.max(1,N.interval)*1e3);const M=N.verificationUriComplete||N.verificationUri;m(M)}catch(N){A()&&(console.error("Failed to start GitHub connect:",N),q.error(t("settings.github.page.toast.startConnectFailed")))}finally{A()&&f(!1)}},[I,m,e,t]);d.useEffect(()=>{if(!p?.flowId||!h||b.current!=null)return;const A=async()=>{const N=I();if(w.current!==Xt()){E();return}try{if(!e)throw new Error("Source control runtime API unavailable");const M=await e.authComplete(rn,p.flowId);if(!N()||w.current!==Xt())return;if(M.status==="connected"){if(E(),await c(e,rn,{force:!0}),!N()||(await l(e,{force:!0}),!N()))return;q.success(t("settings.github.page.toast.connected"));return}M.status==="pending"&&M.slowDown&&j(F=>F?F+5e3:5e3),M.status==="pending"&&S(F=>F+1),M.status==="error"&&(q.error(M.message||t("settings.github.page.toast.authorizationFailed")),E())}catch(M){N()&&w.current===Xt()&&(console.warn("GitHub polling failed:",M),S(F=>F+1))}};return b.current=window.setTimeout(()=>{A()},h),()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null)}},[I,p,x,h,l,c,e,E,t]);const R=d.useCallback(async A=>{const N=I();f(!0);try{if(!e||(await e.authSetCliDisabled(rn,A),!N())||(await c(e,rn,{force:!0}),!N()))return;q.success(t(A?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled"))}catch(M){N()&&(console.error("Failed to update gh CLI setting:",M),q.error(t("settings.github.page.toast.ghCliUpdateFailed")))}finally{N()&&f(!1)}},[I,c,e,t]),C=d.useCallback(async A=>{const N=I();f(!0);try{if(E(),!e||(await e.authDisconnect(rn,A),!N())||(await c(e,rn,{force:!0}),!N())||(await l(e,{force:!0}),!N()))return;q.success(t("settings.github.page.toast.disconnected"))}catch(M){N()&&(console.error("Failed to remove GitHub account:",M),q.error(t("settings.github.page.toast.disconnectFailed")))}finally{N()&&f(!1)}},[I,l,c,e,E,t]);if(o&&!r)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.sourceControl.status.checking")});const T=i?.accounts??[],P=i?.cli??null,L=i?.status==="unreachable"||i?.status==="temporarily-unavailable"?i.message||t("sessionAuth.error.networkRetry"):null,O=!!(P?.available&&!P.active&&(!P.user||P.disabled));return s.jsxs("div",{className:"space-y-3","data-settings-item":"git.github-account",children:[L&&s.jsx(yt,{label:t("sessionAuth.error.networkTitle"),description:L,children:s.jsx(B,{size:"sm",variant:"outline",disabled:u||o||!e,onClick:()=>{e&&c(e,rn,{force:!0})},children:t("sessionAuth.error.retry")})}),T.length===0?!L&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.status.notConnected")}):s.jsx(Iu,{accounts:T,avatarAlt:A=>t("settings.github.page.avatarAlt.withLogin",{login:A}),currentLabel:t("settings.sourceControl.accounts.inUse"),sourceLabel:A=>A.source==="cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth"),statusLabel:A=>A.status==="valid"?null:t("settings.sourceControl.accounts.needsAuthentication"),renderActions:A=>s.jsxs(s.Fragment,{children:[A.status==="invalid"?s.jsx(B,{size:"sm",variant:"outline",onClick:v,disabled:u,children:t("settings.sourceControl.actions.reauthenticate")}):null,s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>A.source==="cli"?R(!0):C(A.id),disabled:u,children:A.source==="cli"?t("settings.github.page.ghCli.actions.disable"):t("settings.sourceControl.actions.remove")})]})}),p?s.jsx(Pu,{code:p.userCode,description:t("settings.github.page.flow.description"),openLabel:t("settings.github.page.actions.openGithub"),onOpen:()=>{m(p.verificationUriComplete||p.verificationUri)},onCancel:E,disabled:u}):s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(B,{"data-settings-item":"git.github-connect",size:"sm",variant:T.length>0?"outline":"default",onClick:v,disabled:u,children:T.length>0?t("settings.github.page.actions.addAccount"):t("settings.github.page.actions.connect")})}),O&&P?s.jsx(yt,{label:t("settings.github.page.ghCli.title"),description:P.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(B,{size:"sm",variant:"outline",onClick:()=>R(!P.disabled),disabled:u,children:P.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})}):null]})},d1=()=>{const t=$e.c(37),{t:e}=_e(),n=Od(rn),a=n?.status??null,i=n?.isLoading??!1,o=n?.hasChecked??!1,[r,c]=d.useState(!1),l=a?.connected===!0;let m;if(t[0]!==l||t[1]!==o||t[2]!==i||t[3]!==a||t[4]!==e){const T=a?.accounts??[],P=(T.find(u1)??T[0])?.user.username.trim()??(a?.status==="connected"?a.user.username.trim():"");m=i&&!o?e("common.loading"):l?T.length>1?e("settings.sourceControl.accounts.connectedCount",{count:T.length}):P||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=l,t[1]=o,t[2]=i,t[3]=a,t[4]=e,t[5]=m}else m=t[5];const u=m,f=l?"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(J,{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 j;t[11]!==e?(j=e("settings.integrations.github.description"),t[11]=e,t[12]=j):j=t[12];let x;t[13]!==j?(x=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:j}),t[13]=j,t[14]=x):x=t[14];let S;t[15]!==h||t[16]!==x?(S=s.jsxs("div",{className:"min-w-0 flex-1",children:[h,x]}),t[15]=h,t[16]=x,t[17]=S):S=t[17];let b;t[18]!==f?(b=je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",f),t[18]=f,t[19]=b):b=t[19];let w;t[20]!==u||t[21]!==b?(w=s.jsx("span",{"aria-live":"polite",className:b,children:u}),t[20]=u,t[21]=b,t[22]=w):w=t[22];const k=r&&"rotate-180";let I;t[23]!==k?(I=je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",k),t[23]=k,t[24]=I):I=t[24];let y;t[25]!==I?(y=s.jsx(J,{name:"arrow-down-s",className:I}),t[25]=I,t[26]=y):y=t[26];let E;t[27]!==y||t[28]!==S||t[29]!==w?(E=s.jsxs(Qs,{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,S,w,y]}),t[27]=y,t[28]=S,t[29]=w,t[30]=E):E=t[30];let v;t[31]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Ys,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(c1,{embedded:!0})}),t[31]=v):v=t[31];let R;t[32]!==E?(R=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[E,v]}),t[32]=E,t[33]=R):R=t[33];let C;return t[34]!==r||t[35]!==R?(C=s.jsx(Js,{open:r,onOpenChange:c,children:R}),t[34]=r,t[35]=R,t[36]=C):C=t[36],C};function u1(t){return t.current}const m1={provider:"gitlab",instance:"https://gitlab.com"},Au="overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)]",$a="px-3 py-3",so="border-t border-[var(--surface-subtle)]",p1=t=>{try{const e=new URL(t.includes("://")?t:`https://${t}`),n=["localhost","127.0.0.1","::1","[::1]"].includes(e.hostname.toLowerCase()),a=!!(e.username||e.password||e.search||e.hash||e.pathname&&e.pathname!=="/"),i=e.protocol==="https:"||e.protocol==="http:"&&n;return a||!i?null:{provider:"gitlab",instance:e.origin}}catch{return null}},g1=({identity:t,sourceControl:e,onSaved:n})=>{const{t:a}=_e(),i=Gs(Q=>Q.refreshInstances),o=Gs(Q=>Q.refreshStatus),r=Gs(Q=>Q.setStatus),c=Od(t),[l,m]=d.useState(null),[u,f]=d.useState(!1),[p,g]=d.useState(0),[h,j]=d.useState(null),[x,S]=d.useState(0),[b,w]=d.useState(0),[k,I]=d.useState(""),[y,E]=d.useState(!1),[v,R]=d.useState(!1),[C,T]=d.useState(!1),[P,L]=d.useState(!1),O=d.useRef(""),A=d.useRef(0),N=d.useCallback(()=>{const Q=Xt(),ue=A.current;return()=>ue===A.current&&Q===Xt()},[]),M=c?.status??null,F=M?.accounts??[],H=M&&"cli"in M?M.cli:void 0,W=d.useCallback(()=>{O.current="",j(null),S(0)},[]);d.useEffect(()=>{const Q=dl(()=>{A.current+=1,W()});return()=>{A.current+=1,Q()}},[W]),d.useEffect(()=>W(),[t.instance,t.provider,W]),d.useEffect(()=>{let Q=!1;const ue=N();return f(!1),Promise.all([e.capabilities(t),o(e,t)]).then(([ge])=>{!Q&&ue()&&m(ge)}).catch(()=>{!Q&&ue()&&f(!0)}),()=>{Q=!0}},[p,N,t,o,e]),d.useEffect(()=>{if(!h||x<=0)return;const Q=async()=>{const ge=N();if(O.current!==Xt()){W();return}try{const fe=await e.authComplete(t,h.flowId);if(!ge()||O.current!==Xt())return;if(fe.status==="connected"){if(W(),E(!1),await o(e,t,{force:!0}),!ge()||(await i(e,{force:!0}),!ge()))return;n?.(),T(!1);return}if(fe.status==="pending"){S((fe.slowDown?x+5e3:x)||5e3),w(Ie=>Ie+1);return}W(),T(!0)}catch{ge()&&O.current===Xt()&&w(fe=>fe+1)}},ue=window.setTimeout(()=>{Q()},x);return()=>window.clearTimeout(ue)},[N,h,t,n,b,x,i,o,e,W]);const G=async()=>{const Q=N();R(!0),T(!1),L(!1);try{const ue=await e.authStart(t);if(!Q())return;O.current=Xt(),j(ue),w(0),S(Math.max(1,ue.interval)*1e3),await Ss(ue.verificationUriComplete||ue.verificationUri)}catch{Q()&&T(!0)}finally{Q()&&R(!1)}},$=async()=>{if(!k.trim())return;const Q=N();R(!0),T(!1),L(!1);try{const ue=await e.authSetToken(t,k.trim());if(!Q()||(r(t,ue),I(""),E(!1),await o(e,t,{force:!0}),!Q())||(await i(e,{force:!0}),!Q()))return;n?.()}catch(ue){if(!Q())return;ue instanceof Error&&"code"in ue&&ue.code==="INVALID_TOKEN"?L(!0):T(!0)}finally{Q()&&R(!1)}},z=async Q=>{const ue=N();R(!0),T(!1),L(!1);try{if(await e.authDisconnect(t,Q),!ue()||(await o(e,t,{force:!0}),!ue()))return;await i(e,{force:!0})}catch{ue()&&T(!0)}finally{ue()&&R(!1)}},U=async()=>{if(!H)return;const Q=N();R(!0),T(!1),L(!1);try{if(await e.authSetCliDisabled(t,!H.disabled),!Q())return;await o(e,t,{force:!0})}catch{Q()&&T(!0)}finally{Q()&&R(!1)}},_=()=>{E(!1),j(null),S(0),w(0),I(""),T(!1),L(!1)},V=F.length>0,Z=!V||y;let Y;return c?.isLoading?Y=a("settings.sourceControl.status.checking"):P?Y=a("settings.gitlab.status.tokenRejected"):C||u||M?.status==="unreachable"?Y=a("settings.gitlab.status.operationFailed"):F.length>0?Y=null:Y=a("settings.gitlab.status.notConnected"),s.jsxs("div",{className:Au,children:[s.jsxs("div",{className:je($a,"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}),Y?s.jsx("div",{className:"typography-meta mt-0.5 text-muted-foreground",children:Y}):null]}),u||M?.status==="unreachable"?s.jsx(B,{size:"sm",variant:"outline",disabled:v||c?.isLoading,onClick:()=>g(Q=>Q+1),children:a("sessionAuth.error.retry")}):null]}),F.length>0?s.jsx("div",{className:je($a,so),children:s.jsx(Iu,{accounts:F,avatarAlt:Q=>Q,currentLabel:a("settings.sourceControl.accounts.inUse"),sourceLabel:Q=>a(Q.source==="cli"?"settings.gitlab.cli.label":Dd(Q.source)),statusLabel:Q=>Q.status==="valid"?null:a("settings.sourceControl.accounts.needsAuthentication"),renderActions:Q=>s.jsxs(s.Fragment,{children:[Q.status==="invalid"&&Q.source!=="cli"?s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:v,children:a("settings.sourceControl.actions.reauthenticate")}):null,s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>Q.source==="cli"?U():z(Q.id),disabled:v,children:Q.source==="cli"?a("settings.gitlab.actions.disableCli"):a("settings.sourceControl.actions.remove")})]})})}):null,V&&!y&&s.jsx("div",{className:je($a,so),children:s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:v,children:a("settings.github.page.actions.addAccount")})}),Z&&s.jsxs("div",{className:je(ws,$a,so),children:[l?.authenticationMethods.device.available&&!h&&s.jsx(yt,{label:a("settings.gitlab.device.label"),children:s.jsx(B,{size:"sm",onClick:G,disabled:v,children:a("settings.gitlab.actions.connect")})}),h&&s.jsx(Pu,{code:h.userCode,description:a("settings.gitlab.device.waiting"),openLabel:a("settings.gitlab.actions.openGitLab"),onOpen:()=>{Ss(h.verificationUriComplete||h.verificationUri)},onCancel:_}),l?.authenticationMethods.pat.available&&s.jsx(yt,{label:a("settings.gitlab.token.label"),info:a("settings.gitlab.token.info"),children:s.jsxs("div",{className:`${ks} flex flex-col gap-2 @xl:flex-row @xl:items-center`,children:[s.jsx(He,{className:"h-8 w-full min-w-0 rounded-md",type:"password",value:k,onChange:Q=>I(Q.target.value),"aria-label":a("settings.gitlab.token.label")}),s.jsx(B,{className:"w-full @xl:w-auto",size:"sm",onClick:$,disabled:v||!k.trim(),children:a("settings.common.actions.saveChanges")})]})}),y&&!h&&s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{size:"sm",variant:"ghost",onClick:_,disabled:v,children:a("settings.common.actions.cancel")})})]}),(V||H?.disabled)&&H&&(H.available||H.disabled)&&s.jsx("div",{className:je($a,so),children:s.jsx(yt,{label:a("settings.gitlab.cli.label"),info:a("settings.gitlab.cli.info"),children:s.jsx(B,{size:"sm",variant:"outline",onClick:U,disabled:v,children:H.disabled?a("settings.gitlab.actions.enableCli"):a("settings.gitlab.actions.disableCli")})})})]})},f1=()=>{const t=$e.c(51),{t:e}=_e(),n=xa()?.sourceControl,a=Gs(h1),i=Gs(x1),o=Gs(b1),[r,c]=d.useState(!1),[l,m]=d.useState(null),[u,f]=d.useState(""),[p,g]=d.useState(!1),[h,j]=d.useState(!1);let x;t[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>m(null),t[0]=x):x=t[0];const S=x,b=a.filter(v1),w=[...b];l&&!b.some(te=>te.instance===l.instance)&&w.push(l),w.length===0&&w.push(m1);let k,I;t[1]!==o?(k=()=>{n&&o(n)},I=[o,n],t[1]=o,t[2]=k,t[3]=I):(k=t[2],I=t[3]),d.useEffect(k,I);let y;t[4]!==u?(y=()=>{const te=p1(u);if(!te){j(!0);return}m(te),f(""),g(!1),j(!1)},t[4]=u,t[5]=y):y=t[5];const E=y;if(!n)return null;let v;t[6]!==i?(v=te=>i[ol(te)],t[6]=i,t[7]=v):v=t[7];const R=b.map(v),C=R.flatMap(y1).filter(j1),T=C.find(k1)??C[0]??null,P=T!==null,O=R.some(w1)&&!P?e("common.loading"):P?C.length>1?e("settings.sourceControl.accounts.connectedCount",{count:C.length}):T.user.username.trim()||e("settings.gitlab.status.connected"):e("settings.gitlab.status.notConnected"),A=P?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let N;t[8]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(J,{name:"gitlab",className:"size-5 text-foreground"})}),t[8]=N):N=t[8];let M;t[9]!==e?(M=e("settings.gitlab.title"),t[9]=e,t[10]=M):M=t[10];let F;t[11]!==M?(F=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:M}),t[11]=M,t[12]=F):F=t[12];let H;t[13]!==e?(H=e("settings.gitlab.info"),t[13]=e,t[14]=H):H=t[14];let W;t[15]!==H?(W=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:H}),t[15]=H,t[16]=W):W=t[16];let G;t[17]!==F||t[18]!==W?(G=s.jsxs("div",{className:"min-w-0 flex-1",children:[F,W]}),t[17]=F,t[18]=W,t[19]=G):G=t[19];let $;t[20]!==A?($=je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",A),t[20]=A,t[21]=$):$=t[21];let z;t[22]!==O||t[23]!==$?(z=s.jsx("span",{"aria-live":"polite",className:$,children:O}),t[22]=O,t[23]=$,t[24]=z):z=t[24];const U=r&&"rotate-180";let _;t[25]!==U?(_=je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",U),t[25]=U,t[26]=_):_=t[26];let V;t[27]!==_?(V=s.jsx(J,{name:"arrow-down-s",className:_}),t[27]=_,t[28]=V):V=t[28];let Z;t[29]!==G||t[30]!==z||t[31]!==V?(Z=s.jsxs(Qs,{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:[N,G,z,V]}),t[29]=G,t[30]=z,t[31]=V,t[32]=Z):Z=t[32];let Y;t[33]!==e?(Y=e("settings.gitlab.instances.title"),t[33]=e,t[34]=Y):Y=t[34];const Q=w.map(te=>s.jsx(g1,{identity:te,sourceControl:n,onSaved:l?.instance===te.instance?S:void 0},`${Xt()}:${te.instance}`));let ue;t[35]!==E||t[36]!==h||t[37]!==u||t[38]!==p||t[39]!==e?(ue=p?s.jsx("div",{className:je(Au,$a),children:s.jsx(yt,{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(He,{className:"h-8 w-full min-w-0 rounded-md",value:u,onChange:te=>f(te.target.value),placeholder:"https://gitlab.example.com","aria-label":e("settings.gitlab.instance.customLabel")}),s.jsx(B,{className:"w-full @xl:w-auto",size:"sm",onClick:E,children:e("settings.gitlab.actions.useInstance")}),s.jsx(B,{className:"w-full @xl:w-auto",size:"sm",variant:"ghost",onClick:()=>{f(""),g(!1),j(!1)},children:e("settings.common.actions.cancel")})]})})}):s.jsx(B,{size:"sm",variant:"outline",onClick:()=>g(!0),children:e("settings.gitlab.actions.addInstance")}),t[35]=E,t[36]=h,t[37]=u,t[38]=p,t[39]=e,t[40]=ue):ue=t[40];let ge;t[41]!==Y||t[42]!==Q||t[43]!==ue?(ge=s.jsx(Ys,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs(vs,{title:Y,contentClassName:"space-y-3",settingsItem:"git.gitlab-connect",children:[Q,ue]})}),t[41]=Y,t[42]=Q,t[43]=ue,t[44]=ge):ge=t[44];let fe;t[45]!==Z||t[46]!==ge?(fe=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,ge]}),t[45]=Z,t[46]=ge,t[47]=fe):fe=t[47];let Ie;return t[48]!==r||t[49]!==fe?(Ie=s.jsx(Js,{open:r,onOpenChange:c,children:fe}),t[48]=r,t[49]=fe,t[50]=Ie):Ie=t[50],Ie};function h1(t){return t.identities}function x1(t){return t.entries}function b1(t){return t.refreshInstances}function v1(t){return t.provider==="gitlab"}function y1(t){return t?.status?.status==="connected"?t.status.accounts:[]}function j1(t){return t.status==="valid"}function k1(t){return t.current}function w1(t){return t?.isLoading&&!t.hasChecked}const no="__none__",ao="__inherit__";function S1({linear:t,connected:e,organizationId:n}){const{t:a}=_e(),i=un(x=>x.projects),[o,r]=d.useState(null),[c,l]=d.useState(!1),[m,u]=d.useState(!1),f=d.useCallback(async()=>{if(!e){r(null),l(!1);return}try{const x=await t.mappingGet();if(x.connected===!1){r(null),l(!1);return}r(x),l(!1)}catch(x){console.error("Failed to load Linear mapping:",x),l(!0)}},[e,t]);d.useEffect(()=>{f()},[f,n]);const p=d.useCallback(async x=>{const S={};for(const b of x.teams??[])b.projectPath&&(S[b.id]=b.projectPath);u(!0),ss("saving");try{const b=await t.mappingSet({defaultProjectPath:x.defaultProjectPath??null,teamProjectPaths:S});if(b.connected===!1){r(null),ss("error");return}r(b),l(!1),ss("saved")}catch(b){console.error("Failed to save Linear mapping:",b),ss("error")}finally{u(!1)}},[t]);if(!e)return null;if(c&&!o)return s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.mapping.loadFailed")});if(!o)return null;const g=x=>i.find(b=>b.path===x)?.label?.trim()||x,h=x=>!x||x===no?a("settings.integrations.linear.mapping.defaultProject.placeholder"):g(x),j=x=>!x||x===ao?a("settings.integrations.linear.mapping.teams.useDefault"):g(x);return s.jsxs("div",{className:ws,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(yt,{label:a("settings.integrations.linear.mapping.defaultProject"),info:a("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Dt,{value:o.defaultProjectPath||no,disabled:m||i.length===0,onValueChange:x=>{p({...o,defaultProjectPath:x===no?null:x})},children:[s.jsx(Tt,{size:qt,className:dn,"aria-label":a("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx($t,{placeholder:a("settings.integrations.linear.mapping.defaultProject.placeholder"),children:h})}),s.jsxs(Et,{children:[s.jsx(dt,{value:no,children:a("settings.integrations.linear.mapping.defaultProject.placeholder")}),o.defaultProjectPath&&!i.some(x=>x.path===o.defaultProjectPath)?s.jsx(dt,{value:o.defaultProjectPath,children:o.defaultProjectPath}):null,i.map(x=>s.jsx(dt,{value:x.path,children:g(x.path)},x.id))]})]})}),s.jsx(vs,{title:a("settings.integrations.linear.mapping.teams"),info:a("settings.integrations.linear.mapping.teams.info"),children:(o.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:ws,children:(o.teams??[]).map(x=>s.jsx(yt,{label:`${x.key} · ${x.name}`,children:s.jsxs(Dt,{value:x.projectPath||ao,disabled:m||i.length===0,onValueChange:S=>{p({...o,teams:(o.teams??[]).map(b=>b.id===x.id?{...b,projectPath:S===ao?null:S}:b)})},children:[s.jsx(Tt,{size:qt,className:dn,"aria-label":a("settings.integrations.linear.mapping.teams.aria",{team:x.key}),children:s.jsx($t,{placeholder:a("settings.integrations.linear.mapping.teams.useDefault"),children:j})}),s.jsxs(Et,{children:[s.jsx(dt,{value:ao,children:a("settings.integrations.linear.mapping.teams.useDefault")}),x.projectPath&&!i.some(S=>S.path===x.projectPath)?s.jsx(dt,{value:x.projectPath,children:x.projectPath}):null,i.map(S=>s.jsx(dt,{value:S.path,children:g(S.path)},S.id))]})]})},x.id))})})]})}function N1({linear:t,connected:e}){const{t:n}=_e(),[a,i]=d.useState(null),[o,r]=d.useState(!1),[c,l]=d.useState(!1);d.useEffect(()=>{if(!e){i(null),r(!1);return}let u=!1;return t.preferencesGet().then(f=>{u||(i(f.sessionComments),r(!1))}).catch(()=>{u||r(!0)}),()=>{u=!0}},[e,t]);const m=d.useCallback(async u=>{const f=a;i(u),l(!0);try{const p=await t.preferencesSet({sessionComments:u});i(p.sessionComments),ss("saved")}catch{i(f),ss("error")}finally{l(!1)}},[a,t]);return e?o?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:ws,children:s.jsx(yt,{label:n("settings.integrations.linear.sessionComments.label"),info:n("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(ha,{checked:a===!0,disabled:a===null||c,onCheckedChange:u=>{m(u)},"aria-label":n("settings.integrations.linear.sessionComments.aria")})})}):null}const C1=3*6e4,I1=1500;function Zc(t){const e=t?.workspaces??[],n=e.find(a=>a.current);return{connected:!!t?.connected,ids:e.map(a=>a.id).slice().sort().join(","),currentId:n?.id||t?.organization?.id||"",currentAuthorizedAt:n?.authorizedAt??0}}function P1(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const A1=()=>{const{t}=_e(),e=xa()?.linear,n=La(T=>T.status),a=La(T=>T.isLoading),i=La(T=>T.hasChecked),o=La(T=>T.refreshStatus),r=La(T=>T.setStatus),[c,l]=d.useState(!1),[m,u]=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),u(!1)},[]);d.useEffect(()=>{if(e)return i||o(e),()=>{h()}},[i,o,e,h]);const j=d.useCallback(async()=>{if(!e)return;h(),l(!0);const T=Zc(La.getState().status);try{const P=await e.authStart(cs()?"desktop":"web");u(!0),p(!0),Ss(P.authorizationUrl);const L=Date.now()+C1;g.current=window.setInterval(()=>{(async()=>{if(Date.now()>L){h(),q.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const O=await o(e,{force:!0});P1(T,Zc(O))&&(h(),q.success(t("settings.integrations.linear.toast.connected")),Jd())})()},I1)}catch(P){console.error("Failed to start Linear connect:",P),q.error(t("settings.integrations.linear.toast.startConnectFailed")),h()}finally{l(!1)}},[o,e,h,t]),x=d.useCallback(async T=>{if(!(!e||!T)){l(!0);try{const P=await e.authActivate(T);r(P),q.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(P){console.error("Failed to switch Linear workspace:",P),q.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{l(!1)}}},[e,r,t]),S=d.useCallback(async()=>{if(e){l(!0);try{h(),await e.authDisconnect(),q.success(t("settings.integrations.linear.toast.disconnected")),await o(e,{force:!0})}catch(T){console.error("Failed to disconnect Linear:",T),q.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{l(!1)}}},[o,e,h,t]);if(!e)return null;const b=!!n?.connected,w=n?.user,k=n?.organization,y=(n?.workspaces??[]).filter(T=>!T.current),E=w?.displayName?.trim()||w?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),v=m?t("settings.integrations.linear.status.waiting"):a&&!i?t("common.loading"):b?k?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),R=m?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":b?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",C=m||f;return s.jsx(Js,{open:C,onOpenChange:T=>{if(m){p(!0);return}p(T)},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(Qs,{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(J,{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:je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",R),children:v}),s.jsx(J,{name:"arrow-down-s",className:je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",C&&"rotate-180")})]}),s.jsx(Ys,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[b?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:E}),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(J,{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:E}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[k?.name,w?.email].filter(Boolean).join(" · ")})]})]}):m?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,b?s.jsxs(s.Fragment,{children:[s.jsx(S1,{linear:e,connected:b,organizationId:k?.id??null}),s.jsx(N1,{linear:e,connected:b}),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(T=>{const P=T.user,L=T.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:L}),P?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:P.email}):null]}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>{x(T.id)},disabled:c,children:t("settings.integrations.linear.actions.switchTo")})]},T.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{type:"button",size:"sm",variant:"outline",onClick:()=>{j()},disabled:c||m,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},disabled:c,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(B,{type:"button",size:"sm",variant:"ghost",disabled:c,onClick:h,children:t("settings.common.actions.cancel")})]}):s.jsxs(B,{type:"button",size:"sm",variant:"default",onClick:()=>{j()},disabled:c||a&&!i,children:[c?s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},wr=[{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"}],T1=(t,e)=>t===e||t.startsWith(`${e}@`);function Sr(t,e,n){const a=t.filter(l=>T1(l.spec,e)),i=a.filter(l=>l.scope==="user"),o=a.filter(l=>l.scope==="project"),r=i.length===1?i[0]:null,c=n[r?.spec??e]??n[e]??null;return{userEntry:r,userEntryIsAmbiguous:i.length>1,projectEntries:o,registry:c}}function Qr(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function Xc(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const n=Qr(e,t.registry);return n&&n!==t.userEntry.spec?"update":"setup"}function E1(t,e={}){const n=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:n}:e.restartRequired?{status:"restart-required",latestVersion:n}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:n}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:n}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:n}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:n}:t.registry?.kind==="npm-ok"&&n?{status:"update-available",latestVersion:n}:{status:"installed",latestVersion:n}:{status:"not-installed",latestVersion:n}}const D1={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"},Tu=t=>{const e=$e.c(33),{settingsItem:n,logo:a,name:i,description:o,status:r,statusTone:c,open:l,onOpenChange:m,children:u}=t;let f;e[0]!==a?(f=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:a}),e[0]=a,e[1]=f):f=e[1];let p;e[2]!==i?(p=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:i}),e[2]=i,e[3]=p):p=e[3];let g;e[4]!==o?(g=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:o}),e[4]=o,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 j=D1[c];let x;e[9]!==j?(x=je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",j),e[9]=j,e[10]=x):x=e[10];let S;e[11]!==r||e[12]!==x?(S=s.jsx("span",{"aria-live":"polite",className:x,children:r}),e[11]=r,e[12]=x,e[13]=S):S=e[13];const b=l&&"rotate-180";let w;e[14]!==b?(w=je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",b),e[14]=b,e[15]=w):w=e[15];let k;e[16]!==w?(k=s.jsx(J,{name:"arrow-down-s",className:w}),e[16]=w,e[17]=k):k=e[17];let I;e[18]!==f||e[19]!==k||e[20]!==h||e[21]!==S?(I=s.jsxs(Qs,{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,S,k]}),e[18]=f,e[19]=k,e[20]=h,e[21]=S,e[22]=I):I=e[22];let y;e[23]!==u?(y=s.jsx(Ys,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:u}),e[23]=u,e[24]=y):y=e[24];let E;e[25]!==n||e[26]!==I||e[27]!==y?(E=s.jsxs("div",{"data-settings-item":n,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[I,y]}),e[25]=n,e[26]=I,e[27]=y,e[28]=E):E=e[28];let v;return e[29]!==m||e[30]!==l||e[31]!==E?(v=s.jsx(Js,{open:l,onOpenChange:m,children:E}),e[29]=m,e[30]=l,e[31]=E,e[32]=v):v=e[32],v},M1=t=>t.requiresManualRestart===!0||t.reloadFailed===!0,R1=({divider:t=!0})=>{const{t:e}=_e(),n=Zs(),a=d.useCallback(()=>{ne.getState().requestSettingsJump("plugins")},[]),i=d.useCallback(async N=>{if(await rt.getState().loadProviders({directory:n,source:"settings:third-party-provider-setup"}),!Ad(rt.getState(),n).some(H=>H.id===N))return!1;const F=ne.getState();return F.setSettingsProvidersOpenRequested(N),F.requestSettingsJump("providers"),!0},[n]),{entries:o,registryInfo:r,loadPlugins:c,loadRegistryInfo:l,createEntry:m,updateEntry:u,deleteEntry:f}=Ft(Os(N=>({entries:N.entries,registryInfo:N.registryInfo,loadPlugins:N.loadPlugins,loadRegistryInfo:N.loadRegistryInfo,createEntry:N.createEntry,updateEntry:N.updateEntry,deleteEntry:N.deleteEntry}))),[p,g]=d.useState(!1),[h,j]=d.useState(null),[x,S]=d.useState(()=>new Set),[b,w]=d.useState(()=>new Set),[k,I]=d.useState(null),[y,E]=d.useState(()=>new Set),v=d.useCallback(async()=>{if(!await c({force:!0})){g(!0);return}const M=Ft.getState().entries,F=new Set(wr.map(W=>W.packageName));for(const W of M)wr.some(G=>W.spec===G.packageName||W.spec.startsWith(`${G.packageName}@`))&&F.add(W.spec);const H=await l({specs:[...F],force:!0});g(!H)},[c,l]);d.useEffect(()=>{v()},[v]);const R=d.useCallback((N,M)=>{S(F=>{const H=new Set(F);return M?H.add(N):H.delete(N),H})},[]),C=d.useCallback((N,M)=>{w(F=>{const H=new Set(F);return M?H.add(N):H.delete(N),H})},[]),T=d.useCallback(async(N,M,F)=>{j({pluginId:N.id,action:M});try{const H=await F();if(!H.ok){q.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}C(N.id,!1);const W=M1(H);R(N.id,W);const G=W?{description:e("settings.integrations.thirdParty.toast.restartRequired")}:void 0;M==="install"?q.success(e("settings.integrations.thirdParty.toast.installed",{name:e(N.nameKey)}),G):M==="update"?q.success(e("settings.integrations.thirdParty.toast.updated",{name:e(N.nameKey)}),G):q.success(e("settings.integrations.thirdParty.toast.removed",{name:e(N.nameKey)}),G),await v()}finally{j(null)}},[v,C,R,e]),P=d.useCallback(async N=>{const M=Sr(o,N.packageName,r),F=Xc(M,N.packageName);if(F==="manage"){a();return}if(F==="setup"){j({pluginId:N.id,action:F});try{const W=await i(N.providerId);C(N.id,!W),W?R(N.id,!1):q.error(e("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{j(null)}return}const H=Qr(N.packageName,M.registry);if(!H){g(!0);return}if(F==="install"){await T(N,"install",()=>m({spec:H,scope:"user"}));return}M.userEntry&&await T(N,"update",()=>u(M.userEntry.id,{spec:H}))},[m,o,a,i,r,T,C,R,e,u]),L=d.useCallback(async()=>{const N=k;if(!N)return;const M=Sr(o,N.packageName,r);if(!M.userEntry||M.userEntryIsAmbiguous){I(null),a();return}I(null),await T(N,"remove",()=>f(M.userEntry.id))},[f,o,a,r,k,T]),O=d.useCallback((N,M)=>{E(F=>{const H=new Set(F);return M?H.add(N):H.delete(N),H})},[]),A=N=>{const M=Sr(o,N.packageName,r),F=Xc(M,N.packageName),H=Qr(N.packageName,M.registry),W=h?.pluginId===N.id,G=x.has(N.id),$=b.has(N.id),z=p||M.registry?.kind==="npm-network",U=W||G&&F!=="setup"||(F==="install"||F==="update")&&(z||!H),_=E1(M,{registryUnavailable:z,restartRequired:G,providerUnavailable:$});let V;switch(_.status){case"installed-version":V=_.latestVersion?e("settings.integrations.thirdParty.status.installedVersion",{version:_.latestVersion}):e("settings.integrations.thirdParty.status.installed");break;case"update-available":V=_.latestVersion?e("settings.integrations.thirdParty.status.updateAvailable",{version:_.latestVersion}):e("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":V=e("settings.integrations.thirdParty.status.notInstalled");break;case"installed":V=e("settings.integrations.thirdParty.status.installed");break;case"unpinned":V=e("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":V=e("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":V=e("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":V=e("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":V=e("settings.integrations.thirdParty.status.providerUnavailable");break}const Z=_.status==="installed-version"?"success":_.status==="update-available"||_.status==="ambiguous"||_.status==="restart-required"||_.status==="registry-unavailable"||_.status==="provider-unavailable"?"warning":"neutral",Y={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],Q=y.has(N.id);return s.jsx(Tu,{settingsItem:`integrations.third-party.${N.id}`,logo:s.jsx(bn,{providerId:N.providerId,alt:"",className:"size-5"}),name:e(N.nameKey),description:e(N.descriptionKey),status:V,statusTone:Z,open:Q,onOpenChange:ue=>O(N.id,ue),children:s.jsxs("div",{className:"space-y-3",children:[M.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(B,{type:"button",size:"sm",variant:F==="manage"?"outline":"default",onClick:()=>{P(N)},disabled:U,children:[W?s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):F==="setup"?s.jsx(J,{name:"plug-2",className:"size-3.5"}):null,Y]}),s.jsxs(B,{type:"button",size:"sm",variant:"secondary",onClick:()=>{Ss(N.homepage)},children:[s.jsx(J,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),M.userEntry&&!M.userEntryIsAmbiguous?s.jsxs(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>I(N),disabled:W,children:[s.jsx(J,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})]})},N.id)};return s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:e("settings.integrations.thirdParty.title"),info:e("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:wr.map(A)}),s.jsx(zt,{open:k!==null,onOpenChange:N=>!N&&I(null),children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(Ht,{children:e("settings.integrations.thirdParty.dialog.remove.description",{name:k?e(k.nameKey):""})})]}),s.jsxs(ns,{children:[s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>I(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{L()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Eu=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":"settings.extensions.toast.failed",Du=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",L1=rs({error:ml(["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:Nt().trim().min(1).max(64).optional(),id:Nt().trim().min(1).max(128).optional()}),O1=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 n=/^[a-zA-Z]:[\\/]/.test(e);return/^[a-z][a-z0-9+.-]*:/i.test(e)&&!n?{ok:!1,code:"invalid-url"}:e.startsWith("/")||n||e.startsWith("\\\\")?{ok:!0,request:{path:e}}:{ok:!1,code:"invalid-path"}},Mu=async t=>{try{const e=L1.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"}}},Ru=async(t,e)=>{if(!t.ok)return{ok:!1,...await Mu(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const n=await t.text().catch(()=>null),a=n===null?null:Fd(n);return a?{ok:!0,guest:a,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},Lu=async(t,e={})=>{const n=O1(t);if(!n.ok)return n;const a={...n.request};e.replace&&(a.replace=!0),"url"in a&&e.gitIdentityId&&(a.gitIdentityId=e.gitIdentityId);try{const i=await Lt("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(a)});return await Ru(i,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},F1=async(t,e={})=>{try{const n=await Lt("/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 Ru(n,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},Ou=async t=>{const e=As.getState(),n=Xt(),a=e.runtimeKey===n?e.guests.find(i=>i.id===t)?.storageId:void 0;try{const i=await Lt(`/api/guests/${t}`,{method:"DELETE"});return i.status===204?(a&&globalThis.indexedDB&&await ap({runtimeKey:n,guestId:t,storageId:a}).catch(()=>{console.warn("Could not clear local extension preferences.")}),{ok:!0}):{ok:!1,code:(await Mu(i)).code}}catch{return{ok:!1,code:"failed"}}},Fu=async(t,e)=>{try{return(await Lt(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},K1=async(t,e)=>{try{return(await Lt(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},z1=rs({updates:Dn(Nt().min(1),ip)}),U1=rs({error:ml(["not-git","clone-failed","clone-auth-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found","enterprise-mode"]),required:Nt().trim().min(1).max(64).optional()}),ed=async t=>{try{const e=await Lt("/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 n=z1.safeParse(JSON.parse(await e.text()));return n.success?{ok:!0,updates:n.data.updates}:{ok:!1}}catch{return{ok:!1}}},$1=async t=>{try{const e=U1.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"}}},Ku=async t=>{try{const e=await Lt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const a=await $1(e);return a.required?{ok:!1,code:a.code,required:a.required}:{ok:!1,code:a.code}}const n=Fd(await e.text());return n?{ok:!0,guest:n}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},_1={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"},B1=[_1],V1=(t,e)=>{const n=t.find(a=>a.id===e.guestId);return n?n.enterpriseBlocked?.length?{kind:"blocked",guest:n}:Wa(n)?{kind:"needs-approval",guest:n}:n.enabled===!1?{kind:"paused",guest:n}:n.update?{kind:"update-available",guest:n,version:n.update.version}:{kind:"installed",guest:n}:{kind:"not-installed"}},H1=({divider:t=!0})=>{const{t:e}=_e(),n=As(b=>b.guests),a=As(b=>b.status),[i,o]=d.useState(null),[r,c]=d.useState(()=>new Set),[l,m]=d.useState(null);d.useEffect(()=>{cn()},[]);const u=d.useCallback(()=>{ne.getState().requestSettingsJump("extensions")},[]),f=d.useCallback(async(b,w,k)=>{const I=Xt();o({guestId:b.guestId,action:w});try{await k(),Xt()===I&&await cn()}finally{o(null)}},[]),p=b=>f(b,"install",async()=>{const w=await Lu(b.gitUrl);if(!w.ok){q.error(w.code==="host-too-old"&&w.required?e("settings.extensions.toast.hostTooOld",{version:w.required}):e(Eu(w.code)));return}q.success(e("settings.integrations.thirdParty.toast.installed",{name:e(b.nameKey)})),Wa(w.guest)&&u()}),g=b=>f(b,"update",async()=>{const w=await Ku(b.guestId);if(!w.ok){q.error(w.code==="host-too-old"&&w.required?e("settings.extensions.toast.hostTooOld",{version:w.required}):e(Du(w.code)));return}vi(b.guestId),q.success(e("settings.integrations.thirdParty.toast.updated",{name:e(b.nameKey)})),Wa(w.guest)&&u()}),h=b=>f(b,"enable",async()=>{if(!await Fu(b.guestId,!0)){q.error(e("settings.integrations.extensionCatalog.toast.enableFailed",{name:e(b.nameKey)}));return}q.success(e("settings.integrations.extensionCatalog.toast.enabled",{name:e(b.nameKey)}))}),j=async()=>{const b=l;b&&(m(null),await f(b,"remove",async()=>{if(!(await Ou(b.guestId)).ok){q.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}vi(b.guestId),q.success(e("settings.integrations.thirdParty.toast.removed",{name:e(b.nameKey)}))}))},x=b=>{switch(b.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:b.version}),tone:"warning"};case"installed":return{status:b.guest.version?e("settings.integrations.thirdParty.status.installedVersion",{version:b.guest.version}):e("settings.integrations.thirdParty.status.installed"),tone:"success"}}},S=b=>{const w=V1(n,b),k=a==="idle"||a==="loading",{status:I,tone:y}=k?{status:e("common.loading"),tone:"neutral"}:x(w),E=i?.guestId===b.guestId||k,v=r.has(b.guestId),R=s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}),C=w.kind==="not-installed"?{label:e("settings.integrations.thirdParty.actions.install"),onClick:()=>{p(b)},variant:"default"}:w.kind==="update-available"?{label:e("settings.integrations.thirdParty.actions.update"),onClick:()=>{g(b)},variant:"default"}:w.kind==="paused"?{label:e("settings.integrations.extensionCatalog.actions.enable"),onClick:()=>{h(b)},variant:"default"}:w.kind==="needs-approval"||w.kind==="blocked"?{label:e("settings.integrations.extensionCatalog.actions.manage"),onClick:u,variant:"outline"}:null;return s.jsx(Tu,{settingsItem:`integrations.extensions.${b.guestId}`,logo:s.jsx(op,{filePath:b.logoFileName,className:"size-5"}),name:e(b.nameKey),description:e(b.descriptionKey),status:I,statusTone:y,open:v,onOpenChange:T=>c(P=>{const L=new Set(P);return T?L.add(b.guestId):L.delete(b.guestId),L}),children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[C?s.jsxs(B,{type:"button",size:"sm",variant:C.variant,onClick:C.onClick,disabled:E,children:[E?R:null,C.label]}):null,s.jsxs(B,{type:"button",size:"sm",variant:"secondary",onClick:()=>{Ss(b.homepage)},children:[s.jsx(J,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),w.kind!=="not-installed"?s.jsxs(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>m(b),disabled:E,children:[s.jsx(J,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})},b.guestId)};return a==="unsupported"?null:s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:e("settings.integrations.extensionCatalog.title"),info:e("settings.integrations.extensionCatalog.info"),divider:t,settingsItem:"integrations.extensions",contentClassName:"space-y-3",children:B1.map(S)}),s.jsx(zt,{open:l!==null,onOpenChange:b=>!b&&m(null),children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Vt,{children:e("settings.integrations.extensionCatalog.dialog.remove.title")}),s.jsx(Ht,{children:e("settings.integrations.extensionCatalog.dialog.remove.description",{name:l?e(l.nameKey):""})})]}),s.jsxs(ns,{children:[s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>m(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{j()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},q1=()=>{const t=$e.c(26),{t:e}=_e();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=os(),t[0]=n):n=t[0];const a=!n;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=os(),t[1]=i):i=t[1];const o=!i,r=!!xa()?.linear,c=As(W1),l=As(G1);let m,u,f,p,g,h;if(t[2]!==c||t[3]!==l||t[4]!==e){const w=!os()&&!Qd()?c.filter(J1):[];u=a||o||r||w.length>0,m=es,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=u?s.jsxs(qe,{title:e("settings.integrations.firstParty.title"),info:e("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[a?s.jsx(d1,{}):null,o?s.jsx(f1,{}):null,r?s.jsx(A1,{}):null,w.map(k=>s.jsx(Cu,{guest:k},`${l}:${k.id}`))]}):null,t[2]=c,t[3]=l,t[4]=e,t[5]=m,t[6]=u,t[7]=f,t[8]=p,t[9]=g,t[10]=h}else m=t[5],u=t[6],f=t[7],p=t[8],g=t[9],h=t[10];let j;t[15]!==u?(j=s.jsx(R1,{divider:u}),t[15]=u,t[16]=j):j=t[16];let x,S;t[17]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(H1,{}),S=s.jsx(s1,{}),t[17]=x,t[18]=S):(x=t[17],S=t[18]);let b;return t[19]!==m||t[20]!==f||t[21]!==p||t[22]!==g||t[23]!==h||t[24]!==j?(b=s.jsxs(m,{title:f,description:p,showSaveStatus:g,children:[h,j,x,S]}),t[19]=m,t[20]=f,t[21]=p,t[22]=g,t[23]=h,t[24]=j,t[25]=b):b=t[25],b};function W1(t){return t.guests}function G1(t){return t.runtimeKey}function J1(t){return t.source==="bundled"&&t.integration&&rl(t)}const ui="__default__",Q1=500,Y1=(t,e)=>{const n=a=>JSON.stringify({...a,categories:a.categories.map(i=>({...i,name:i.name.trim(),description:i.description.trim()}))});return n(t)===n(e)},Z1=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),zu=(t,e)=>{const n=$e.c(7),a=rt(tj);let i;e:{if(!t||!e){let r;n[0]===Symbol.for("react.memo_cache_sentinel")?(r=[],n[0]=r):r=n[0],i=r;break e}let o;if(n[1]!==e||n[2]!==t||n[3]!==a){let r;n[5]!==t?(r=m=>m.id===t,n[5]=t,n[6]=r):r=n[6];const l=a.find(r)?.models.find(m=>m.id===e);o=Sd(l),n[1]=e,n[2]=t,n[3]=a,n[4]=o}else o=n[4];i=o}return i},Uu=(t,e)=>t&&(e.length===0||e.includes(t))?t:null,$u=t=>{const e=$e.c(51),{providerID:n,modelID:a,value:i,onChange:o,ariaLabel:r,className:c}=t,{t:l}=_e(),m=zu(n,a);let u,f,p,g,h,j,x,S,b,w,k;if(e[0]!==r||e[1]!==c||e[2]!==o||e[3]!==l||e[4]!==i||e[5]!==m){const P=Uu(i,m)??ui;let L;e[17]!==l?(L=O=>O===ui?l("settings.routing.thinking.default"):O.charAt(0).toUpperCase()+O.slice(1),e[17]=l,e[18]=L):L=e[18],g=L,p=Dt,b=P,e[19]!==o?(w=O=>o(O===ui?null:O),e[19]=o,e[20]=w):w=e[20],k=m.length===0,f=Tt,j=qt,e[21]!==c?(x=je(dn,c),e[21]=c,e[22]=x):x=e[22],S=r,u=$t,h=g(P),e[0]=r,e[1]=c,e[2]=o,e[3]=l,e[4]=i,e[5]=m,e[6]=u,e[7]=f,e[8]=p,e[9]=g,e[10]=h,e[11]=j,e[12]=x,e[13]=S,e[14]=b,e[15]=w,e[16]=k}else u=e[6],f=e[7],p=e[8],g=e[9],h=e[10],j=e[11],x=e[12],S=e[13],b=e[14],w=e[15],k=e[16];let I;e[23]!==u||e[24]!==h?(I=s.jsx(u,{children:h}),e[23]=u,e[24]=h,e[25]=I):I=e[25];let y;e[26]!==f||e[27]!==j||e[28]!==x||e[29]!==S||e[30]!==I?(y=s.jsx(f,{size:j,className:x,"aria-label":S,children:I}),e[26]=f,e[27]=j,e[28]=x,e[29]=S,e[30]=I,e[31]=y):y=e[31];let E;e[32]!==g?(E=g(ui),e[32]=g,e[33]=E):E=e[33];let v;e[34]!==E?(v=s.jsx(dt,{value:ui,children:E}),e[34]=E,e[35]=v):v=e[35];let R;if(e[36]!==g||e[37]!==m){let P;e[39]!==g?(P=L=>s.jsx(dt,{value:L,children:g(L)},L),e[39]=g,e[40]=P):P=e[40],R=m.map(P),e[36]=g,e[37]=m,e[38]=R}else R=e[38];let C;e[41]!==v||e[42]!==R?(C=s.jsxs(Et,{children:[v,R]}),e[41]=v,e[42]=R,e[43]=C):C=e[43];let T;return e[44]!==p||e[45]!==C||e[46]!==b||e[47]!==w||e[48]!==k||e[49]!==y?(T=s.jsxs(p,{value:b,onValueChange:w,disabled:k,children:[y,C]}),e[44]=p,e[45]=C,e[46]=b,e[47]=w,e[48]=k,e[49]=y,e[50]=T):T=e[50],T},X1=t=>{const e=$e.c(52),{category:n,expanded:a,onToggle:i,onChange:o,onReset:r,onRemove:c}=t,{t:l}=_e(),m=zu(n.model?.providerID,n.model?.modelID);let u;e[0]!==n.variant||e[1]!==m?(u=Uu(n.variant,m),e[0]=n.variant,e[1]=m,e[2]=u):u=e[2];const f=u;let p;e[3]!==n.model||e[4]!==f||e[5]!==l?(p=n.model?`${n.model.modelID}${f?` / ${f}`:""}`:l("settings.routing.model.useFallback"),e[3]=n.model,e[4]=f,e[5]=l,e[6]=p):p=e[6];const g=p;let h;e[7]!==n.agent||e[8]!==g?(h=[g,n.agent].filter(Boolean),e[7]=n.agent,e[8]=g,e[9]=h):h=e[9];const j=h.join(" · "),x=!n.enabled&&"opacity-60";let S;e[10]!==x?(S=je("py-1",x),e[10]=x,e[11]=S):S=e[11];const b=a?"arrow-down-s":"arrow-right-s";let w;e[12]!==b?(w=s.jsx(J,{name:b,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[12]=b,e[13]=w):w=e[13];const k=n.name||n.id;let I;e[14]!==k?(I=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:k}),e[14]=k,e[15]=I):I=e[15];let y;e[16]!==j?(y=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j}),e[16]=j,e[17]=y):y=e[17];let E;e[18]!==a||e[19]!==i||e[20]!==y||e[21]!==w||e[22]!==I?(E=s.jsxs("button",{type:"button",onClick:i,"aria-expanded":a,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:[w,I,y]}),e[18]=a,e[19]=i,e[20]=y,e[21]=w,e[22]=I,e[23]=E):E=e[23];const v=n.enabled;let R;e[24]!==o?(R=A=>o({enabled:A}),e[24]=o,e[25]=R):R=e[25];let C;e[26]!==n.name||e[27]!==l?(C=l("settings.routing.category.enabledAria",{name:n.name}),e[26]=n.name,e[27]=l,e[28]=C):C=e[28];let T;e[29]!==n.enabled||e[30]!==R||e[31]!==C?(T=s.jsx(ha,{checked:v,onCheckedChange:R,"aria-label":C}),e[29]=n.enabled,e[30]=R,e[31]=C,e[32]=T):T=e[32];let P;e[33]!==E||e[34]!==T?(P=s.jsxs("div",{className:"flex items-center gap-2",children:[E,T]}),e[33]=E,e[34]=T,e[35]=P):P=e[35];let L;e[36]!==n.agent||e[37]!==n.description||e[38]!==n.model?.modelID||e[39]!==n.model?.providerID||e[40]!==n.name||e[41]!==n.variant||e[42]!==a||e[43]!==o||e[44]!==c||e[45]!==r||e[46]!==l?(L=a?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(Cn,{children:[s.jsx(Rt,{label:l("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(He,{value:n.name,onChange:A=>o({name:A.target.value}),"aria-label":l("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(Rt,{label:l("settings.routing.category.agent"),info:l("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(sl,{agentName:n.agent??"",onChange:A=>o({agent:A||null}),filter:sj,className:je(qs,"w-full")})}),s.jsx(Rt,{label:l("settings.routing.category.model"),info:l("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(fa,{providerId:n.model?.providerID??"",modelId:n.model?.modelID??"",onChange:(A,N)=>o({model:{providerID:A,modelID:N},variant:null}),className:je(qs,"w-full"),placeholder:l("settings.routing.model.useFallback")})}),s.jsx(Rt,{label:l("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx($u,{providerID:n.model?.providerID,modelID:n.model?.modelID,value:n.variant,onChange:A=>o({variant:A}),ariaLabel:l("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(Rt,{label:l("settings.routing.category.description"),info:l("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(Ts,{value:n.description,onChange:A=>o({description:A.target.value}),"aria-label":l("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(B,{size:"sm",variant:"outline",onClick:r,children:l("settings.routing.category.reset")}):null,s.jsx(B,{size:"sm",variant:"ghost",onClick:c,children:l("settings.routing.category.remove")})]})]}):null,e[36]=n.agent,e[37]=n.description,e[38]=n.model?.modelID,e[39]=n.model?.providerID,e[40]=n.name,e[41]=n.variant,e[42]=a,e[43]=o,e[44]=c,e[45]=r,e[46]=l,e[47]=L):L=e[47];let O;return e[48]!==P||e[49]!==L||e[50]!==S?(O=s.jsxs("div",{className:S,children:[P,L]}),e[48]=P,e[49]=L,e[50]=S,e[51]=O):O=e[51],O},ej=()=>{const{t}=_e(),e=Qt(N=>N.available),n=Qt(N=>N.autoReady),a=Qt(N=>N.config),i=Qt(N=>N.builtins),o=Qt(N=>N.loaded),r=Qt(N=>N.loadError),c=Qt(N=>N.load),l=Qt(N=>N.saveConfig),[m,u]=d.useState(a),[f,p]=d.useState(""),[g,h]=d.useState(null),j=d.useRef(null),x=d.useRef(null),S=d.useRef(Promise.resolve()),b=d.useRef(0);d.useEffect(()=>{c()},[c]),d.useEffect(()=>{j.current||b.current>0||u(N=>N&&a&&Y1(a,N)?N:a)},[a]);const w=d.useCallback(()=>{const N=j.current;if(!N||(j.current=null,N.runtimeKey!==Xt()))return S.current;b.current+=1,ss("saving");const M=S.current.then(async()=>{try{if(N.runtimeKey!==Xt()){ss("saved");return}await l(N.config),ss("saved")}catch{ss("error")}finally{b.current-=1}});return S.current=M,M},[l]);d.useEffect(()=>()=>{x.current&&clearTimeout(x.current),w()},[w]);const k=rt(N=>N.settingsDefaultModel),I=rt(N=>N.settingsDefaultVariant),y=d.useRef(!1);d.useEffect(()=>{if(y.current||!o||!a||a.fallback)return;const N=En(k);!N||Yd(N.providerId,N.modelId)||(y.current=!0,E(M=>M.fallback?M:{...M,fallback:{model:{providerID:N.providerId,modelID:N.modelId},variant:I??null}}))},[o,a,k,I]);const E=d.useCallback(N=>{u(M=>{if(!M)return M;const F=N(M);return j.current={config:F,runtimeKey:Xt()},x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{x.current=null,w()},Q1),F})},[w]),v=d.useCallback((N,M)=>{E(F=>({...F,categories:F.categories.map(H=>H.id===N?{...H,...M}:H)}))},[E]),R=()=>{const N=f.trim();if(!N||!m)return;const M=Z1(N)||`category-${Date.now()}`;let F=M,H=2;for(;m.categories.some(W=>W.id===F);)F=`${M}-${H++}`;E(W=>({...W,categories:[...W.categories,{id:F,builtin:!1,enabled:!0,name:N,description:"",model:null,variant:null,agent:null}]})),p(""),h(F)},C=N=>{const M=i.find(F=>F.id===N);M&&v(N,{name:M.name,description:M.description,model:null,variant:null,agent:null,enabled:!0})},T=N=>{const M=i.find(F=>F.id===N);M&&E(F=>({...F,categories:[...F.categories,{id:N,builtin:!0,enabled:!0,name:M.name,description:M.description,model:null,variant:null,agent:null}]}))},P=N=>{E(M=>({...M,categories:M.categories.filter(F=>F.id!==N)}))},L=m?.categories.filter(N=>N.enabled).length??0,O=i.filter(N=>!m?.categories.some(M=>M.id===N.id)),A=m?.enabled?m.fallback?L<2?t("settings.routing.status.tooFewCategories"):t(n?"settings.routing.status.ready":"settings.routing.status.notReady"):t("settings.routing.status.noFallback"):t("settings.routing.status.disabled");return s.jsxs(es,{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,!o||!m?null:e?s.jsxs(s.Fragment,{children:[s.jsx(qe,{title:t("settings.routing.auto.title"),divider:!1,children:s.jsxs("div",{className:ws,children:[s.jsx(Eo,{}),s.jsx("div",{className:xs,children:s.jsx(ct,{settingsItem:"routing.enabled",checked:m.enabled,onChange:N=>E(M=>({...M,enabled:N})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:Mt,children:A}),s.jsx(yt,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(fa,{providerId:m.fallback?.model.providerID??"",modelId:m.fallback?.model.modelID??"",onChange:(N,M)=>E(F=>({...F,fallback:{model:{providerID:N,modelID:M},variant:null}})),className:qs,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(yt,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx($u,{providerID:m.fallback?.model.providerID,modelID:m.fallback?.model.modelID,value:m.fallback?.variant??null,onChange:N=>E(M=>M.fallback?{...M,fallback:{...M.fallback,variant:N}}:M),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(qe,{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(N=>s.jsx(X1,{category:N,expanded:g===N.id,onToggle:()=>h(M=>M===N.id?null:N.id),onChange:M=>v(N.id,M),onReset:N.builtin?()=>C(N.id):null,onRemove:()=>P(N.id)},N.id))}),O.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:O.map(N=>s.jsx(B,{size:"sm",variant:"outline",onClick:()=>T(N.id),children:t("settings.routing.category.restore",{name:N.name})},N.id))}):null,s.jsx(yt,{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(He,{value:f,onChange:N=>p(N.target.value),onKeyDown:N=>{N.key==="Enter"&&R()},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(B,{size:"sm",variant:"outline",onClick:R,disabled:f.trim().length===0,children:t("settings.routing.categories.add")})]})})]})})]}):s.jsx("p",{className:xn,children:t("settings.routing.unavailable")})]})};function tj(t){return t.providers}function sj(t){return Kd(t.mode)}const nj={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"}},aj=t=>{const e=$e.c(77),{guest:n,busy:a,onApprove:i,onDecline:o,onDismiss:r}=t,{t:c}=_e();let l;e[0]!==n?.capabilities.requested?(l=n?.capabilities.requested??[],e[0]=n?.capabilities.requested,e[1]=l):l=e[1];const m=l;let u;e[2]!==n?.filesystem?(u=n?.filesystem??[],e[2]=n?.filesystem,e[3]=u):u=e[3];const f=u;let p;e[4]!==n?.origins?(p=n?.origins??[],e[4]=n?.origins,e[5]=p):p=e[5];const g=p;let h;e[6]!==n?.service?.permissions?.exec?(h=n?.service?.permissions?.exec??[],e[6]=n?.service?.permissions?.exec,e[7]=h):h=e[7];const j=h;let x;e[8]!==n?.service?.permissions?.sockets?(x=n?.service?.permissions?.sockets??[],e[8]=n?.service?.permissions?.sockets,e[9]=x):x=e[9];const S=x,b=n?.service;let w;e[10]!==b?(w=zd(b,"browser"),e[10]=b,e[11]=w):w=e[11];const k=w,I=n?.integration?.apiOrigin??null,y=n!==null;let E;e[12]!==a||e[13]!==r?(E=Z=>{!Z&&!a&&r()},e[12]=a,e[13]=r,e[14]=E):E=e[14];const v=n?.name??"";let R;e[15]!==c||e[16]!==v?(R=c("settings.extensions.dialog.approveTitle",{name:v}),e[15]=c,e[16]=v,e[17]=R):R=e[17];let C;e[18]!==R?(C=s.jsx(Vt,{children:R}),e[18]=R,e[19]=C):C=e[19];const T=n?.name??"",P=n?.version?`v${n.version}`:"";let L;e[20]!==c||e[21]!==T||e[22]!==P?(L=c("settings.extensions.dialog.approveDescription",{name:T,version:P}),e[20]=c,e[21]=T,e[22]=P,e[23]=L):L=e[23];let O;e[24]!==L?(O=s.jsx(Ht,{children:L}),e[24]=L,e[25]=O):O=e[25];let A;e[26]!==C||e[27]!==O?(A=s.jsxs(Bt,{children:[C,O]}),e[26]=C,e[27]=O,e[28]=A):A=e[28];let N;if(e[29]!==I||e[30]!==f||e[31]!==g||e[32]!==k||e[33]!==m||e[34]!==j||e[35]!==S||e[36]!==c){let Z;e[38]!==I||e[39]!==f||e[40]!==g||e[41]!==k||e[42]!==j||e[43]!==S||e[44]!==c?(Z=Y=>{const Q=nj[Y];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(J,{name:Q.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:c(Q.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:c(Q.detailKey)}),Y==="filesystem"&&f.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:f.map(ij)}):null,Y==="origins"&&g.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:g.map(oj)}):null,Y==="network"&&I?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[c("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:I})]}):null,Y==="service"&&j.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[c("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:j.join(", ")})]}):null,Y==="service"&&S.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[c("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:S.join(", ")})]}):null,Y==="service"&&k?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:c("settings.extensions.capability.service.providesBrowser")}):null]})]},Y)},e[38]=I,e[39]=f,e[40]=g,e[41]=k,e[42]=j,e[43]=S,e[44]=c,e[45]=Z):Z=e[45],N=m.map(Z),e[29]=I,e[30]=f,e[31]=g,e[32]=k,e[33]=m,e[34]=j,e[35]=S,e[36]=c,e[37]=N}else N=e[37];let M;e[46]!==N?(M=s.jsx("ul",{className:"space-y-3",children:N}),e[46]=N,e[47]=M):M=e[47];let F;e[48]!==n||e[49]!==o?(F=()=>n&&o(n),e[48]=n,e[49]=o,e[50]=F):F=e[50];let H;e[51]!==c?(H=c("settings.extensions.dialog.decline"),e[51]=c,e[52]=H):H=e[52];let W;e[53]!==a||e[54]!==F||e[55]!==H?(W=s.jsx(B,{size:"sm",variant:"ghost",disabled:a,onClick:F,children:H}),e[53]=a,e[54]=F,e[55]=H,e[56]=W):W=e[56];let G;e[57]!==n||e[58]!==i?(G=()=>n&&i(n),e[57]=n,e[58]=i,e[59]=G):G=e[59];let $;e[60]!==c?($=c("settings.extensions.dialog.approve"),e[60]=c,e[61]=$):$=e[61];let z;e[62]!==a||e[63]!==G||e[64]!==$?(z=s.jsx(B,{size:"sm",disabled:a,onClick:G,children:$}),e[62]=a,e[63]=G,e[64]=$,e[65]=z):z=e[65];let U;e[66]!==W||e[67]!==z?(U=s.jsxs(ns,{children:[W,z]}),e[66]=W,e[67]=z,e[68]=U):U=e[68];let _;e[69]!==A||e[70]!==M||e[71]!==U?(_=s.jsxs(Ut,{className:"max-w-md",children:[A,M,U]}),e[69]=A,e[70]=M,e[71]=U,e[72]=_):_=e[72];let V;return e[73]!==_||e[74]!==y||e[75]!==E?(V=s.jsx(zt,{open:y,onOpenChange:E,children:_}),e[73]=_,e[74]=y,e[75]=E,e[76]=V):V=e[76],V};function ij(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}function oj(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const rj=t=>{if(t.source!=="git"||!t.origin?.url)return null;const e=t.origin.url.trim(),n=/^(?:[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 a=new URL(n?`ssh://${n[1]}/${n[2]}`:e);if(a.protocol!=="https:"&&a.protocol!=="ssh:")return null;const i=a.protocol==="ssh:"?new URL(`https://${a.hostname}${a.pathname}`):a;return i.username="",i.password="",i.search="",i.hash="",i.pathname=i.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),i.pathname==="/"?null:i.href}catch{return null}},Nr=(t,e)=>{const n=`${t.method} ${t.path}`;return t.kind==="network"?`${n}: ${e("settings.extensions.request.noResponse")}`:t.kind==="invalid-response"?`${n}: ${e("settings.extensions.request.invalidResponse",{status:t.status})}`:`${n}: HTTP ${t.status}`},td=t=>t.name.toLowerCase().endsWith(".zip"),lj=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",cj=t=>{const e=(t.service?.socketBindings??[]).map(i=>i.resolved?`${i.id}=${i.resolved}`:`${i.id}?`),n=(t.service?.permissions?.sockets??[]).filter(i=>!(t.service?.socketBindings??[]).some(o=>o.id===i));return[...e,...n,...t.service?.permissions?.exec??[]].join(", ")},dj=t=>{const e=$e.c(27),{guest:n,binding:a,busy:i,onSaved:o}=t,{t:r}=_e(),[c,l]=d.useState(a.override??a.resolved??""),[m,u]=d.useState(!1),[f,p]=d.useState(!a.resolved);let g;e[0]!==a.override||e[1]!==a.resolved?(g=()=>{l(a.override??a.resolved??""),a.resolved||p(!0)},e[0]=a.override,e[1]=a.resolved,e[2]=g):g=e[2];let h;e[3]!==a.id||e[4]!==a.override||e[5]!==a.resolved?(h=[a.id,a.override,a.resolved],e[3]=a.id,e[4]=a.override,e[5]=a.resolved,e[6]=h):h=e[6],d.useEffect(g,h);let j;e[7]!==a.id||e[8]!==n.id||e[9]!==n.name||e[10]!==o||e[11]!==r?(j=async k=>{u(!0);const I=await cp(n.id,a.id,k);if(u(!1),!I){q.error(r("settings.extensions.toast.socketSaveFailed"));return}q.success(r("settings.extensions.toast.socketSaved",{name:n.name})),p(!1),await o()},e[7]=a.id,e[8]=n.id,e[9]=n.name,e[10]=o,e[11]=r,e[12]=j):j=e[12];const x=j;let S;e[13]!==a.override||e[14]!==a.resolved?(S=()=>{l(a.override??a.resolved??""),a.resolved&&p(!1)},e[13]=a.override,e[14]=a.resolved,e[15]=S):S=e[15];const b=S;let w;return e[16]!==a.id||e[17]!==a.override||e[18]!==a.resolved||e[19]!==i||e[20]!==b||e[21]!==f||e[22]!==x||e[23]!==m||e[24]!==r||e[25]!==c?(w=s.jsx("div",{className:"space-y-1",children:f?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(He,{value:c,onChange:k=>l(k.target.value),placeholder:r("settings.extensions.service.socket.path",{id:a.id}),"aria-label":r("settings.extensions.service.socket.path.aria",{id:a.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:i||m,autoFocus:!0}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",disabled:i||m,"aria-label":r("settings.extensions.service.socket.save.aria",{id:a.id}),onClick:()=>{x(c.trim()||null)},children:r("settings.extensions.service.socket.save")}),a.override?s.jsx(B,{type:"button",variant:"ghost",size:"xs",disabled:i||m,"aria-label":r("settings.extensions.service.socket.clear.aria",{id:a.id}),onClick:()=>{x(null)},children:r("settings.extensions.service.socket.clear")}):null,a.resolved?s.jsx(B,{type:"button",variant:"ghost",size:"xs",disabled:i||m,"aria-label":r("settings.extensions.service.socket.cancel.aria",{id:a.id}),onClick:b,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:a.resolved?r("settings.extensions.service.socket.resolved",{path:a.resolved}):r("settings.extensions.service.socket.unresolved")}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:ls,disabled:i||m,"aria-label":r("settings.extensions.service.socket.edit.aria",{id:a.id}),onClick:()=>p(!0),children:s.jsx(J,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=a.id,e[17]=a.override,e[18]=a.resolved,e[19]=i,e[20]=b,e[21]=f,e[22]=x,e[23]=m,e[24]=r,e[25]=c,e[26]=w):w=e[26],w},uj=t=>{const e=$e.c(151),{guest:n,busy:a,onReview:i,onRemove:o,onSetEnabled:r,onUpdate:c}=t,{t:l}=_e(),[m,u]=d.useState(!1),f=n.enabled!==!1,p=(n.enterpriseBlocked?.length??0)>0;let g;e[0]!==p||e[1]!==n?(g=!p&&Wa(n),e[0]=p,e[1]=n,e[2]=g):g=e[2];const h=g;let j,x,S,b,w,k,I,y,E,v,R,C,T,P,L;if(e[3]!==f||e[4]!==p||e[5]!==n||e[6]!==h||e[7]!==m||e[8]!==l){const V=cj(n);S=!!(n.source&&n.source!=="bundled");const Z=n.source==="bundled";let Y;e[24]!==n?(Y=rj(n),e[24]=n,e[25]=Y):Y=e[25],b=Y,L=n.source==="git"?n.update:void 0;let Q;e[26]!==n.icon||e[27]!==n.id?(Q=Md(n.id,n.icon,Gd().authenticatedAsset),e[26]=n.icon,e[27]=n.id,e[28]=Q):Q=e[28];const ue=Q;let ge;e[29]!==Z||e[30]!==n.source||e[31]!==l?(ge=Z?null:l(lj(n.source)),e[29]=Z,e[30]=n.source,e[31]=l,e[32]=ge):ge=e[32];const fe=n.version?`v${n.version}`:null;let Ie;e[33]!==n.entry||e[34]!==l?(Ie=n.entry?null:l("settings.extensions.source.noPanel"),e[33]=n.entry,e[34]=l,e[35]=Ie):Ie=e[35];let te;e[36]!==ge||e[37]!==fe||e[38]!==Ie?(te=[ge,fe,Ie].filter(Boolean),e[36]=ge,e[37]=fe,e[38]=Ie,e[39]=te):te=e[39];const Ce=te.join(" · "),ie=n.path||n.id;let ae;e[40]!==f||e[41]!==p||e[42]!==h||e[43]!==l?(ae=l(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]=l,e[44]=ae):ae=e[44];const re=ae,ye=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";x=Js,w=m,k=u,T="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let Ee;e[45]!==n.icon?(Ee=Ld(n.icon),e[45]=n.icon,e[46]=Ee):Ee=e[46];let Pe;e[47]!==ue||e[48]!==Ee?(Pe=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(Rd,{icon:Ee,iconSrc:ue,className:"size-5 text-foreground"})}),e[47]=ue,e[48]=Ee,e[49]=Pe):Pe=e[49];let ke;e[50]!==n.name?(ke=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n.name}),e[50]=n.name,e[51]=ke):ke=e[51];let Te;e[52]!==Ce?(Te=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:Ce}),e[52]=Ce,e[53]=Te):Te=e[53];let de;e[54]!==ke||e[55]!==Te?(de=s.jsxs("div",{className:"min-w-0 flex-1",children:[ke,Te]}),e[54]=ke,e[55]=Te,e[56]=de):de=e[56];let Me;e[57]!==Z||e[58]!==l?(Me=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:l("settings.extensions.source.bundled")}):null,e[57]=Z,e[58]=l,e[59]=Me):Me=e[59];let Se;e[60]!==l||e[61]!==L?(Se=L?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:l("settings.extensions.update.badge",{version:L.version})}):null,e[60]=l,e[61]=L,e[62]=Se):Se=e[62];let Le;e[63]!==ye?(Le=je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ye),e[63]=ye,e[64]=Le):Le=e[64];let Ke;e[65]!==re||e[66]!==Le?(Ke=s.jsx("span",{"aria-live":"polite",className:Le,children:re}),e[65]=re,e[66]=Le,e[67]=Ke):Ke=e[67];const oe=m&&"rotate-180";let le;e[68]!==oe?(le=je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",oe),e[68]=oe,e[69]=le):le=e[69];let xe;e[70]!==le?(xe=s.jsx(J,{name:"arrow-down-s",className:le}),e[70]=le,e[71]=xe):xe=e[71],e[72]!==Pe||e[73]!==de||e[74]!==Me||e[75]!==Se||e[76]!==Ke||e[77]!==xe?(P=s.jsxs(Qs,{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:[Pe,de,Me,Se,Ke,xe]}),e[72]=Pe,e[73]=de,e[74]=Me,e[75]=Se,e[76]=Ke,e[77]=xe,e[78]=P):P=e[78],j=Ys,C="border-t border-[var(--interactive-border)] px-4 py-4",I="space-y-3",e[79]!==ie?(y=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:ie,children:ie}),e[79]=ie,e[80]=y):y=e[80],e[81]!==p||e[82]!==l?(E=p?s.jsx("p",{className:"typography-meta text-foreground",children:l("settings.extensions.enterpriseBlocked")}):null,e[81]=p,e[82]=l,e[83]=E):E=e[83],e[84]!==Z||e[85]!==l?(v=Z?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l("settings.extensions.builtIn.info")}):null,e[84]=Z,e[85]=l,e[86]=v):v=e[86],R=V?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:l("settings.extensions.service.permissions",{list:V})}):null,e[3]=f,e[4]=p,e[5]=n,e[6]=h,e[7]=m,e[8]=l,e[9]=j,e[10]=x,e[11]=S,e[12]=b,e[13]=w,e[14]=k,e[15]=I,e[16]=y,e[17]=E,e[18]=v,e[19]=R,e[20]=C,e[21]=T,e[22]=P,e[23]=L}else j=e[9],x=e[10],S=e[11],b=e[12],w=e[13],k=e[14],I=e[15],y=e[16],E=e[17],v=e[18],R=e[19],C=e[20],T=e[21],P=e[22],L=e[23];let O;e[87]!==n.service||e[88]!==l?(O=n.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l("settings.extensions.service.warning")}):null,e[87]=n.service,e[88]=l,e[89]=O):O=e[89];let A;e[90]!==a||e[91]!==f||e[92]!==n?(A=f?(n.service?.socketBindings??[]).map(V=>s.jsx(dj,{guest:n,binding:V,busy:a,onSaved:cn},V.id)):null,e[90]=a,e[91]=f,e[92]=n,e[93]=A):A=e[93];let N;e[94]!==a||e[95]!==n||e[96]!==c||e[97]!==l||e[98]!==L?(N=L?s.jsx(B,{type:"button",size:"sm",disabled:a,"aria-label":l("settings.extensions.update.action.aria",{name:n.name,version:L.version}),onClick:()=>{c(n)},children:l("settings.extensions.update.action")}):null,e[94]=a,e[95]=n,e[96]=c,e[97]=l,e[98]=L,e[99]=N):N=e[99];let M;e[100]!==a||e[101]!==n||e[102]!==h||e[103]!==i||e[104]!==l?(M=h?s.jsx(B,{type:"button",size:"sm",disabled:a,"aria-label":l("settings.extensions.review.aria",{name:n.name}),onClick:()=>i(n),children:l("settings.extensions.review")}):null,e[100]=a,e[101]=n,e[102]=h,e[103]=i,e[104]=l,e[105]=M):M=e[105];let F;e[106]!==a||e[107]!==f||e[108]!==n.id||e[109]!==n.name||e[110]!==r||e[111]!==l?(F=f?s.jsx(B,{type:"button",size:"sm",variant:"outline",disabled:a,"aria-label":l("settings.extensions.actions.disable.aria",{name:n.name}),onClick:()=>{r(n.id,n.name,!1)},children:l("settings.extensions.actions.disable")}):s.jsx(B,{type:"button",size:"sm",disabled:a,"aria-label":l("settings.extensions.actions.enable.aria",{name:n.name}),onClick:()=>{r(n.id,n.name,!0)},children:l("settings.extensions.actions.enable")}),e[106]=a,e[107]=f,e[108]=n.id,e[109]=n.name,e[110]=r,e[111]=l,e[112]=F):F=e[112];let H;e[113]!==a||e[114]!==S||e[115]!==n.id||e[116]!==n.name||e[117]!==o||e[118]!==l?(H=S?s.jsx(B,{type:"button",size:"sm",variant:"destructive",disabled:a,"aria-label":l("settings.extensions.remove.aria",{name:n.name}),onClick:()=>{o(n.id,n.name)},children:l("settings.extensions.remove")}):null,e[113]=a,e[114]=S,e[115]=n.id,e[116]=n.name,e[117]=o,e[118]=l,e[119]=H):H=e[119];let W;e[120]!==b||e[121]!==l?(W=b?s.jsxs(B,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{Ss(b)},children:[s.jsx(J,{name:"external-link",className:"size-4"}),l("settings.extensions.actions.openSource")]}):null,e[120]=b,e[121]=l,e[122]=W):W=e[122];let G;e[123]!==N||e[124]!==M||e[125]!==F||e[126]!==H||e[127]!==W?(G=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[N,M,F,H,W]}),e[123]=N,e[124]=M,e[125]=F,e[126]=H,e[127]=W,e[128]=G):G=e[128];let $;e[129]!==O||e[130]!==A||e[131]!==G||e[132]!==I||e[133]!==y||e[134]!==E||e[135]!==v||e[136]!==R?($=s.jsxs("div",{className:I,children:[y,E,v,R,O,A,G]}),e[129]=O,e[130]=A,e[131]=G,e[132]=I,e[133]=y,e[134]=E,e[135]=v,e[136]=R,e[137]=$):$=e[137];let z;e[138]!==j||e[139]!==$||e[140]!==C?(z=s.jsx(j,{className:C,children:$}),e[138]=j,e[139]=$,e[140]=C,e[141]=z):z=e[141];let U;e[142]!==z||e[143]!==T||e[144]!==P?(U=s.jsxs("div",{className:T,children:[P,z]}),e[142]=z,e[143]=T,e[144]=P,e[145]=U):U=e[145];let _;return e[146]!==x||e[147]!==w||e[148]!==k||e[149]!==U?(_=s.jsx(x,{open:w,onOpenChange:k,children:U}),e[146]=x,e[147]=w,e[148]=k,e[149]=U,e[150]=_):_=e[150],_},mj=()=>{const t=$e.c(175),{t:e}=_e(),n=As(pj),a=As(gj),i=As(fj),o=As(hj),[r,c]=d.useState(null),[l,m]=d.useState(!1),[u,f]=d.useState("global"),p=a==="unsupported",[g,h]=d.useState(""),j=zn(),[x,S]=d.useState(!1),[b,w]=d.useState(!1),k=d.useRef(!1),[I,y]=d.useState(null),[E,v]=d.useState(null),[R,C]=d.useState(!1),T=d.useRef(0),P=d.useRef(null);let L;t[0]===Symbol.for("react.memo_cache_sentinel")?(L=rg(),t[0]=L):L=t[0];const O=L;let A;t[1]===Symbol.for("react.memo_cache_sentinel")?(A=[],t[1]=A):A=t[1],d.useEffect(xj,A);let N,M;t[2]!==o||t[3]!==p?(N=()=>{let we=!1;if(c(null),m(!1),f("global"),y(null),v(null),k.current=!1,!p)return Promise.all([rp(),lp()]).then(ze=>{const[pt,Ct]=ze;we||c({runtimeKey:o,profiles:pt,global:Ct})}).catch(()=>{we||m(!0)}),()=>{we=!0}},M=[o,p],t[2]=o,t[3]=p,t[4]=N,t[5]=M):(N=t[4],M=t[5]),d.useEffect(N,M);const F=r?.runtimeKey===o?r:null;let H;t[6]!==e?(H=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=H):H=t[7];const W=F?.global?.userName??"",G=F?.global?.userEmail??"";let $;t[8]!==H||t[9]!==W||t[10]!==G?($={id:"global",name:H,userName:W,userEmail:G,icon:"fingerprint",color:"info"},t[8]=H,t[9]=W,t[10]=G,t[11]=$):$=t[11];let z;t[12]!==F?.profiles||t[13]!==$?(z=[$,...F?.profiles.filter(bj)??[]],t[12]=F?.profiles,t[13]=$,t[14]=z):z=t[14];const U=z;let _;t[15]!==U||t[16]!==u?(_=U.find(we=>we.id===u)??U[0],t[15]=U,t[16]=u,t[17]=_):_=t[17];const V=_;let Z,Y;t[18]!==a?(Z=()=>{if(a!=="ready"||k.current)return;k.current=!0;const we=As.getState().runtimeKey;ed(!1).then(ze=>{ze.ok&&As.getState().applyUpdates(ze.updates,we)})},Y=[a],t[18]=a,t[19]=Z,t[20]=Y):(Z=t[19],Y=t[20]),d.useEffect(Z,Y);let Q;t[21]!==e?(Q=async()=>{w(!0);const we=As.getState().runtimeKey,ze=await ed(!0);if(w(!1),!ze.ok){q.error(e("settings.extensions.toast.checkFailed"));return}As.getState().applyUpdates(ze.updates,we),Object.keys(ze.updates).length===0&&q.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=Q):Q=t[22];const ue=Q;let ge;t[23]!==e?(ge=async we=>{S(!0);const ze=await Ku(we.id);if(S(!1),!ze.ok){q.error(ze.code==="host-too-old"&&ze.required?e("settings.extensions.toast.hostTooOld",{version:ze.required}):e(Du(ze.code)));return}vi(we.id),q.success(e("settings.extensions.toast.updated",{name:ze.guest.name,version:ze.guest.version??""})),await cn(),Wa(ze.guest)&&v(ze.guest)},t[23]=e,t[24]=ge):ge=t[24];const fe=ge;let Ie;if(t[25]!==n||t[26]!==e){const we=async(ze,pt,Ct)=>{const Gt=Ct===void 0?{}:Ct;if(!ze.ok){if(Gt.allowConflictDialog!==!1&&(ze.code==="id-taken"||ze.code==="already-installed")){const Zt=ze.id?n.find(as=>as.id===ze.id):void 0;return y({source:pt,name:Zt?.name??ze.id??(pt.kind==="file"?pt.file.name:pt.input)}),!1}return ze.code==="host-too-old"?q.error(ze.required?e("settings.extensions.toast.hostTooOld",{version:ze.required}):e("settings.extensions.toast.failed"),{description:ze.diagnostic?Nr(ze.diagnostic,e):void 0}):q.error(e(Eu(ze.code)),{description:ze.diagnostic?Nr(ze.diagnostic,e):void 0}),!1}return h(""),y(null),q.success(ze.replaced?e("settings.extensions.toast.reinstalled",{name:ze.guest.name}):e("settings.extensions.toast.added",{name:ze.guest.name})),await cn(),Wa(ze.guest)&&v(ze.guest),!0};Ie=async(ze,pt)=>{const Ct=pt===void 0?{}:pt,Gt=Xt();ze.kind==="input"&&h(ze.input),S(!0);const Zt=ze.kind==="file"?await F1(ze.file,Ct):await Lu(ze.input,{...Ct,gitIdentityId:ze.gitIdentityId});S(!1),Xt()===Gt&&await we(Zt,ze,{allowConflictDialog:!Ct.replace})},t[25]=n,t[26]=e,t[27]=Ie}else Ie=t[27];const te=Ie;let Ce;t[28]!==g||t[29]!==te||t[30]!==V||t[31]!==e?(Ce=async()=>{const we=g.trim();if(!we){q.error(e("settings.extensions.toast.invalidPath"));return}await te({kind:"input",input:we,gitIdentityId:V.id})},t[28]=g,t[29]=te,t[30]=V,t[31]=e,t[32]=Ce):Ce=t[32];const ie=Ce;let ae;t[33]!==te?(ae=async()=>{if(!O)return;const we=await lg("");we.success&&we.path&&await te({kind:"input",input:we.path})},t[33]=te,t[34]=ae):ae=t[34];const re=ae;let ye;t[35]!==te?(ye=async()=>{if(!O){P.current?.click();return}const we=await ul({filters:[{name:"ZIP Archive",extensions:["zip"]}]});we.success&&we.path&&await te({kind:"input",input:we.path})},t[35]=te,t[36]=ye):ye=t[36];const Ee=ye;let Pe;t[37]!==te||t[38]!==e?(Pe=async we=>{const ze=we.target.files?.[0]??null;if(we.target.value="",!!ze){if(!td(ze)){q.error(e("settings.extensions.toast.invalidPath"));return}await te({kind:"file",file:ze})}},t[37]=te,t[38]=e,t[39]=Pe):Pe=t[39];const ke=Pe;let Te;t[40]!==x?(Te=we=>{x||(we.preventDefault(),T.current=T.current+1,C(!0))},t[40]=x,t[41]=Te):Te=t[41];const de=Te;let Me;t[42]!==x?(Me=we=>{x||(we.preventDefault(),we.dataTransfer.dropEffect="copy")},t[42]=x,t[43]=Me):Me=t[43];const Se=Me;let Le;t[44]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>{T.current=Math.max(0,T.current-1),T.current===0&&C(!1)},t[44]=Le):Le=t[44];const Ke=Le;let oe;t[45]!==x||t[46]!==te||t[47]!==e?(oe=async we=>{if(we.preventDefault(),T.current=0,C(!1),x)return;const ze=we.dataTransfer.items[0],pt=ze?.getAsFile()??null,Gt=(ze?.webkitGetAsEntry()??null)?.isDirectory===!0,Zt=pt!==null&&!Gt&&td(pt),as=pt&&O?cg(pt):null;if(as&&(Gt||Zt)){await te({kind:"input",input:as});return}if(Gt){q.error(e(O?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!pt||!Zt){q.error(e("settings.extensions.toast.invalidPath"));return}await te({kind:"file",file:pt})},t[45]=x,t[46]=te,t[47]=e,t[48]=oe):oe=t[48];const le=oe;let xe;t[49]!==I||t[50]!==te?(xe=async()=>{I&&await te(I.source,{replace:!0})},t[49]=I,t[50]=te,t[51]=xe):xe=t[51];const De=xe;let Ve;t[52]!==e?(Ve=async(we,ze)=>{S(!0);const pt=await Ou(we);if(S(!1),!pt.ok){q.error(e("settings.extensions.toast.removeFailed"));return}vi(we),q.success(e("settings.extensions.toast.removed",{name:ze})),await cn()},t[52]=e,t[53]=Ve):Ve=t[53];const Be=Ve;let Ne;t[54]!==e?(Ne=async we=>{S(!0);const ze=await K1(we.id,we.capabilities.requested);if(S(!1),!ze){q.error(e("settings.extensions.toast.approveFailed"));return}v(null),q.success(e("settings.extensions.toast.approved",{name:we.name})),await cn()},t[54]=e,t[55]=Ne):Ne=t[55];const Je=Ne;let ut;t[56]!==Be?(ut=async we=>{v(null),await Be(we.id,we.name)},t[56]=Be,t[57]=ut):ut=t[57];const ht=ut;let st;t[58]!==e?(st=async(we,ze,pt)=>{S(!0);const Ct=await Fu(we,pt);if(S(!1),!Ct){q.error(e("settings.extensions.toast.enabledFailed"));return}pt||vi(we),q.success(pt?e("settings.extensions.toast.enabled",{name:ze}):e("settings.extensions.toast.disabled",{name:ze})),await cn()},t[58]=e,t[59]=st):st=t[59];const jt=st;let St;t[60]!==e?(St=e("settings.page.extensions.title"),t[60]=e,t[61]=St):St=t[61];let Ze;t[62]!==e?(Ze=e("settings.page.extensions.description"),t[62]=e,t[63]=Ze):Ze=t[63];let it;t[64]!==ie||t[65]!==re||t[66]!==Ee||t[67]!==x||t[68]!==R||t[69]!==j||t[70]!==U||t[71]!==r||t[72]!==l||t[73]!==g||t[74]!==de||t[75]!==Se||t[76]!==le||t[77]!==ke||t[78]!==V||t[79]!==e||t[80]!==p?(it=p?null:s.jsxs(qe,{title:e("settings.extensions.add.action"),info:j?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(Rt,{label:e("settings.extensions.add.label"),info:e(O?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:je("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",R&&"border-primary bg-primary/5"),onDragEnter:de,onDragOver:Se,onDragLeave:Ke,onDrop:we=>{le(we)},children:[R?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(He,{value:g,onChange:we=>h(we.target.value),onKeyDown:we=>{we.key==="Enter"&&(we.preventDefault(),ie())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:je("h-8 min-w-0 flex-1 rounded-md pl-3",O?"pr-14":"pr-8"),disabled:x}),s.jsx("input",{ref:P,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:we=>{ke(we)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[O?s.jsx(B,{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:x,onClick:()=>{re()},children:s.jsx(J,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(B,{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:x,onClick:()=>{Ee()},children:s.jsx(J,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(Rg,{activeProfile:V,identities:U,onSelect:we=>f(we.id),isApplying:x||!r&&!l,iconOnly:!0})}),s.jsxs(B,{type:"button",size:"sm",disabled:x,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{ie()},children:[s.jsx(J,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),l?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[64]=ie,t[65]=re,t[66]=Ee,t[67]=x,t[68]=R,t[69]=j,t[70]=U,t[71]=r,t[72]=l,t[73]=g,t[74]=de,t[75]=Se,t[76]=le,t[77]=ke,t[78]=V,t[79]=e,t[80]=p,t[81]=it):it=t[81];let et;t[82]!==e?(et=e("settings.extensions.section.installed"),t[82]=e,t[83]=et):et=t[83];let mt;t[84]!==x||t[85]!==ue||t[86]!==b||t[87]!==a||t[88]!==e||t[89]!==p?(mt=p?null:s.jsxs(B,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:x||b||a!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{ue()},children:[s.jsx(J,{name:"refresh",className:je("h-4 w-4",b&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[84]=x,t[85]=ue,t[86]=b,t[87]=a,t[88]=e,t[89]=p,t[90]=mt):mt=t[90];let ft;t[91]!==i||t[92]!==a||t[93]!==e?(ft=a==="error"||i?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),i?`
30
- ${Nr(i,e)}`:""]}):null,t[91]=i,t[92]=a,t[93]=e,t[94]=ft):ft=t[94];let be;t[95]!==e||t[96]!==p?(be=p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[95]=e,t[96]=p,t[97]=be):be=t[97];let Re;t[98]!==n.length||t[99]!==a||t[100]!==e?(Re=a==="ready"&&n.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[98]=n.length,t[99]=a,t[100]=e,t[101]=Re):Re=t[101];let X;if(t[102]!==x||t[103]!==n||t[104]!==Be||t[105]!==jt||t[106]!==fe){let we;t[108]!==x||t[109]!==Be||t[110]!==jt||t[111]!==fe?(we=ze=>s.jsx(uj,{guest:ze,busy:x,onReview:v,onRemove:Be,onSetEnabled:jt,onUpdate:fe},ze.id),t[108]=x,t[109]=Be,t[110]=jt,t[111]=fe,t[112]=we):we=t[112],X=n.map(we),t[102]=x,t[103]=n,t[104]=Be,t[105]=jt,t[106]=fe,t[107]=X}else X=t[107];let ce;t[113]!==et||t[114]!==mt||t[115]!==ft||t[116]!==be||t[117]!==Re||t[118]!==X?(ce=s.jsxs(qe,{title:et,contentClassName:"space-y-3",headerAction:mt,children:[ft,be,Re,X]}),t[113]=et,t[114]=mt,t[115]=ft,t[116]=be,t[117]=Re,t[118]=X,t[119]=ce):ce=t[119];let Oe;t[120]!==Je?(Oe=we=>{Je(we)},t[120]=Je,t[121]=Oe):Oe=t[121];let We;t[122]!==ht?(We=we=>{ht(we)},t[122]=ht,t[123]=We):We=t[123];let nt;t[124]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>v(null),t[124]=nt):nt=t[124];let at;t[125]!==E||t[126]!==x||t[127]!==Oe||t[128]!==We?(at=s.jsx(aj,{guest:E,busy:x,onApprove:Oe,onDecline:We,onDismiss:nt}),t[125]=E,t[126]=x,t[127]=Oe,t[128]=We,t[129]=at):at=t[129];const vt=I!==null;let kt;t[130]!==x?(kt=we=>{!we&&!x&&y(null)},t[130]=x,t[131]=kt):kt=t[131];let xt;t[132]!==e?(xt=e("settings.extensions.dialog.reinstallTitle"),t[132]=e,t[133]=xt):xt=t[133];let It;t[134]!==xt?(It=s.jsx(Vt,{children:xt}),t[134]=xt,t[135]=It):It=t[135];const _t=I?.name??"";let Ye;t[136]!==e||t[137]!==_t?(Ye=e("settings.extensions.dialog.reinstallDescription",{name:_t}),t[136]=e,t[137]=_t,t[138]=Ye):Ye=t[138];let Xe;t[139]!==Ye?(Xe=s.jsx(Ht,{children:Ye}),t[139]=Ye,t[140]=Xe):Xe=t[140];let gt;t[141]!==It||t[142]!==Xe?(gt=s.jsxs(Bt,{children:[It,Xe]}),t[141]=It,t[142]=Xe,t[143]=gt):gt=t[143];let Ue;t[144]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>y(null),t[144]=Ue):Ue=t[144];let ee;t[145]!==e?(ee=e("settings.common.actions.cancel"),t[145]=e,t[146]=ee):ee=t[146];let ve;t[147]!==x||t[148]!==ee?(ve=s.jsx(B,{size:"sm",variant:"ghost",disabled:x,onClick:Ue,children:ee}),t[147]=x,t[148]=ee,t[149]=ve):ve=t[149];let Fe;t[150]!==De?(Fe=()=>{De()},t[150]=De,t[151]=Fe):Fe=t[151];let se;t[152]!==e?(se=e("settings.extensions.dialog.reinstall"),t[152]=e,t[153]=se):se=t[153];let Ae;t[154]!==x||t[155]!==Fe||t[156]!==se?(Ae=s.jsx(B,{size:"sm",disabled:x,onClick:Fe,children:se}),t[154]=x,t[155]=Fe,t[156]=se,t[157]=Ae):Ae=t[157];let tt;t[158]!==ve||t[159]!==Ae?(tt=s.jsxs(ns,{children:[ve,Ae]}),t[158]=ve,t[159]=Ae,t[160]=tt):tt=t[160];let ot;t[161]!==gt||t[162]!==tt?(ot=s.jsxs(Ut,{className:"max-w-md",children:[gt,tt]}),t[161]=gt,t[162]=tt,t[163]=ot):ot=t[163];let At;t[164]!==vt||t[165]!==kt||t[166]!==ot?(At=s.jsx(zt,{open:vt,onOpenChange:kt,children:ot}),t[164]=vt,t[165]=kt,t[166]=ot,t[167]=At):At=t[167];let pe;return t[168]!==St||t[169]!==Ze||t[170]!==it||t[171]!==ce||t[172]!==at||t[173]!==At?(pe=s.jsxs(es,{title:St,description:Ze,children:[it,ce,at,At]}),t[168]=St,t[169]=Ze,t[170]=it,t[171]=ce,t[172]=at,t[173]=At,t[174]=pe):pe=t[174],pe};function pj(t){return t.guests}function gj(t){return t.status}function fj(t){return t.failure}function hj(t){return t.runtimeKey}function xj(){cn()}function bj(t){return t.id!=="global"}function vj(t,e,n=!1){if(n)return;const{surface:a,primary:i,status:o,interactive:r,markdown:c,chat:l,tools:m,syntax:u}=t.colors,f=t.metadata.variant==="dark",p=a.background,g=Us(p,p),h=(T,P)=>lo(T,P,p)??1,j=(T,P,L)=>{if(L(T))return T;let O=0,A=1,N=P;for(let M=0;M<16;M++){const F=(O+A)/2,H=ys(P,T,F,p);L(H)?(A=F,N=H):O=F}return N},x=T=>h(T,"#000000"),S=Math.min(4.6,h(g,p)),b=(T,P)=>{const L=P?"#ffffff":"#000000",A=(P?x(T)>x(p):x(T)<x(p))?ys(T,p,1,p):p,N=j(A,p,F=>h(F,p)<=1.1),M=h(L,p)<1.04?L:j(N,L,F=>h(F,p)>=1.04);return j(M,p,F=>h(g,F)>=S)};a.muted=b(a.muted,!1),a.elevated=b(a.elevated,f),a.subtle=ys(g,p,.025,p);const w=[p,a.muted,a.elevated],k=T=>Math.min(...w.map(P=>h(T,P))),I=T=>j(T,g,P=>k(P)>=4.6),y=(T,P,L=4.6)=>j(j(T,p,O=>h(O,p)<=P),g,O=>k(O)>=L);a.foreground=y(a.foreground,f?10:9,7),a.mutedForeground=y(a.mutedForeground,Math.min(6,h(a.foreground,p)*.7)),a.elevatedForeground=y(a.elevatedForeground,f?10:9,7);const E=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder];i.base=I(E.find(T=>T!==void 0&&k(T)>=3)??i.base),i.foreground=Us(i.base,p),i.hover=ys(g,i.base,.08,p),i.active=ys(g,i.base,.16,p),i.muted=la(i.base,.5),k(r.focusRing)<1.1&&(r.focus=i.base,r.focusRing=i.base,r.borderFocus=i.base),r.selection=j(r.selection,ys(i.base,p,.18,p),T=>k(T)>=1.1);const v=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]},R=(T,[P,L,O])=>{const A=Math.max(P,L,O),N=G=>G+(A-G)*.2,M=G=>h(G,p)<=N(P)&&h(G,a.muted)<=N(L)&&h(G,a.elevated)<=N(O);if(M(T))return T;let F=0,H=1,W=la(T,0);for(let G=0;G<16;G++){const $=(F+H)/2,z=la(T,$);M(z)?(F=$,W=z):H=$}return W};r.border=R(r.border,v.border),r.borderHover=R(r.borderHover,v.hover),r.hover=R(r.hover,[1.18,1.18,1.18]),r.active=R(r.active,[1.25,1.25,1.25]),r.selection=R(r.selection,[1.6,1.7,1.45]),r.selectionForeground=An(a.foreground,r.selection,p);const C=(T,P,L,O)=>{const A=dp(T,p);return I(A!==null&&A>=L&&A<=O?T:P)};o.error=C(o.error,f?"#e07777":"#b43b45",10,40),o.warning=C(o.warning,f?"#d6b467":"#916b17",65,100),o.success=C(o.success,f?"#80b888":"#357b47",125,165),o.info=C(o.info,f?"#83afe0":"#366eaa",230,275);for(const T of["error","warning","success","info"])o[`${T}Foreground`]=Us(o[T],p),o[`${T}Background`]=la(o[T],f?.16:.12),o[`${T}Border`]=la(o[T],f?.45:.35);if(t.colors.pr={open:o.success,closed:o.error,draft:a.mutedForeground,blocked:C(e["terminal.ansiYellow"]??"",f?"#d99464":"#a65b25",40,65),merged:C(e["terminal.ansiMagenta"]??"",f?"#b79bd9":"#8255b0",285,325)},l){let T=j(p,g,P=>h(P,p)>=1.12);h(g,T)<S&&(T=j(p,g==="#ffffff"?"#000000":"#ffffff",P=>h(P,p)>=1.12)),l.userMessageBackground=j(ys(i.base,T,.03,p),T,P=>h(P,p)>=1.1&&h(g,P)>=S),w.push(l.userMessageBackground),a.foreground=j(a.foreground,g,P=>k(P)>=7),a.mutedForeground=I(a.mutedForeground),l.userMessage=An(a.foreground,l.userMessageBackground,p),l.assistantMessage=a.foreground,l.timestamp=a.mutedForeground,l.typing=a.mutedForeground,l.avatarForeground=e["chat.avatarForeground"]??a.foreground,l.slashCommandBackground=e["chat.slashCommandBackground"]??i.base,l.slashCommandForeground=e["chat.slashCommandForeground"]??Us(l.slashCommandBackground,p),l.inputWorkingBorderColor1=e["chat.inputWorkingBorderColor1"]??i.base,l.inputWorkingBorderColor2=e["chat.inputWorkingBorderColor2"]??i.hover,l.inputWorkingBorderColor3=e["chat.inputWorkingBorderColor3"]??i.muted,l.divider=R(l.divider??r.border,v.divider)}t.colors.pr&&(t.colors.pr.draft=a.mutedForeground),m&&(m.border=R(m.border??r.border,v.tools),m.title=a.foreground,m.description=a.mutedForeground,m.icon=a.mutedForeground),c&&(c.bold=ys(g,a.foreground,.12,p),c.italic=a.foreground,c.blockquote=a.mutedForeground,c.blockquoteBorder=R(c.blockquoteBorder??r.border,v.divider),c.hr=R(c.hr??r.border,v.divider),c.link=I(e["textLink.foreground"]??i.base),c.linkHover=I(e["textLink.activeForeground"]??i.hover),c.listMarker=la(i.base,.6),c.inlineCodeBackground=a.subtle,c.inlineCode=An(I(e["textPreformat.foreground"]??i.base),a.subtle,p)),u.base.background=j(u.base.background,p,T=>h(T,p)<=1.1),u.base.foreground=An(a.foreground,u.base.background,p)}const zs=la,yj=t=>{const e={...t,colors:{...t.colors}},n=e.kind==="dark"||e.kind==="high-contrast",a=up(n),i=e.colors,o=i["chat.list.background"]??i["editor.background"]??a.colors.surface.background,r=i["interactive-session.foreground"]??i.foreground??i["editor.foreground"]??Us(o,o);i.foreground??=r,i["sideBar.background"]??=i["panel.background"]??ys(r,o,.03,o),!i["editorWidget.background"]&&!i["dropdown.background"]&&!i["input.background"]&&(i["editorWidget.background"]=ys(r,o,.04,o),i["editorWidget.foreground"]=An(r,i["editorWidget.background"],o)),i.descriptionForeground??=An(ys(r,o,.6,o),o),i["widget.border"]??=i["input.border"]??i["panel.border"]??ys(r,o,.15,o),i["toolbar.hoverBackground"]??=i["list.hoverBackground"]??ys(r,o,.08,o),i["toolbar.activeBackground"]??=ys(r,o,.12,o),!i["list.activeSelectionBackground"]&&!i["menu.selectionBackground"]&&!i["editor.selectionBackground"]&&(i["list.activeSelectionBackground"]=ys(r,o,.16,o),i["list.activeSelectionForeground"]=An(r,i["list.activeSelectionBackground"],o)),i["button.background"]||(i["button.background"]=i["textLink.foreground"]??i.focusBorder??r,i["button.foreground"]=Us(i["button.background"],o)),i.focusBorder??=i["button.background"],i["editorCursor.foreground"]??=i["editor.foreground"]??r;const c=(de,Me)=>e.colors[de]??Me,l=de=>de!=="transparent"&&(lo(de,"#000000")!==1||lo(de,"#ffffff")!==1),m=(de,Me)=>{const Se=c(de,Me);return l(Se)?Se:Me},u=c("chat.list.background",c("editor.background",a.colors.surface.background)),f=c("interactive-session.foreground",c("foreground",c("editor.foreground",a.colors.surface.foreground))),g=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([de])=>e.colors[de]),h=g?c(g[0],a.colors.surface.elevated):a.colors.surface.elevated,j=An(f,h,u),x=g?c(g[1],j):j,S=c("sideBar.background",c("panel.background",a.colors.surface.muted)),b=c("descriptionForeground",c("input.placeholderForeground",a.colors.surface.mutedForeground)),w=c("textBlockQuote.background",S),k=a.colors.surface.overlay,I=c("button.background",c("textLink.foreground",a.colors.primary.base)),y=c("button.hoverBackground",I),E=e.colors["button.background"]?c("button.foreground",Us(I,u)):Us(I,u),v=zs(I,.5),C=[e.kind==="high-contrast"||e.highContrast?c("contrastBorder",""):"",c("widget.border",""),c("input.border",""),c("panel.border",""),c("sideBar.border",""),c("editorWidget.border",""),c("contrastBorder","")].find(de=>de&&l(de))||zs(f,n?.25:.2),T=c("toolbar.hoverBackground",c("list.hoverBackground",a.colors.interactive.hover)),P=c("toolbar.activeBackground",T),O=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([de])=>e.colors[de]),A=O.find(([de])=>[u,S,h].every(Me=>{const Se=lo(c(de,""),Me,u);return Se===null||Se>1.01}))??O[0],N=A?c(A[0],a.colors.interactive.selection):a.colors.interactive.selection,M=A?c(A[1],f):f,F=c("focusBorder",c("inputOption.activeBorder",I)),H=F,W=c("editorCursor.foreground",a.colors.interactive.cursor),G=c("editorError.foreground",c("testing.iconFailed",a.colors.status.error)),$=m("editorError.background",zs(G,n?.16:.12)),z=c("problemsWarningIcon.foreground",c("notificationsWarningIcon.foreground",c("editorWarning.foreground",a.colors.status.warning))),U=m("editorWarning.background",zs(z,n?.16:.12)),_=c("testing.iconPassed",c("gitDecoration.addedResourceForeground",a.colors.status.success)),V=zs(_,n?.16:.12),Z=c("problemsInfoIcon.foreground",c("editorInfo.foreground",a.colors.status.info)),Y=m("editorInfo.background",zs(Z,n?.16:.12)),Q=c("editorLineNumber.foreground",b),ue=c("textPreformat.foreground",c("terminal.ansiGreen",a.colors.syntax.base.string)),ge=c("terminal.ansiBlue",I),fe=c("terminal.ansiYellow",a.colors.syntax.base.number),Ie=c("terminal.ansiCyan",a.colors.syntax.base.function),te=c("terminal.ansiMagenta",f),Ce=c("terminal.ansiYellow",a.colors.syntax.base.type),ie=c("chat.requestBorder",C),ae=c("diffEditor.insertedLineBackground",c("diffEditor.insertedTextBackground",V)),re=c("diffEditor.removedLineBackground",c("diffEditor.removedTextBackground",$)),ye=c("chat.linesAddedForeground",c("gitDecoration.addedResourceForeground",_)),Ee=c("chat.linesRemovedForeground",c("gitDecoration.deletedResourceForeground",G)),Pe=c("gitDecoration.modifiedResourceForeground",Z),ke=c("chat.requestBubbleBackground",c("chat.requestBackground",h)),Te={...a,metadata:{...a.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:n?"dark":"light",tags:["vscode","auto"]},colors:{...a.colors,primary:{base:I,hover:y,active:y,foreground:E,muted:v},surface:{background:u,foreground:f,muted:S,mutedForeground:b,elevated:h,elevatedForeground:x,overlay:k,subtle:w},interactive:{border:C,borderHover:c("toolbar.hoverOutline",C),borderFocus:F,selection:N,selectionForeground:M,focus:F,focusRing:H,cursor:W,hover:T,active:P},status:{error:G,errorForeground:Us(G,u),errorBackground:$,errorBorder:zs(G,n?.45:.35),warning:z,warningForeground:Us(z,u),warningBackground:U,warningBorder:zs(z,n?.45:.35),success:_,successForeground:Us(_,u),successBackground:V,successBorder:zs(_,n?.45:.35),info:Z,infoForeground:Us(Z,u),infoBackground:Y,infoBorder:zs(Z,n?.45:.35)},pr:a.colors.pr?{...a.colors.pr,open:_,closed:G,draft:b}:void 0,syntax:{tokens:{},highlights:{diffAdded:ye,diffAddedBackground:ae,diffRemoved:Ee,diffRemovedBackground:re,diffModified:Pe,diffModifiedBackground:zs(Pe,n?.16:.12),lineNumber:c("editorLineNumber.foreground",b),lineNumberActive:c("editorLineNumber.activeForeground",f)},base:{background:c("editor.background",u),foreground:c("editor.foreground",f),comment:Q,keyword:ge,string:ue,number:fe,function:Ie,variable:te,type:Ce,operator:I}},tools:{border:ie,icon:c("icon.foreground",b),title:f,description:zs(b,.8),edit:{added:ye,addedBackground:ae,removed:Ee,removedBackground:re,modified:Pe,modifiedBackground:zs(Pe,n?.16:.12),lineNumber:Q}},chat:{background:u,userMessage:f,userMessageBackground:ke,assistantMessage:f,assistantMessageBackground:u,timestamp:b,divider:C,typing:c("chat.thinkingShimmer",b),avatarBackground:c("chat.avatarBackground",u),avatarForeground:c("chat.avatarForeground",f),slashCommandBackground:c("chat.slashCommandBackground",I),slashCommandForeground:c("chat.slashCommandForeground",E),inputWorkingBorderColor1:c("chat.inputWorkingBorderColor1",I),inputWorkingBorderColor2:c("chat.inputWorkingBorderColor2",y),inputWorkingBorderColor3:c("chat.inputWorkingBorderColor3",v)},markdown:{link:c("textLink.foreground",I),linkHover:c("textLink.activeForeground",y),inlineCode:c("textPreformat.foreground",ue),inlineCodeBackground:c("textPreformat.background",c("editor.background",u)),blockquote:f,blockquoteBackground:c("textBlockQuote.background","transparent"),blockquoteBorder:c("textBlockQuote.border",C),listMarker:zs(I,.6)}}};return vj(Te,t.colors,e.kind==="high-contrast"||e.highContrast===!0),Te},No=Nt().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),Cl=rs({foreground:No.optional()}),_u=rs({scope:Kr([Nt(),sn(Nt())]).optional(),settings:Cl}),jj=rs({name:Nt().trim().min(1).max(160).optional(),author:Nt().max(160).optional(),description:Nt().max(1024).optional(),type:ml(["light","dark","hc","hc-black","hc-light"]).optional(),include:Nt().optional(),colors:Dn(Nt(),No.nullable()).default({}),tokenColors:Kr([sn(_u),Nt()]).optional(),semanticHighlighting:Pi().optional(),semanticTokenColors:Dn(Nt(),Kr([No,Cl])).optional()});function kj(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(a=>a.split(",").map(i=>({scope:i.trim(),color:e.settings.foreground}))))}function wj(t,e){for(const n of e){let a,i=-1;for(const o of t)!o.color||!o.scope||(n===o.scope||n.startsWith(`${o.scope}.`))&&o.scope.length>=i&&(a=o.color,i=o.scope.length);if(a)return a}}function Sj(t,e){for(const n of e.length?[...e,"*"]:e){const a=t[n];if(a===void 0)continue;const i=No.safeParse(a);if(i.success)return i.data;const o=Cl.safeParse(a);if(o.success&&o.data.foreground)return o.data.foreground}}function Nj(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function Bu(t,e){if(new TextEncoder().encode(t).byteLength>Ud)throw new ma("size");let n;try{n=jj.parse(JSON.parse(qg(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ma("invalid")}const a=sn(_u).safeParse(n.tokenColors??[]);if(n.include||!a.success)throw new ma("include");const i={};for(const[E,v]of Object.entries(n.colors))v!==null&&(i[E]=v);const o=i["editor.background"];if(!o)throw new ma("background");const r=n.type?["dark","hc","hc-black"].includes(n.type):Us(o,"#ffffff")==="#ffffff",c=r?"dark":"light",l=ys(o,r?"#000000":"#ffffff",1),m=kj(a.data),u=a.data.filter(E=>!E.scope&&E.settings.foreground).at(-1)?.settings.foreground,f=i["editor.foreground"]??u??i.foreground??Us(l,l);i["editor.background"]=l,i["editor.foreground"]=f;const p=n.type?.startsWith("hc")??!1;p&&i.contrastBorder&&(i["widget.border"]=i.contrastBorder);const h=yj({kind:r&&p?"high-contrast":c,colors:i,highContrast:p}),j=n.semanticHighlighting===!1?{}:n.semanticTokenColors??{},x=(E,v,R)=>Sj(j,E)??wj(m,v)??R,S=h.colors.syntax.base.foreground,b={background:h.colors.syntax.base.background,foreground:h.colors.syntax.base.foreground,comment:x(["comment"],["comment","comment.line","comment.block"],An(ys(f,l,.6,l),l)),keyword:x(["keyword"],["keyword","storage","keyword.control","storage.type"],S),string:x(["string"],["string","string.quoted","string.template"],S),number:x(["number"],["constant.numeric"],S),function:x(["function"],["entity.name.function","support.function"],S),variable:x(["variable"],["variable.other.readwrite","variable"],S),type:x(["type"],["entity.name.type","support.type","support.class"],S),operator:x(["operator"],["keyword.operator"],S)},w=x(["class"],["entity.name.type.class","entity.name.class"],b.type),k=x(["property"],["variable.other.property","support.type.property-name"],b.variable),I={base:b,tokens:{className:w,interface:x(["interface"],["entity.name.type.interface"],b.type),enum:x(["enum"],["entity.name.type.enum"],w),method:x(["method"],["entity.name.function.method"],b.function),variableProperty:k,parameter:x(["parameter"],["variable.parameter"],b.variable),constant:x(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],b.number),boolean:x([],["constant.language.boolean","constant.language"],b.number),punctuation:x([],["punctuation","punctuation.separator"],b.operator),stringEscape:x([],["constant.character.escape"],b.string),commentDoc:x([],["comment.block.documentation","comment.documentation"],b.comment),keywordImport:x([],["keyword.control.import","keyword.import"],b.keyword),tag:x([],["entity.name.tag"],b.keyword),tagAttribute:x([],["entity.other.attribute-name"],k)},highlights:h.colors.syntax.highlights},y=Nj(n.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return mp({metadata:{id:`vscode-import-${c}`,name:y,variant:c,author:n.author,description:n.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...h.colors,syntax:I}})}const Cj=rs({namespace:Nt(),name:Nt(),version:Nt(),label:Nt(),icon:Nt().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Ij(t,e){const n=await Lt("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!n.ok)throw new Error("catalog");return rs({items:sn(Cj).max(24)}).parse(await n.json()).items}async function Pj(t,e){const n=await Lt("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!n.ok)throw new Error("catalog");const{items:a}=rs({items:sn(rs({path:Nt(),name:Nt(),text:Nt(),error:Pi()})).max(40)}).parse(await n.json());return a.map((i,o)=>{const r=`${o}:${i.path}`;try{if(i.error)throw new Error("invalid");const c=Bu(i.text,i.path);return c.metadata.name=i.name,c.metadata.author=t.namespace,{status:"ready",key:r,name:i.name,definition:c,theme:pp(c)}}catch{return{status:"invalid",key:r,name:i.name}}})}function Aj(t){const e=$e.c(3),{extension:n}=t,[a,i]=d.useState(!1);let o;return e[0]!==n.icon||e[1]!==a?(o=n.icon&&!a?s.jsx("img",{src:n.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>i(!0)}):s.jsx(J,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=n.icon,e[1]=a,e[2]=o):o=e[2],o}function Tj(t){const e=$e.c(93),{pickFile:n,fileBusy:a,onClose:i}=t,{t:o}=_e(),r=ne(Mj),{isMobile:c}=Qn(),l=r||c,{importTheme:m}=va(),[u,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 j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=new Set,e[1]=j):j=e[1];const[x,S]=d.useState(j);let b;e[2]===Symbol.for("react.memo_cache_sentinel")?(b=new Set,e[2]=b):b=e[2];const[w,k]=d.useState(b),[I,y]=d.useState(!1),[E,v]=d.useState(null),R=d.useRef(null);let C,T;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const V=new AbortController;R.current=V;const Z=Ao(()=>V.abort());return()=>{Z(),V.abort()}},T=[],e[3]=C,e[4]=T):(C=e[3],T=e[4]),d.useEffect(C,T);let P,L;e[5]!==u||e[6]!==g.step?(P=()=>{if(g.step!=="search")return;const V=new AbortController,Z=u.trim(),Y=setTimeout(async()=>{if(!Z){h({step:"search",status:"idle",results:[]});return}h({step:"search",status:"loading",results:[]});try{const Q=await Ij(Z,V.signal);V.signal.aborted||h({step:"search",status:"ready",results:Q})}catch{V.signal.aborted||h({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(Y),V.abort()}},L=[u,g.step],e[5]=u,e[6]=g.step,e[7]=P,e[8]=L):(P=e[7],L=e[8]),d.useEffect(P,L);let O,A;if(e[9]!==a||e[10]!==m||e[11]!==l||e[12]!==n||e[13]!==u||e[14]!==E||e[15]!==w||e[16]!==I||e[17]!==x||e[18]!==g.extension||e[19]!==g.results||e[20]!==g.status||e[21]!==g.step||e[22]!==g.variants||e[23]!==o){const V=async ae=>{const re=R.current?.signal;if(re){h({step:"package",status:"loading",extension:ae}),k(new Set),v(null),S(new Set);try{const ye=await Pj(ae,re);re.aborted||h({step:"variants",extension:ae,variants:ye})}catch{re.aborted||h({step:"package",status:"error",extension:ae})}}};let Z;e[26]!==m||e[27]!==w||e[28]!==I||e[29]!==x||e[30]!==g.step||e[31]!==g.variants||e[32]!==o?(Z=async()=>{if(g.step!=="variants"||I)return;const ae=R.current?.signal;if(!ae)return;y(!0),v(null);let re=!1;for(const ye of g.variants){if(ae.aborted)break;if(!(ye.status!=="ready"||!x.has(ye.key)||w.has(ye.key)))try{if(await m(ye.definition,{activate:!1}),ae.aborted)break;k(Ee=>new Set(Ee).add(ye.key)),S(Ee=>{const Pe=new Set(Ee);return Pe.delete(ye.key),Pe})}catch{re=!0}}ae.aborted||(y(!1),v(re?"partial":null),re?Va.error(o("settings.themeImport.partialError")):Va.success(o("settings.themeImport.complete")))},e[26]=m,e[27]=w,e[28]=I,e[29]=x,e[30]=g.step,e[31]=g.variants,e[32]=o,e[33]=Z):Z=e[33];const Y=Z;let Q,ue;e[34]!==w||e[35]!==x||e[36]!==g.step||e[37]!==g.variants?(Q=g.step==="variants"?g.variants.filter(ae=>ae.status==="ready"&&!w.has(ae.key)):[],ue=Q.length>0&&Q.every(ae=>x.has(ae.key)),e[34]=w,e[35]=x,e[36]=g.step,e[37]=g.variants,e[38]=Q,e[39]=ue):(Q=e[38],ue=e[39]);const ge=ue;let fe;e[40]!==a||e[41]!==Y||e[42]!==I||e[43]!==x||e[44]!==g.step||e[45]!==o?(fe=g.step==="variants"&&s.jsx(B,{disabled:!x.size||I||a,onClick:()=>{Y()},children:o(I?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=a,e[41]=Y,e[42]=I,e[43]=x,e[44]=g.step,e[45]=o,e[46]=fe):fe=e[46];const Ie=I||a;let te;e[47]!==o?(te=o("settings.themeImport.chooseFile"),e[47]=o,e[48]=te):te=e[48];let Ce;e[49]!==n||e[50]!==Ie||e[51]!==te?(Ce=s.jsx(B,{variant:"outline",className:"self-start",disabled:Ie,onClick:n,children:te}),e[49]=n,e[50]=Ie,e[51]=te,e[52]=Ce):Ce=e[52];let ie;e[53]!==fe||e[54]!==Ce?(ie=s.jsxs(s.Fragment,{children:[fe,Ce]}),e[53]=fe,e[54]=Ce,e[55]=ie):ie=e[55],O=ie,A=s.jsx(s.Fragment,{children:g.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(He,{autoFocus:!0,"aria-label":o("settings.themeImport.search"),placeholder:o("settings.themeImport.search"),value:u,maxLength:160,onChange:ae=>f(ae.target.value)}),s.jsxs("div",{className:l?"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:o("common.loading")}),g.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.catalogError")}),g.status==="ready"&&!g.results.length&&s.jsx("p",{className:"text-muted-foreground",children:o("settings.themeImport.empty")}),g.results.map(ae=>s.jsxs(B,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{V(ae)},children:[s.jsx(Aj,{extension:ae}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ae.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ae.namespace})]})]},`${ae.namespace}.${ae.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(B,{variant:"ghost",size:"sm",className:"justify-start",disabled:I||g.step==="package"&&g.status==="loading",onClick:()=>h({step:"search",status:"idle",results:[]}),children:[s.jsx(J,{name:"arrow-left",className:"size-4"}),o("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:g.extension.label}),E==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.partialError")}),g.step==="package"?g.status==="loading"?s.jsx("p",{role:"status",children:o("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[g.variants.length>1&&s.jsx(B,{variant:"ghost",size:"sm",className:"self-start",disabled:I||a||!Q.length,onClick:()=>S(ge?new Set:new Set(Q.map(Dj))),children:o(ge?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:l?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:g.variants.map(ae=>s.jsxs("div",{className:"flex items-center gap-3",children:[ae.status==="ready"&&s.jsxs("div",{"aria-hidden":"true",className:"flex w-20 shrink-0 items-center gap-2 rounded px-2 py-3",style:{backgroundColor:ae.theme.colors.surface.background,color:ae.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ae.theme.colors.syntax.base.keyword,ae.theme.colors.syntax.base.string,ae.theme.colors.syntax.base.function].map(Ej)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[w.has(ae.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(J,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ae.name})]}):s.jsx(ct,{checked:x.has(ae.key),disabled:ae.status!=="ready"||I||a,label:ae.name,onChange:re=>S(ye=>{const Ee=new Set(ye);return re?Ee.add(ae.key):Ee.delete(ae.key),Ee})}),s.jsx("p",{className:w.has(ae.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ae.status!=="ready"?o("settings.themeImport.error.invalid"):w.has(ae.key)?o("settings.themeImport.installed"):o(ae.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ae.key))})]})]})}),e[9]=a,e[10]=m,e[11]=l,e[12]=n,e[13]=u,e[14]=E,e[15]=w,e[16]=I,e[17]=x,e[18]=g.extension,e[19]=g.results,e[20]=g.status,e[21]=g.step,e[22]=g.variants,e[23]=o,e[24]=O,e[25]=A}else O=e[24],A=e[25];const N=A;if(l){let V;e[56]!==o?(V=o("settings.themeImport.catalogTitle"),e[56]=o,e[57]=V):V=e[57];let Z;e[58]!==O?(Z=s.jsx("div",{className:"flex flex-col gap-2",children:O}),e[58]=O,e[59]=Z):Z=e[59];let Y;e[60]!==o?(Y=o("settings.themeImport.catalogHint"),e[60]=o,e[61]=Y):Y=e[61];let Q;e[62]!==Y?(Q=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Y}),e[62]=Y,e[63]=Q):Q=e[63];let ue;e[64]!==N||e[65]!==Q?(ue=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[Q,N]}),e[64]=N,e[65]=Q,e[66]=ue):ue=e[66];let ge;return e[67]!==i||e[68]!==Z||e[69]!==ue||e[70]!==V?(ge=s.jsx($d,{open:!0,title:V,onClose:i,footer:Z,children:ue}),e[67]=i,e[68]=Z,e[69]=ue,e[70]=V,e[71]=ge):ge=e[71],ge}let M;e[72]!==i?(M=V=>{V||i()},e[72]=i,e[73]=M):M=e[73];let F;e[74]===Symbol.for("react.memo_cache_sentinel")?(F={forceRender:!0},e[74]=F):F=e[74];let H;e[75]!==o?(H=o("settings.themeImport.catalogTitle"),e[75]=o,e[76]=H):H=e[76];let W;e[77]!==H?(W=s.jsx(Vt,{children:H}),e[77]=H,e[78]=W):W=e[78];let G;e[79]!==o?(G=o("settings.themeImport.catalogHint"),e[79]=o,e[80]=G):G=e[80];let $;e[81]!==G?($=s.jsx(Ht,{children:G}),e[81]=G,e[82]=$):$=e[82];let z;e[83]!==W||e[84]!==$?(z=s.jsxs(Bt,{children:[W,$]}),e[83]=W,e[84]=$,e[85]=z):z=e[85];let U;e[86]!==O||e[87]!==N||e[88]!==z?(U=s.jsxs(Ut,{className:"max-w-lg",backdropProps:F,children:[z,N,O]}),e[86]=O,e[87]=N,e[88]=z,e[89]=U):U=e[89];let _;return e[90]!==U||e[91]!==M?(_=s.jsx(zt,{open:!0,onOpenChange:M,children:U}),e[90]=U,e[91]=M,e[92]=_):_=e[92],_}function Ej(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function Dj(t){return t.key}function Mj(t){return t.isMobile}function Rj(){const{t}=_e(),{importTheme:e,customThemesLoading:n}=va(),a=Za(),[i,o]=d.useState(!1),r=d.useCallback(()=>o(!1),[]),c=d.useRef(null),l=d.useRef(0),m=d.useRef(null),[u,f]=d.useState(!1);d.useEffect(()=>Ao(()=>{l.current+=1,o(!1)}),[]);const p=async(j,x)=>{f(!0);try{if(j.size>Ud)throw new ma("size");const S=await j.text();if(x.key!==Xt()||x.generation!==l.current)throw new ma("connection");const b=await e(Bu(S,j.name));Va.success(t("settings.themeImport.success",{name:b.metadata.name})),o(!1)}catch(S){const b=S instanceof ma?S.code:"invalid";Va.error(t(`settings.themeImport.error.${b}`))}finally{f(!1)}},g=async()=>{if(u)return;const j={key:Xt(),generation:l.current};if(m.current=j,!a.themeFiles){c.current?.click();return}f(!0);try{const x=await a.themeFiles.pick();if(x?.status==="picked"){if(x.file){const S=x.file;await p({name:S.name,size:S.size,text:async()=>S.text},j)}return}c.current?.click()}catch{Va.error(t("settings.themeImport.error.invalid"))}finally{f(!1)}},h=async j=>{const x=j.target.files?.[0];j.target.value="",x&&!u&&m.current&&await p(x,m.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(B,{variant:"outline",size:"sm",disabled:u||n,onClick:()=>o(!0),children:[s.jsx(J,{name:u?"loader":"add",className:u?"size-3.5 animate-spin":"size-3.5"}),t(u?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Wt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:c,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:h}),i&&s.jsx(Tj,{pickFile:()=>{g()},fileBusy:u,onClose:r})]})}const sd=(t,e,n)=>{const a=t?.querySelector("[cmdk-list]"),i=t?.querySelector(`[cmdk-item][data-value="${CSS.escape(e)}"]`);if(!a||!i)return;const o=a.getBoundingClientRect(),r=a.offsetHeight>0?o.height/a.offsetHeight:1;if(r<=0)return;const c=i.getBoundingClientRect(),l=(c.top-o.top)/r+a.scrollTop,m=c.height/r;n?.onlyIfHidden&&l>=a.scrollTop&&l+m<=a.scrollTop+a.clientHeight||(a.scrollTop=Math.max(0,l-(a.clientHeight-m)/2))};function nd({options:t,value:e,onValueChange:n,placeholder:a,ariaLabel:i}){const{t:o}=_e(),{deleteImportedTheme:r,customThemeIds:c}=va(),{isMobile:l}=Qn(),[m,u]=d.useState(!1),[f,p]=d.useState(""),[g,h]=d.useState(void 0),[j,x]=d.useState(null),S=d.useRef(null),b=d.useRef(null),[w,k]=d.useState(null),[I,y]=d.useState(null),E=d.useCallback(N=>{const M=N instanceof HTMLElement?N:null,F=M?.closest('[data-slot="dialog-content"], [role="dialog"]');k(F instanceof HTMLElement?F:null),y(M?.closest("main")??null)},[]);d.useEffect(()=>{if(m)return gp.suspend()},[m]);const v=d.useRef(e);v.current=e;const R=d.useCallback(N=>{N&&sd(N,v.current)},[]),C=t.find(N=>N.id===e),T=d.useMemo(()=>m?Wn(t,f,N=>[N.label]):t,[m,t,f]),P=N=>{n(N),u(!1)},L=async N=>{if(!j){x(N.id);try{await r(N.id),S.current?.focus()}catch{Va.error(o("settings.themeImport.deleteError"))}finally{x(null)}}},O=N=>{if(!c.includes(N.id))return null;const M=j===N.id;return s.jsx(B,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:M,"aria-label":o("settings.themeImport.delete",{name:N.label}),onPointerDown:F=>F.stopPropagation(),onClick:F=>{F.stopPropagation(),L(N)},children:s.jsx(J,{name:M?"loader":"delete-bin",className:M?"size-4 animate-spin":"size-4"})})},A=s.jsx("div",{role:"status",className:"px-3 py-6 text-center typography-ui-label text-muted-foreground",children:o("settings.openchamber.visual.field.noThemesFound")});return l?s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button","aria-label":i,"aria-haspopup":"dialog",className:je(qs,!C&&"text-muted-foreground"),onClick:()=>{p(""),u(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:C?.label??a}),s.jsx(J,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx($d,{open:m,title:i,onClose:()=>u(!1),children:s.jsxs("div",{className:"flex flex-col gap-2 px-3 pb-4 pt-1",children:[s.jsx(He,{value:f,onChange:N=>p(N.target.value),placeholder:o("settings.openchamber.visual.field.searchThemes"),"aria-label":o("settings.openchamber.visual.field.searchThemes"),className:"h-9"}),s.jsx("div",{className:"flex flex-col",role:"listbox","aria-label":i,children:T.length===0?A:T.map(N=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{type:"button",role:"option","aria-selected":N.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:()=>P(N.id),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:N.label}),N.id===e?s.jsx(J,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),O(N)]},N.id))})]})})]}):s.jsxs(Wg,{open:m,onOpenChange:N=>{p(""),h(N?e:void 0),u(N)},onOpenChangeComplete:N=>{if(!N){b.current?.focus();return}S.current?.focus(),sd(S.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs(Gg,{ref:b,"aria-label":i,"aria-haspopup":"dialog",className:je(qs,!C&&"text-muted-foreground"),onPointerDownCapture:N=>E(N.currentTarget),onFocusCapture:N=>E(N.currentTarget),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:C?.label??a}),s.jsx(J,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(Jg,{container:w??void 0,children:s.jsx(Qg,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:I??void 0,className:"z-[120]",children:s.jsx(Yg,{role:"dialog","aria-label":i,className:je(jp,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(fp,{ref:R,className:"min-h-0 flex-1",shouldFilter:!1,value:g,onValueChange:h,children:[s.jsx(hp,{ref:S,"aria-label":o("settings.openchamber.visual.field.searchThemes"),placeholder:o("settings.openchamber.visual.field.searchThemes"),value:f,onValueChange:p,onKeyDown:N=>{if(xp(N)){N.stopPropagation();return}bp(N,M=>{N.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:M,bubbles:!0,cancelable:!0}))})}}),s.jsx(vp,{label:i,className:"max-h-[20rem] p-1",children:T.length===0?A:T.map(N=>s.jsxs(yp,{value:N.id,onSelect:P,"aria-current":N.id===e?!0:void 0,className:"max-w-full typography-ui-label",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:N.label}),N.id===e?s.jsx(J,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,O(N)]},N.id))})]})})})})]})}const Lj=2e3,Oj=3,Fj=(t,e)=>t.state==="unsupported"||t.state==="failed"?!0:e?t.state==="on"&&t.index?.backfill.state!=="running":t.state==="off",Kj=t=>{const e=t/1e6;return new Intl.NumberFormat(Io(),{style:"unit",unit:"megabyte",maximumFractionDigits:e<10?1:0}).format(e)},zj=()=>{const t=$e.c(70),{t:e}=_e(),n=ne(Uj),a=ne($j),i=ne(_j),o=ne(Bj);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"loading"},t[0]=r):r=t[0];const[c,l]=d.useState(r),[m,u]=d.useState(!1),f=d.useRef(i);let p,g;t[1]!==n||t[2]!==i?(p=()=>{const W=n&&i&&!f.current;f.current=i;const G=new AbortController;let $,z=W?Oj:0;const U=()=>{wp(G.signal).then(_=>{if(G.signal.aborted)return;l({kind:"ready",status:_}),_.index?.backfill.state==="running"&&(z=0);const V=z>0;z=z-1,(!Fj(_,n)||V)&&($=setTimeout(U,Lj))}).catch(()=>{G.signal.aborted||l({kind:"error"})})};return U(),()=>{G.abort(),clearTimeout($)}},g=[n,i],t[1]=n,t[2]=i,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=()=>{u(!0),kp().then(W=>l({kind:"ready",status:W})).catch(()=>l({kind:"error"})).finally(()=>u(!1))},t[5]=h):h=t[5];const j=h,x=c.kind==="ready"?c.status:null,S=x?.state==="unsupported";let b;if(t[6]!==n||t[7]!==x?.sizeBytes||t[8]!==e||t[9]!==c.kind||t[10]!==c.status){const W=Kj(x?.sizeBytes??0);if(c.kind==="loading"){let G;t[12]!==e?(G=e("settings.openchamber.messageSearch.status.loading"),t[12]=e,t[13]=G):G=t[13],b=G}else if(c.kind==="error"){let G;t[14]!==e?(G=e("settings.openchamber.messageSearch.status.error"),t[14]=e,t[15]=G):G=t[15],b=G}else if(c.status.state==="unsupported"){let G;t[16]!==e?(G=e("settings.openchamber.messageSearch.status.unsupported"),t[16]=e,t[17]=G):G=t[17],b=G}else if(!n)b=c.status.sizeBytes>0?e("settings.openchamber.messageSearch.status.offWithFile",{size:W}):e("settings.openchamber.messageSearch.status.off");else if(c.status.state==="failed"){let G;t[18]!==e?(G=e("settings.openchamber.messageSearch.status.failed"),t[18]=e,t[19]=G):G=t[19],b=G}else if(c.status.state==="on"&&c.status.index?.backfill.state==="running")b=e("settings.openchamber.messageSearch.status.indexing",{done:c.status.index.backfill.done,total:c.status.index.backfill.total,size:W});else if(c.status.state==="on"&&c.status.index)b=e("settings.openchamber.messageSearch.status.ready",{sessions:c.status.index.sessions,messages:c.status.index.messages,size:W});else{let G;t[20]!==e?(G=e("settings.openchamber.messageSearch.status.loading"),t[20]=e,t[21]=G):G=t[21],b=G}t[6]=n,t[7]=x?.sizeBytes,t[8]=e,t[9]=c.kind,t[10]=c.status,t[11]=b}else b=t[11];let w;t[22]!==e?(w=e("settings.openchamber.messageSearch.title"),t[22]=e,t[23]=w):w=t[23];let k;t[24]!==e?(k=e("settings.openchamber.messageSearch.field.enabled"),t[24]=e,t[25]=k):k=t[25];let I;t[26]!==e?(I=e("settings.openchamber.messageSearch.field.enabled"),t[26]=e,t[27]=I):I=t[27];let y;t[28]!==e?(y=e("settings.openchamber.messageSearch.field.enabledInfo"),t[28]=e,t[29]=y):y=t[29];let E;t[30]!==n||t[31]!==a||t[32]!==k||t[33]!==I||t[34]!==y||t[35]!==S?(E=s.jsx(ct,{settingsItem:"chat.message-search-enabled",checked:n,onChange:a,disabled:S,label:k,ariaLabel:I,info:y}),t[30]=n,t[31]=a,t[32]=k,t[33]=I,t[34]=y,t[35]=S,t[36]=E):E=t[36];const v=n&&i,R=!n||S;let C;t[37]!==e?(C=e("settings.openchamber.messageSearch.field.reasoning"),t[37]=e,t[38]=C):C=t[38];let T;t[39]!==e?(T=e("settings.openchamber.messageSearch.field.reasoning"),t[39]=e,t[40]=T):T=t[40];let P;t[41]!==e?(P=e("settings.openchamber.messageSearch.field.reasoningInfo"),t[41]=e,t[42]=P):P=t[42];let L;t[43]!==o||t[44]!==R||t[45]!==C||t[46]!==T||t[47]!==P||t[48]!==v?(L=s.jsx(ct,{settingsItem:"chat.message-search-reasoning",checked:v,onChange:o,disabled:R,label:C,ariaLabel:T,info:P}),t[43]=o,t[44]=R,t[45]=C,t[46]=T,t[47]=P,t[48]=v,t[49]=L):L=t[49];let O;t[50]!==e?(O=e("settings.openchamber.messageSearch.field.index"),t[50]=e,t[51]=O):O=t[51];let A;t[52]!==n||t[53]!==x||t[54]!==e||t[55]!==m?(A=n?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:j,disabled:m||x?.state!=="on"&&x?.state!=="failed",children:e(m?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.rebuild")}):s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:j,disabled:m||!x||x.state==="on"||x.sizeBytes===0,children:e(m?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.delete")}),t[52]=n,t[53]=x,t[54]=e,t[55]=m,t[56]=A):A=t[56];let N;t[57]!==O||t[58]!==A?(N=s.jsx(yt,{label:O,children:A}),t[57]=O,t[58]=A,t[59]=N):N=t[59];let M;t[60]!==b?(M=s.jsx("p",{className:Mt,"aria-live":"polite",children:b}),t[60]=b,t[61]=M):M=t[61];let F;t[62]!==L||t[63]!==N||t[64]!==M?(F=s.jsxs(Gn,{children:[L,N,M]}),t[62]=L,t[63]=N,t[64]=M,t[65]=F):F=t[65];let H;return t[66]!==F||t[67]!==w||t[68]!==E?(H=s.jsxs(qe,{title:w,settingsItem:"chat.message-search",children:[E,F]}),t[66]=F,t[67]=w,t[68]=E,t[69]=H):H=t[69],H};function Uj(t){return t.messageSearchEnabled}function $j(t){return t.setMessageSearchEnabled}function _j(t){return t.messageSearchReasoningEnabled}function Bj(t){return t.setMessageSearchReasoningEnabled}const Vj=()=>{ne.getState().requestSettingsJump("sessions","sessions.small-model")},Hj=t=>{const e=$e.c(33),{disabled:n}=t,a=n===void 0?!1:n,{t:i}=_e(),o=ne(Wj),r=ne(Gj),c=Qt(ll),l=!zn(),m=c?o:"small-model";let u;e[0]!==i?(u=i("settings.openchamber.visual.goal.checkerLabel"),e[0]=i,e[1]=u):u=e[1];let f;e[2]!==i?(f=i("settings.openchamber.visual.goal.checkerInfo"),e[2]=i,e[3]=f):f=e[3];let p;e[4]!==i?(p=i("settings.openchamber.visual.goal.checkerLabel"),e[4]=i,e[5]=p):p=e[5];const g=a||!c;let h;e[6]!==g?(h={value:"classifier",label:"Jev",disabled:g},e[6]=g,e[7]=h):h=e[7];let j;e[8]!==i?(j=i("settings.openchamber.visual.goal.checker.smallModel"),e[8]=i,e[9]=j):j=e[9];let x;e[10]!==a||e[11]!==j?(x={value:"small-model",label:j,disabled:a},e[10]=a,e[11]=j,e[12]=x):x=e[12];let S;e[13]!==h||e[14]!==x?(S=[h,x],e[13]=h,e[14]=x,e[15]=S):S=e[15];let b;e[16]!==r||e[17]!==m||e[18]!==p||e[19]!==S?(b=s.jsx(Ws,{"aria-label":p,value:m,onChange:r,options:S}),e[16]=r,e[17]=m,e[18]=p,e[19]=S,e[20]=b):b=e[20];let w;e[21]!==b||e[22]!==u||e[23]!==f?(w=s.jsx(yt,{settingsItem:"chat.session-goal-checker",label:u,info:f,children:b}),e[21]=b,e[22]=u,e[23]=f,e[24]=w):w=e[24];let k;e[25]!==l||e[26]!==c||e[27]!==m||e[28]!==i?(k=m==="classifier"?s.jsx(Eo,{}):s.jsxs("p",{className:Mt,children:[i(c?"settings.openchamber.visual.goal.checker.viaSmallModel":"settings.openchamber.visual.goal.checker.jevMissing")," ",s.jsx(Mn,{onClick:Vj,children:i("settings.openchamber.visual.goal.checker.smallModelLink")}),c||!l?null:s.jsxs(s.Fragment,{children:[" · ",s.jsx(Mn,{onClick:ko,children:i("settings.jevAccess.setUp")})]})]}),e[25]=l,e[26]=c,e[27]=m,e[28]=i,e[29]=k):k=e[29];let I;return e[30]!==w||e[31]!==k?(I=s.jsxs("div",{className:"space-y-1",children:[w,k]}),e[30]=w,e[31]=k,e[32]=I):I=e[32],I},qj=t=>{const e=$e.c(32),{disabled:n}=t,a=n===void 0?!1:n,{t:i}=_e(),o=ne(Jj),r=ne(Qj);let c;e[0]!==i?(c=i("settings.openchamber.visual.goal.maxTurnsLabel"),e[0]=i,e[1]=c):c=e[1];let l;e[2]!==i?(l=i("settings.openchamber.visual.goal.maxTurnsInfo"),e[2]=i,e[3]=l):l=e[3];let m;e[4]!==r?(m=k=>r(Math.floor(k)),e[4]=r,e[5]=m):m=e[5];let u;e[6]!==i?(u=i("settings.openchamber.visual.goal.maxTurnsLabel"),e[6]=i,e[7]=u):u=e[7];let f;e[8]!==a||e[9]!==o||e[10]!==m||e[11]!==u?(f=s.jsx(gs,{value:o,onValueChange:m,min:1,max:dg,step:1,disabled:a,className:bs,"aria-label":u}),e[8]=a,e[9]=o,e[10]=m,e[11]=u,e[12]=f):f=e[12];let p;e[13]!==r?(p=()=>r(Hl),e[13]=r,e[14]=p):p=e[14];const g=a||o===Hl;let h;e[15]!==i?(h=i("settings.openchamber.visual.goal.maxTurnsResetAria"),e[15]=i,e[16]=h):h=e[16];let j;e[17]!==i?(j=i("settings.common.actions.reset"),e[17]=i,e[18]=j):j=e[18];let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"}),e[19]=x):x=e[19];let S;e[20]!==j||e[21]!==p||e[22]!==g||e[23]!==h?(S=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:p,disabled:g,className:ls,"aria-label":h,title:j,children:x}),e[20]=j,e[21]=p,e[22]=g,e[23]=h,e[24]=S):S=e[24];let b;e[25]!==S||e[26]!==f?(b=s.jsxs("div",{className:ca,children:[f,S]}),e[25]=S,e[26]=f,e[27]=b):b=e[27];let w;return e[28]!==b||e[29]!==c||e[30]!==l?(w=s.jsx(yt,{settingsItem:"chat.session-goal-max-turns",label:c,info:l,children:b}),e[28]=b,e[29]=c,e[30]=l,e[31]=w):w=e[31],w};function Wj(t){return t.sessionGoalChecker}function Gj(t){return t.setSessionGoalChecker}function Jj(t){return t.sessionGoalMaxAutoTurns}function Qj(t){return t.setSessionGoalMaxAutoTurns}const Yj=[{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"}],Zj=[{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"}],Xj=[{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"}],mi="OpenChamber - AI Coding Assistant",ad=[{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"}],Cr=t=>t==="portrait"||t==="landscape"?t:"system",ek=[{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"}],tk=[{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"}],od=[{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"}],sk=[{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"}],rd=[{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"}],ld=[{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"}],nk=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],ak=[{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"}],ik=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],ok=t=>t==="markdown"?"markdown":"plain",rk=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],lk=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],Mo=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:a,label:i,t:o}=_e(),r=d.useCallback(D=>o(D),[o]),{isMobile:c}=Qn(),{terminal:l}=Za(),{browserTab:m}=Lg(),u=ug(),f=ne(D=>D.showReasoningTraces),p=ne(D=>D.sessionRecapEnabled),g=ne(D=>D.sessionSuggestionEnabled),h=ne(D=>D.setSessionRecapEnabled),j=ne(D=>D.setSessionSuggestionEnabled),x=ne(D=>D.sessionGoalEnabled),S=ne(D=>D.setSessionGoalEnabled),b=ne(D=>D.sessionGoalDefaultBudgetEnabled),w=ne(D=>D.setSessionGoalDefaultBudgetEnabled),k=ne(D=>D.sessionGoalDefaultBudget),I=ne(D=>D.setSessionGoalDefaultBudget),y=ne(D=>D.setShowReasoningTraces),E=ne(D=>D.streamingAutoFollowEnabled),v=ne(D=>D.setStreamingAutoFollowEnabled),R=ne(D=>D.collapsibleThinkingBlocks),C=ne(D=>D.setCollapsibleThinkingBlocks),T=ne(D=>D.expandReasoningWhileStreaming),P=ne(D=>D.setExpandReasoningWhileStreaming),L=ql(D=>D.animatedActivityIndicators),O=ql(D=>D.setAnimatedActivityIndicators),A=ne(D=>D.mermaidRenderingMode),N=ne(D=>D.setMermaidRenderingMode),M=ne(D=>D.userMessageRenderingMode),F=ne(D=>D.setUserMessageRenderingMode),H=ne(D=>D.collapsibleUserMessages),W=ne(D=>D.setCollapsibleUserMessages),G=ne(D=>D.stickyUserHeader),$=ne(D=>D.promptNavigatorEnabled),z=ne(D=>D.setStickyUserHeader),U=ne(D=>D.setPromptNavigatorEnabled),_=ne(D=>D.autoSaveEnabled),V=ne(D=>D.setAutoSaveEnabled),Z=ne(D=>D.wideChatLayoutEnabled),Y=ne(D=>D.setWideChatLayoutEnabled),Q=ne(D=>D.codeBlockLineWrap),ue=ne(D=>D.setCodeBlockLineWrap),ge=ne(D=>D.tableCellWrap),fe=ne(D=>D.setTableCellWrap),Ie=ne(D=>D.copyMessagesAsPlainText),te=ne(D=>D.setCopyMessagesAsPlainText),Ce=ne(D=>D.chatRenderMode),ie=ne(D=>D.setChatRenderMode),ae=ne(D=>D.activityRenderMode),re=ne(D=>D.setActivityRenderMode),ye=ne(D=>D.fontSize),Ee=ne(D=>D.setFontSize),Pe=ne(D=>D.terminalFontSize),ke=ne(D=>D.setTerminalFontSize),Te=ne(D=>D.terminalShell),de=ne(D=>D.setTerminalShell),Me=ne(D=>D.terminalLoginShells),Se=ne(D=>D.setTerminalLoginShells),Le=ne(D=>D.editorFontSize),Ke=ne(D=>D.setEditorFontSize),{uiFont:oe,monoFont:le}=Sp(),xe=ne(D=>D.setUiFont),De=ne(D=>D.setMonoFont),Ve=ne(D=>D.customUiFont),Be=ne(D=>D.customMonoFont),Ne=ne(D=>D.setCustomUiFont),Je=ne(D=>D.setCustomMonoFont),ut=zn(),ht=ne(D=>D.padding),st=ne(D=>D.setPadding),jt=ne(D=>D.inputBarOffset),St=ne(D=>D.setInputBarOffset),Ze=ne(D=>D.mobileKeyboardMode),it=ne(D=>D.setMobileKeyboardMode),et=ne(D=>D.diffLayoutPreference),mt=ne(D=>D.setDiffLayoutPreference),ft=ne(D=>D.showTerminalQuickKeysOnDesktop),be=ne(D=>D.sessionTabsEnabled),Re=ne(D=>D.setSessionTabsEnabled),X=ne(D=>D.setShowTerminalQuickKeysOnDesktop),ce=ne(D=>D.fileEditorKeymap),Oe=ne(D=>D.setFileEditorKeymap),We=Wl(D=>D.followUpBehavior),nt=Wl(D=>D.setFollowUpBehavior),at=Wi(D=>D.scope),vt=Wi(D=>D.entryLimit),kt=Wi(D=>D.applyScope),xt=Wi(D=>D.applyEntryLimit),It=ne(D=>D.persistChatDraft),_t=ne(D=>D.setPersistChatDraft),Ye=ne(D=>D.inputSpellcheckEnabled),Xe=ne(D=>D.setInputSpellcheckEnabled),gt=ne(D=>D.largeTextPasteBehavior),Ue=ne(D=>D.setLargeTextPasteBehavior),ee=ne(D=>D.enterToSend),ve=ne(D=>D.setEnterToSend),Fe=ne(D=>D.enterToSendConfigured),se=ne(D=>D.setEnterToSendConfigured),Ae=Fe?ee:!c,tt=ne(D=>D.showToolFileIcons),ot=ne(D=>D.setShowToolFileIcons),At=ne(D=>D.showTurnChangedFiles),pe=ne(D=>D.setShowTurnChangedFiles),we=ne(D=>D.showExpandedBashTools),ze=ne(D=>D.setShowExpandedBashTools),pt=ne(D=>D.showExpandedEditTools),Ct=ne(D=>D.setShowExpandedEditTools),Gt=ne(D=>D.timeFormatPreference),Zt=ne(D=>D.setTimeFormatPreference),as=ne(D=>D.weekStartPreference),Jt=ne(D=>D.setWeekStartPreference),Es=ne(D=>D.showSplitAssistantMessageActions),pn=ne(D=>D.setShowSplitAssistantMessageActions),Un=ne(D=>D.allowPromptingSubagentSessions),Ro=ne(D=>D.setAllowPromptingSubagentSessions),Lo=ne(D=>D.draftStartersVisible),$n=ne(D=>D.setDraftStartersVisible),Ei=rt(D=>D.settingsMessageStreamTransport),ti=rt(D=>D.setSettingsMessageStreamTransport),ja=Ei,Di=rt(D=>D.settingsDefaultFileViewerPreview),Yn=rt(D=>D.setSettingsDefaultFileViewerPreview),Mi=ne(D=>D.isSettingsDialogOpen),{themeMode:si,setThemeMode:Ri,availableThemes:Zn,customThemesLoading:jn,reloadCustomThemes:Li,lightThemeId:Fs,darkThemeId:Oi,setLightThemePreference:Oo,setDarkThemePreference:Fo}=va(),[ni,ai]=d.useState(!1),Ko=d.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),zo=ne(D=>D.dockBadgeEnabled),Uo=ne(D=>D.setDockBadgeEnabled),$s=ne(D=>D.alwaysShowScrollbars===!0),ii=ne(D=>D.setAlwaysShowScrollbars),$o=mg(),Fi=ne(D=>D.desktopWindowControlsPosition),Ki=ne(D=>D.setDesktopWindowControlsPosition),_o=ne(D=>D.desktopWindowControlsStyle),zi=ne(D=>D.setDesktopWindowControlsStyle),[Bo,Vo]=d.useState(0),Ks=ne(D=>D.reportUsage),Xs=ne(D=>D.setReportUsage),ka=d.useCallback(D=>{Xs(D),bt({reportUsage:D})},[Xs]),kn=d.useCallback(D=>{const wt=n.find(ms=>ms===D);wt&&(a(wt),bt({locale:wt}))},[n,a]),_n=d.useCallback(D=>{Ki(D),bt({desktopWindowControlsPosition:D})},[Ki]),Al=d.useCallback(D=>{zi(D),bt({desktopWindowControlsStyle:D})},[zi]),nn=(Mi||c||os())&&(t?t.includes("chatRenderMode"):!0);d.useEffect(()=>{if(!nn)return;let D=null,wt=Date.now();const ms=()=>{const gn=Date.now();gn-wt>=420&&(Vo(ia=>(ia+1)%24),wt=gn),D=requestAnimationFrame(ms)};(typeof document>"u"||document.visibilityState==="visible")&&(D=requestAnimationFrame(ms));const Ms=()=>{document.visibilityState==="visible"&&D===null?D=requestAnimationFrame(ms):document.visibilityState!=="visible"&&D!==null&&(cancelAnimationFrame(D),D=null)};return document.addEventListener("visibilitychange",Ms),()=>{document.removeEventListener("visibilitychange",Ms),D!==null&&cancelAnimationFrame(D)}},[nn]);const Ho=d.useCallback(D=>{F(D),bt({userMessageRenderingMode:D})},[F]),wa=d.useCallback(D=>{z(D),bt({stickyUserHeader:D})},[z]),Sa=d.useCallback(D=>{U(D),bt({promptNavigatorEnabled:D})},[U]),Xn=d.useCallback(D=>{$n(D),bt({draftStartersVisible:D})},[$n]),oi=d.useCallback(D=>{W(D),bt({collapsibleUserMessages:D})},[W]),qo=d.useCallback(D=>{Y(D),bt({wideChatLayoutEnabled:D})},[Y]),ps=d.useCallback(D=>{pn(D),bt({showSplitAssistantMessageActions:D})},[pn]),Wo=d.useCallback(D=>{Xe(D),bt({inputSpellcheckEnabled:D})},[Xe]),ea=d.useCallback(D=>{ve(D),se(!0),bt({enterToSend:D,enterToSendConfigured:!0})},[ve,se]),Na=d.useCallback(D=>{ie(D),bt({chatRenderMode:D})},[ie]),Go=d.useCallback(D=>{ti(D),bt({messageStreamTransport:D})},[ti]),Ui=d.useCallback(D=>{kt(D),bt({inputHistoryScope:D})},[kt]),$i=d.useCallback(D=>{const wt=Math.round(D);pg(wt)&&(xt(wt),bt({inputHistoryLimit:wt}))},[xt]),_i=d.useCallback(D=>{re(D),bt({activityRenderMode:D})},[re]),Ca=d.useCallback(D=>{N(D),bt({mermaidRenderingMode:D})},[N]),Ia=d.useCallback(D=>{ot(D),bt({showToolFileIcons:D})},[ot]),Bi=d.useCallback(D=>{pe(D),bt({showTurnChangedFiles:D})},[pe]),Jo=d.useCallback(D=>{Yn(D),bt({defaultFileViewerPreview:D}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:D}}))},[Yn]),Pa=d.useCallback(D=>{ze(D),bt({showExpandedBashTools:D})},[ze]),Qo=d.useCallback(D=>{Ct(D),bt({showExpandedEditTools:D})},[Ct]),Aa=d.useCallback(D=>{Zt(D),bt({timeFormatPreference:D})},[Zt]),Yo=d.useCallback(D=>{Jt(D),bt({weekStartPreference:D})},[Jt]),ta=d.useMemo(()=>Zn.filter(D=>D.metadata.variant==="light").sort((D,wt)=>D.metadata.name.localeCompare(wt.metadata.name)),[Zn]),sa=d.useMemo(()=>Zn.filter(D=>D.metadata.variant==="dark").sort((D,wt)=>D.metadata.name.localeCompare(wt.metadata.name)),[Zn]),Zo=d.useMemo(()=>ta.find(D=>D.metadata.id===Fs)??ta[0],[ta,Fs]),Xo=d.useMemo(()=>sa.find(D=>D.metadata.id===Oi)??sa[0],[sa,Oi]),Ta=d.useCallback((D,wt)=>{const ms=wt==="dark"?" Dark":" Light";return D.endsWith(ms)?D.slice(0,-ms.length):D},[]),er=d.useMemo(()=>ta.map(D=>({id:D.metadata.id,label:Ta(D.metadata.name,"light")})),[ta,Ta]),na=d.useMemo(()=>sa.map(D=>({id:D.metadata.id,label:Ta(D.metadata.name,"dark")})),[sa,Ta]),he=D=>D==="enterToSend"&&c?!1:t?t.includes(D):!0,hs=os(),Ea=he("theme")&&!hs,K=he("windowControlsPosition")&&$o,me=he("theme")||he("timeFormat")||he("weekStart"),Qe=hs?me:he("theme")||K||he("pwaInstallName")||he("pwaOrientation")||he("timeFormat")||he("weekStart"),lt=he("fontSize")||he("terminalFontSize")||he("editorFontSize")||he("spacing")||he("scrollbars")&&!Ea||he("inputBarOffset")&&c,Kt=he("terminalQuickKeys")&&!c||(he("terminalShell")||he("terminalLoginShell"))&&!hs||he("fileEditorKeymap")||he("autoSaveEnabled")||he("sessionTabs")&&!hs&&!c,Ns=he("mermaidRendering")||he("sessionGoal")&&!hs||he("userMessageRendering")||he("chatRenderMode")||he("messageTransport")||he("activityRenderMode")||he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")||he("wideChatLayout")||he("codeBlockLineWrap")||he("tableCellWrap")||he("copyMessagesAsPlainText")||he("splitAssistantMessageActions")||he("subagentReadOnlyBanner")||he("diffLayout")||he("dotfiles")||he("fileViewerPreview")||he("reasoning")||he("followUpBehavior")||he("inputHistoryScope")||he("inputHistoryLimit")||he("persistDraft")||he("largeTextPaste")||he("showToolFileIcons")||he("expandedTools")||!c&&he("inputSpellcheck")||he("enterToSend"),_s=he("chatRenderMode")||he("activityRenderMode"),us=he("messageTransport"),Ds=he("userMessageRendering")||he("mermaidRendering")||he("diffLayout")&&!hs||he("followUpBehavior")||he("inputHistoryScope")||he("inputHistoryLimit"),wn=he("sessionAssist")||he("sessionGoal")&&!hs||he("subagentReadOnlyBanner")||he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")||he("wideChatLayout")||he("codeBlockLineWrap")||he("tableCellWrap")||he("copyMessagesAsPlainText")||he("splitAssistantMessageActions")||he("dotfiles")||he("fileViewerPreview")||he("persistDraft")||he("largeTextPaste")||he("showToolFileIcons")||he("showTurnChangedFiles")||!c&&he("inputSpellcheck")||he("enterToSend")||he("reasoning")||he("expandedTools"),Bs=Qe||lt||Kt,an=he("pwaInstallName")&&ba()&&m&&!cs()&&!hs,on=he("pwaOrientation")&&ba()&&!cs()&&!hs,Ot=he("mobileKeyboardMode")&&ba()&&!cs()&&!hs&&gg(),ts=(he("terminalShell")||he("terminalLoginShell"))&&!hs,[Sn,Bn]=d.useState([]),[Yt,Cs]=d.useState(0);d.useEffect(()=>Ao(()=>{Bn([]),Cs(D=>D+1)}),[]),d.useEffect(()=>{let D=!1;if(!(!ts||!l.listShells))return l.listShells().then(wt=>{D||Bn(wt)}).catch(()=>{D||Bn([])}),()=>{D=!0}},[ts,l,Yt]);const Da=d.useMemo(()=>{const D=Sn.filter(wt=>wt.id!=="auto");return Te==="auto"||D.some(wt=>wt.id===Te)?D:[{id:Te,name:Te,supportsLogin:!1},...D]},[Sn,Te]),Ma=Sn.find(D=>D.id===Te)?.supportsLogin===!0,Vi=Me.includes(Te),om=D=>{Se(D?[...Me.filter(wt=>wt!==Te),Te]:Me.filter(wt=>wt!==Te))},[tr,aa]=d.useState(""),[Hi,Ra]=d.useState("system"),rm=d.useMemo(()=>{const D=rd.find(wt=>wt.id===Gt);return r(D?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Gt,r]),lm=d.useMemo(()=>{const D=ld.find(wt=>wt.id===as);return r(D?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[as,r]),cm=d.useMemo(()=>{const D=ad.find(wt=>wt.id===Hi);return D?r(D.labelKey):void 0},[Hi,r]),dm=d.useMemo(()=>{const D=id.find(wt=>wt.id===Ze);return D?r(D.labelKey):void 0},[Ze,r]),sr=d.useCallback(async D=>{if(typeof window>"u")return;const wt=window,Ms=D.trim().replace(/\s+/g," ").slice(0,64);if(await bt({pwaAppName:Ms}),typeof wt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const gn=wt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ms);aa(gn);return}aa(Ms||mi),wt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Tl=d.useCallback(async D=>{if(typeof window>"u")return;const wt=window,ms=Cr(D);if(await bt({pwaOrientation:ms}),typeof wt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ms=wt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ms);Ra(Ms);return}Ra(ms),wt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);d.useEffect(()=>{if(typeof window>"u"||!an&&!on&&!Ot)return;let D=!1;return(async()=>{try{const ms=await yn();if(!ms){D||aa(mi);return}const gn=(ms.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),ia=Cr(ms.pwaOrientation),qi=Zl(ms.mobileKeyboardMode);D||(an&&aa(gn||mi),on&&Ra(ia),Ot&&it(qi))}catch{D||(an&&aa(mi),on&&Ra("system"),Ot&&it("native"))}})(),()=>{D=!0}},[it,Ot,an,on]);const nr=he("scrollbars")?s.jsx(ct,{checked:$s,onChange:ii,label:o("settings.openchamber.visual.field.alwaysShowScrollbars"),info:o("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Qe&&s.jsxs("div",{className:"space-y-0",children:[Ea&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Cn,{children:[s.jsx("div",{className:ws,children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.colorMode"),children:Yj.map(D=>s.jsx(is,{selected:si===D.value,onSelect:()=>Ri(D.value),label:r(D.labelKey),ariaLabel:r(D.labelKey)},D.value))})}),s.jsxs("div",{className:ws,children:[s.jsx(Rt,{label:o("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(nd,{options:er,value:Zo?.metadata.id??"",onValueChange:Oo,placeholder:o("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:o("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Rt,{label:o("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(nd,{options:na,value:Xo?.metadata.id??"",onValueChange:Fo,placeholder:o("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:o("settings.openchamber.visual.field.selectDarkThemeAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:jn||ni,onClick:()=>{const D=Date.now();ai(!0),Li().finally(()=>{const wt=Date.now()-D;if(wt<500){window.setTimeout(()=>{ai(!1)},500-wt);return}ai(!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(J,{name:"restart",className:je("h-3.5 w-3.5",ni&&"animate-spin")}),o(ni?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Wt,{children:o("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(Rj,{})]})]}),Ko&&s.jsx(Gn,{settingsItem:"appearance.dock-badge",children:s.jsx(ct,{checked:zo,onChange:Uo,label:o("settings.openchamber.visual.field.dockBadge"),info:o("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:o("settings.openchamber.visual.field.dockBadge")})}),nr&&s.jsx(Gn,{children:nr})]}),K&&s.jsx(qe,{title:o("settings.openchamber.desktopNetwork.field.windowControls"),info:o("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Ea,children:s.jsxs(Cn,{children:[s.jsx(Rt,{label:o("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ws,{value:Fi,options:rk.map(D=>({value:D.id,label:r(D.labelKey)})),onChange:_n,"aria-label":o("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Rt,{label:o("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ws,{value:_o,options:lk.map(D=>({value:D.id,label:r(D.labelKey)})),onChange:Al,"aria-label":o("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),me&&s.jsx(qe,{title:o("settings.openchamber.visual.section.localization"),children:s.jsxs(Cn,{children:[s.jsx(Rt,{label:o("settings.appearance.language.label"),info:o("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Dt,{value:e,onValueChange:kn,children:[s.jsx(Tt,{"aria-label":o("settings.appearance.language.select"),size:qt,className:Oa,children:s.jsx($t,{children:i(e)})}),s.jsx(Et,{children:n.map(D=>s.jsx(dt,{value:D,children:i(D)},D))})]})}),(he("timeFormat")||he("weekStart"))&&s.jsxs("div",{className:ws,children:[he("timeFormat")&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Dt,{value:Gt,onValueChange:D=>Aa(D),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectTimeFormatAria"),size:qt,className:Oa,children:s.jsx($t,{children:rm})}),s.jsx(Et,{children:rd.map(D=>s.jsx(dt,{value:D.id,children:r(D.labelKey)},D.id))})]})}),he("weekStart")&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Dt,{value:as,onValueChange:D=>Yo(D),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectWeekStartAria"),size:qt,className:Oa,children:s.jsx($t,{children:lm})}),s.jsx(Et,{children:ld.map(D=>s.jsx(dt,{value:D.id,children:r(D.labelKey)},D.id))})]})})]})]})}),(an||on||Ot)&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.appInstall"),contentClassName:ws,children:[an&&s.jsxs(yt,{label:o("settings.openchamber.visual.field.installAppName"),info:o("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:ks,children:[s.jsx(He,{value:tr,onChange:D=>{aa(D.target.value)},onBlur:()=>{sr(tr)},onKeyDown:D=>{D.key==="Enter"&&(D.preventDefault(),sr(tr))},className:"min-w-0 flex-1",maxLength:64,"aria-label":o("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{aa(mi),sr("")},className:ls,"aria-label":o("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]}),on&&s.jsxs(yt,{label:o("settings.openchamber.visual.field.installOrientation"),description:o("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:ks,children:[s.jsxs(Dt,{value:Hi,onValueChange:D=>{const wt=Cr(D);Ra(wt),Tl(wt)},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:qt,className:Ol,children:s.jsx($t,{placeholder:o("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:cm})}),s.jsx(Et,{children:ad.map(D=>s.jsx(dt,{value:D.id,children:r(D.labelKey)},D.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ra("system"),Tl("system")},disabled:Hi==="system",className:ls,"aria-label":o("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]}),Ot&&s.jsxs(yt,{label:o("settings.openchamber.visual.field.mobileKeyboardMode"),info:o("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:ks,children:[s.jsxs(Dt,{value:Ze,onValueChange:D=>{const wt=Zl(D);it(wt),bt({mobileKeyboardMode:wt})},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:qt,className:Ol,children:s.jsx($t,{placeholder:o("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:dm})}),s.jsx(Et,{children:id.map(D=>s.jsx(dt,{value:D.id,children:r(D.labelKey)},D.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{it("native"),bt({mobileKeyboardMode:"native"})},disabled:Ze==="native",className:ls,"aria-label":o("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),lt&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.densityAndType"),contentClassName:ws,children:[he("fontSize")&&!c||he("terminalFontSize")?s.jsxs(Cn,{children:[he("fontSize")&&!c&&s.jsxs(Rt,{label:o("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full flex-wrap",children:[s.jsxs(Dt,{value:oe,onValueChange:D=>xe(D),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectInterfaceFontAria"),size:qt,className:Oa,children:s.jsx($t,{children:oe===Ka?o("settings.openchamber.visual.field.customFont"):Gl.find(D=>D.id===oe)?.label})}),s.jsxs(Et,{children:[Gl.map(D=>s.jsx(dt,{value:D.id,disabled:ut&&!!D.source,children:s.jsx("span",{style:{fontFamily:D.stack},children:D.label})},D.id)),s.jsx(dt,{value:Ka,children:o("settings.openchamber.visual.field.customFont")})]})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(Jl),disabled:oe===Jl,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})}),oe===Ka?s.jsx(He,{value:Ve,onChange:D=>Ne(D.target.value),placeholder:o("settings.openchamber.visual.field.customFontPlaceholder"),"aria-label":o("settings.openchamber.visual.field.customFontAria"),spellCheck:!1,autoComplete:"off",className:"h-8 basis-full rounded-md px-3"}):null]}),he("terminalFontSize")&&s.jsxs(Rt,{label:o("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full flex-wrap",children:[s.jsxs(Dt,{value:le,onValueChange:D=>De(D),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectCodeFontAria"),size:qt,className:Oa,children:s.jsx($t,{children:le===Ka?o("settings.openchamber.visual.field.customFont"):Ql.find(D=>D.id===le)?.label})}),s.jsxs(Et,{children:[Ql.map(D=>s.jsx(dt,{value:D.id,disabled:ut&&!!D.source,children:s.jsx("span",{style:{fontFamily:D.stack},children:D.label})},D.id)),s.jsx(dt,{value:Ka,children:o("settings.openchamber.visual.field.customFont")})]})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>De(Yl),disabled:le===Yl,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetCodeFontAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})}),le===Ka?s.jsx(He,{value:Be,onChange:D=>Je(D.target.value),placeholder:o("settings.openchamber.visual.field.customFontPlaceholder"),"aria-label":o("settings.openchamber.visual.field.customFontAria"),spellCheck:!1,autoComplete:"off",className:"h-8 basis-full rounded-md px-3"}):null]})]}):null,ut&&(he("fontSize")&&!c||he("terminalFontSize"))?s.jsx("p",{className:Mt,children:o("settings.openchamber.visual.field.webFontsEnterprise")}):null,he("fontSize")&&!c||he("terminalFontSize")||he("editorFontSize")?s.jsxs(Cn,{children:[he("fontSize")&&!c&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:ye,onValueChange:Ee,min:50,max:200,step:5,className:bs,"aria-label":o("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ee(100),disabled:ye===100,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("terminalFontSize")&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:Pe,onValueChange:ke,min:9,max:52,step:1,className:bs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ke(13),disabled:Pe===13,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("editorFontSize")&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:Le,onValueChange:Ke,min:9,max:32,step:1,className:bs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(13),disabled:Le===13,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,he("spacing")||he("inputBarOffset")&&c?s.jsxs(Cn,{children:[he("spacing")&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:ht,onValueChange:st,min:50,max:200,step:5,className:bs}),s.jsx("span",{className:Fa,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>st(100),disabled:ht===100,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetSpacingAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("inputBarOffset")&&c&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.inputBarOffset"),info:o("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:jt,onValueChange:St,min:0,max:100,step:5,className:bs}),s.jsx("span",{className:Fa,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>St(0),disabled:jt===0,className:ls,"aria-label":o("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:o("settings.common.actions.reset"),children:s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!Ea&&nr]}),he("animatedActivityIndicators")&&s.jsx(qe,{title:o("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:xs,children:s.jsx(ct,{checked:L,onChange:O,label:o("settings.openchamber.visual.field.animatedActivityIndicators"),ariaLabel:o("settings.openchamber.visual.field.animatedActivityIndicatorsAria"),info:o("settings.openchamber.visual.field.animatedActivityIndicatorsInfo"),settingsItem:"appearance.animated-activity-indicators"})}),Kt&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[he("fileEditorKeymap")&&s.jsx(vs,{title:o("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(D=>s.jsx(is,{selected:ce===D,onSelect:()=>Oe(D),label:o(`settings.openchamber.visual.option.fileEditorKeymap.${D}`),ariaLabel:o(`settings.openchamber.visual.option.fileEditorKeymap.${D}`)},D))})}),s.jsxs("div",{className:xs,children:[he("autoSaveEnabled")&&s.jsx(ct,{checked:_,onChange:V,label:o("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:o("settings.openchamber.visual.field.autoSaveEnabledAria"),info:o("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),ts&&s.jsx(Rt,{label:o("settings.openchamber.visual.field.terminalShell"),info:o("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Dt,{value:Te,onValueChange:D=>{fg(D)&&de(D)},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.terminalShellAria"),size:qt,className:Oa,children:s.jsx($t,{})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"auto",children:o("settings.openchamber.visual.option.terminalShell.auto")}),Da.map(D=>s.jsx(dt,{value:D.id,children:D.name},D.id))]})]})}),ts&&Ma&&s.jsx(ct,{checked:Vi,onChange:om,label:o("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:o("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),he("terminalQuickKeys")&&!c&&s.jsx(ct,{checked:ft,onChange:X,label:o("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:o("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:o("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:Jn("ctrl"),alt:Jn("alt")})})]}),he("sessionTabs")&&!hs&&!c&&s.jsx(vs,{title:o("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(ct,{checked:be,onChange:Re,label:o("settings.openchamber.visual.field.sessionTabs"),ariaLabel:o("settings.openchamber.visual.field.sessionTabsAria"),info:o("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Ns&&s.jsxs(s.Fragment,{children:[_s&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.chatDisplay"),divider:Bs,contentClassName:"space-y-6",children:[he("chatRenderMode")&&s.jsx(vs,{title:o("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":o("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:tk.map(D=>{const wt=Ce===D.id,ms=Bo%12;return s.jsxs("button",{type:"button",onClick:()=>Na(D.id),"aria-pressed":wt,className:je("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",wt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:je("typography-ui-label",wt?"text-inherit":"text-muted-foreground"),children:r(D.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:D.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ms=>{const gn=Ms*3+1,ia=ms-gn+1,qi=ia<=0?0:ia===1?42:ia===2?68:92,um=qi>0;return s.jsxs("div",{className:je("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:`${qi}%`}})]},Ms)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ms=>{const gn=ms>=(Ms+1)*3;return s.jsxs("div",{className:je("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",gn?"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%"}})]},Ms)})})})]},D.id)})})}),he("activityRenderMode")&&s.jsx(vs,{title:o("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.activityDefaultAria"),children:sk.map(D=>s.jsx(is,{selected:ae===D.id,onSelect:()=>_i(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.activityDefaultModeAria",{option:r(D.labelKey)})},D.id))})})]}),us&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.messageStreamTransport"),divider:_s||Bs,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ws,{value:ja,options:od.map(D=>({value:D.id,label:r(D.labelKey)})),onChange:Go,"aria-label":o("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const D=od.find(wt=>wt.id===ja);return D?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r(D.descriptionKey)}):null})()]}),Ds&&s.jsx(qe,{title:o("settings.openchamber.visual.section.chatMessageOptions"),divider:_s||us||Bs,children:s.jsxs(Cn,{className:"lg:gap-y-6",children:[he("userMessageRendering")&&s.jsx(vs,{title:o("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.userMessageRenderingAria"),children:ek.map(D=>s.jsx(is,{selected:ok(M)===D.id,onSelect:()=>Ho(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.userMessageRenderingAria",{option:r(D.labelKey)})},D.id))})}),he("mermaidRendering")&&s.jsx(vs,{title:o("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.mermaidRenderingAria"),children:Xj.map(D=>s.jsx(is,{selected:A===D.id,onSelect:()=>Ca(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.mermaidRenderingAria",{option:r(D.labelKey)})},D.id))})}),he("diffLayout")&&!hs&&s.jsx(vs,{title:o("settings.openchamber.visual.section.diffLayout"),children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.diffLayoutAria"),children:Zj.map(D=>s.jsx(is,{selected:et===D.id,onSelect:()=>mt(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.diffLayoutAria",{option:r(D.labelKey)})},D.id))})}),he("followUpBehavior")&&s.jsx(vs,{title:o("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.followUpBehaviorAria"),children:nk.map(D=>s.jsx(is,{selected:We===D.id,onSelect:()=>nt(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.followUpBehaviorAria",{option:r(D.labelKey)})},D.id))})}),he("inputHistoryScope")&&s.jsx(vs,{title:o("settings.openchamber.visual.field.inputHistoryScope"),info:o("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.section.inputHistoryScopeAria"),children:ik.map(D=>s.jsx(is,{selected:at===D.id,onSelect:()=>Ui(D.id),label:r(D.labelKey),ariaLabel:r(D.labelKey)},D.id))})}),he("inputHistoryLimit")&&s.jsx(vs,{title:o("settings.openchamber.visual.field.inputHistoryLimit"),description:o("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:ks,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:ca,children:[s.jsx(gs,{value:vt,onValueChange:$i,min:xg,max:hg,step:1,className:bs,deferExternalValueWhileFocused:!0,"aria-label":o("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Fa,children:o("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),he("messageSearch")&&!hs&&s.jsx(zj,{}),wn&&s.jsxs(s.Fragment,{children:[he("expandedTools")&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:_s||us||Ds||Bs,contentClassName:xs,children:[s.jsx(ct,{checked:we,onChange:Pa,label:o("settings.openchamber.visual.field.bash"),ariaLabel:o("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(ct,{checked:pt,onChange:Qo,label:o("settings.openchamber.visual.field.editTools"),ariaLabel:o("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(qe,{title:o("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:xs,children:[s.jsx(ct,{checked:Lo,onChange:Xn,label:o("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:o("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),he("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(ct,{checked:p,onChange:h,label:o("settings.openchamber.visual.field.sessionRecap"),ariaLabel:o("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(ct,{checked:g,onChange:j,label:o("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:o("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),he("subagentReadOnlyBanner")&&s.jsx(ct,{checked:Un,onChange:Ro,label:o("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:o("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),he("sessionGoal")&&!hs&&s.jsxs(qe,{title:o("settings.openchamber.visual.goal.sectionTitle"),info:o("settings.openchamber.visual.goal.description"),contentClassName:xs,children:[s.jsx(ct,{checked:x,onChange:S,label:o("settings.openchamber.visual.field.sessionGoal"),ariaLabel:o("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsx(Hj,{disabled:!x}),s.jsx(qj,{disabled:!x}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(ct,{checked:b,onChange:w,disabled:!x,label:o("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:o("settings.openchamber.visual.goal.budgetAria")}),x&&b?s.jsx(gs,{value:k,onValueChange:D=>{typeof D=="number"&&Number.isFinite(D)&&D>0&&I(Math.floor(D))},min:1e3,max:1e8,step:5e4}):null]})]}),he("reasoning")&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:xs,children:[s.jsx(ct,{checked:f,onChange:y,label:o("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:o("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),f&&s.jsx(ct,{checked:R,onChange:C,label:o("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:o("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),f&&R&&s.jsx(ct,{checked:T,onChange:P,label:o("settings.openchamber.visual.field.expandReasoningWhileStreaming"),ariaLabel:o("settings.openchamber.visual.field.expandReasoningWhileStreamingAria"),info:o("settings.openchamber.visual.field.expandReasoningWhileStreamingInfo")})]}),s.jsx(qe,{title:o("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:xs,children:s.jsx(ct,{checked:E,onChange:v,label:o("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:o("settings.openchamber.visual.field.streamingAutoFollowAria"),info:o("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")||he("wideChatLayout")||he("splitAssistantMessageActions")||he("codeBlockLineWrap")||he("tableCellWrap")||he("copyMessagesAsPlainText"))&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:xs,children:[he("collapsibleUserMessages")&&s.jsx(ct,{checked:H,onChange:oi,label:o("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:o("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),he("stickyUserHeader")&&s.jsx(ct,{checked:G,onChange:wa,label:o("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:o("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),he("promptNavigatorEnabled")&&s.jsx(ct,{checked:$,onChange:Sa,label:o("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:o("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),he("wideChatLayout")&&s.jsx(ct,{checked:Z,onChange:qo,label:o("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:o("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),he("splitAssistantMessageActions")&&s.jsx(ct,{checked:Es,onChange:ps,label:o("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:o("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:o("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),he("codeBlockLineWrap")&&s.jsx(ct,{checked:Q,onChange:ue,label:o("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:o("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"}),he("tableCellWrap")&&s.jsx(ct,{checked:ge,onChange:fe,label:o("settings.openchamber.visual.field.tableCellWrap"),ariaLabel:o("settings.openchamber.visual.field.tableCellWrapAria"),info:o("settings.openchamber.visual.field.tableCellWrapInfo"),settingsItem:"chat.table-cell-wrap"}),he("copyMessagesAsPlainText")&&s.jsx(ct,{checked:Ie,onChange:te,label:o("settings.openchamber.visual.field.copyMessagesAsPlainText"),ariaLabel:o("settings.openchamber.visual.field.copyMessagesAsPlainTextAria"),info:o("settings.openchamber.visual.field.copyMessagesAsPlainTextInfo"),settingsItem:"chat.copy-plain-text"})]}),(he("showToolFileIcons")||he("showTurnChangedFiles")||he("dotfiles")&&!os()||he("fileViewerPreview"))&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:xs,children:[he("showToolFileIcons")&&s.jsx(ct,{checked:tt,onChange:Ia,label:o("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:o("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),he("showTurnChangedFiles")&&s.jsx(ct,{checked:At,onChange:Bi,label:o("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:o("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),he("dotfiles")&&!os()&&s.jsx(ct,{checked:u,onChange:bg,label:o("settings.openchamber.visual.field.showDotfiles"),ariaLabel:o("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),he("fileViewerPreview")&&s.jsx(ct,{checked:Di,onChange:Jo,label:o("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:o("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(he("persistDraft")||he("largeTextPaste")||!c&&he("inputSpellcheck")||he("enterToSend"))&&s.jsxs(qe,{title:o("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(he("persistDraft")||!c&&he("inputSpellcheck"))&&s.jsxs("div",{className:xs,children:[he("persistDraft")&&s.jsx(ct,{checked:It,onChange:_t,label:o("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:o("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!c&&he("inputSpellcheck")&&s.jsx(ct,{checked:Ye,onChange:Wo,label:o("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:o("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),he("largeTextPaste")&&s.jsx(vs,{title:o("settings.openchamber.visual.field.largeTextPaste"),info:o("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(Vs,{"aria-label":o("settings.openchamber.visual.field.largeTextPasteAria"),children:ak.map(D=>s.jsx(is,{selected:gt===D.id,onSelect:()=>Ue(D.id),label:r(D.labelKey),ariaLabel:o("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:r(D.labelKey)})},D.id))})}),he("enterToSend")&&s.jsx(vs,{title:o("settings.openchamber.visual.field.enterToSend"),info:o("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(Vs,{"aria-label":o("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(is,{selected:Ae,onSelect:()=>ea(!0),label:o("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:o("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(is,{selected:!Ae,onSelect:()=>ea(!1),label:o("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:o("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),he("reportUsage")&&s.jsx(qe,{title:o("settings.openchamber.visual.section.privacy"),children:s.jsx(ct,{checked:Ks,onChange:ka,label:o("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:o("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:o("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},ck=1,dk=365,cd=30,uk=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Vu=()=>{const t=$e.c(105),{t:e}=_e(),n=ne(mk),a=ne(pk),i=ne(gk),o=ne(fk),r=ne(hk),c=ne(xk),l=ne(bk);let m;t[0]===Symbol.for("react.memo_cache_sentinel")?(m={autoRun:!1},t[0]=m):m=t[0];const{candidates:u,isRunning:f,runCleanup:p,action:g,status:h}=Np(m),j=u.length;let x;t[1]!==p||t[2]!==e?(x=async()=>{const re=await p({force:!0}).catch(()=>(q.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!re||re.skippedReason&&re.skippedReason!=="no-candidates")){if(re.completedIds.length===0&&re.failedIds.length===0){q.message(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}re.completedIds.length>0&&q.success(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:re.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:re.completedIds.length})),re.failedIds.length>0&&q.error(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:re.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:re.failedIds.length}))}},t[1]=p,t[2]=e,t[3]=x):x=t[3];const S=x;let b;t[4]!==e?(b=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=b):b=t[5];const w=i?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let k;t[6]!==e||t[7]!==w?(k=e(w),t[6]=e,t[7]=w,t[8]=k):k=t[8];let I;t[9]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=I):I=t[10];let y;t[11]!==e?(y=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=y):y=t[12];let E;t[13]!==n||t[14]!==o||t[15]!==I||t[16]!==y?(E=s.jsx(ct,{settingsItem:"sessions.auto-cleanup",checked:n,onChange:o,label:I,ariaLabel:y}),t[13]=n,t[14]=o,t[15]=I,t[16]=y,t[17]=E):E=t[17];let v;t[18]!==e?(v=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=v):v=t[19];let R;t[20]!==e?(R=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=R):R=t[21];let C;t[22]!==e?(C=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=C):C=t[23];let T;t[24]!==f||t[25]!==i||t[26]!==l||t[27]!==C||t[28]!==v||t[29]!==R?(T=s.jsx(ct,{settingsItem:"sessions.retention-only-archived",checked:i,onChange:l,disabled:f,label:v,ariaLabel:R,info:C}),t[24]=f,t[25]=i,t[26]=l,t[27]=C,t[28]=v,t[29]=R,t[30]=T):T=t[30];let P;t[31]!==e?(P=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=P):P=t[32];let L;t[33]!==e?(L=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=L):L=t[34];let O;t[35]===Symbol.for("react.memo_cache_sentinel")?(O=je(bs,"tabular-nums"),t[35]=O):O=t[35];let A;t[36]!==a||t[37]!==r||t[38]!==L?(A=s.jsx(gs,{value:a,onValueChange:r,min:ck,max:dk,step:1,"aria-label":L,className:O}),t[36]=a,t[37]=r,t[38]=L,t[39]=A):A=t[39];let N;t[40]!==e?(N=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=N):N=t[41];let M;t[42]!==N?(M=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:N}),t[42]=N,t[43]=M):M=t[43];let F;t[44]!==r?(F=()=>r(cd),t[44]=r,t[45]=F):F=t[45];const H=a===cd;let W;t[46]!==e?(W=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=W):W=t[47];let G;t[48]!==e?(G=e("settings.common.actions.reset"),t[48]=e,t[49]=G):G=t[49];let $;t[50]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(J,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=$):$=t[50];let z;t[51]!==F||t[52]!==H||t[53]!==W||t[54]!==G?(z=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:F,disabled:H,className:ls,"aria-label":W,title:G,children:$}),t[51]=F,t[52]=H,t[53]=W,t[54]=G,t[55]=z):z=t[55];let U;t[56]!==P||t[57]!==A||t[58]!==M||t[59]!==z?(U=s.jsxs(yt,{settingsItem:"sessions.retention-period",label:P,children:[A,M,z]}),t[56]=P,t[57]=A,t[58]=M,t[59]=z,t[60]=U):U=t[60];let _;t[61]!==e?(_=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=_):_=t[62];let V;t[63]!==i||t[64]!==e?(V=uk.map(re=>({value:re.value,label:e(re.labelKey),disabled:i&&re.value==="archive"})),t[63]=i,t[64]=e,t[65]=V):V=t[65];let Z;t[66]!==g||t[67]!==c||t[68]!==V?(Z=s.jsx(Ws,{value:g,onChange:c,options:V}),t[66]=g,t[67]=c,t[68]=V,t[69]=Z):Z=t[69];let Y;t[70]!==_||t[71]!==Z?(Y=s.jsx(yt,{settingsItem:"sessions.retention-action",label:_,children:Z}),t[70]=_,t[71]=Z,t[72]=Y):Y=t[72];let Q;t[73]!==T||t[74]!==U||t[75]!==Y?(Q=s.jsxs(Gn,{className:"space-y-0",children:[T,U,Y]}),t[73]=T,t[74]=U,t[75]=Y,t[76]=Q):Q=t[76];let ue;t[77]!==e?(ue=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=ue):ue=t[78];let ge;t[79]!==f||t[80]!==e?(ge=e(f?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=f,t[80]=e,t[81]=ge):ge=t[81];let fe;t[82]!==S||t[83]!==f||t[84]!==ge?(fe=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:S,disabled:f,className:"!font-normal",children:ge}),t[82]=S,t[83]=f,t[84]=ge,t[85]=fe):fe=t[85];let Ie;t[86]!==ue||t[87]!==fe?(Ie=s.jsx(yt,{label:ue,children:fe}),t[86]=ue,t[87]=fe,t[88]=Ie):Ie=t[88];let te;t[89]!==g||t[90]!==j||t[91]!==h||t[92]!==e?(te=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:j}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:j}),t[89]=g,t[90]=j,t[91]=h,t[92]=e,t[93]=te):te=t[93];let Ce;t[94]!==te?(Ce=s.jsx("p",{className:"typography-meta text-muted-foreground",children:te}),t[94]=te,t[95]=Ce):Ce=t[95];let ie;t[96]!==Ie||t[97]!==Ce?(ie=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[Ie,Ce]}),t[96]=Ie,t[97]=Ce,t[98]=ie):ie=t[98];let ae;return t[99]!==b||t[100]!==Q||t[101]!==ie||t[102]!==k||t[103]!==E?(ae=s.jsxs(qe,{title:b,info:k,children:[E,Q,ie]}),t[99]=b,t[100]=Q,t[101]=ie,t[102]=k,t[103]=E,t[104]=ae):ae=t[104],ae};function mk(t){return t.autoDeleteEnabled}function pk(t){return t.autoDeleteAfterDays}function gk(t){return t.sessionRetentionOnlyArchived}function fk(t){return t.setAutoDeleteEnabled}function hk(t){return t.setAutoDeleteAfterDays}function xk(t){return t.setSessionRetentionAction}function bk(t){return t.setSessionRetentionOnlyArchived}const Hu=()=>{const t=$e.c(17),{t:e}=_e(),n=ne(vk),a=ne(yk);let i;t[0]!==e?(i=e("settings.openchamber.mergedWorktreeCleanup.title"),t[0]=e,t[1]=i):i=t[1];let o;t[2]!==e?(o=e("settings.openchamber.mergedWorktreeCleanup.info"),t[2]=e,t[3]=o):o=t[3];let r;t[4]!==e?(r=e("settings.openchamber.mergedWorktreeCleanup.field.enable"),t[4]=e,t[5]=r):r=t[5];let c;t[6]!==e?(c=e("settings.openchamber.mergedWorktreeCleanup.field.enableDescription"),t[6]=e,t[7]=c):c=t[7];let l;t[8]!==n||t[9]!==a||t[10]!==r||t[11]!==c?(l=s.jsx(ct,{settingsItem:"sessions.merged-worktree-cleanup",checked:n,onChange:a,label:r,description:c}),t[8]=n,t[9]=a,t[10]=r,t[11]=c,t[12]=l):l=t[12];let m;return t[13]!==i||t[14]!==o||t[15]!==l?(m=s.jsx(qe,{settingsItem:"sessions.merged-worktree-cleanup-section",title:i,info:o,children:l}),t[13]=i,t[14]=o,t[15]=l,t[16]=m):m=t[16],m};function vk(t){return t.mergedWorktreeCleanupEnabled}function yk(t){return t.setMergedWorktreeCleanupEnabled}const qu=()=>{const t=$e.c(25),{t:e}=_e();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=os(),t[0]=n):n=t[0];const a=n,i=ne(jk),o=ne(kk),r=ne(wk),c=ne(Sk),l=Qt(ll);let m;t[1]!==e?(m=e("settings.openchamber.sessionWork.title"),t[1]=e,t[2]=m):m=t[2];let u;t[3]!==e?(u=e("settings.openchamber.sessionWork.info"),t[3]=e,t[4]=u):u=t[4];let f;t[5]!==e?(f=e("settings.openchamber.sessionWork.field.enabled"),t[5]=e,t[6]=f):f=t[6];let p;t[7]!==e?(p=e("settings.openchamber.sessionWork.field.enabled"),t[7]=e,t[8]=p):p=t[8];let g;t[9]!==i||t[10]!==r||t[11]!==f||t[12]!==p?(g=s.jsx(ct,{settingsItem:"sessions.work-enabled",checked:i,onChange:r,label:f,ariaLabel:p}),t[9]=i,t[10]=r,t[11]=f,t[12]=p,t[13]=g):g=t[13];let h;t[14]!==o||t[15]!==i||t[16]!==l||t[17]!==c||t[18]!==e?(h=a?null:s.jsxs(Gn,{className:"space-y-0",children:[s.jsx(ct,{settingsItem:"sessions.work-auto-open",checked:i&&l&&o,onChange:c,disabled:!i||!l,label:e("settings.openchamber.sessionWork.field.autoOpen"),ariaLabel:e("settings.openchamber.sessionWork.field.autoOpen"),info:e("settings.openchamber.sessionWork.field.autoOpenInfo")}),s.jsx(Eo,{})]}),t[14]=o,t[15]=i,t[16]=l,t[17]=c,t[18]=e,t[19]=h):h=t[19];let j;return t[20]!==m||t[21]!==u||t[22]!==g||t[23]!==h?(j=s.jsxs(qe,{title:m,info:u,settingsItem:"sessions.work",children:[g,h]}),t[20]=m,t[21]=u,t[22]=g,t[23]=h,t[24]=j):j=t[24],j};function jk(t){return t.sessionWorkEnabled}function kk(t){return t.sessionWorkAutoOpen}function wk(t){return t.setSessionWorkEnabled}function Sk(t){return t.setSessionWorkAutoOpen}const dd=(t,e,n)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Io(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(t),Wu=()=>{const{t}=_e(),e=ne(E=>E.timeFormatPreference),[n,a]=d.useState(!1),[i,o]=d.useState(!0),[r,c]=d.useState(!1),[l,m]=d.useState(null),[u,f]=d.useState(!1),[p,g]=d.useState([]),[h,j]=d.useState(Cp),[x,S]=d.useState(""),b=d.useMemo(()=>Ip(),[]),w=d.useCallback(async()=>{o(!0),S("");try{const E=await Pp();g(E)}catch(E){const v=E instanceof Error?E.message:t("settings.openchamber.passkeys.toast.loadFailed");S(v)}finally{o(!1)}},[t]);d.useEffect(()=>{let E=!1;return(async()=>{try{if(!b.supported){E||(a(!1),o(!1));return}E||a(!0)}catch{E||a(!1)}if(!E){const v=await rr();if(j(v),!v.enabled){g([]),o(!1);return}await w()}})(),()=>{E=!0,Fl()}},[w,b.supported]);const k=d.useCallback(async()=>{if(!h.enabled){const E=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");S(E),q.message(E);return}if(!n){S(b.reason),q.message(b.reason);return}if(r){Fl(),c(!1);return}S(""),c(!0);try{await Ap(),j(await rr()),await w(),q.success(t("settings.openchamber.passkeys.toast.added"))}catch(E){if(Tp(E)){q.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const v=E instanceof Error?E.message:t("settings.openchamber.passkeys.toast.addFailed");S(v),q.error(v)}finally{c(!1)}},[r,w,h.enabled,b.reason,n,t]),I=d.useCallback(async E=>{m(E),S("");try{await Ep(E),j(await rr()),await w(),q.success(t("settings.openchamber.passkeys.toast.removed"))}catch(v){const R=v instanceof Error?v.message:t("settings.openchamber.passkeys.toast.removeFailed");S(R),q.error(R)}finally{m(null)}},[w,t]),y=d.useCallback(async()=>{f(!0),S("");try{await Dp(),window.location.reload()}catch(E){const v=E instanceof Error?E.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");S(v),q.error(v),f(!1)}},[t]);return s.jsxs(qe,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(yt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:r?"secondary":"outline",size:"xs",onClick:()=>{k()},disabled:i||u,className:"!font-normal",children:t(r?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{y()},disabled:i||r||u,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(u?"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&&!n&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:b.reason}),i?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(E=>s.jsxs(yt,{label:s.jsx("span",{title:E.label,children:E.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:E.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:dd(E.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:dd(E.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(E.id)},disabled:l===E.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:l===E.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},E.id))})]}),x&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:x})})]})},Gu=()=>{const t=$e.c(14),{t:e}=_e(),n=Kl(Nk),a=Kl(Ck);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let o;t[2]!==e?(o=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=o):o=t[3];let r;t[4]!==a||t[5]!==e||t[6]!==n?(r=n.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):n.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(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>a(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]=a,t[5]=e,t[6]=n,t[7]=r):r=t[7];let c;t[8]!==r?(c=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:r}),t[8]=r,t[9]=c):c=t[9];let l;return t[10]!==i||t[11]!==o||t[12]!==c?(l=s.jsx(qe,{title:i,description:o,children:c}),t[10]=i,t[11]=o,t[12]=c,t[13]=l):l=t[13],l};function Nk(t){return t.trustedSchemes}function Ck(t){return t.removeTrustedScheme}const Ik=()=>{const{t}=_e(),[e,n]=d.useState(null),a=d.useRef(0);d.useEffect(()=>{let o=!1;return Ps.getConfig(null).then(r=>{!o&&a.current===0&&n(!!r.warming)},r=>console.warn("[session-warming] failed to read config",r)),()=>{o=!0}},[]);const i=d.useCallback(async o=>{const r=e,c=++a.current;n(o),ss("saving");try{const l=await Lt("/api/config/warming",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({enabled:o})});if(!l.ok)throw new Error(`HTTP ${l.status}`);ss("saved"),Ps.clearConfigCache()}catch(l){console.warn("[session-warming] failed to save",l),ss("error"),c===a.current&&n(r)}},[e]);return s.jsx(ct,{settingsItem:"sessions.warming",checked:e??!1,disabled:e===null,onChange:o=>{i(o)},label:t("settings.openchamber.defaults.field.sessionWarming"),info:t("settings.openchamber.defaults.field.sessionWarmingInfo")})},Pk={ask:{icon:"shield-user",color:void 0},safety:{icon:"shield-star",color:"var(--status-success)"},auto:{icon:"shield-check",color:"var(--status-info)"}},Ak=t=>{const e=$e.c(42),{agentName:n}=t,{t:a}=_e(),i=ne(Tk),o=ne(Ek),r=Qt(ll),c=To(Qt(Dk));let l;e[0]!==i||e[1]!==r?(l=Mp(i,r),e[0]=i,e[1]=r,e[2]=l):l=e[2];const m=l;let u;e[3]!==o?(u=T=>{o(T),bt({permissionDefaultMode:T})},e[3]=o,e[4]=u):u=e[4];const f=u;let p;e[5]!==n?(p=()=>{const T=n??rt.getState().currentAgentName;T&&Rn.getState().setSelectedAgent(T),ne.getState().requestSettingsJump("agents","agents.permissions")},e[5]=n,e[6]=p):p=e[6];const g=p;let h;e[7]!==g||e[8]!==c||e[9]!==r||e[10]!==a?(h=T=>T==="safety"&&!r?s.jsxs(s.Fragment,{children:[a("settings.sessions.permissions.explain.safetyUnavailable")," ",s.jsx(Mn,{onClick:ko,children:a("settings.jevAccess.setUp")})]}):T==="safety"?s.jsxs(s.Fragment,{children:[c?a("settings.sessions.permissions.explain.safetyVia",{provider:c}):a("settings.sessions.permissions.explain.safety")," ",s.jsx(Mn,{onClick:ko,children:a("settings.jevAccess.manage")})]}):s.jsxs(s.Fragment,{children:[a(T==="auto"?"settings.sessions.permissions.explain.auto":"settings.sessions.permissions.explain.ask")," ",s.jsx(Mn,{onClick:g,children:a("settings.sessions.permissions.agentPermissionsLink")})]}),e[7]=g,e[8]=c,e[9]=r,e[10]=a,e[11]=h):h=e[11];const j=h;let x;e[12]!==j||e[13]!==r?(x=(T,P)=>{const{icon:L,color:O}=Pk[T];return{value:T,label:s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(J,{name:L,className:"size-3.5",style:O?{color:O}:void 0}),P]}),tooltip:j(T),disabled:T==="safety"&&!r}},e[12]=j,e[13]=r,e[14]=x):x=e[14];const S=x;let b;e[15]!==a?(b=a("settings.sessions.permissions.defaultMode"),e[15]=a,e[16]=b):b=e[16];let w;e[17]!==a?(w=a("settings.sessions.permissions.defaultModeInfo"),e[17]=a,e[18]=w):w=e[18];let k;e[19]!==a?(k=a("settings.sessions.permissions.defaultMode"),e[19]=a,e[20]=k):k=e[20];let I;e[21]!==S||e[22]!==a?(I=[S("ask",a("settings.sessions.permissions.mode.ask")),S("safety",a("settings.sessions.permissions.mode.safety")),S("auto",a("settings.sessions.permissions.mode.auto"))],e[21]=S,e[22]=a,e[23]=I):I=e[23];let y;e[24]!==f||e[25]!==m||e[26]!==k||e[27]!==I?(y=s.jsx(Ws,{"aria-label":k,value:m,onChange:f,options:I}),e[24]=f,e[25]=m,e[26]=k,e[27]=I,e[28]=y):y=e[28];let E;e[29]!==y||e[30]!==b||e[31]!==w?(E=s.jsx(yt,{settingsItem:"sessions.permission-default",label:b,info:w,children:y}),e[29]=y,e[30]=b,e[31]=w,e[32]=E):E=e[32];let v;e[33]!==j||e[34]!==m?(v=s.jsx("p",{className:Mt,children:j(m)}),e[33]=j,e[34]=m,e[35]=v):v=e[35];let R;e[36]!==r?(R=r?null:s.jsx(Eo,{}),e[36]=r,e[37]=R):R=e[37];let C;return e[38]!==E||e[39]!==v||e[40]!==R?(C=s.jsxs("div",{className:"space-y-1",children:[E,v,R]}),e[38]=E,e[39]=v,e[40]=R,e[41]=C):C=e[41],C};function Tk(t){return t.permissionDefaultMode}function Ek(t){return t.setPermissionDefaultMode}function Dk(t){return t.classifier?.effective??null}const Ir=t=>{const e=En(t);return e||{providerId:"",modelId:""}},Ju=()=>{const{t}=_e(),e=rt(ie=>ie.setProvider),n=rt(ie=>ie.setModel),a=rt(ie=>ie.setAgent),i=rt(ie=>ie.setCurrentVariant),o=rt(ie=>ie.setCurrentVariantOverride),r=rt(ie=>ie.setSettingsDefaultModel),c=rt(ie=>ie.setSettingsDefaultVariant),l=rt(ie=>ie.setSettingsDefaultAgent),m=rt(ie=>ie.selectionSource==="manual"),u=Rp(ie=>ie.currentSessionId),f=zl(ie=>ie.getSessionModelSelection),p=zl(ie=>ie.getSessionAgentSelection),g=rt(ie=>ie.agentSelectionSource==="manual"),j=!!(rt(ie=>{if(ie.agentSelectionSource!=="manual")return!1;const ae=ie.agents.find(re=>re.name===ie.currentAgentName);return!!(ae?.model?.providerID&&ae.model.id)})||m&&u&&f(u)),x=!!(g&&u&&p(u)),S=d.useMemo(()=>os(),[]),b=ne(ie=>ie.showDeletionDialog),w=ne(ie=>ie.setShowDeletionDialog),k=rt(ie=>ie.providers),I=rt(ie=>ie.modelsMetadata),[y,E]=d.useState(),[v,R]=d.useState(),[C,T]=d.useState(),[P,L]=d.useState(!0),[O,A]=d.useState(),[N,M]=d.useState([]),[F,H]=d.useState(),[W,G]=d.useState(!0),$=d.useMemo(()=>Ir(y),[y]);d.useEffect(()=>{(async()=>{try{const ae=await yn();if(ae){const re=ae.defaultModel?.trim()||void 0,ye=ae.defaultVariant?.trim()||void 0,Ee=ae.defaultAgent?.trim()||void 0;re!==void 0&&E(re),ye!==void 0&&R(ye),Ee!==void 0&&T(Ee),ae.smallModelUseDefault!==void 0&&L(ae.smallModelUseDefault);const Pe=ae.smallModelOverride?.trim();Pe&&A(Pe);const ke=ae.walkthroughModelOverride?.trim();ke&&H(ke)}}catch(ae){console.warn("Failed to load defaults settings:",ae)}finally{G(!1)}})()},[]);const z=d.useCallback(async(ie,ae)=>{const re=ie&&ae?`${ie}/${ae}`:void 0;E(re),R(void 0),c(void 0),r(re),j||(i(void 0),ie&&ae&&(k.find(Ee=>Ee.id===ie)||Yd(ie,ae))&&(e(ie),n(ae)));try{await bt({defaultModel:re??"",defaultVariant:""})}catch(ye){console.warn("Failed to save default model:",ye)}},[j,k,i,n,e,r,c]),U="__default__",_=d.useCallback(ie=>ie===U?t("settings.openchamber.defaults.option.default"):ie.charAt(0).toUpperCase()+ie.slice(1),[t]),V=d.useCallback(async ie=>{const ae=ie===U?void 0:ie||void 0;R(ae),c(ae),j||o(ae??null,ae);try{await bt({defaultVariant:ae??""})}catch(re){console.warn("Failed to save default variant:",re)}},[j,o,c]),Z=d.useCallback(async ie=>{const ae=ie||void 0;T(ae),l(ae),ie&&!x&&a(ie);try{await bt({defaultAgent:ae??""})}catch(re){console.warn("Failed to save default agent:",re)}},[x,a,l]),Y=d.useCallback(async ie=>{L(ie);try{await bt({smallModelUseDefault:ie})}catch(ae){console.warn("Failed to save small model preference:",ae)}},[]),Q=d.useCallback(async(ie,ae)=>{const re=ie&&ae?`${ie}/${ae}`:void 0;A(re);try{await bt({smallModelOverride:re??""})}catch(ye){console.warn("Failed to save small model override:",ye)}},[]),ue=d.useCallback(async(ie,ae)=>{const re=ie&&ae?`${ie}/${ae}`:void 0;H(re);try{await bt({walkthroughModelOverride:re??""})}catch(ye){console.warn("Failed to save walkthrough model override:",ye)}},[]),ge=d.useCallback((ie,ae)=>I.get(`${ie}/${ae}`)?.structured_output!==!1,[I]),fe=d.useMemo(()=>Ir(O),[O]),Ie=d.useMemo(()=>Ir(F),[F]);d.useEffect(()=>{let ie=!1;return(async()=>{try{const ae=await Lt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ae.ok)return;const re=await ae.json().catch(()=>null);!ie&&Array.isArray(re?.authenticatedProviders)&&M(re.authenticatedProviders.filter(ye=>typeof ye=="string"))}catch{}})(),()=>{ie=!0}},[]);const te=d.useMemo(()=>{if(!$.providerId||!$.modelId)return[];const ae=k.find(re=>re.id===$.providerId)?.models.find(re=>re.id===$.modelId);return Lp(ae?.variants)},[$.modelId,$.providerId,k]),Ce=te.length>0;return W?null:s.jsx(s.Fragment,{children:s.jsx(qe,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-4 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",$.providerId?s.jsxs("span",{className:"text-foreground",children:[$.providerId,"/",$.modelId,Ce?` (${v??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),C&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:C})]})]}),s.jsxs("div",{className:ws,children:[s.jsx(yt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(fa,{providerId:$.providerId,modelId:$.modelId,onChange:z,className:qs,offerAuto:!0})}),s.jsx(yt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Dt,{value:v??U,onValueChange:V,disabled:!Ce,children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:_(v??U)})}),s.jsxs(Et,{children:[s.jsx(dt,{value:U,children:t("settings.openchamber.defaults.option.default")}),te.map(ie=>s.jsx(dt,{value:ie,children:_(ie)},ie))]})]})}),s.jsx(yt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(sl,{agentName:C||"",onChange:Z,filter:ie=>Kd(ie.mode),className:qs})}),S?null:s.jsx(Ak,{agentName:C})]}),s.jsxs(Gn,{className:xs,children:[s.jsx(ct,{settingsItem:"sessions.deletion-dialog",checked:b,onChange:w,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx(Ik,{})]}),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(Wt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(ct,{settingsItem:"sessions.small-model",checked:P,onChange:ie=>{Y(ie)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),P?null:s.jsx(yt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(fa,{providerId:fe.providerId,modelId:fe.modelId,onChange:Q,allowedProviderIds:N,className:qs})}),s.jsxs(Gn,{className:xs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ln,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Wt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(yt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(fa,{providerId:Ie.providerId,modelId:Ie.modelId,onChange:ue,allowedProviderIds:N,isModelAllowed:ge,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:qs})})]})]})]})})})},ud={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"}},Mk={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"},Rk=()=>{const{t}=_e(),e=d.useMemo(()=>cs(),[]),n=d.useMemo(()=>os(),[]),a=d.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!n&&!a,o=ne(z=>z.nativeNotificationsEnabled),r=ne(z=>z.setNativeNotificationsEnabled),c=ne(z=>z.notificationMode),l=ne(z=>z.setNotificationMode),m=ne(z=>z.notifyOnSubtasks),u=ne(z=>z.setNotifyOnSubtasks),f=ne(z=>z.notifyOnCompletion),p=ne(z=>z.setNotifyOnCompletion),g=ne(z=>z.notifyOnError),h=ne(z=>z.setNotifyOnError),j=ne(z=>z.notifyOnQuestion),x=ne(z=>z.setNotifyOnQuestion),S=ne(z=>z.notificationTemplates),b=ne(z=>z.setNotificationTemplates),[w,k]=d.useState("default"),[I,y]=d.useState(!1),[E,v]=d.useState(!1),[R,C]=d.useState(!1);d.useEffect(()=>{if(!i){y(!1),v(!1);return}typeof Notification<"u"&&k(Notification.permission);const z=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;y(z),(async()=>{if(!z){v(!1);return}try{const _=await navigator.serviceWorker.getRegistration();if(!_){v(!1);return}const V=await _.pushManager.getSubscription();v(!!V)}catch{v(!1)}})()},[i]);const T=async z=>{if(e){r(z);return}if(!i){r(z);return}if(z&&typeof Notification<"u"&&Notification.permission==="default")try{const U=await Notification.requestPermission();k(U),U==="granted"?r(!0):q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(U){console.error("Failed to request notification permission:",U),q.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else r(!!(z&&w==="granted"))},P=e||n||a||i&&typeof Notification<"u"&&Notification.permission==="granted",L=(z,U,_)=>{b(V=>({...V,[z]:{...V[z],[U]:_}}))},O=z=>{const U="=".repeat((4-z.length%4)%4),_=(z+U).replace(/-/g,"+").replace(/_/g,"/"),V=atob(_),Z=new Uint8Array(V.length);for(let Y=0;Y<V.length;Y+=1)Z[Y]=V.charCodeAt(Y);return Z},A=async(z,U,_)=>{let V=null;const Z=new Promise((Y,Q)=>{V=setTimeout(()=>{Q(new Error(_))},U)});try{return await Promise.race([z,Z])}finally{V&&clearTimeout(V)}},N=async z=>{if(z.active)return;const U=z.installing||z.waiting;U&&U.state!=="activated"&&await A(new Promise(_=>{const V=()=>{U.state==="activated"&&(U.removeEventListener("statechange",V),_())};U.addEventListener("statechange",V),V()}),15e3,"Service worker activation timed out")},M=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const z=[{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 U=null;for(const _ of z)try{const V=_.opts?navigator.serviceWorker.register("/sw.js",_.opts):navigator.serviceWorker.register("/sw.js");return await A(V,1e4,`Service worker registration timed out (${_.label})`)}catch(V){U=V}throw U instanceof Error?U:new Error("Service worker registration failed")},F=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const z=await navigator.serviceWorker.getRegistration();if(z)return z;const U=await M();try{await U.update()}catch{}return await N(U),U},H=z=>{const U=z,_=[`type=${typeof z}`,`toString=${String(z)}`,`name=${String(U?.name??"")}`,`message=${String(U?.message??"")}`];let V="";try{V=JSON.stringify(z)}catch{}return{summary:_.filter(Boolean).join(" | "),json:V,stack:typeof U?.stack=="string"?U.stack:""}},W=async()=>{const z=xa();if(!z?.notifications){q.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await z.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?q.success(t("settings.notifications.page.toast.testNotificationSent")):q.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(U){console.error("Test notification failed:",U),q.error(t("settings.notifications.page.toast.testNotificationFailed"))}},G=async()=>{if(!I){q.error(t("settings.notifications.page.toast.pushUnsupported"));return}const z=xa();if(!z?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ge=await Notification.requestPermission();if(k(ge),ge!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const U=await z.push.getVapidPublicKey();if(!U?.publicKey){q.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const _=await F();await N(_);const V=await _.pushManager.getSubscription();if(!("pushManager"in _)||!_.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(V??await A(_.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:O(U.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Q=Y.keys;if(!Y.endpoint||!Q?.p256dh||!Q.auth)throw new Error("Push subscription missing keys");if(!(await A(z.push.subscribe({endpoint:Y.endpoint,keys:{p256dh:Q.p256dh,auth:Q.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:vg()}),15e3,"Push subscribe request timed out"))?.ok){q.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}v(!0),q.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(U){console.error("[Push] Enable failed:",U);const _=H(U);q.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:_.summary})}finally{C(!1)}},$=async()=>{if(!I){v(!1);return}const z=xa();if(!z?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{const _=await(await F()).pushManager.getSubscription();if(!_){v(!1);return}const V=_.endpoint;await _.unsubscribe(),await z.push.unsubscribe({endpoint:V}),v(!1),q.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{C(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(qe,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:xs,children:[s.jsx(ct,{checked:o&&P,onChange:z=>{T(z)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):n?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),o&&P&&!a&&s.jsxs(s.Fragment,{children:[s.jsx(ct,{checked:c==="always",onChange:z=>l(z?"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(B,{type:"button",variant:"outline",size:"sm",onClick:()=>{W()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[w==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),w==="granted"&&!o&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),o&&P&&s.jsxs(s.Fragment,{children:[s.jsx(qe,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:xs,children:[s.jsx(ct,{checked:f,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(ct,{checked:m,onChange:u,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(ct,{checked:g,onChange:h,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(ct,{checked:j,onChange:x,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!a&&s.jsx(qe,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{last_message}"})]}),children:s.jsx(Cn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(z=>s.jsxs("section",{className:"p-2",children:[s.jsx(Ln,{className:"capitalize",children:t(Mk[z])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:S[z].title,onChange:U=>L(z,"title",U.target.value),className:"h-7",placeholder:t(ud[z].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:S[z].message,onChange:U=>L(z,"message",U.target.value),className:"h-7",placeholder:t(ud[z].messageKey)})]})]})]},z))})})]}),i&&s.jsx(qe,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(ct,{checked:I?E:!1,disabled:!I||R,onChange:z=>{z?G():$()},label:t("settings.notifications.page.push.enableLabel"),description:I?void 0:t("settings.notifications.page.push.unsupportedHint"),info:I?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:R?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Rs=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},qn="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",Lk=[{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"}],md=t=>{const e=$e.c(8),{value:n,label:a}=t,i=`${a}: ${n}/5`,o=`${n/5*100}%`;let r;e[0]!==o?(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:o}})}),e[0]=o,e[1]=r):r=e[1];let c;e[2]!==a?(c=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:a}),e[2]=a,e[3]=c):c=e[3];let l;return e[4]!==i||e[5]!==r||e[6]!==c?(l=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[r,c]}),e[4]=i,e[5]=r,e[6]=c,e[7]=l):l=e[7],l},Ok=({selectedModelId:t,onSelect:e})=>{const{t:n}=_e(),a=Ge.useCallback(p=>n(p),[n]),[i,o]=Ge.useState(new Map),[r,c]=Ge.useState(null),l=Ge.useCallback(async()=>{try{const p=await Lt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const g=await p.json();Array.isArray(g?.models)&&o(new Map(g.models.map(h=>[h.id,h])))}catch{}},[]);Ge.useEffect(()=>{l()},[l]);const m=Array.from(i.values()).some(p=>p.downloading);Ge.useEffect(()=>{if(!m)return;const p=setInterval(()=>{l()},2e3);return()=>clearInterval(p)},[m,l]);const u=async p=>{c(p);try{await Lt(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await l()}catch{}finally{c(null)}},f=async p=>{c(p);try{await Lt(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await l()}catch{}finally{c(null)}};return s.jsx("div",{role:"radiogroup","aria-label":n("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:Lk.map(p=>{const g=t===p.id,h=i.get(p.id)??null;return s.jsx("div",{className:je("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:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(al,{checked:g,onChange:()=>e(p.id),ariaLabel:a(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:je("typography-ui-label font-normal",g?"text-foreground":"text-foreground/50"),children:a(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:a(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(md,{value:p.accuracy,label:n("settings.voice.page.stt.meta.accuracy")}),s.jsx(md,{value:p.speed,label:n("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(B,{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:n("settings.voice.page.stt.modelDelete"),"aria-label":n("settings.voice.page.stt.modelDelete"),children:s.jsx(J,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(J,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":n("settings.voice.page.stt.modelInstalled")})]}):h?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(J,{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(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:r===p.id,onClick:()=>{u(p.id)},title:n("settings.voice.page.stt.modelDownload"),"aria-label":n("settings.voice.page.stt.modelDownload"),children:s.jsx(J,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},Fk=[{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)"}],Yr="kokoro-en-v0_19",Kk="kokoro-multi-lang-v1_1",zk=[{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)"}],pi=(t,e)=>`${t}:${e}`,Uk=()=>{const[t,e]=Ge.useState([]),[n,a]=Ge.useState(null),i=Ge.useCallback(async()=>{try{const c=await Lt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const l=await c.json();Array.isArray(l?.ttsModels)&&e(l.ttsModels)}catch{}},[]);Ge.useEffect(()=>{i()},[i]);const o=t.some(c=>c.downloading);Ge.useEffect(()=>{if(!o)return;const c=setInterval(()=>{i()},2e3);return()=>clearInterval(c)},[o,i]);const r=Ge.useCallback(async(c,l)=>{a(c);try{const m=l==="POST"?`/api/dictation/models/${c}/download`:`/api/dictation/models/${c}`;await Lt(m,{method:l}),await i()}catch{}finally{a(null)}},[i]);return{models:t,requestingId:n,request:r,refresh:i}},$k=t=>{const e=Fk.map(n=>({modelId:Yr,speakerId:n.id,label:n.label}));for(const n of t)if(!(n.id===Yr||!n.installed)){if(n.id===Kk){for(const a of zk)e.push({modelId:n.id,speakerId:a.id,label:`${a.label} · Kokoro zh/en`});continue}e.push({modelId:n.id,speakerId:0,label:n.description??n.id})}return e},pd=t=>{const e=$e.c(16),{model:n,requestingId:a,request:i,t:o}=t,r=n.description??n.id;let c;e[0]!==r?(c=s.jsx("span",{className:"typography-ui-label text-foreground",children:r}),e[0]=r,e[1]=c):c=e[1];let l;e[2]!==n.downloadProgress||e[3]!==n.downloading||e[4]!==n.id||e[5]!==n.installed||e[6]!==i||e[7]!==a||e[8]!==o?(l=n.installed?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":o("settings.voice.page.stt.modelInstalled")}),s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:a!==null,onClick:()=>{i(n.id,"DELETE")},title:o("settings.voice.page.stt.modelDelete"),"aria-label":o("settings.voice.page.stt.modelDelete"),children:s.jsx(J,{name:"delete-bin",className:"h-4 w-4"})})]}):n.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(J,{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 n.downloadProgress=="number"?`${n.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:a!==null,onClick:()=>{i(n.id,"POST")},title:o("settings.voice.page.stt.modelDownload"),"aria-label":o("settings.voice.page.stt.modelDownload"),children:s.jsx(J,{name:"download",className:"h-4 w-4"})}),e[2]=n.downloadProgress,e[3]=n.downloading,e[4]=n.id,e[5]=n.installed,e[6]=i,e[7]=a,e[8]=o,e[9]=l):l=e[9];let m;e[10]!==n.downloadError?(m=n.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:n.downloadError}):null,e[10]=n.downloadError,e[11]=m):m=e[11];let u;return e[12]!==c||e[13]!==l||e[14]!==m?(u=s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[c,l,m]}),e[12]=c,e[13]=l,e[14]=m,e[15]=u):u=e[15],u},_k=t=>{const e=$e.c(21),{models:n,requestingId:a,request:i}=t,{t:o}=_e(),[r,c]=Ge.useState(!1),[l,m]=Ge.useState("");if(n.length===0)return null;let u,f,p;if(e[0]!==l||e[1]!==n){f=[],u=[];for(const b of n)b.id===Yr||b.installed||b.downloading||b.downloadError?f.push(b):u.push(b);const S=l.trim().toLowerCase();p=S?u.filter(b=>(b.description??"").toLowerCase().includes(S)||b.id.toLowerCase().includes(S)):u,e[0]=l,e[1]=n,e[2]=u,e[3]=f,e[4]=p}else u=e[2],f=e[3],p=e[4];const g=p;let h;e[5]!==f||e[6]!==i||e[7]!==a||e[8]!==o?(h=f.map(S=>s.jsx(pd,{model:S,requestingId:a,request:i,t:o},S.id)),e[5]=f,e[6]=i,e[7]=a,e[8]=o,e[9]=h):h=e[9];let j;e[10]!==u.length||e[11]!==r||e[12]!==l||e[13]!==g||e[14]!==i||e[15]!==a||e[16]!==o?(j=u.length>0?s.jsxs(Js,{open:r,onOpenChange:c,children:[s.jsxs(Qs,{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:o("settings.voice.page.localTts.availableToDownload")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",u.length,")"]})]}),s.jsx(J,{name:r?"arrow-down-s":"arrow-right-s",className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})]}),s.jsxs(Ys,{className:"pt-1",children:[s.jsx("input",{type:"text",value:l,onChange:S=>m(S.target.value),placeholder:o("settings.voice.page.localTts.filterPlaceholder"),"aria-label":o("settings.voice.page.localTts.filterPlaceholder"),className:je(qn,"mb-1")}),g.length===0?s.jsx("div",{className:"typography-meta py-1.5 text-muted-foreground",children:o("settings.voice.page.localTts.filterNoMatch")}):g.map(S=>s.jsx(pd,{model:S,requestingId:a,request:i,t:o},S.id))]})]}):null,e[10]=u.length,e[11]=r,e[12]=l,e[13]=g,e[14]=i,e[15]=a,e[16]=o,e[17]=j):j=e[17];let x;return e[18]!==h||e[19]!==j?(x=s.jsxs("div",{className:"flex flex-col",children:[h,j]}),e[18]=h,e[19]=j,e[20]=x):x=e[20],x},Bk=[{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"}],Pr=t=>{const e=$e.c(34),{kind:n}=t,{t:a}=_e();let i;e[0]!==n?(i=E=>E.voiceApiKeys[n],e[0]=n,e[1]=i):i=e[1];const o=rt(i),r=rt(Hk),[c,l]=Ge.useState(""),[m,u]=Ge.useState(!1);let f;e[2]!==n||e[3]!==r||e[4]!==a?(f=async E=>{u(!0);const v=await r(n,E);u(!1),v?l(""):q.error(a("settings.voice.page.toast.apiKeySaveFailed"))},e[2]=n,e[3]=r,e[4]=a,e[5]=f):f=e[5];const p=f;let g;e[6]!==c||e[7]!==p?(g=()=>{const E=c.trim();E&&p(E)},e[6]=c,e[7]=p,e[8]=g):g=e[8];const h=g;let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=je("relative",ks),e[9]=j):j=e[9];let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=E=>l(E.target.value),e[10]=x):x=e[10];let S;e[11]!==h?(S=E=>{E.key==="Enter"&&h()},e[11]=h,e[12]=S):S=e[12];let b;e[13]!==o||e[14]!==a?(b=o?a("settings.voice.page.field.apiKeySavedPlaceholder"):"sk-...",e[13]=o,e[14]=a,e[15]=b):b=e[15];let w;e[16]!==a?(w=a("settings.voice.page.field.apiKey"),e[16]=a,e[17]=w):w=e[17];let k;e[18]!==h||e[19]!==c||e[20]!==m||e[21]!==S||e[22]!==b||e[23]!==w?(k=s.jsx("input",{type:"password",value:c,disabled:m,onChange:x,onBlur:h,onKeyDown:S,placeholder:b,className:qn,"aria-label":w}),e[18]=h,e[19]=c,e[20]=m,e[21]=S,e[22]=b,e[23]=w,e[24]=k):k=e[24];let I;e[25]!==c||e[26]!==m||e[27]!==p||e[28]!==o||e[29]!==a?(I=o&&!c&&s.jsx("button",{type:"button",onClick:()=>{p(null)},disabled:m,"aria-label":a("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(J,{name:"close",className:"w-3.5 h-3.5"})}),e[25]=c,e[26]=m,e[27]=p,e[28]=o,e[29]=a,e[30]=I):I=e[30];let y;return e[31]!==I||e[32]!==k?(y=s.jsxs("div",{className:j,children:[k,I]}),e[31]=I,e[32]=k,e[33]=y):y=e[33],y},Vk=()=>{const{t}=_e(),{isMobile:e}=Qn(),n=rt(X=>X.voiceProvider),a=rt(X=>X.setVoiceProvider),i=rt(X=>X.speechRate),o=rt(X=>X.setSpeechRate),r=rt(X=>X.speechPitch),c=rt(X=>X.setSpeechPitch),l=rt(X=>X.speechVolume),m=rt(X=>X.setSpeechVolume),u=rt(X=>X.sayVoice),f=rt(X=>X.setSayVoice),p=rt(X=>X.localTtsVoiceId),g=rt(X=>X.localTtsModelId),h=rt(X=>X.setLocalTtsModelId),j=Uk(),x=Ge.useMemo(()=>$k(j.models),[j.models]),S=rt(X=>X.ttsFollowTextLanguage),b=rt(X=>X.setTtsFollowTextLanguage),w=rt(X=>X.setLocalTtsVoiceId),{speak:k,stop:I,isPlaying:y,error:E}=Op(),v=Ge.useCallback(()=>{if(y){I();return}const X=x.find(ce=>ce.modelId===g&&ce.speakerId===p)?.label??String(p);k(t("settings.voice.page.preview.voiceLine",{voiceName:X}),{model:g,speakerId:p,speed:rt.getState().speechRate})},[y,g,p,x,k,I,t]),R=rt(X=>X.browserVoice),C=rt(X=>X.setBrowserVoice),T=rt(X=>X.openaiVoice),P=rt(X=>X.setOpenaiVoice),L=rt(X=>X.voiceApiKeys.openai),O=rt(X=>X.refreshVoiceApiKeys),A=rt(X=>X.openaiCompatibleUrl),N=rt(X=>X.setOpenaiCompatibleUrl),M=rt(X=>X.openaiCompatibleVoice),F=rt(X=>X.setOpenaiCompatibleVoice),H=rt(X=>X.openaiCompatibleTtsModel),W=rt(X=>X.setOpenaiCompatibleTtsModel),G=rt(X=>X.showMessageTTSButtons),$=rt(X=>X.ttsInputMode),z=rt(X=>X.setTtsInputMode),U=rt(X=>X.ttsChunkedMode),_=rt(X=>X.setTtsChunkedMode),V=rt(X=>X.sttProvider),Z=rt(X=>X.setSttProvider),Y=rt(X=>X.sttServerUrl),Q=rt(X=>X.setSttServerUrl),ue=rt(X=>X.sttModel),ge=rt(X=>X.setSttModel),fe=rt(X=>X.sttLocalModel),Ie=rt(X=>X.setSttLocalModel),te=rt(X=>X.sttLanguage),Ce=rt(X=>X.setSttLanguage),ie=rt(X=>X.setShowMessageTTSButtons),ae=rt(X=>X.dictationEnabled),re=rt(X=>X.setDictationEnabled),[ye,Ee]=Ge.useState(!1),[Pe,ke]=Ge.useState([]),[Te,de]=Ge.useState(!1),[Me,Se]=Ge.useState(null),[Le,Ke]=Ge.useState(!1),[oe,le]=Ge.useState(!1),[xe,De]=Ge.useState(!1),[Ve,Be]=Ge.useState(null),[Ne,Je]=Ge.useState(!1),[ut,ht]=Ge.useState(null),[st,jt]=Ge.useState([]),[St,Ze]=Ge.useState(!1);Ge.useEffect(()=>((async()=>{const ce=await lr.waitForVoices();jt(ce)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{jt(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const it=Ge.useMemo(()=>st.filter(X=>X.lang).sort((X,ce)=>{const Oe=X.lang.startsWith("en"),We=ce.lang.startsWith("en");if(Oe&&!We)return-1;if(!Oe&&We)return 1;const nt=X.lang.localeCompare(ce.lang);return nt!==0?nt:X.name.localeCompare(ce.name)}),[st]),et=Ge.useCallback(()=>{if(St){lr.cancelSpeech(),Ze(!1);return}const X=st.find(nt=>nt.name===R),ce=X?.name??t("settings.voice.page.preview.browserVoiceFallback"),Oe=t("settings.voice.page.preview.voiceLine",{voiceName:ce});Ze(!0);const We=new SpeechSynthesisUtterance(Oe);We.rate=i,We.pitch=r,We.volume=l,X&&(We.voice=X,We.lang=X.lang),We.onend=()=>Ze(!1),We.onerror=()=>Ze(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(We)},[R,st,i,r,l,St,t]);Ge.useEffect(()=>()=>{St&&lr.cancelSpeech()},[St]),Ge.useEffect(()=>{O({force:!0})},[O]),Ge.useEffect(()=>{if(!G||n!=="openai"&&n!=="openai-compatible"){Ke(L);return}(async()=>{try{const Oe=await(await Lt("/api/tts/status")).json(),We=Oe.available,nt=L,at=Oe.enterpriseMode===!0;le(at),Ke(!at&&(We||nt))}catch{Ke(L)}})()},[L,G,n]),Ge.useEffect(()=>{if(!G){Ee(!1),ke([]);return}Lt("/api/tts/say/status").then(X=>X.json()).then(X=>{if(Ee(X.available),X.voices){const ce=X.voices.filter((Oe,We,nt)=>nt.findIndex(at=>at.name===Oe.name)===We).sort((Oe,We)=>Oe.name.localeCompare(We.name));ke(ce)}}).catch(()=>{Ee(!1)})},[G]);const mt=Ge.useCallback(async()=>{if(Me){Rs(Me),Se(null),de(!1);return}de(!0);let X=null;try{const ce=await Lt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:u}),voice:u,rate:Math.round(100+(i-.5)*200)})});if(!ce.ok)throw new Error("Preview failed");const Oe=await ce.blob(),We=URL.createObjectURL(Oe);X=new Audio(We),X.onended=()=>{Rs(X),Se(null),de(!1)},X.onerror=()=>{Rs(X),Se(null),de(!1)},Se(X),await X.play()}catch{Rs(X),Se(null),de(!1)}},[u,i,Me,t]);Ge.useEffect(()=>()=>{Rs(Me)},[Me]);const ft=Ge.useCallback(async()=>{if(Ve){Rs(Ve),Be(null),De(!1);return}De(!0);let X=null;try{const ce=await Lt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:T}),voice:T,speed:i})});if(!ce.ok){const nt=await ce.json().catch(()=>({error:"Unknown error"}));throw new Error(nt.error||`HTTP ${ce.status}`)}const Oe=await ce.blob(),We=URL.createObjectURL(Oe);X=new Audio(We),X.onended=()=>{Rs(X),Be(null),De(!1)},X.onerror=()=>{Rs(X),Be(null),De(!1)},Be(X),await X.play()}catch{Rs(X),Be(null),De(!1)}},[T,i,Ve,t]);Ge.useEffect(()=>()=>{Rs(Ve)},[Ve]);const be=Ge.useCallback(async()=>{if(ut){Rs(ut),ht(null),Je(!1);return}if(!A.trim())return;Je(!0);let X=null;try{const ce=await Lt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:M,model:H||void 0,speed:i,baseURL:A})});if(!ce.ok){const nt=await ce.json().catch(()=>({error:"Unknown error"}));throw new Error(nt.error||`HTTP ${ce.status}`)}const Oe=await ce.blob(),We=URL.createObjectURL(Oe);X=new Audio(We),X.onended=()=>{Rs(X),ht(null),Je(!1)},X.onerror=()=>{Rs(X),ht(null),Je(!1)},ht(X),await X.play()}catch{Rs(X),ht(null),Je(!1)}},[A,M,H,i,ut,t]);Ge.useEffect(()=>()=>{Rs(ut)},[ut]);const Re="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(qe,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(ct,{checked:G,onChange:ie,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),G&&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(Ws,{value:n,onChange:a,"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")},...ye?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),oe&&(n==="openai"||n==="openai-compatible")&&s.jsx("p",{className:Mt,children:t("settings.voice.page.enterpriseMode")}),n==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:je(Pt,!Le&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:je(Mt,!Le&&"text-[var(--status-error)]/80"),children:t(Le&&!L?"settings.voice.page.field.apiKeyHintUsingConfig":Le?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsx(Pr,{kind:"openai"})]}),n==="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:je(Pt,!A.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Wt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:je("relative",ks),children:[s.jsx("input",{type:"text",value:A,onChange:X=>N(X.target.value),placeholder:"http://localhost:8880/v1",className:qn}),A&&s.jsx("button",{type:"button",onClick:()=>N(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(J,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Mt,children:t("settings.voice.page.field.apiKeyOptional")}),s.jsx(Pr,{kind:"openaiCompatible"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",ks),children:s.jsx("input",{type:"text",value:H,onChange:X=>W(X.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:qn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.voice")}),s.jsx(Wt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:je("flex items-center gap-2",ks),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:M,onChange:X=>F(X.target.value),placeholder:"af_sky",className:qn})}),s.jsx(B,{size:"xs",variant:"ghost",onClick:be,title:t("settings.voice.page.actions.preview"),disabled:!A.trim(),children:Ne?s.jsx(J,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(J,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),n==="local"&&s.jsx(_k,{...j}),(n==="local"||n==="say")&&s.jsx(ct,{checked:S,onChange:b,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(yt,{label:t("settings.voice.page.field.voice"),children:[n==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:pi(g,p),onValueChange:X=>{const ce=x.find(Oe=>pi(Oe.modelId,Oe.speakerId)===X);ce&&(h(ce.modelId),w(ce.speakerId))},children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:X=>x.find(ce=>pi(ce.modelId,ce.speakerId)===X)?.label??X})}),s.jsx(Et,{children:x.map(X=>s.jsx(dt,{value:pi(X.modelId,X.speakerId),children:X.label},pi(X.modelId,X.speakerId)))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:v,title:t("settings.voice.page.actions.preview"),children:y?s.jsx(J,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(J,{name:"play",className:"w-3.5 h-3.5"})}),E?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:E}):null]}),n==="openai"&&Le&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:T,onValueChange:P,children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Et,{children:Bk.map(X=>s.jsx(dt,{value:X.value,children:X.label},X.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:ft,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(J,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(J,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="openai-compatible"&&s.jsx("span",{className:Mt,children:t("settings.voice.page.field.configuredAbove")}),n==="say"&&ye&&Pe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:u,onValueChange:f,children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Et,{children:Pe.map(X=>s.jsx(dt,{value:X.name,children:X.name},X.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:mt,title:t("settings.voice.page.actions.preview"),children:Te?s.jsx(J,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(J,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="browser"&&it.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:R||"$auto",onValueChange:X=>C(X==="$auto"?"":X),children:[s.jsx(Tt,{size:qt,className:dn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Et,{children:[s.jsx(dt,{value:"$auto",children:t("settings.voice.page.field.auto")}),it.map(X=>s.jsxs(dt,{value:X.name,children:[X.name," (",X.lang,")"]},X.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:et,title:t("settings.voice.page.actions.preview"),children:St?s.jsx(J,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(J,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(yt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:X=>o(Number(X.target.value)),className:Re}),s.jsx(gs,{value:i,onValueChange:o,min:.5,max:2,step:.1,className:je(bs,"tabular-nums")})]}),s.jsxs(yt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:X=>c(Number(X.target.value)),className:Re}),s.jsx(gs,{value:r,onValueChange:c,min:.5,max:2,step:.1,className:je(bs,"tabular-nums")})]}),s.jsxs(yt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:l,onChange:X=>m(Number(X.target.value)),className:Re}),e?s.jsx(gs,{value:Math.round(l*100),onValueChange:X=>m(X/100),min:0,max:100,step:10,className:je(bs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(l*100),"%"]})]}),s.jsx(vs,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ws,{value:$,onChange:z,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})}),(n==="openai"||n==="openai-compatible")&&s.jsx(ct,{checked:U,onChange:_,label:t("settings.voice.page.field.ttsChunkedMode"),ariaLabel:t("settings.voice.page.field.ttsChunkedModeAria"),info:t("settings.voice.page.tooltip.ttsChunked")})]})]}),s.jsxs(qe,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(ct,{checked:ae,onChange:re,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ae&&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(Ws,{value:V,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")}]})}),V==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx(Ok,{selectedModelId:fe,onSelect:Ie})]}),V==="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:je(Pt,!Y.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Wt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:je("relative",ks),children:[s.jsx("input",{type:"text",value:Y,onChange:X=>Q(X.target.value),placeholder:"http://localhost:8001/v1",className:qn}),Y&&s.jsx("button",{type:"button",onClick:()=>Q(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(J,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Mt,children:t("settings.voice.page.field.apiKeyOptional")}),s.jsx(Pr,{kind:"stt"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",ks),children:s.jsx("input",{type:"text",value:ue,onChange:X=>ge(X.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:qn})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.language")}),s.jsx(Wt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:te,onChange:X=>Ce(X.target.value),placeholder:"auto",className:qn})})]})]})]})]})]})};function Hk(t){return t.setVoiceApiKey}const io=[{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}],oo=[{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}],qk="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Wk="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Ar=[{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"}],Gk=[".yml",".yaml",".json"],Jk="settings.openchamber.tunnel.error.invalidConfigExtension",gi=t=>{const e=t.trim().toLowerCase();return Gk.some(n=>e.endsWith(n))},Qk=t=>t==="ngrok"?"ngrok":"cloudflared",Qu=()=>{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"},Yk=(t,e=Qu())=>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/",Tr=(t,e)=>{const n=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,a=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():Qk(n),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Qu(),o=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Yk(n,i);return{provider:n,dependency:a,installCommand:o}},Yu=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,gd=t=>{const e=$e.c(11),{provider:n}=t;let a;e[0]!==n?(a=Yu(n),e[0]=n,e[1]=a):a=e[1];const i=a,c=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let l;e[2]!==c?(l=je("size-4 shrink-0",c),e[2]=c,e[3]=l):l=e[3];let m;e[4]!==l?(m=s.jsx(J,{name:"cloud",className:l}),e[4]=l,e[5]=m):m=e[5];let u;e[6]!==i?(u=s.jsx("span",{children:i}),e[6]=i,e[7]=u):u=e[7];let f;return e[8]!==m||e[9]!==u?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[m,u]}),e[8]=m,e[9]=u,e[10]=f):f=e[10],f},Hn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Zr=(t,e,n)=>t.find(i=>i.ms===e)?.value||n,fd=(t,e,n)=>{const a=Zr(t,e,n);return t.find(i=>i.value===a)?.label||a},hd=t=>{const e=Math.max(0,t),n=Math.floor(e/1e3),a=Math.floor(n/3600),i=Math.floor(n%3600/60),o=n%60;return a>0?`${a}h ${i}m`:i>0?`${i}m ${o}s`:`${o}s`},Zk=(t,e)=>Ed(t,e,{hour:"2-digit",precision:"second"}),po=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()}},Xk=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,a=[];for(const i of t){if(!i||typeof i!="object")continue;const o=i,r=typeof o.id=="string"?o.id.trim():"",c=typeof o.name=="string"?o.name.trim():"",l=po(typeof o.hostname=="string"?o.hostname:"");!r||!c||!l||e.has(r)||n.has(l)||(e.add(r),n.add(l),a.push({id:r,name:c,hostname:l}))}return a},ew=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,tw=()=>{const{t}=_e(),e=ne(ee=>ee.timeFormatPreference),n=d.useCallback(ee=>t(ee),[t]),[a,i]=d.useState("checking"),[o,r]=d.useState(!1),[c,l]=d.useState(null),[m,u]=d.useState(null),[f,p]=d.useState(null),[g,h]=d.useState(null),[j,x]=d.useState(null),[S,b]=d.useState(!1),[w,k]=d.useState(!1),[I,y]=d.useState(!1),[E,v]=d.useState("cloudflare"),[R,C]=d.useState(()=>Tr("cloudflare")),[T,P]=d.useState([]),[L,O]=d.useState("quick"),[A,N]=d.useState(null),[M,F]=d.useState([]),[H,W]=d.useState({}),[G,$]=d.useState(""),[z,U]=d.useState({}),[_,V]=d.useState(new Set),[Z,Y]=d.useState(!1),[Q,ue]=d.useState(""),[ge,fe]=d.useState(""),[Ie,te]=d.useState(""),[Ce,ie]=d.useState(1800*1e3),[ae,re]=d.useState(480*60*1e3),[ye,Ee]=d.useState(""),[Pe,ke]=d.useState([]),[Te,de]=d.useState(()=>Date.now()),[Me,Se]=d.useState(null),Le=t(Jk),Ke=d.useRef(null),oe=d.useMemo(()=>A?!gi(A):!1,[A]),le=d.useMemo(()=>M.find(ee=>ee.id===G)||M[0]||null,[M,G]),xe=d.useMemo(()=>Pe.map(ee=>{const ve=ee.expiresAt<=Te,Fe=ee.status==="active"&&!ve,se=Fe?hd(ee.expiresAt-Te):ee.inactiveReason==="expired"||ve?"expired":"inactive",Ae=se==="expired"?t("settings.openchamber.tunnel.state.expired"):ee.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),tt=Hn(ee.mode);return{...ee,isActive:Fe,mode:tt,remainingTextForSession:se,inactiveLabel:Ae}}),[Te,Pe,t]),De=d.useMemo(()=>c?.connectUrl?c.bootstrapExpiresAt===null?!0:c.bootstrapExpiresAt>Te:!1,[Te,c?.bootstrapExpiresAt,c?.connectUrl]),Ve=d.useMemo(()=>!c||a!=="active"&&a!=="stopping"?!1:m===L,[m,a,c,L]),Be=d.useMemo(()=>!c||a!=="active"||!m?!1:m!==L,[m,a,c,L]),Ne=d.useMemo(()=>{if(typeof Me=="number"&&Number.isFinite(Me)&&Me>0)return Me;if(typeof window>"u")return null;const ve=Ii()||window.location.href;let Fe=0;try{Fe=Number(new URL(ve).port)}catch{Fe=Number(window.location.port)}return Number.isFinite(Fe)&&Fe>0?Fe:null},[Me]),Je=d.useMemo(()=>T.find(ee=>ee.provider===E)??null,[T,E]),ut=d.useMemo(()=>{const ee=new Set(Je?.modes?.map(ve=>ve.key).filter(ve=>ve==="quick"||ve==="managed-remote"||ve==="managed-local"));return ee.size===0?Ar:Ar.filter(ve=>ee.has(ve.value))},[Je]),ht=d.useMemo(()=>ut.some(ee=>ee.value==="managed-remote"||ee.value==="managed-local"),[ut]),st=d.useMemo(()=>R.provider===E?R:Tr(E),[R,E]),jt=d.useCallback(async ee=>{await Ss(ee)},[]),St=d.useCallback((ee,ve)=>(C(Tr(ve,ee)),ee.available===!0),[]),Ze=d.useCallback(async(ee,ve)=>{try{const Fe=await Lt("/api/openchamber/tunnel/check",{query:{provider:ee},...ve?{signal:ve}:{}});if(!Fe.ok)return null;const se=await Fe.json();if(ve?.aborted)return null;const Ae=St(se,ee);return i(tt=>tt==="checking"||tt==="starting"||tt==="active"||tt==="stopping"?tt:Ae?"idle":"not-available"),Ae}catch{return null}},[St]),it=d.useCallback(async ee=>{try{const[ve,Fe,se,Ae]=await Promise.all([Lt("/api/openchamber/tunnel/check",{signal:ee}),Lt("/api/openchamber/tunnel/status",{signal:ee}),yn(),Lt("/api/openchamber/tunnel/providers",{signal:ee})]),tt=await ve.json(),ot=await Fe.json(),At=se??{},pe=Ae.ok?await Ae.json():{},we=ot.ttlConfig?.bootstrapTtlMs??(At.tunnelBootstrapTtlMs===void 0?1800*1e3:At.tunnelBootstrapTtlMs),ze=typeof ot.ttlConfig?.sessionTtlMs=="number"?ot.ttlConfig.sessionTtlMs:At.tunnelSessionTtlMs??480*60*1e3,pt=Hn(ot.mode??At.tunnelMode),Ct=At.tunnelProvider??"cloudflare",Gt=At.managedLocalTunnelConfigPath??null,Zt=St(tt,Ct),as=Xk(ot?.managedRemoteTunnelPresets),Jt=typeof ot.managedRemoteTunnelHostname=="string"?ot.managedRemoteTunnelHostname:"",Es=as.length>0?as:Jt?[{id:`legacy-${po(Jt)}`,name:Jt,hostname:po(Jt)}]:[],pn=Es[0]?.id||"";if(r(ot.enterpriseMode===!0),ie(we),re(ze),v(Ct),P(Array.isArray(pe?.providers)?pe.providers:[]),O(pt),N(Gt),F(Es),$(pn),ke(Array.isArray(ot.activeSessions)?ot.activeSessions:[]),u(ot.activeTunnelMode?Hn(ot.activeTunnelMode):ot.active&&ot.mode?Hn(ot.mode):null),V(new Set(Array.isArray(ot.managedRemoteTunnelTokenPresetIds)?ot.managedRemoteTunnelTokenPresetIds:[])),Se(typeof ot.localPort=="number"?ot.localPort:null),ot.active&&ot.url){l({url:ot.url,connectUrl:null,bootstrapExpiresAt:typeof ot.bootstrapExpiresAt=="number"?ot.bootstrapExpiresAt:null}),i("active");return}i(Zt?"idle":"not-available")}catch{ee.aborted||(i("error"),h(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[St,t]);d.useEffect(()=>{const ee=new AbortController;return it(ee.signal),()=>ee.abort()},[it]),d.useEffect(()=>{if(!c?.connectUrl){p(null);return}let ee=!1;return tu.toDataURL(c.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(ve=>{ee||p(ve)}).catch(()=>{ee||p(null)}),()=>{ee=!0}},[c?.connectUrl]),d.useEffect(()=>{if(!c?.bootstrapExpiresAt){Ee(t("settings.openchamber.tunnel.state.noExpiry"));return}let ee=null,ve=Date.now();const Fe=()=>{const tt=c.bootstrapExpiresAt?c.bootstrapExpiresAt-Date.now():0;tt<=0?Ee(t("settings.openchamber.tunnel.state.expired")):Ee(hd(tt))},se=()=>{const tt=Date.now();tt-ve>=1e3&&(Fe(),ve=tt),ee=requestAnimationFrame(se)};Fe(),(typeof document>"u"||document.visibilityState==="visible")&&(ee=requestAnimationFrame(se));const Ae=()=>{document.visibilityState==="visible"&&ee===null?ee=requestAnimationFrame(se):document.visibilityState!=="visible"&&ee!==null&&(cancelAnimationFrame(ee),ee=null)};return document.addEventListener("visibilitychange",Ae),()=>{document.removeEventListener("visibilitychange",Ae),ee!==null&&cancelAnimationFrame(ee)}},[t,c?.bootstrapExpiresAt]),d.useEffect(()=>{let ee=null,ve=Date.now();const Fe=()=>{const Ae=Date.now();Ae-ve>=1e3&&(de(Ae),ve=Ae),ee=requestAnimationFrame(Fe)};(typeof document>"u"||document.visibilityState==="visible")&&(ee=requestAnimationFrame(Fe));const se=()=>{document.visibilityState==="visible"&&ee===null?ee=requestAnimationFrame(Fe):document.visibilityState!=="visible"&&ee!==null&&(cancelAnimationFrame(ee),ee=null)};return document.addEventListener("visibilitychange",se),()=>{document.removeEventListener("visibilitychange",se),ee!==null&&cancelAnimationFrame(ee)}},[]),d.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let ee=!1;const ve=async()=>{try{const se=await Lt("/api/openchamber/tunnel/status");if(!se.ok||ee)return;const Ae=await se.json();if(ee)return;ke(Array.isArray(Ae.activeSessions)?Ae.activeSessions:[]),V(new Set(Array.isArray(Ae.managedRemoteTunnelTokenPresetIds)?Ae.managedRemoteTunnelTokenPresetIds:[])),Se(typeof Ae.localPort=="number"?Ae.localPort:null)}catch{}},Fe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ve()},5e3);return()=>{ee=!0,window.clearInterval(Fe)}},[a]);const et=d.useCallback(async ee=>{y(!0);try{await bt(ee),Object.prototype.hasOwnProperty.call(ee,"tunnelMode")&&ee.tunnelMode&&O(ee.tunnelMode),Object.prototype.hasOwnProperty.call(ee,"tunnelProvider")&&typeof ee.tunnelProvider=="string"&&v(ee.tunnelProvider),Object.prototype.hasOwnProperty.call(ee,"managedLocalTunnelConfigPath")&&N(ee.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ee,"managedRemoteTunnelPresets")&&ee.managedRemoteTunnelPresets&&F(ee.managedRemoteTunnelPresets)}catch{q.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),mt=d.useCallback(async(ee,ve)=>{k(!0);try{await bt({tunnelBootstrapTtlMs:ee,tunnelSessionTtlMs:ve})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{k(!1)}},[t]),ft=d.useCallback(async ee=>{const ve=ee.token.trim();if(ve)try{const Fe={...z,[ee.presetId]:ve};await bt({managedRemoteTunnelPresetTokens:Fe}),V(se=>{const Ae=new Set(se);return Ae.add(ee.presetId),Ae})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[z,t]),be=d.useCallback(async ee=>{x(null),h(null);const ve=T.find(se=>se.provider===ee),Fe=ve?.modes?.some(se=>se.key===L)?L:Hn(ve?.modes?.[0]?.key);await et({tunnelProvider:ee,tunnelMode:Fe}),Ze(ee)},[T,Ze,et,L]),Re=d.useCallback(async()=>{const ee=await ul({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ee.success&&typeof ee.path=="string"&&ee.path.trim().length>0){const ve=ee.path.trim();if(!gi(ve)){q.error(Le);return}N(ve),await et({managedLocalTunnelConfigPath:ve});return}Ke.current?.click()},[Le,et]),X=d.useCallback(ee=>{const ve=ee.trim();N(ve.length>0?ve:null)},[]),ce=d.useCallback(async()=>{if(A&&!gi(A)){q.error(Le);return}await et({managedLocalTunnelConfigPath:A})},[Le,A,et]),Oe=d.useCallback(async()=>{N(null),await et({managedLocalTunnelConfigPath:null})},[et]),We=d.useCallback(async ee=>{const ve=ee.target.files?.[0];if(!ve)return;const Fe=ve.name.trim();if(Fe.length!==0){if(!gi(Fe)){q.error(Le);return}N(Fe),await et({managedLocalTunnelConfigPath:Fe}),ee.target.value=""}},[Le,et]),nt=d.useCallback(async()=>{if(h(null),x(null),L==="managed-local"&&A&&!gi(A)){h(Le),q.error(Le);return}i("starting");try{let ee="",ve="";if(L==="managed-remote"){if(!le){i("idle"),x(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),q.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ee=le.hostname,ve=(z[le.id]||"").trim(),await et({tunnelMode:"managed-remote",managedRemoteTunnelPresets:M})}const Fe=await Lt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:E,mode:L,...L==="managed-remote"&&le?{managedRemoteTunnelPresetId:le.id,managedRemoteTunnelPresetName:le.name}:{},...L==="managed-remote"&&ee?{managedRemoteTunnelHostname:ee}:{},...L==="managed-remote"&&ve?{managedRemoteTunnelToken:ve}:{},...L==="managed-local"&&A?{configPath:A}:{}})}),se=await Fe.json();if(!Fe.ok||!se.ok){if(L==="managed-remote"&&typeof se.error=="string"&&se.error.includes("Managed remote tunnel token is required")){i("idle"),x(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),q.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),h(se.error||t("settings.openchamber.tunnel.toast.startFailed")),q.error(se.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const Ae=typeof se.url=="string"?se.url:"";if(!Ae){i("error"),h(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),q.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:Ae,connectUrl:typeof se.connectUrl=="string"?se.connectUrl:null,bootstrapExpiresAt:typeof se.bootstrapExpiresAt=="number"?se.bootstrapExpiresAt:null}),u(se.activeTunnelMode?Hn(se.activeTunnelMode):se.mode?Hn(se.mode):L),ke(Array.isArray(se.activeSessions)?se.activeSessions:[]),Array.isArray(se.managedRemoteTunnelTokenPresetIds)&&V(new Set(se.managedRemoteTunnelTokenPresetIds)),typeof se.localPort=="number"&&Se(se.localPort),typeof se.mode=="string"&&O(Hn(se.mode)),i("active"),se.replacedTunnel){const tt=typeof se.revokedBootstrapCount=="number"?se.revokedBootstrapCount:0,ot=typeof se.invalidatedSessionCount=="number"?se.invalidatedSessionCount:0;tt===1&&ot===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):tt===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ot})):ot===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:tt})):q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:tt,invalidatedSessionCount:ot}))}else q.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),h(t("settings.openchamber.tunnel.toast.startFailed")),q.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Le,M,et,le,z,t,E,L,A]),at=d.useCallback(async()=>{i("stopping");try{await Lt("/api/openchamber/tunnel/stop",{method:"POST"});const ee=await Lt("/api/openchamber/tunnel/status");if(ee.ok){const ve=await ee.json();ke(Array.isArray(ve.activeSessions)?ve.activeSessions:[]),V(new Set(Array.isArray(ve.managedRemoteTunnelTokenPresetIds)?ve.managedRemoteTunnelTokenPresetIds:[])),Se(typeof ve.localPort=="number"?ve.localPort:null)}l(null),u(null),p(null),i("idle"),q.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),h(t("settings.openchamber.tunnel.toast.stopFailed")),q.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),vt=d.useCallback(async()=>{if(c?.connectUrl)try{await navigator.clipboard.writeText(c.connectUrl),b(!0),q.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{q.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,c?.connectUrl]),kt=d.useCallback(async ee=>{const ve=io.find(Fe=>Fe.value===ee);ve&&(ie(ve.ms),await mt(ve.ms,ae))},[mt,ae]),xt=d.useCallback(async ee=>{const ve=oo.find(Fe=>Fe.value===ee);!ve||ve.ms===null||(re(ve.ms),await mt(Ce,ve.ms))},[Ce,mt]),It=d.useCallback(async ee=>{x(null),h(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&i("idle"),await et({tunnelMode:ee,managedRemoteTunnelPresets:M})},[M,et,a]),_t=d.useCallback(async(ee,ve)=>{try{await bt({managedRemoteTunnelPresets:ve})}catch{q.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ye=d.useCallback(ee=>{const ve=M.find(Fe=>Fe.id===ee);ve&&($(ve.id),x(null),_t(ve,M))},[M,_t]),Xe=d.useCallback(async()=>{const ee=Q.trim(),ve=po(ge),Fe=Ie.trim();if(!ee){q.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!ve){q.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Fe){q.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(M.some(tt=>tt.hostname===ve)){q.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const se={id:ew(),name:ee,hostname:ve},Ae=[...M,se];F(Ae),$(se.id),W(tt=>({...tt,[se.id]:!0})),U(tt=>({...tt,[se.id]:Fe})),x(null),Y(!1),ue(""),fe(""),te(""),await et({tunnelMode:"managed-remote",managedRemoteTunnelPresets:Ae,managedRemoteTunnelPresetTokens:{...z,[se.id]:Fe}}),await ft({presetId:se.id,presetName:se.name,hostname:se.hostname,token:Fe}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[M,ge,Q,Ie,ft,et,z,t]),gt=d.useCallback(async ee=>{const ve=M.find(ot=>ot.id===ee);if(!ve)return;const Fe=M.filter(ot=>ot.id!==ve.id),se=Fe[0]?.id||"",Ae=G===ve.id?se:G,tt=Object.fromEntries(Object.entries(z).filter(([ot,At])=>ot!==ve.id&&At.trim().length>0));F(Fe),$(Ae),W(ot=>{const At={...ot};return delete At[ve.id],At}),U(ot=>{const At={...ot};return delete At[ve.id],At}),V(ot=>{const At=new Set(ot);return At.delete(ve.id),At}),x(null),await et({managedRemoteTunnelPresets:Fe,managedRemoteTunnelPresetTokens:tt}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[M,et,G,z,t]),Ue="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 a==="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")})}):o?s.jsx(qe,{title:t("settings.openchamber.tunnel.title"),divider:!1,children:s.jsx("p",{className:xn,children:t("settings.openchamber.tunnel.enterpriseMode")})}):s.jsx(qe,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[xe.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(J,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Or,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:xe.map(ee=>{const ve=ee.mode==="quick",Fe=ee.mode==="managed-remote",se=ve?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Fe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",Ae=ee.isActive?ve?"text-[var(--status-warning)]":Fe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",tt=t(ve?"settings.openchamber.tunnel.badge.quick":Fe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(J,{name:"checkbox-blank-circle-fill",className:je("size-2.5 shrink-0",Ae)}),s.jsx("span",{className:je("typography-micro rounded border px-1.5 py-0.5 uppercase",se),children:tt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Zk(ee.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:ee.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:ee.remainingTextForSession}):ee.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ee.inactiveLabel})})]},ee.sessionId)})})]})}),a==="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(J,{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:Or,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:st.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:st.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:Pt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Dt,{value:E,onValueChange:ee=>{be(ee)},disabled:I||a==="starting"||a==="stopping",children:[s.jsx(Tt,{size:qt,className:"max-w-[16rem]",children:s.jsx($t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Yu(E)})}),s.jsxs(Et,{children:[T.length>0?T.map(ee=>s.jsx(dt,{value:ee.provider,children:s.jsx(gd,{provider:ee.provider})},ee.provider)):s.jsx(dt,{value:"cloudflare",children:s.jsx(gd,{provider:"cloudflare"})}),s.jsx(dt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ut.map(ee=>s.jsxs(_d,{children:[s.jsx(Bd,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":L===ee.value,className:"!font-normal",onClick:()=>{It(ee.value)},disabled:I||a==="starting"||a==="stopping",children:n(ee.labelKey)})}),s.jsx(Fp,{sideOffset:8,className:"max-w-xs",children:n(ee.tooltipKey)})]},ee.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:je(Pt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Dt,{value:Zr(io,Ce,"1800000"),onValueChange:ee=>{kt(ee)},disabled:w||I||a==="starting"||a==="stopping",children:[s.jsx(Tt,{size:qt,className:"max-w-[11rem] min-w-0",children:s.jsx($t,{className:"truncate",children:fd(io,Ce,"1800000")})}),s.jsx(Et,{children:io.map(ee=>s.jsx(dt,{value:ee.value,children:ee.label},ee.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je(Pt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Dt,{value:Zr(oo,ae,"28800000"),onValueChange:ee=>{xt(ee)},disabled:w||I||a==="starting"||a==="stopping",children:[s.jsx(Tt,{size:qt,className:"max-w-[11rem] min-w-0",children:s.jsx($t,{className:"truncate",children:fd(oo,ae,"28800000")})}),s.jsx(Et,{children:oo.map(ee=>s.jsx(dt,{value:ee.value,children:ee.label},ee.value))})]})]})]}),L==="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(J,{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")}),ht&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),L==="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 Ne=="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:",Ne]})]})}),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(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Y(ee=>!ee),disabled:a==="starting"||a==="stopping"||I,children:[s.jsx(J,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),M.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:M.map((ee,ve)=>{const Fe=z[ee.id]||"",se=_.has(ee.id),Ae=H[ee.id]??!1;return s.jsx("div",{className:je(ve<M.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Js,{open:Ae,onOpenChange:tt=>{W(ot=>({...ot,[ee.id]:tt})),tt&&Ye(ee.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Qs,{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:a==="starting"||a==="stopping"||I,children:[Ae?s.jsx(J,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(J,{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:ee.name})]}),s.jsx(B,{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:ee.name}),onClick:()=>{gt(ee.id)},disabled:a==="starting"||a==="stopping"||I,children:s.jsx(J,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Ys,{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:ee.hostname})]}),s.jsx(He,{type:"password",value:Fe,onChange:tt=>{const ot=tt.target.value;x(null),U(At=>({...At,[ee.id]:ot}))},onBlur:tt=>{const ot=tt.currentTarget.value.trim();ot&&ft({presetId:ee.id,presetName:ee.name,hostname:ee.hostname,token:ot})},placeholder:t(se?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",disabled:a==="starting"||a==="stopping"||Fe.trim().length===0,onClick:()=>{ft({presetId:ee.id,presetName:ee.name,hostname:ee.hostname,token:Fe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ee.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(He,{value:Q,onChange:ee=>ue(ee.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),s.jsx(He,{value:ge,onChange:ee=>fe(ee.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),s.jsx(He,{type:"password",value:Ie,onChange:ee=>te(ee.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),typeof Ne=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ne]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xe()},disabled:I||a==="starting"||a==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Y(!1),ue(""),fe(""),te("")},disabled:I||a==="starting"||a==="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(Wt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!le&&j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:j})]}),L==="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:Pt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ke,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ee=>{We(ee)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:A||"",onChange:ee=>{X(ee.target.value)},onBlur:()=>{ce()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||I}),s.jsx(B,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Re()},disabled:a==="starting"||a==="stopping"||I,children:s.jsx(J,{name:"folder",className:"size-3.5"})}),A&&s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Oe()},disabled:a==="starting"||a==="stopping"||I,children:s.jsx(J,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(A?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),oe&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Le})]})}),!Ve&&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(J,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[L==="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:()=>{jt(qk)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(J,{name:"external-link",className:"size-3.5"})]})]}),L==="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:()=>{jt(Wk)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(J,{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:n(Ar.find(ee=>ee.value===L)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),L==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Dt,{value:G||(M[0]?.id??""),onValueChange:ee=>{Ye(ee)},disabled:I||a==="starting"||a==="stopping"||M.length<=1,children:[s.jsx(Tt,{size:qt,children:s.jsx($t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:le?.name})}),s.jsx(Et,{fitContent:!0,children:M.map(ee=>s.jsx(dt,{value:ee.id,children:ee.name},ee.id))})]})]}),Be&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(J,{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(B,{size:"sm",variant:"outline",onClick:nt,disabled:a==="starting"||I||L==="managed-remote"&&!le||L==="managed-local"&&oe,className:je(Ue,a==="starting"&&"opacity-70"),children:a==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ve&&c&&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:c.url})]}),De&&c.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:c.connectUrl}),s.jsxs(B,{size:"sm",variant:"ghost",onClick:vt,className:"shrink-0 gap-1.5",children:[S?s.jsx(J,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(J,{name:"file-copy",className:"size-3.5"}),t(S?"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"),": ",c.bootstrapExpiresAt?ye: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(B,{size:"sm",variant:"outline",onClick:nt,disabled:a==="stopping"||I||L==="managed-local"&&oe,className:Ue,children:[s.jsx(J,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:at,disabled:a==="stopping"||I,className:"gap-2 text-[var(--status-error)]",children:a==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),a==="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(B,{size:"sm",variant:"ghost",onClick:nt,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Zu=()=>{const{t}=_e(),e=Ni(h=>h.opencodeBinary),[n,a]=Ge.useState(""),[i,o]=Ge.useState(!0),[r,c]=Ge.useState(!1),l=ne(h=>h.showOpenCodeUpdateNotifications),m=ne(h=>h.setShowOpenCodeUpdateNotifications);Ge.useEffect(()=>{let h=!1;return(async()=>{try{const j=await yn();if(h||!j)return;a(j.opencodeBinary??"")}catch{}finally{h||o(!1)}})(),()=>{h=!0}},[]);const u=Ge.useCallback(async()=>{if(!(typeof window>"u")&&cs())try{const h=await ul();h.success&&h.path&&h.path.trim().length>0&&a(h.path.trim())}catch{}},[]),f=Ge.useCallback(async()=>{c(!0);try{const h=n.trim(),j=h.length>=2&&(h.startsWith('"')&&h.endsWith('"')||h.startsWith("'")&&h.endsWith("'"))?h.slice(1,-1).trim():h;await bt({opencodeBinary:j}),await kd({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(h){if(h?.requiresManualRestart){q.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}q.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{c(!1)}},[t,n]),p=Ge.useCallback(async()=>{c(!0);try{await eu(t)}finally{c(!1)}},[t]),g=Ge.useCallback(h=>{m(h),bt({showOpenCodeUpdateNotifications:h})},[m]);return s.jsx(qe,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(yt,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),description:e?t("settings.openchamber.opencodeCli.field.pinnedByAdministrator"):void 0,alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e??n,onChange:h=>a(h.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:i||r||e!==null,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:u,disabled:i||r||!cs()||e!==null,className:ls,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(J,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Gn,{className:xs,children:[s.jsx(ct,{settingsItem:"sessions.opencode-update-notifications",checked:l,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(B,{type:"button",size:"xs",onClick:f,disabled:i||r||e!==null,className:"shrink-0 !font-normal",children:t(r?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")}),s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:i||r,className:"shrink-0 !font-normal",children:t("settings.openchamber.opencodeCli.actions.restart")})]})]})]})})},Xu=()=>{const{t}=_e(),e=zn(),[n,a]=d.useState({state:"loading"}),[i,o]=d.useState(!1),[r,c]=d.useState(!1);d.useEffect(()=>{let u=!1;return Og().then(f=>{u||a({state:"ready",names:f.names})}).catch(()=>{u||a({state:"failed"})}),()=>{u=!0}},[]);const l=d.useCallback(async u=>{ss("saving");try{const f=await Fg(u);return a({state:"ready",names:f.names}),o(!0),ss("saved"),!0}catch{return ss("error"),q.error(t("settings.environment.editor.saveFailed")),!1}},[t]),m=d.useCallback(async()=>{c(!0);try{await eu(t),o(!1)}finally{c(!1)}},[t]);return s.jsx(qe,{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,n.state==="failed"?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.environment.editor.loadFailed")}):s.jsx(Kg,{names:n.state==="ready"?n.names:[],disabled:n.state!=="ready",onSet:(u,f)=>l({[u]:f}),onRemove:u=>l({[u]:null})}),i&&!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(B,{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]})})},Er="builtin",sw=t=>t.filter(e=>rl(e)&&zd(e.service,"browser")),nw="pl-[3.75rem]",ro=t=>{const e=$e.c(23),{icon:n,title:a,summary:i,info:o,ariaLabel:r,checked:c,onChange:l,settingsItem:m}=t;let u;e[0]!==n?(u=s.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-foreground",children:s.jsx(J,{name:n,className:"size-4"})}),e[0]=n,e[1]=u):u=e[1];let f;e[2]!==a?(f=s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}),e[2]=a,e[3]=f):f=e[3];let p;e[4]!==o?(p=s.jsx(Wt,{children:o}),e[4]=o,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]!==i?(h=s.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),e[9]=i,e[10]=h):h=e[10];let j;e[11]!==g||e[12]!==h?(j=s.jsxs("div",{className:"min-w-0 flex-1",children:[g,h]}),e[11]=g,e[12]=h,e[13]=j):j=e[13];let x;e[14]!==r||e[15]!==c||e[16]!==l?(x=s.jsx(ha,{checked:c,onCheckedChange:l,"aria-label":r}),e[14]=r,e[15]=c,e[16]=l,e[17]=x):x=e[17];let S;return e[18]!==m||e[19]!==u||e[20]!==j||e[21]!==x?(S=s.jsxs("div",{"data-settings-item":m,className:"flex items-center gap-3 px-4 py-3",children:[u,j,x]}),e[18]=m,e[19]=u,e[20]=j,e[21]=x,e[22]=S):S=e[22],S},em=()=>{const t=$e.c(130),{t:e}=_e(),n=ne(aw),a=ne(iw),i=ne(ow),o=ne(rw),r=ne(lw),c=ne(cw),l=As(dw),m=ne(uw),u=ne(mw),f=ne(pw),p=ne(gw),g=ne(fw),h=ne(hw),j=ne(xw);let x;t[0]!==a?(x=Je=>{a(Je),bt({agentControlToolEnabled:Je})},t[0]=a,t[1]=x):x=t[1];const S=x;let b;t[2]!==o?(b=Je=>{o(Je),bt({agentWebToolEnabled:Je})},t[2]=o,t[3]=b):b=t[3];const w=b;let k;t[4]!==g?(k=Je=>{g(Je),bt({agentNotifyToolEnabled:Je})},t[4]=g,t[5]=k):k=t[5];const I=k;let y;t[6]!==j?(y=Je=>{j(Je),bt({agentToolsCodeMode:Je})},t[6]=j,t[7]=y):y=t[7];const E=y;let v;t[8]===Symbol.for("react.memo_cache_sentinel")?(v=[],t[8]=v):v=t[8],Ge.useEffect(bw,v);let R;t[9]!==l?(R=sw(l),t[9]=l,t[10]=R):R=t[10];const C=R;let T;t[11]!==r||t[12]!==C?(T=C.some(Je=>Je.id===r)?r:Er,t[11]=r,t[12]=C,t[13]=T):T=t[13];const P=T;let L;t[14]!==c?(L=Je=>{c(Je),bt({browserProvider:Je})},t[14]=c,t[15]=L):L=t[15];const O=L;let A;t[16]!==f?(A=Je=>{f(Je),bt({agentMemoryToolEnabled:Je}).finally(()=>{Je&&Kp.getState().refresh()})},t[16]=f,t[17]=A):A=t[17];const N=A;let M;t[18]!==e?(M=e("settings.openchamber.tools.title"),t[18]=e,t[19]=M):M=t[19];let F;t[20]!==e?(F=e("settings.openchamber.tools.field.agentControlTool"),t[20]=e,t[21]=F):F=t[21];let H;t[22]!==e?(H=e("settings.openchamber.tools.field.agentControlToolSummary"),t[22]=e,t[23]=H):H=t[23];let W;t[24]!==e?(W=e("settings.openchamber.tools.field.agentControlToolInfo"),t[24]=e,t[25]=W):W=t[25];let G;t[26]!==e?(G=e("settings.openchamber.tools.field.agentControlToolAria"),t[26]=e,t[27]=G):G=t[27];let $;t[28]!==n||t[29]!==S||t[30]!==F||t[31]!==H||t[32]!==W||t[33]!==G?($=s.jsx(ro,{icon:"node-tree",settingsItem:"sessions.agent-control-tool",checked:n,onChange:S,title:F,summary:H,info:W,ariaLabel:G}),t[28]=n,t[29]=S,t[30]=F,t[31]=H,t[32]=W,t[33]=G,t[34]=$):$=t[34];let z;t[35]!==e?(z=e("settings.openchamber.tools.field.agentWebTool"),t[35]=e,t[36]=z):z=t[36];let U;t[37]!==e?(U=e("settings.openchamber.tools.field.agentWebToolSummary"),t[37]=e,t[38]=U):U=t[38];let _;t[39]!==e?(_=e("settings.openchamber.tools.field.agentWebToolInfo"),t[39]=e,t[40]=_):_=t[40];let V;t[41]!==e?(V=e("settings.openchamber.tools.field.agentWebToolAria"),t[41]=e,t[42]=V):V=t[42];let Z;t[43]!==i||t[44]!==w||t[45]!==z||t[46]!==U||t[47]!==_||t[48]!==V?(Z=s.jsx(ro,{icon:"global",settingsItem:"sessions.agent-web-tool",checked:i,onChange:w,title:z,summary:U,info:_,ariaLabel:V}),t[43]=i,t[44]=w,t[45]=z,t[46]=U,t[47]=_,t[48]=V,t[49]=Z):Z=t[49];let Y;t[50]===Symbol.for("react.memo_cache_sentinel")?(Y=je("flex min-w-0 items-center gap-2 pb-3 pr-4",nw),t[50]=Y):Y=t[50];let Q;t[51]!==e?(Q=e("settings.openchamber.tools.browserProvider.label"),t[51]=e,t[52]=Q):Q=t[52];let ue;t[53]!==Q?(ue=s.jsx("span",{className:"truncate typography-meta text-muted-foreground",children:Q}),t[53]=Q,t[54]=ue):ue=t[54];let ge;t[55]!==e?(ge=e("settings.openchamber.tools.browserProvider.info"),t[55]=e,t[56]=ge):ge=t[56];let fe;t[57]!==ge?(fe=s.jsx(Wt,{children:ge}),t[57]=ge,t[58]=fe):fe=t[58];const Ie=!i||C.length===0;let te;t[59]!==e?(te=e("settings.openchamber.tools.browserProvider.aria"),t[59]=e,t[60]=te):te=t[60];let Ce;t[61]!==C||t[62]!==e?(Ce=s.jsx($t,{children:Je=>Je===Er?e("settings.openchamber.tools.browserProvider.option.builtin"):C.find(ut=>ut.id===Je)?.name??null}),t[61]=C,t[62]=e,t[63]=Ce):Ce=t[63];let ie;t[64]!==te||t[65]!==Ce?(ie=s.jsx(Tt,{size:qt,className:"ml-auto w-auto min-w-0 max-w-[14rem]","aria-label":te,children:Ce}),t[64]=te,t[65]=Ce,t[66]=ie):ie=t[66];let ae;t[67]!==e?(ae=e("settings.openchamber.tools.browserProvider.option.builtin"),t[67]=e,t[68]=ae):ae=t[68];let re;t[69]!==ae?(re=s.jsx(dt,{value:Er,children:ae}),t[69]=ae,t[70]=re):re=t[70];let ye;t[71]!==C?(ye=C.map(vw),t[71]=C,t[72]=ye):ye=t[72];let Ee;t[73]!==re||t[74]!==ye?(Ee=s.jsxs(Et,{children:[re,ye]}),t[73]=re,t[74]=ye,t[75]=Ee):Ee=t[75];let Pe;t[76]!==O||t[77]!==P||t[78]!==Ie||t[79]!==ie||t[80]!==Ee?(Pe=s.jsxs(Dt,{value:P,onValueChange:O,disabled:Ie,children:[ie,Ee]}),t[76]=O,t[77]=P,t[78]=Ie,t[79]=ie,t[80]=Ee,t[81]=Pe):Pe=t[81];let ke;t[82]!==ue||t[83]!==fe||t[84]!==Pe?(ke=s.jsxs("div",{"data-settings-item":"sessions.browser-provider",className:Y,children:[ue,fe,Pe]}),t[82]=ue,t[83]=fe,t[84]=Pe,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 de;t[89]!==e?(de=e("settings.openchamber.tools.field.agentNotifyTool"),t[89]=e,t[90]=de):de=t[90];let Me;t[91]!==e?(Me=e("settings.openchamber.tools.field.agentNotifyToolSummary"),t[91]=e,t[92]=Me):Me=t[92];let Se;t[93]!==e?(Se=e("settings.openchamber.tools.field.agentNotifyToolInfo"),t[93]=e,t[94]=Se):Se=t[94];let Le;t[95]!==e?(Le=e("settings.openchamber.tools.field.agentNotifyToolAria"),t[95]=e,t[96]=Le):Le=t[96];let Ke;t[97]!==p||t[98]!==I||t[99]!==de||t[100]!==Me||t[101]!==Se||t[102]!==Le?(Ke=s.jsx(ro,{icon:"notification-3",settingsItem:"sessions.agent-notify-tool",checked:p,onChange:I,title:de,summary:Me,info:Se,ariaLabel:Le}),t[97]=p,t[98]=I,t[99]=de,t[100]=Me,t[101]=Se,t[102]=Le,t[103]=Ke):Ke=t[103];let oe;t[104]!==u||t[105]!==m||t[106]!==N||t[107]!==e?(oe=u?s.jsx(ro,{icon:"brain",settingsItem:"sessions.agent-memory-tool",checked:m,onChange:N,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]=u,t[105]=m,t[106]=N,t[107]=e,t[108]=oe):oe=t[108];let le;t[109]!==$||t[110]!==Te||t[111]!==Ke||t[112]!==oe?(le=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:[$,Te,Ke,oe]}),t[109]=$,t[110]=Te,t[111]=Ke,t[112]=oe,t[113]=le):le=t[113];let xe;t[114]!==e?(xe=e("settings.openchamber.tools.field.agentToolsCodeMode"),t[114]=e,t[115]=xe):xe=t[115];let De;t[116]!==e?(De=e("settings.openchamber.tools.field.agentToolsCodeModeAria"),t[116]=e,t[117]=De):De=t[117];let Ve;t[118]!==e?(Ve=e("settings.openchamber.tools.field.agentToolsCodeModeInfo"),t[118]=e,t[119]=Ve):Ve=t[119];let Be;t[120]!==h||t[121]!==E||t[122]!==xe||t[123]!==De||t[124]!==Ve?(Be=s.jsx(ct,{className:"mt-4",settingsItem:"sessions.agent-tools-code-mode",checked:h,onChange:E,label:xe,ariaLabel:De,info:Ve}),t[120]=h,t[121]=E,t[122]=xe,t[123]=De,t[124]=Ve,t[125]=Be):Be=t[125];let Ne;return t[126]!==le||t[127]!==Be||t[128]!==M?(Ne=s.jsxs(qe,{title:M,children:[le,Be]}),t[126]=le,t[127]=Be,t[128]=M,t[129]=Ne):Ne=t[129],Ne};function aw(t){return t.agentControlToolEnabled}function iw(t){return t.setAgentControlToolEnabled}function ow(t){return t.agentWebToolEnabled}function rw(t){return t.setAgentWebToolEnabled}function lw(t){return t.browserProvider}function cw(t){return t.setBrowserProvider}function dw(t){return t.guests}function uw(t){return t.agentMemoryToolEnabled}function mw(t){return t.agentMemoryFeatureAvailable}function pw(t){return t.setAgentMemoryToolEnabled}function gw(t){return t.agentNotifyToolEnabled}function fw(t){return t.setAgentNotifyToolEnabled}function hw(t){return t.agentToolsCodeMode}function xw(t){return t.setAgentToolsCodeMode}function bw(){cn()}function vw(t){return s.jsx(dt,{value:t.id,children:t.name},t.id)}const tm=new Set(["shift","control","alt","meta"]),Il=3,yw=3e3;function Pl(t,e=!1){const n=new Set;return t.altKey&&n.add("alt"),t.ctrlKey&&n.add("control"),t.metaKey&&n.add("meta"),t.shiftKey&&n.add("shift"),e&&n.add(t.key.toLowerCase()),n.size}function jw(t){return t.action.customizable}function xd(t){if(Pl(t)>Il)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Po(e.join("+")):null}function kw(t){if(tm.has(t.key.toLowerCase())||Pl(t,!0)>Il)return null;const e=$p(_p(t));if(!e)return null;const n=[];return(t.metaKey||t.ctrlKey)&&n.push("mod"),t.shiftKey&&n.push("shift"),t.altKey&&n.push("alt"),n.push(e),Po(n.join("+"))}function ww(t){const e=t.key.toLowerCase();if(!tm.has(e)||Pl(t,!0)>Il)return null;const n=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&n.push("mod"),(t.shiftKey||e==="shift")&&n.push("shift"),(t.altKey||e==="alt")&&n.push("alt"),n.length>0?Po(n.join("+")):null}function bd(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Sw(t,e,n,a=2){if(e.repeat||e.isComposing)return t;if(n==="keyup")return{...t,livePreview:xd(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const i=kw(e);if(i){if(t.settled){const r=[i];return{chords:r,livePreview:null,settled:r.length>=a}}const o=t.chords.length<a?[...t.chords,i]:t.chords;return{chords:o,livePreview:null,settled:o.length>=a}}return{...t,livePreview:xd(e)}}const sm=t=>{const e=$e.c(120),{action:n,overrides:a,onSave:i,onOpenChange:o,maxChords:r}=t,c=r===void 0?2:r,{t:l}=_e();let m;e[0]!==l?(m=ie=>l(ie.settingsLabelKey),e[0]=l,e[1]=m):m=e[1];const u=m;let f;e[2]!==u?(f=ie=>ie.action.customizable?u(ie.action):Jn(ie.action.defaultBinding),e[2]=u,e[3]=f):f=e[3];const p=f;let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g={chords:[],livePreview:null,settled:!1},e[4]=g):g=e[4];const[h,j]=d.useState(g),x=d.useRef(null);let S,b;e[5]!==n?(S=()=>{n&&(j({chords:[],livePreview:null,settled:!1}),x.current?.focus())},b=[n],e[5]=n,e[6]=S,e[7]=b):(S=e[6],b=e[7]),d.useEffect(S,b);const w=h.chords.length===1&&!h.settled;let k,I;e[8]!==w?(k=()=>{if(!w)return;const ie=window.setTimeout(()=>j(bd),yw);return()=>window.clearTimeout(ie)},I=[w],e[8]=w,e[9]=k,e[10]=I):(k=e[9],I=e[10]),d.useEffect(k,I);let y;e[11]!==h.chords?(y=Po(h.chords.join(" ")),e[11]=h.chords,e[12]=y):y=e[12];const E=y;let v;e[13]!==n||e[14]!==E||e[15]!==a?(v=n&&E?zp(n.id,E,a):[],e[13]=n,e[14]=E,e[15]=a,e[16]=v):v=e[16];const R=v;let C;e[17]!==R?(C=R.find(Nw),e[17]=R,e[18]=C):C=e[18];const T=C;let P,L,O,A,N,M,F,H,W,G,$,z,U,_,V;if(e[19]!==n||e[20]!==u||e[21]!==E||e[22]!==p||e[23]!==R||e[24]!==c||e[25]!==o||e[26]!==i||e[27]!==T||e[28]!==h||e[29]!==l){const ie=R.filter(jw);N=ie.find(Cw);const ae=ie.find(Iw),re=R.find(Pw);let ye;e[45]!==o?(ye=()=>o(!1),e[45]=o,e[46]=ye):ye=e[46],O=ye,A=()=>{h.settled||j(bd),!(!n||!E||T||N)&&(i(n.id,E,ae?.action.id),O())};let Ee;e[47]!==n||e[48]!==c||e[49]!==h?(Ee=(Be,Ne)=>{Be.preventDefault(),Be.stopPropagation();const Je=!!(n&&"prefixStyle"in n&&n.prefixStyle);if(Ne==="keyup"&&Je&&h.chords.length===0){const ht=ww(Be);if(ht){j({chords:[ht],livePreview:null,settled:!0});return}}const ut=Sw(h,{altKey:Be.altKey,code:Be.nativeEvent.code,ctrlKey:Be.ctrlKey,isComposing:Be.nativeEvent.isComposing,key:Be.key,metaKey:Be.metaKey,repeat:Be.repeat,shiftKey:Be.shiftKey},Ne,c);j(Je&&ut.chords.length>1?h:ut)},e[47]=n,e[48]=c,e[49]=h,e[50]=Ee):Ee=e[50];const Pe=Ee;L=zt,_=n!==null,V=Aw,P=Ut,M="max-w-md",F=x,H=!1;let ke;e[51]!==n||e[52]!==u||e[53]!==l?(ke=n?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:u(n)}):"",e[51]=n,e[52]=u,e[53]=l,e[54]=ke):ke=e[54];let Te;e[55]!==ke?(Te=s.jsx(Vt,{children:ke}),e[55]=ke,e[56]=Te):Te=e[56];const de=c===1?"settings.openchamber.keyboardShortcuts.dialog.instructionsSingle":"settings.openchamber.keyboardShortcuts.dialog.instructions";let Me;e[57]!==l||e[58]!==de?(Me=l(de),e[57]=l,e[58]=de,e[59]=Me):Me=e[59];let Se;e[60]!==Me?(Se=s.jsx(Ht,{children:Me}),e[60]=Me,e[61]=Se):Se=e[61],e[62]!==Te||e[63]!==Se?(W=s.jsxs(Bt,{children:[Te,Se]}),e[62]=Te,e[63]=Se,e[64]=W):W=e[64];let Le,Ke;e[65]!==Pe?(Le=Be=>Pe(Be,"keydown"),Ke=Be=>Pe(Be,"keyup"),e[65]=Pe,e[66]=Le,e[67]=Ke):(Le=e[66],Ke=e[67]);let oe;e[68]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>j(Tw),e[68]=oe):oe=e[68];let le;e[69]!==h.chords?(le=h.chords.map(Ew),e[69]=h.chords,e[70]=le):le=e[70];let xe;e[71]!==h.livePreview?(xe=h.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:Jn(h.livePreview)}):null,e[71]=h.livePreview,e[72]=xe):xe=e[72];let De;e[73]!==h.chords.length||e[74]!==h.livePreview||e[75]!==l?(De=h.chords.length===0&&!h.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[73]=h.chords.length,e[74]=h.livePreview,e[75]=l,e[76]=De):De=e[76];let Ve;e[77]!==le||e[78]!==xe||e[79]!==De?(Ve=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[le,xe,De]}),e[77]=le,e[78]=xe,e[79]=De,e[80]=Ve):Ve=e[80],e[81]!==Le||e[82]!==Ke||e[83]!==Ve?(G=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:Le,onKeyUp:Ke,onBlur:oe,children:Ve}),e[81]=Le,e[82]=Ke,e[83]=Ve,e[84]=G):G=e[84],$=h.settled&&T?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):h.settled&&N?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:u(N.action)})}):null,z=h.settled&&ae&&!T&&!N?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:u(ae.action)})}):null,U=h.settled&&re&&!T&&!N?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:p(re)})}):null,e[19]=n,e[20]=u,e[21]=E,e[22]=p,e[23]=R,e[24]=c,e[25]=o,e[26]=i,e[27]=T,e[28]=h,e[29]=l,e[30]=P,e[31]=L,e[32]=O,e[33]=A,e[34]=N,e[35]=M,e[36]=F,e[37]=H,e[38]=W,e[39]=G,e[40]=$,e[41]=z,e[42]=U,e[43]=_,e[44]=V}else P=e[30],L=e[31],O=e[32],A=e[33],N=e[34],M=e[35],F=e[36],H=e[37],W=e[38],G=e[39],$=e[40],z=e[41],U=e[42],_=e[43],V=e[44];let Z;e[85]!==E||e[86]!==h.settled||e[87]!==l?(Z=h.settled&&E&&Up(E)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[85]=E,e[86]=h.settled,e[87]=l,e[88]=Z):Z=e[88];let Y;e[89]!==l?(Y=l("settings.common.actions.cancel"),e[89]=l,e[90]=Y):Y=e[90];let Q;e[91]!==O||e[92]!==Y?(Q=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:O,children:Y}),e[91]=O,e[92]=Y,e[93]=Q):Q=e[93];const ue=!E||h.settled&&(!!T||!!N);let ge;e[94]!==l?(ge=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[94]=l,e[95]=ge):ge=e[95];let fe;e[96]!==A||e[97]!==ue||e[98]!==ge?(fe=s.jsx(B,{type:"button",size:"sm",disabled:ue,onClick:A,children:ge}),e[96]=A,e[97]=ue,e[98]=ge,e[99]=fe):fe=e[99];let Ie;e[100]!==Q||e[101]!==fe?(Ie=s.jsxs(ns,{children:[Q,fe]}),e[100]=Q,e[101]=fe,e[102]=Ie):Ie=e[102];let te;e[103]!==P||e[104]!==M||e[105]!==F||e[106]!==H||e[107]!==W||e[108]!==G||e[109]!==$||e[110]!==z||e[111]!==U||e[112]!==Z||e[113]!==Ie?(te=s.jsxs(P,{className:M,initialFocus:F,showCloseButton:H,children:[W,G,$,z,U,Z,Ie]}),e[103]=P,e[104]=M,e[105]=F,e[106]=H,e[107]=W,e[108]=G,e[109]=$,e[110]=z,e[111]=U,e[112]=Z,e[113]=Ie,e[114]=te):te=e[114];let Ce;return e[115]!==L||e[116]!==_||e[117]!==V||e[118]!==te?(Ce=s.jsx(L,{open:_,onOpenChange:V,children:te}),e[115]=L,e[116]=_,e[117]=V,e[118]=te,e[119]=Ce):Ce=e[119],Ce};function Nw(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Cw(t){return t.kind==="prefix"}function Iw(t){return t.kind==="exact"}function Pw(t){return t.kind==="contextual-prefix"}function Aw(t,e){t||e.cancel()}function Tw(t){return{...t,livePreview:null}}function Ew(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:Jn(t)},`${t}-${e}`)}const nm=()=>{const{t}=_e(),e=cs()&&Xa(),n=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[i,o]=Ge.useState(!1),[r,c]=Ge.useState(!1),[l,m]=Ge.useState(!1),[u,f]=Ge.useState(""),[p,g]=Ge.useState(!1),[h,j]=Ge.useState(!1),[x,S]=Ge.useState(null),[b,w]=Ge.useState(!0),[k,I]=Ge.useState(!1),[y,E]=Ge.useState(!1),[v,R]=Ge.useState(!1),[C,T]=Ge.useState(!1),[P,L]=Ge.useState(!1),[O,A]=Ge.useState(!1),[N,M]=Ge.useState(!1),[F,H]=Ge.useState(!0),[W,G]=Ge.useState(!0),[$,z]=Ge.useState(!1),[U,_]=Ge.useState(!1),[V,Z]=Ge.useState(!1),[Y,Q]=Ge.useState(!1),[ue,ge]=Ge.useState(!1),[fe,Ie]=Ge.useState(!1),[te,Ce]=Ge.useState(null),[ie,ae]=Ge.useState(!1),[re,ye]=Ge.useState(!1),[Ee,Pe]=Ge.useState(!1),ke=ne(be=>be.shortcutOverrides),Te=ne(be=>be.setShortcutOverride),de=Ge.useMemo(()=>Vd().find(be=>be.id==="mini_chat_global")??null,[]),[Me,Se]=Ge.useState(null),[Le,Ke]=Ge.useState(null);Ge.useEffect(()=>{if(!e){w(!1);return}let be=!1;return(async()=>{try{const Re=await yn();if(!Re)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(be)return;const X=Re.desktopLanAccessEnabled===!0;o(X),c(X),m(Re.hasDesktopUiPassword===!0),f(""),g(!1),j(Re.desktopLanAccessActive===!0),S(Re.desktopLanAccessBlockedReason??null);const ce=Re.desktopMacMenuBarEnabled!==!1;H(ce),G(ce);const Oe=Re.desktopLinuxNativeFrame===!0;z(Oe),_(Oe),Se(null)}catch(Re){be||Se(Re instanceof Error?Re.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{be||w(!1)}})(),()=>{be=!0}},[e,t]),Ge.useEffect(()=>{if(!e){E(!1);return}let be=!1;return(async()=>{const Re=await yg();be||(E(Re?.supported===!0),R(Re?.enabled===!0))})(),()=>{be=!0}},[e]),Ge.useEffect(()=>{if(!e){L(!1);return}let be=!1;return(async()=>{const Re=await jg();be||(L(Re?.supported===!0),A(Re?.enabled===!0))})(),()=>{be=!0}},[e]),Ge.useEffect(()=>{if(!e){Z(!1);return}let be=!1;return(async()=>{const Re=await kg();be||(Z(Re?.supported===!0),Q(Re?.enabled===!0))})(),()=>{be=!0}},[e]),Ge.useEffect(()=>{if(!e){Ie(!1);return}let be=!1;return(async()=>{const Re=await Zd();be||(Ie(Re?.supported===!0),Ce(Re?.combo??null),ae(Re?.active===!0))})(),()=>{be=!0}},[e]),Ge.useEffect(()=>{if(!e||!r){Ke(null);return}let be=!1;return(async()=>{const Re=await Wd();be||Ke(Re)})(),()=>{be=!0}},[r,e]);const oe=u.trim(),le=oe.length>0||p,xe=r!==i||le||W!==F||U!==$,De=Ge.useMemo(()=>{if(typeof window>"u")return null;const Re=Ii()||window.location.href;let X=0;try{X=Number(new URL(Re).port)}catch{X=Number(window.location.port)}return Number.isFinite(X)&&X>0?X:null},[]),Ve=r&&h&&Le&&De?`http://${Le}:${De}`:null,Be=oe.length>0||l&&!p,Ne=r&&!Be,Je=i&&!h&&x==="missing-password",ut=Ni(be=>be.networkAccessBlocked)||x==="enterprise-mode",ht=b||k||!xe||Ne,st=Ge.useCallback(be=>{f(be),be.trim()&&g(!1)},[]),jt=Ge.useCallback(()=>{f(""),g(!0),c(!1)},[]),St=Ge.useCallback(async()=>{if(!y||C)return;const be=!v;R(be),T(!0),Se(null);try{const Re=await wg(be);if(!Re?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));R(Re.enabled)}catch(Re){R(!be),Se(Re instanceof Error?Re.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[C,v,y,t]),Ze=Ge.useCallback(async()=>{if(!P||N)return;const be=!O;A(be),M(!0),Se(null);try{const Re=await Sg(be);if(!Re)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Re.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));A(Re.enabled)}catch(Re){A(!be),Se(Re instanceof Error?Re.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{M(!1)}},[N,O,P,t]),it=Ge.useCallback(async()=>{if(!V||ue)return;const be=!Y;Q(be),ge(!0),Se(null);try{const Re=await Ng(be);if(!Re?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));Q(Re.enabled)}catch(Re){Q(!be),Se(Re instanceof Error?Re.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{ge(!1)}},[ue,Y,V,t]),et=Ge.useCallback(async be=>{if(!fe||re)return!1;ye(!0),Se(null);try{const Re=await Xd(be);if(!Re?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutSaveFailed"));return Ce(Re.combo??null),ae(Re.active===!0),Re.error==="unsupported-combo"?(Se(t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutUnsupported")),!1):!0}catch(Re){return Se(Re instanceof Error?Re.message:t("settings.openchamber.desktopNetwork.error.miniChatGlobalShortcutSaveFailed")),!1}finally{ye(!1)}},[re,fe,t]),mt=Ge.useCallback((be,Re,X)=>{et(Re).then(ce=>{!ce||!X||(Te(X,yi),bt({shortcutOverrides:{...ke,[X]:yi}}))})},[et,Te,ke]),ft=Ge.useCallback(async()=>{if(xe){I(!0),Se(null);try{if(!(await bt({desktopLanAccessEnabled:r,...oe?{desktopUiPassword:oe}:p?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:W,desktopLinuxNativeFrame:U})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(o(r),oe?m(!0):p&&m(!1),f(""),g(!1),H(W),z(U),!await Cg())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(be){Se(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),I(!1)}}},[U,W,r,xe,oe,p,t]);return e?s.jsxs(qe,{title:t("settings.openchamber.desktopNetwork.title"),children:[s.jsxs("div",{className:"space-y-3",children:[y||n||a||P||V||fe?s.jsxs("div",{className:xs,children:[y?s.jsx(ct,{settingsItem:"sessions.desktop-launch-at-login",checked:v,onChange:be=>{be!==v&&St()},disabled:C,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,n?s.jsx(ct,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:G,disabled:b||k,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,a?s.jsx(ct,{settingsItem:"sessions.desktop-linux-native-frame",checked:U,onChange:_,disabled:b||k,label:t("settings.openchamber.desktopNetwork.field.linuxNativeFrame"),info:t("settings.openchamber.desktopNetwork.field.linuxNativeFrameDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.linuxNativeFrame")}):null,P?s.jsx(ct,{settingsItem:"sessions.desktop-minimize-to-tray",checked:O,onChange:be=>{be!==O&&Ze()},disabled:N,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,V?s.jsx(ct,{settingsItem:"sessions.desktop-keep-awake",checked:Y,onChange:be=>{be!==Y&&it()},disabled:ue,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null,fe?s.jsxs(yt,{settingsItem:"sessions.desktop-mini-chat-global-shortcut",label:t("settings.openchamber.desktopNetwork.field.miniChatGlobalShortcut"),info:t("settings.openchamber.desktopNetwork.field.miniChatGlobalShortcutDescription"),description:te&&!ie?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:te?Jn(te):t("settings.openchamber.keyboardShortcuts.unassigned")}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",disabled:re,onClick:()=>Pe(!0),children:t("settings.openchamber.keyboardShortcuts.actions.edit")}),te?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",disabled:re,onClick:()=>{et(null)},children:t("settings.common.actions.reset")}):null]}):null]}):null,s.jsxs(Rt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:u,onChange:be=>st(be.target.value),placeholder:t(l&&!p?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:b||k,required:r&&!Be,"aria-invalid":Ne}),l&&!p?s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:jt,disabled:b||k,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:xs,children:s.jsx(ct,{settingsItem:"sessions.desktop-lan-access",checked:r&&!ut,onChange:c,disabled:b||k||ut,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:ut?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")}),Ne||Je?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")})}),Me?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Me}):null,Ve&&!ut?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(xe&&!i?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:Ve})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:ft,disabled:ht,className:"shrink-0 !font-normal",children:t(k?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]}),s.jsx(sm,{action:Ee?de:null,overrides:ke,onSave:mt,onOpenChange:be=>{be||Pe(!1)},maxChords:1})]}):null},Dw=["session","models","panels","navigation","application"],Mw=()=>{const t=$e.c(30),{t:e}=_e(),n=ne(Rw),a=ne(Lw),i=ne(Ow),o=ne(Fw),[r,c]=d.useState(null),[l,m]=d.useState(null);let u;t[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{Zd().then(P=>m(P?.combo??null)).catch(Kw)},t[0]=u):u=t[0];const f=u;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);let h;t[3]===Symbol.for("react.memo_cache_sentinel")?(h=Vd(),t[3]=h):h=t[3];const j=h,x=zw;let S;t[4]!==a||t[5]!==n?(S=(P,L,O)=>{const A={...n,[P]:L};a(P,L),O==="mini_chat_global"?Xd(null).then(N=>{N&&m(N.combo)}):O&&(A[O]=yi,a(O,yi)),x(A)},t[4]=a,t[5]=n,t[6]=S):S=t[6];const b=S;let w;t[7]!==i||t[8]!==n?(w=P=>{const L={...n};delete L[P],i(P),x(L)},t[7]=i,t[8]=n,t[9]=w):w=t[9];const k=w;let I;t[10]!==n||t[11]!==e?(I=P=>{const L="prefixStyle"in P&&P.prefixStyle,O=L?Bp(P.id,n):Hd(P.id,n),A=Jn(O,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!L||!O||O===yi)return A;const N=P.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${A}${N}`},t[10]=n,t[11]=e,t[12]=I):I=t[12];const y=I;let E;t[13]!==o||t[14]!==k||t[15]!==y||t[16]!==n||t[17]!==e?(E=Dw.map((P,L)=>{const O=j.filter(A=>A.category===P);return O.length===0?null:s.jsx(qe,{settingsItem:L===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${P}`),divider:L!==0,info:L===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:L===0?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{o(),x({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:O.map(A=>s.jsxs(yt,{label:e(A.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:y(A)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{f(),c(A)},children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),A.id in n?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>k(A.id),children:e("settings.common.actions.reset")}):null]},A.id))})},P)}),t[13]=o,t[14]=k,t[15]=y,t[16]=n,t[17]=e,t[18]=E):E=t[18];let v;t[19]!==l||t[20]!==n?(v=l?{...n,mini_chat_global:l}:n,t[19]=l,t[20]=n,t[21]=v):v=t[21];let R;t[22]===Symbol.for("react.memo_cache_sentinel")?(R=P=>{P||c(null)},t[22]=R):R=t[22];let C;t[23]!==r||t[24]!==b||t[25]!==v?(C=s.jsx(sm,{action:r,overrides:v,onSave:b,onOpenChange:R}),t[23]=r,t[24]=b,t[25]=v,t[26]=C):C=t[26];let T;return t[27]!==C||t[28]!==E?(T=s.jsxs(s.Fragment,{children:[E,C]}),t[27]=C,t[28]=E,t[29]=T):T=t[29],T};function Rw(t){return t.shortcutOverrides}function Lw(t){return t.setShortcutOverride}function Ow(t){return t.clearShortcutOverride}function Fw(t){return t.resetAllShortcutOverrides}function Kw(){}function zw(t){bt({shortcutOverrides:t})}const am=()=>{const t=$e.c(2),[e,n]=d.useState(0);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Ao(()=>n(Yw)),i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),d.useEffect(a,i),e},Uw=t=>{const e=$e.c(91),{section:n}=t,{t:a}=_e(),{isMobile:i}=Qn(),o=am();let r;e[0]!==i?(r=i&&ba(),e[0]=i,e[1]=r):r=e[1];const c=r;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=os(),e[2]=l):l=e[2];const m=l;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=cs()&&Xa(),e[3]=u):u=e[3];const f=u;if(!n){let z;e[4]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(Mo,{}),e[4]=z):z=e[4];let U;e[5]!==o?(U=s.jsx(Ju,{},o),e[5]=o,e[6]=U):U=e[6];let _,V,Z;e[7]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(qu,{}),V=f&&s.jsx(nm,{}),Z=!m&&s.jsx(Zu,{}),e[7]=_,e[8]=V,e[9]=Z):(_=e[7],V=e[8],Z=e[9]);let Y;e[10]!==o?(Y=!m&&s.jsx(Xu,{},o),e[10]=o,e[11]=Y):Y=e[11];let Q,ue,ge,fe,Ie;e[12]===Symbol.for("react.memo_cache_sentinel")?(Q=!m&&s.jsx(em,{}),ue=s.jsx(Vu,{}),ge=!m&&s.jsx(Hu,{}),fe=s.jsx(Gu,{}),Ie=ba()&&!cs()&&!m&&!cl()&&s.jsx(Wu,{}),e[12]=Q,e[13]=ue,e[14]=ge,e[15]=fe,e[16]=Ie):(Q=e[12],ue=e[13],ge=e[14],fe=e[15],Ie=e[16]);let te;e[17]!==c?(te=c&&s.jsx(su,{}),e[17]=c,e[18]=te):te=e[18];let Ce;return e[19]!==te||e[20]!==U||e[21]!==Y?(Ce=s.jsxs(es,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[z,U,_,V,Z,Y,Q,ue,ge,fe,Ie,te]}),e[19]=te,e[20]=U,e[21]=Y,e[22]=Ce):Ce=e[22],Ce}let p;e[23]!==o||e[24]!==n?(p=()=>{switch(n){case"general":return s.jsx(_w,{});case"visual":return s.jsx(Bw,{});case"chat":return s.jsx(Vw,{});case"sessions":return s.jsx(Hw,{runtimeEndpointEpoch:o});case"shortcuts":return s.jsx($w,{});case"git":return s.jsx(qw,{});case"notifications":return s.jsx(Ww,{});case"voice":return s.jsx(Gw,{});case"tunnel":return s.jsx(Qw,{});case"spaces":return s.jsx(Jw,{});default:return null}},e[23]=o,e[24]=n,e[25]=p):p=e[25];const g=p;let h;e[26]!==a?(h=a("settings.page.general.title"),e[26]=a,e[27]=h):h=e[27];let j;e[28]!==a?(j=a("settings.page.appearance.title"),e[28]=a,e[29]=j):j=e[29];let x;e[30]!==a?(x=a("settings.page.chat.title"),e[30]=a,e[31]=x):x=e[31];let S;e[32]!==a?(S=a("settings.page.sessions.title"),e[32]=a,e[33]=S):S=e[33];let b;e[34]!==a?(b=a("settings.page.shortcuts.title"),e[34]=a,e[35]=b):b=e[35];let w;e[36]!==a?(w=a("settings.page.git.title"),e[36]=a,e[37]=w):w=e[37];let k;e[38]!==a?(k=a("settings.page.git.title"),e[38]=a,e[39]=k):k=e[39];let I;e[40]!==a?(I=a("settings.page.notifications.title"),e[40]=a,e[41]=I):I=e[41];let y;e[42]!==a?(y=a("settings.page.voice.title"),e[42]=a,e[43]=y):y=e[43];let E;e[44]!==a?(E=a("settings.page.tunnel.title"),e[44]=a,e[45]=E):E=e[45];let v;e[46]!==a?(v=a("settings.openchamber.spaces.title"),e[46]=a,e[47]=v):v=e[47];let R;e[48]!==w||e[49]!==k||e[50]!==I||e[51]!==y||e[52]!==E||e[53]!==v||e[54]!==h||e[55]!==j||e[56]!==x||e[57]!==S||e[58]!==b?(R={general:h,visual:j,chat:x,sessions:S,shortcuts:b,git:w,github:k,notifications:I,voice:y,tunnel:E,spaces:v},e[48]=w,e[49]=k,e[50]=I,e[51]=y,e[52]=E,e[53]=v,e[54]=h,e[55]=j,e[56]=x,e[57]=S,e[58]=b,e[59]=R):R=e[59];const C=R[n];let T;e[60]!==a?(T=a("settings.page.general.description"),e[60]=a,e[61]=T):T=e[61];let P;e[62]!==a?(P=a("settings.page.appearance.description"),e[62]=a,e[63]=P):P=e[63];let L;e[64]!==a?(L=a("settings.page.chat.description"),e[64]=a,e[65]=L):L=e[65];let O;e[66]!==a?(O=a("settings.page.sessions.description"),e[66]=a,e[67]=O):O=e[67];let A;e[68]!==a?(A=a("settings.page.shortcuts.description"),e[68]=a,e[69]=A):A=e[69];let N;e[70]!==a?(N=a("settings.page.notifications.description"),e[70]=a,e[71]=N):N=e[71];let M;e[72]!==a?(M=a("settings.page.voice.description"),e[72]=a,e[73]=M):M=e[73];let F;e[74]!==a?(F=a("settings.page.tunnel.description"),e[74]=a,e[75]=F):F=e[75];let H;e[76]!==T||e[77]!==P||e[78]!==L||e[79]!==O||e[80]!==A||e[81]!==N||e[82]!==M||e[83]!==F?(H={general:T,visual:P,chat:L,sessions:O,shortcuts:A,git:void 0,github:void 0,notifications:N,voice:M,tunnel:F,spaces:void 0},e[76]=T,e[77]=P,e[78]=L,e[79]=O,e[80]=A,e[81]=N,e[82]=M,e[83]=F,e[84]=H):H=e[84];const W=H[n];let G;e[85]!==g?(G=g(),e[85]=g,e[86]=G):G=e[86];let $;return e[87]!==W||e[88]!==C||e[89]!==G?($=s.jsx(es,{title:C,description:W,showSaveStatus:!0,className:"openchamber-page-body",children:G}),e[87]=W,e[88]=C,e[89]=G,e[90]=$):$=e[90],$},$w=()=>{const t=$e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Mw,{}),t[0]=e):e=t[0],e},_w=()=>{const t=$e.c(14);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=os(),t[0]=e):e=t[0];const n=e,a=am();let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=cs()&&Xa(),t[1]=i):i=t[1];const o=i;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=ba()&&!cs()&&!n&&!cl(),t[2]=r):r=t[2];const c=r;let l,m,u,f;t[3]===Symbol.for("react.memo_cache_sentinel")?(l=o&&s.jsx(nm,{}),m=c&&s.jsx(Wu,{}),u=s.jsx(Gu,{}),f=!n&&s.jsx(Zu,{}),t[3]=l,t[4]=m,t[5]=u,t[6]=f):(l=t[3],m=t[4],u=t[5],f=t[6]);let p;t[7]!==a?(p=!n&&s.jsx(Xu,{},a),t[7]=a,t[8]=p):p=t[8];let g;t[9]===Symbol.for("react.memo_cache_sentinel")?(g=!n&&s.jsx(em,{}),t[9]=g):g=t[9];let h;t[10]===Symbol.for("react.memo_cache_sentinel")?(h=n?[]:["sessionTabs"],t[10]=h):h=t[10];let j;t[11]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Mo,{visibleSettings:["fileEditorKeymap",...h,"autoSaveEnabled",...n?[]:["terminalQuickKeys"],...n?[]:["terminalShell"],...n?[]:["terminalLoginShell"],"messageTransport","reportUsage"]}),t[11]=j):j=t[11];let x;return t[12]!==p?(x=s.jsxs(s.Fragment,{children:[l,m,u,f,p,g,j]}),t[12]=p,t[13]=x):x=t[13],x},Bw=()=>{const t=$e.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=os(),t[0]=e):e=t[0];const n=e;let a;return t[1]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Mo,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...n?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=a):a=t[1],a},Vw=()=>{const t=$e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Mo,{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},Hw=t=>{const e=$e.c(7),{runtimeEndpointEpoch:n}=t;let a;e[0]!==n?(a=s.jsx(Ju,{},n),e[0]=n,e[1]=a):a=e[1];let i,o,r;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(qu,{}),o=s.jsx(Vu,{}),r=!os()&&s.jsx(Hu,{}),e[2]=i,e[3]=o,e[4]=r):(i=e[2],o=e[3],r=e[4]);let c;return e[5]!==a?(c=s.jsxs(s.Fragment,{children:[a,i,o,r]}),e[5]=a,e[6]=c):c=e[6],c},qw=()=>{const t=$e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Nu,{}),t[0]=e):e=t[0],e},Ww=()=>{const t=$e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Rk,{}),t[0]=e):e=t[0],e},Gw=()=>{const t=$e.c(1);if(os())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Vk,{}),t[0]=e):e=t[0],e},Jw=()=>{if($e.c(1),os()||!zr)return null},Qw=()=>{const t=$e.c(1);if(os())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tw,{}),t[0]=e):e=t[0],e};function Yw(t){return t+1}const Zw=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.animated-activity-indicators",page:"appearance",titleKey:"settings.openchamber.visual.field.animatedActivityIndicators",descriptionKey:"settings.openchamber.visual.field.animatedActivityIndicatorsInfo",keywords:["spinner","animation","session","activity","motion","running","indicator"]},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue"],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.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.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-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&&zr},{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&&zr&&ne.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&&ne.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.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.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 vd(t){return t.trim().toLocaleLowerCase()}function Xw({query:t,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:i}){const o=vd(t);if(!o)return[];const r=n?new Set(n):null,c=o.split(/\s+/).filter(Boolean);return Zw.flatMap(l=>{if(r&&!r.has(l.page))return[];const m=Ua(l.page);if(!m||m.isAvailable&&!m.isAvailable(e)||l.isAvailable&&!l.isAvailable(e))return[];const u=a(l.titleKey),f=l.descriptionKey?a(l.descriptionKey):null,p=vd([u,f,i(l.page),...l.keywords??[]].filter(Boolean).join(" "));return c.every(g=>p.includes(g))?[{...l,title:u,description:f,pageTitle:i(l.page)}]:[]})}const yd=280,im="__openchamberSettingsDetail",e2=30,t2=["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"],s2=["general","projects","opencode","content"];function n2(t,e,n,a,i){const o=os(),r=!t&&ba();return{isVSCode:o,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:n,enterpriseMode:a,jevBlockedByEnterprise:i}}function jd(t,e){return t.isAvailable?t.isAvailable(e):!0}function fi(t,e){const n=new Set(e);let a=t,i=1;for(;n.has(a);)a=`${t}-${i}`,i+=1;return a}function Dr(t){const e=t?.[im];return e?.page==null||e.stage!=="page-content"?null:{page:Ur(e.page),stage:e.stage}}function a2(){return window.history.state??{}}const y2=({onClose:t,forceMobile:e,isWindowed:n,visiblePageSlugs:a,initialMobileStage:i="nav",registerBackHandler:o})=>{const{t:r}=_e(),c=Qn(),l=e??c.isMobile,m=ne(oe=>oe.settingsPage),u=ne(oe=>oe.isSettingsDialogOpen),f=ne(oe=>oe.setSettingsPage),p=ne(oe=>oe.shortcutOverrides.open_settings),g=Ur(m),[h,j]=d.useState(i),x=d.useRef(i==="nav"?g:null);d.useEffect(()=>{!l&&g==="home"&&f("general")},[l,f,g]);const[S,b]=d.useState(""),[w,k]=d.useState(null),[I,y]=d.useState(0),E=d.useRef(null),v=d.useRef(!1),R=d.useRef([]),C=d.useRef(0),T=d.useRef(!1),P=d.useMemo(()=>cs(),[]),L=d.useMemo(()=>cs()&&Xa(),[]),O=d.useMemo(()=>cs()&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),A=d.useMemo(()=>cs()&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),N=d.useMemo(()=>cs()&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),M=ne(oe=>oe.routingFeatureAvailable),F=zn(),H=Vp(),W=d.useMemo(()=>n2(P,l,M,F,H),[P,l,M,F,H]),G=d.useMemo(()=>{const oe=a?new Set(a):null;return zg.filter(le=>le.slug!=="home").filter(le=>!oe||oe.has(le.slug)).filter(le=>jd(le,W)).filter(le=>!(W.isVSCode&&le.slug==="projects")).filter(le=>!(l&&le.slug==="shortcuts"))},[W,l,a]),$=d.useMemo(()=>{const oe=new Map(t2.map((le,xe)=>[le,xe]));return G.slice().sort((le,xe)=>(oe.get(le.slug)??999)-(oe.get(xe.slug)??999))},[G]),z=un(oe=>oe.activeProjectId),U=Zs();d.useEffect(()=>{if(!(!u&&!W.isVSCode&&!n)){if(g==="agents"){Rn.getState().loadAgents(U);return}if(g==="commands"){qa.getState().loadCommands(U);return}if(g==="mcp"){Tn.getState().loadMcpConfigs({directory:U});return}if(g==="plugins"){Ft.getState().loadPlugins();return}(g==="skills.installed"||g==="skills.catalog")&&(tn.getState().loadSkills(U),Pn.getState().loadCatalog()),g==="snippets"&&ho.getState().loadSnippets()}},[z,u,n,W.isVSCode,U,g]);const _=d.useCallback(oe=>{if(f(oe),x.current=oe,!l)return;const le=Ua(oe);if(!le||le.slug==="home"){j("nav");return}j(le.kind==="split"?"page-sidebar":"page-content")},[l,f]),V=d.useMemo(()=>Ua(g),[g]),Z=d.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel","isolated-spaces":"spaces"}),[]),Y=d.useCallback(oe=>{switch(oe){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]),Q=d.useMemo(()=>Xw({query:S,runtimeCtx:{...W,isDesktopLocalOrigin:L,isMac:O,isWindows:A,isLinux:N},visiblePageSlugs:a,t:r,getPageTitle:Y}),[Y,L,O,A,N,W,S,r,a]),ue=d.useCallback(oe=>{if(oe.id.startsWith("agents.")){const le=Rn.getState(),xe=fi("new-agent",le.agents.map(De=>De.name));return le.setAgentDraft({name:xe,scope:"user"}),le.setSelectedAgent(xe),oe.id==="agents.create"?"agents.name":oe.id}if(oe.id.startsWith("commands.")){const le=qa.getState(),xe=fi("new-command",le.commands.map(De=>De.name));return le.setCommandDraft({name:xe,scope:"user"}),le.setSelectedCommand(xe),oe.id==="commands.create"?"commands.name":oe.id}if(oe.id.startsWith("mcp.")){const le=Tn.getState(),xe=fi("new-mcp-server",le.mcpServers.map(De=>De.name));return le.setMcpDraft({name:xe,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}),le.setSelectedMcp(xe),oe.id==="mcp.create"?"mcp.server":oe.id}if(oe.id.startsWith("snippets.")){const le=ho.getState(),xe=fi("new-snippet",le.snippets.map(De=>De.name));return le.setSnippetDraft({name:xe,scope:"global"}),le.setSelectedSnippet(xe),oe.id==="snippets.create"?"snippets.content":oe.id}if(oe.id.startsWith("skills.")){const le=tn.getState(),xe=fi("new-skill",le.skills.map(De=>De.name));return le.setSkillDraft({name:xe,scope:"user",source:"opencode",description:"",instructions:""}),le.setSelectedSkill(xe),oe.id==="skills.create"?"skills.basic-information":oe.id}return oe.id==="providers.connect"&&ne.getState().setSettingsProvidersConnectRequested(!0),oe.id==="providers.classification"&&ne.getState().setSettingsProvidersClassificationRequested(!0),oe.id==="plugins.create"?"plugins.spec":oe.id},[]),ge=d.useMemo(()=>{const oe=[],le=new Map;for(const xe of Q){let De=le.get(xe.page);De||(De={page:xe.page,pageTitle:xe.pageTitle,results:[]},le.set(xe.page,De),oe.push(De)),De.results.push(xe)}return oe},[Q]);d.useEffect(()=>{y(0),C.current=0,T.current=!1},[S]),d.useEffect(()=>{C.current=I},[I]),d.useEffect(()=>{R.current[I]?.scrollIntoView({block:"nearest"})},[I]),d.useEffect(()=>{I>=Q.length&&y(Math.max(0,Q.length-1)),R.current.length=Q.length},[I,Q.length]);const fe=d.useCallback(oe=>{const le=ue(oe);k(le),_(oe.page),l&&j("page-content"),oe.id==="plugins.create"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[l,_,ue]),Ie=d.useCallback(oe=>{if(S.trim()){if(oe.key==="Escape"){oe.preventDefault(),b("");return}if(Q.length!==0){if(oe.key==="ArrowDown"){oe.preventDefault(),T.current=!0,y(le=>(le+1)%Q.length);return}if(oe.key==="ArrowUp"){oe.preventDefault(),T.current=!0,y(le=>(le-1+Q.length)%Q.length);return}if(oe.key==="Enter"){oe.preventDefault();const le=(C.current%Q.length+Q.length)%Q.length,xe=Q[le]??Q[0];xe&&fe(xe)}}}},[fe,S,Q]),te=ne(oe=>oe.settingsJumpRequest);d.useEffect(()=>{te&&(ne.getState().clearSettingsJumpRequest(),k(te.itemId),_(Ur(te.page)),l&&j("page-content"))},[l,_,te]),d.useEffect(()=>{const oe=w;if(!oe)return;let le=!1,xe=0,De=0;const Ve=()=>{if(le)return;const Be=globalThis.CSS?.escape?globalThis.CSS.escape(oe):oe.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Ne=E.current?.querySelector(`[data-settings-item="${Be}"]`);if(!Ne){xe+=1,xe<e2&&(De=window.requestAnimationFrame(Ve));return}k(null),Ne.scrollIntoView({block:"center",behavior:"smooth"}),Ne.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Ne.removeAttribute("data-settings-search-highlight")},1600)};return De=window.requestAnimationFrame(Ve),()=>{le=!0,window.cancelAnimationFrame(De)}},[w,g]);const Ce=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:Pd,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ie=d.useCallback((oe,le)=>{switch(oe){case"projects":return s.jsx(Eb,{onItemSelect:le.onItemSelect});case"agents":return s.jsx(bf,{onItemSelect:le.onItemSelect});case"commands":return s.jsx(rh,{onItemSelect:le.onItemSelect});case"skills.installed":return s.jsx(Qx,{onItemSelect:le.onItemSelect});case"usage":return s.jsx(yy,{onItemSelect:le.onItemSelect});case"magic-prompts":return s.jsx(Fy,{onItemSelect:le.onItemSelect});case"snippets":return s.jsx($y,{onItemSelect:le.onItemSelect});default:return null}},[]),ae=d.useCallback(oe=>{const le=Ua(oe);if(le&&!jd(le,W))return Ce();switch(oe){case"projects":return s.jsx(Ob,{});case"remote-instances":return s.jsx(ov,{});case"agents":return s.jsx(Bf,{});case"behavior":return s.jsx(Jf,{});case"commands":return s.jsx(gh,{});case"mcp":return s.jsx(ex,{});case"plugins":return s.jsx(Dx,{});case"skills.installed":return s.jsx(yc,{view:"installed"});case"skills.catalog":return s.jsx(yc,{view:"catalog"});case"providers":return s.jsx(by,{});case"web-search":return s.jsx(eh,{});case"usage":return s.jsx(Ly,{});case"about":return s.jsx(es,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(su,{})});case"magic-prompts":return s.jsx(Uy,{});case"snippets":return s.jsx(Hy,{});case"git":return s.jsx(Yy,{});case"integrations":return s.jsx(q1,{});case"routing":return s.jsx(ej,{});case"extensions":return s.jsx(mj,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":case"isolated-spaces":{const xe=Z[oe]??"visual";return s.jsx(Uw,{section:xe})}default:return null}},[Z,Ce,W,r]);d.useEffect(()=>{if(!l||h!=="nav"||g==="home"||x.current===g)return;const oe=Ua(g);!oe||oe.slug==="home"||(x.current=g,j(oe.kind==="split"?"page-sidebar":"page-content"))},[l,h,g]);const re=l&&h!=="nav",ye=l&&h==="page-content"&&V?.kind==="split",Ee=r(ye?"settings.view.actions.back":re?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),Pe=Hd("open_settings",p===void 0?void 0:{open_settings:p}),ke=Pe?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Jn(Pe)}):r("settings.view.actions.closeSettings"),Te=d.useCallback(oe=>{if(W.isVSCode)return;const le=Dr(window.history.state);le?.page===oe&&le.stage==="page-content"||window.history.pushState({...a2(),[im]:{page:oe,stage:"page-content"}},"",window.location.href)},[W.isVSCode]),de=d.useCallback(()=>{v.current=!0,j("page-content"),Te(g)},[Te,g]);d.useEffect(()=>{if(!l||h!=="page-content"||!v.current)return;v.current=!1;const oe=window.requestAnimationFrame(()=>{E.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(oe)}},[l,h,g]);const Me=d.useCallback(()=>{if(ye){if(Dr(window.history.state)?.page===g&&!W.isVSCode){window.history.back();return}j("page-sidebar");return}j("nav")},[ye,W.isVSCode,g]);d.useEffect(()=>{if(o)return o(()=>!l||h==="nav"?!1:(Me(),!0)),()=>o(null)},[Me,l,h,o]),d.useEffect(()=>{if(!l||W.isVSCode)return;const oe=le=>{if(Ua(g)?.kind!=="split")return;if(Dr(le.state)?.page===g){j("page-content");return}j(De=>De==="page-content"?"page-sidebar":De)};return window.addEventListener("popstate",oe),()=>{window.removeEventListener("popstate",oe)}},[l,W.isVSCode,g]);const Se=()=>{const oe=S.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(J,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:S,onChange:le=>b(le.target.value),onKeyDown:Ie,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"}),oe&&s.jsx("button",{type:"button",onClick:()=>b(""),"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(J,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(js,{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:oe?Q.length>0?(()=>{let le=0;return ge.map(xe=>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:xe.pageTitle}),xe.results.map(De=>{const Ve=le;le+=1;const Be=Ve===I,Ne=!!De.description;return s.jsxs("button",{type:"button",ref:Je=>{R.current[Ve]=Je},onMouseMove:()=>{T.current=!1,y(Ve)},onClick:()=>fe(De),className:je("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Ne?"min-h-11 py-1.5":"py-2",Be?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:De.title}),Ne&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:De.description})]},De.id)})]},xe.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const le=new Map;for(const De of $){const Ve=De.group,Be=le.get(Ve);Be?Be.push(De):le.set(Ve,[De])}return s2.map(De=>({group:De,pages:le.get(De)??[]})).filter(De=>De.pages.length>0).map(({group:De,pages:Ve},Be)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:je("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Be===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${De}`)}),Ve.map(Ne=>{const Je=g===Ne.slug&&!(l&&h==="nav"),ut=Ug(Ne.slug);return!ut&&Ne.slug!=="mcp"?null:s.jsx(_d,{children:s.jsx(Bd,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>_(Ne.slug),"aria-current":Je?"page":void 0,className:je("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",Je?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ne.slug==="mcp"?s.jsx(Hp,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(J,{name:ut,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:Y(Ne.slug)}),Ne.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")})]})]})})},Ne.slug)})]},De))})()})})]})},Le=()=>{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(Vn,{children:Se()})})});if(!V)return s.jsx("div",{className:"flex-1 bg-background"});if(h==="page-sidebar"){if(V.kind!=="split"){const le=ae(g);return s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:le})})}return s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ie(g,{onItemSelect:de})})})}const oe=ae(g);return s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:oe})})},Ke=()=>!V||g==="home"?null:V.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:je("border-r",W.isVSCode?"bg-background":"bg-sidebar"),style:{width:yd,minWidth:yd,borderColor:"var(--interactive-border)"},children:s.jsx(Vn,{children:ie(g,{})})}),s.jsx(js,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ae(g)})})]}):s.jsx(js,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Vn,{children:ae(g)})});return s.jsxs("div",{ref:E,"data-settings-view":"true",className:je("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[l?s.jsxs("div",{className:je("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:[re?s.jsx("button",{type:"button",onClick:Me,"aria-label":Ee,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(J,{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"):V?Y(V.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(J,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[re&&s.jsx("div",{className:je("absolute left-3 z-50",n?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Me,"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(J,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:je("absolute right-0.5 z-50",n?"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(J,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:l?Le():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:je("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",P?"bg-sidebar":W.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Vn,{children:Se()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Ke()})]})})]})};export{su as A,y2 as S};